grimmdude / MidiWriterJS

♬ A JavaScript library which provides an API for programmatically generating and creating expressive multi-track MIDI files and JSON.
MIT License
557 stars 60 forks source link

Key Signature support #14

Closed lplume closed 8 years ago

lplume commented 8 years ago

Hello Garrett,

this morning I felt brillant. The key signature could be expressed as:

// pair of sharps/flat and mode
setKeySignature(-1, 0); // 1b major: Bb
setKeySignature(0, 0); // flat C
setKeySignature(1, 0); // 1# major: G
// same apply to minors
setKeySignature(sf, 1); // Am

// passing the tonality string
setKeySignature('c')

// accept also weirdo strings
setKeySignature('cm')
setKeySignature('c-')
setKeySignature('Cm')
setKeySignature('C-')

// alteration will be preserved of course

The last char indicates and forces the mode:

if the last char is not one of the above, the mode is indicated in the first char:

grimmdude commented 8 years ago

Hey,

Sorry for the late reply. Looks great man, thanks for putting in the work. I've tested this with the Chopin example and it works well. While I don't really see a need to support the low level MIDI number parameters (setKeySignature(-1, 0);) it doesn't hurt to have. Nice job,

-Garrett

lplume commented 8 years ago

Our latest journey through indian music teach me that :p I am considering to suggest you to give in the API a really low level way to define MIDI events in order to overcome any more or less singular request :D

Anyway I am very glad you like my work :)

-Mauro