NeoVim Event Highlighting + custom keybindings

Just in case someone is curious about that kind of stuff. I extended the NeoVim lua plugin from grddavies and made some adjustments:

  1. I added the TidalCycles Event Highlighting (!),
  2. I made it more efficient, so that the plugin can handle bigger files and evaluations fast (nearly immediately)
  3. The Notification window can be removed and added again.,

GitHub Link: https://github.com/thgrund/tidal.nvim

I did this, because I wanted to play around with some makros and keybindings. This is really promising and makes a lot of fun. My motiviation is, to shape a pattern with makros way more efficient, to produce more versatile patterns during a live coding performance.
GitHub Link: https://github.com/thgrund/tidal-makros.nvim

And I created a YouTube Video, where I tried to explain how to setup everything. And of course I did a showcase of the makros and keybindings as well. Feel free to have a look, if you like:
https://www.youtube.com/watch?v=DVYm-c1AV-8

11 Likes

Incredible. Trying this out now but running into some problems. Install seems to require some extra stuff (losc, luasocket?). Do you have something configured for that in your nvim config?

edit: this extra dependency seems to remedy it for me

		{
			"davidgranstrom/losc",
			lazy = false,
			init = function()
				local root = vim.fn.stdpath("data") .. "/lazy/losc/src"
				package.path = package.path .. ";" .. root .. "/?.lua;" .. root .. "/?/init.lua"
			end,
		},

1 Like

Stupid me, I needed to make some adjustments in the losc plugin to make everything work. But I still referenced the original plugin from davidgranstrom in a file. Could you please try it out again without this extra dependency? This should not be needed anymore and I removed it from my local environment as well :slight_smile:

And you are very welcome to provide some more feedback!

1 Like

Works! There’s some more I’m having trouble with right now on trying this out. Some stuff might be setup specific (I’m fairly new to tidal, not new to nvim).

  1. setting sclang to true causes a crash
    I’m guessing this is because Repl:start(..) does not return a self instance when proc:is_active() is true, which then causes state.sclang to be nil in M.sclang(..), which causes a panic.
    I haven’t changed anything from my previous setup, and was using tidal.nvim succesfully, so this is new behaviour. I’m starting both tidal and superdirt with TidalLaunch, I’m guessing that’s different for you.

  2. I’m currently starting SuperDirt at port 57120. Noticed you have some extra ports (6013, 3335). Wondering if those are related somehow. If I set sclang.enabled = false, and then start sclang myself, I am able to start tidal with TidalLaunch, and produce sounds, but no highlights. Wondering if there’s anything else I need to make that happen?

There may be a chance, that I broke the SuperCollider Repl:Start command. But I will definitely have a look asap. I usually open SuperCollider within the respective IDE.

Regarding the event highlighting, you need to respect two points to make it workin:

  1. You need to create a target for the editor highlight in your BootTidal.hs. The default one in the plugin contains an example: tidal.nvim/bootfiles/BootTidal.hs at develop · thgrund/tidal.nvim · GitHub - this is the structure for TidalCycles 1.10 - but I know that the target definition looks similar in older versions (1.9.x)
  2. You need to launch TidalCycles and then execute :TidalStartEventHighlighting

The port 6013 is the port for receiving event highlighting messages. At least this is definied in the target, that I shared above. I must confess, that port 3335 is used for a not yet documented feature. But this is the next feature that I will shape and publish. With this you can change the color of the event highlighting. The idea is, that you have a global style, one style to overwrite it for a specific stream, and then a style for each stream that you can change via a remote source.

Ok, I did get it to work! I was on a very old version of tidal (1.9.something) from the aur. The sclang boot still fails though.

Hey @mrreason this is awesome ! I have a small issue tho, the CodeHighlight highlight doesn’t seems to get registered on init. If i run :lua vim.api.nvim_set_hl(0, "CodeHighlight", { bg = "#7eaefc", foreground = "#000000" }) manually it works fine.

Ooh it is because I am using the auto-dark-mode plugin ! But investigating this I found that setting the colorscheme with :coloscheme <sometheme> from inside the tidal session loose the highlights for some reason.

I literally started with this about 10 days ago because I am a neovim user and loved your work with pulsar, so thank you, it’s been a lot of work but I just wanted highlighting in neovim. I didn’t actually fork the plugin, but did chose the same plugin for expanding upon so I was on the right track

1 Like

So, I am fairly sure I have it set up according to documentation, BootTidal.hs looks good, When I use :TidalLaunch it even says [tidal-fast] ghci started (pipe mode): ghci —- :TidalStartEventHighlighting passes fine, but no REPL as in the original grddavies/tidal.nvim and upon evaluating a phrase

I am not running Lazy.nvim I am running AstroNVIM, and that could be the issue. Would love to hear your feedback as I am very much exited about neovim use of TidalCycles highlighting.

So, it turns out it is Tidal 1.9.5 that is the issue. Arch hasn’t placed 1.1 in the repo yet, so sadly I have to wait.

Hey @bmstr , @b0id and @vlachaizle ! :slight_smile: Thanks for the feedback and the interest :slight_smile:
I will answer and solve all the topics. I do it as soon as possible, but I don’t know whether it will take a day or a week. But we will be able to manage that. Here is the overview of what I will do (before I answer some of you directly):

  1. Fix the sclang boot (I know the root cause).
  2. Extend the styling possibilites (for each stream ID, and passing the name for the global style to avoid naming conflicts) - this I already planned, but I wasn’t aware of the naming conflict.
  3. Extend the documentation (Styling, Backward compatibility)
  4. Test whether all functions mentioned in the documentation works like expected, or fix it

@bmstr just a quick question here for you: would you mind to extract the Supercollider repl to a complete separate plugin? My gut feeling is, that this should be separated to keep the plugin small and easier maintainable (especially because of Lua). WDYT? What is the reason for you to have directly inside of the TC plugin? I just had a quick look, but this really looks promising: GitHub - davidgranstrom/scnvim: Neovim frontend for SuperCollider. :slight_smile:

Best regards
MrReason

1 Like

TL;DR I should be able to figure out how to make it work. I don’t see a real blocker to use it with 1.9.x - I think you just need to change your BootTidal (and maybe adjust some parameters).

TidalCycles had a lot of changes in 1.10.x and I realized that the scheduler behaves differently compared to previous versions. But it still should work out of the box. The only point is, that I am not sure, whether the Live mode works exactly the same. I just upgraded the default BootTidal within the project, because in the Pulsar project that improved the event receiving reliability - but there I used the pre bundled timestamps to somehow manage the unreliable javascript clock. In NeoVim this isn’t needed at all and there I let TidalCycles take care completely about the scheduling of the event highlighting. This reduces the osc message payload btw.

Anyway, to give you a recommendation, I need to have a look.

My working hypothesis is, that you need to add something like this in your BootTidal.hs:

let editorTarget = Target {oName = "editor", oAddress = "127.0.0.1", oPort = 6013, oLatency = 0, oSchedule = Live, oWindow = Nothing, oHandshake = False, oBusPort = Nothing }
let editorShape = OSCContext "/editor/highlights"
tidal <- startStream (defaultConfig {cFrameTimespan = 1/40, cProcessAhead = (1/20)}) [(superdirtTarget {oLatency = 0.02}, [superdirtShape]), (editorTarget, [editorShape])]

It could be, that you need to adjust the oLatency value. But in any case you need to use the old BootTidal version and add it into your plugin configuration. Hopefully this helps to get started.

I must confess, that I was just curious, how my event highlighting algorithm will work within NeoVim and I wanted to use NeoVim since quite a while.

The foundation of grddavies plugin is awesome! It wasn’t planned to replace it. Actually I wanted to create a separate plugin, like you did. But I wanted to keep it as simple as possible and only exchange events between the editor and TidalCycles. Unfortunately you need to wrap the deltaContext function around every string that contains the mini notation. This is why I needed to hijack the TidalCycles plugin anyway. And then I made some optimizations that introduces a lot of bigger changes (like piping the repl directly to stdin, instead of using a separate buffer; make the notifcation toggleable, add syntax higlight to the notifcation, add the event highlighting). This summed up, changed the plugin that it covers all my needs now.

And I didn’t expected that much interest in that topic. But I am glad that it turned out like this :slight_smile:
Maybe I was sloppy with some features that I didn’t use yet…But the origin story was: I just want to replicate my setup - and this I did as fast as possible.

Anyway, your lightweight osc implementation looks charming. I just used losc, pasted it in the project and adjusted the parts that killed the main thread. Is there anything I need to know? Or could I just use it? :slight_smile:

Did you had the plan to create strudel like animations with your implementation? How should this looks like? Right now you can not look into “the future”™ - I would really like to know your thoughts about that.

I ended up installing through cabal. Works fine. To be clear:

  1. ghcup through aur
  2. cabal through ghcup
  3. tidal through cabal

My working hypothesis is, that you need to add something like this in your BootTidal.hs:

That’s exactly it. That api has changed from 1.9 to 1.10

I’m now starting it somewhere else entirely. Totally fine. For beginners it’s a lot of components to keep track of. It’s kinda nice to just have one command that starts everything up. But it’s also annoying having all those terminals polluting your nvim windows.

1 Like

Valid points @bmstr! Thanks for mentioning that. I fixed the SuperCollider repl issues and as a bonus point, I added an optional property to automatically start the event highlighting with a property in the configuration file. I introduced a separate ex command for displaying the SuperCollider stdout and stderr changes with :SuperColliderNotification. If you don’t mind I would like you to try it out :slight_smile:

This means, now you can start everything with one single command! And it’s quite charming, that everything get shut down, when I close the editor.

Hey @vlachaizle I added a bunch of extensions to make the styles of the event highlights more customizable. You can change the baseName (for avoiding naming conflicts) and change the styles in many different ways (global, stream individual, via osc). A more detailed explanation can be found here: GitHub - thgrund/tidal.nvim: Neovim Plugin for livecoding with TidalCycles

I just wont use cabal, I don’t have the energy to manage another environment and I nuked my haskell installation the last time, I can’t afford downtime.

Yes, that’s essentially what I was going for, was a strudel like parsing system. It has some development to be done before it is a quality abstract syntax tree though. As you know everything is a work in progress. Currently working on more modular based synthesis, but as soon as I can get highlights in Neovim, I will start using it more. You have to understand how much time I have spent learning vim as a whole. I will never learn another text editor again. I am vim until I die. Also vim is like Stockholm Syndrome.