local wk = require("which-key") local fluidsynth_job = nil -- setup interactive midi player wk.add({ { mode = "n", "p", desc = "Lilypond: output" }, { mode = "n", "pm", function() local midi = vim.fn.expand("%:r") .. ".midi" if fluidsynth_job then vim.fn.jobstop(fluidsynth_job) fluidsynth_job = nil print("fluidsynth stopped") return end fluidsynth_job = vim.fn.jobstart({ "fluidsynth", "-i", midi }) print("fluidsynth playing (Ctrl-C to stop)") end, desc = "Lilypond: output MIDI", buffer = true, }, { mode = "n", "pp", "Viewer", desc = "Lilypond: open PDF", buffer = true, }, { mode = "n", "", function() if fluidsynth_job then vim.fn.jobstop(fluidsynth_job) fluidsynth_job = nil print("fluidsynth stopped") else vim.cmd("normal! ") end end, desc = "Stop MIDI playback", buffer = true, }, }) -- autostart if vim.b.first_start_lilypond then return end vim.b.first_start_lilypond = true vim.schedule(function() if vim.fn.exists(":Viewer") == 2 then vim.cmd.Viewer() end end)