n-armstrong / fosc

A SuperCollider API for generating musical notation in LilyPond.
GNU General Public License v3.0
43 stars 7 forks source link

Feature request: Implement midi #6

Open madskjeldgaard opened 12 months ago

madskjeldgaard commented 12 months ago

Hi

It would be awesome if Fosc could convert the ly files to midi. An easy way of doing this initially would be to add a midi {} section to the output lilypond file, and then let lilypond create it on compile.

Thanks <3

n-armstrong commented 11 months ago

You can play midi from any Fosc component or selection by accessing its pattern.

a = FoscMusicMaker().(durations: [1/16], pitches: (60..72)); m = MIDIOut(0); p = Pbindf(a.pattern, \type, 'midi', \midiout, m, \midicmd, 'noteOn'); p.play;

You can also access the eventList of any Fosc component or selection, which could then be used with MIDIFile libraries (e.g. SimpleMidiFile: http://quark.sccode.org/wslib/wslib-help/wslib.html).

a = FoscMusicMaker().(durations: [1/16], pitches: (60..72)); a.eventList.printAll;

n-armstrong commented 11 months ago

Generating a midi file using lilypond is a bit more clunky, but it's possible. You'd need to add a 'midi' block to the FoscLilyPondFile, and then add some dummy content to the 'midi' block (empty blocks don't get written to the file).

a = FoscMusicMaker().(durations: [1/16], pitches: (60..72)); b = FoscStaff([a]); f = FoscLilyPondFile(b); c = FoscBlock('midi'); c.items.add(FoscLilyPondLiteral("")); f.scoreBlock.items.add(c); p = "~/test.ly".standardizePath; f.writeLY(p); FoscIOManager.runLilypond(p);