martineausimon / nvim-lilypond-suite

Neovim plugin for writing LilyPond scores, with asynchronous make, midi/mp3 player, fast syntax highlighting, "hyphenation" function, and support for LaTex and Texinfo files
GNU General Public License v3.0
130 stars 11 forks source link

FluidSynth: Path to Soundfont for SF3 #29

Closed KaiVinter closed 11 months ago

KaiVinter commented 12 months ago

Hello! This is something between a bug and a feature request, but I'll bring it out in case there's a way to solve it. I was wondering if there was a way to add a custom path when invoking fluidsynth. I've seen that when doing:

fluidsynth $PATH_TO_SOUNDFONT

FluidSynth starts with that soundfont loaded.

My issue is that setting a default.sf2 symlink only limits the usage to SF2 files, when fluidsynth can also work with SF3 files. And setting the symlink from an SF3 file to default.sf2 gives an error (for obvious reasons). And also setting a symlink to default.sf3 doesn't load anything at all because if nothing is specified when invoking fluidsynth, it expects a default.sf2.

In case this is relevant. I've tried in both MacOS Monterrey (Intel) and Ventura (M1).

martineausimon commented 12 months ago

Hello,

Thanks for your message,

It's indeed a good idea and can also simplify the configuration of FluidSynth for nvim-lilypond-suite. I've just added this option :

require('nvls').setup({
  player = {
  options = {
    midi_synth = "fluidsynth",
    soundfont_path = "/usr/share/soundfonts/FluidR3_GM.sf2", --(default is nil)
    }
  }
})

Please let me know if this works for you.

I would like to be able to use this option with timidity, but for the moment I don't know how to do it...

KaiVinter commented 12 months ago

Hello!

Today I tried it and it does work. Thank you so much!

At first it didn't, but it was an error on my end, because I was doing:

\score {
  <<
    \new PianoStaff <<
      \set PianoStaff.instrumentName = "Piano"
      \set PianoStaff.shortInstrumentName = "Pno."
      \set PianoStaff.midiInstrument = "Grand Piano" % <-- THIS
      \new Staff = "1" <<
        \mergeDifferentlyDottedOn \mergeDifferentlyHeadedOn
        \new Voice = "Piano-RH-One" {  \voiceOne \Piano-RH-One }
        \new Voice = "Piano-RH-Two" {  \voiceTwo \Piano-RH-Two }
      >> 
      \new Staff = "2" <<
        \mergeDifferentlyDottedOn \mergeDifferentlyHeadedOn
        \new Voice = "Piano-LH-One" {  \voiceOne \Piano-LH-One }
        \new Voice = "Piano-LH-Two" {  \voiceTwo \Piano-LH-Two }
      >>
    >>
  >>
    \layout {}
    \midi {\tempo 4 = 84 }
}

instead of:

\score {
  <<
    \new PianoStaff <<
      \set PianoStaff.instrumentName = "Piano"
      \set PianoStaff.shortInstrumentName = "Pno."
      \new Staff = "1" <<
        \set Staff.midiInstrument = "Grand Piano" % <-- THIS
        \mergeDifferentlyDottedOn \mergeDifferentlyHeadedOn
        \new Voice = "Piano-RH-One" {  \voiceOne \Piano-RH-One }
        \new Voice = "Piano-RH-Two" {  \voiceTwo \Piano-RH-Two }
      >> 
      \new Staff = "2" <<
        \set Staff.midiInstrument = "Grand Piano" % <-- THIS
        \mergeDifferentlyDottedOn \mergeDifferentlyHeadedOn
        \new Voice = "Piano-LH-One" {  \voiceOne \Piano-LH-One }
        \new Voice = "Piano-LH-Two" {  \voiceTwo \Piano-LH-Two }
      >>
    >>
  >>
    \layout {}
    \midi {\tempo 4 = 84 }
}

So it looks like PianoStaff can't send MIDI data from both staves at once. So I just did the second one.

About timidity, I found this page that shows how to use multiple soundfonts in timidity, so it's probably better to configure them that way instead of in here, but I've never used timidity, so I'm not sure what's best in that case.

Anyways, thatnk you for your fix! ✨

KaiVinter commented 12 months ago

Adding to my previous comment, I found that you can also have a config file for FluidSynth in case you want to specify different soundfonts and more things, so it's probably a good idea to have an option in nvim-lilypond-suite to add custom flags for both fluidsynth and timidity at start. That way you just set a flag to add your config file and the synth does the rest. This is where I found about the config file for FluidSynth: https://github-wiki-see.page/m/FluidSynth/fluidsynth/wiki/UserManual

Probably a good approach would be something like in #7

martineausimon commented 11 months ago

Thank you for the feedback!

I am currently adding the fluidsynth_flags and timidity_flags options. I wonder if soundfont_path will still be useful, as these two settings will be equivalent :

require('nvls').setup({
  player = {
    options = {
      midi_synth = "fluidsynth",
      fluidsynth_flags = {
        "-g", "2"
      },
      soundfont_path = "/usr/share/soundfonts/FluidR3_GM.sf2",
    }
  }
})
require('nvls').setup({
  player = {
    options = {
      midi_synth = "fluidsynth",
      fluidsynth_flags = {
        "/usr/share/soundfonts/FluidR3_GM.sf2",
        "-g", "2"
      },
    }
  }
})

Removing the soundfont_path option can also prevent confusion if the MIDI synth used is Timidity (it seems that there is no such option in the command line).

What do you think ?

KaiVinter commented 11 months ago

Sounds good to me, although something tells me soundfont_path might be easier to understand. 😅 What I would probably do is to stay with fluidsynth_flags and timidity_flags and specify in the configuration page what you can do with those options, at least some of the most important things like adding soundfonts and config files, and probably a link to a manual page for both synths in case someone wants do something more elaborated.

martineausimon commented 11 months ago

OK, thank you ! I will do that and update the wiki.

martineausimon commented 11 months ago

https://github.com/martineausimon/nvim-lilypond-suite/commit/b4192e0323bafe3a53109360424354afb741a30b