Try it out here.
This is another attempt at porting the music notation part of the Haskell School of Music (HSoM) to the browser. It consists of a PSoM library (ported from HSoM) together with an editor that runs in the browser. This allows you to enter melodies using a DSL and then play them.
It follows an abortive attempt in Elm in conjunction with danigb. This failed largely because of the lack of type classes in Elm but also because of the time delays inherent in Elm's port system when requesting that a sound should actually be played.
PSoM uses instruments from Benjamin Gleitzman's soundfont library which are enumerated in purescript-midi. It recognizes all the instruments listed here. The names differ slightly from those originally used by HSoM - the mapping between the two is shown here. MIDI allows up to 10 such instruments to be available for any given melody.
Melodies are presented to the browser using a DSL which has been designed to be as close as possible to the API itself.
The editor has been developed using Halogen and allows you to enter PSoM text and will parse the text after every keystroke. If it is valid, a player will appear, otherwise an error message is shown. On startup, it loads a pre-selected set of instrument soundfonts which you can later change if you prefer. It also allows you to import an ABC file as PSoM and to load or save the PSoM text.
This is now deprecated in favour of share-a-tune which has used this code as a starting point and then added tune URL sharing facilities.
Try it here.
The player is essentially identical to the editor in that, when the ABC is loaded, the tune can be played and the score viewed. Monophonic tunes just play normally. However, if the tune is polyphonic, the user can choose to play the entire polyphonic melody or just one of the parts. The scores for the various parts are displayed separately.
Because the transformation to PSoM is relatively expensive, there is no editor window. It would no longer be possible to update the melody and the score after each keystroke and have reasonable responsiveness.
spago build
npm run test
npm run halogen-editor
and then navigate to halogen-editor/dist/index.html
npm run polyphonic-player
and then navigate to polyphonic-player/dist/index.html
What features would make the DSL pleasant and convenient to use?
What would be a sensible default value for a note volume (currently 100)?
- Allow variable definitions to refer to other variables defined earlier in the same scope
- Add quickcheck style tests to the PSoM library
The following control mechanisms are unimplemented because they also have not been implemented in HSoM:
- Custom
- KeySig
- Ornamentation
- Articulation other than Staccato, Legato and Slurred
There seem to be various problems surrounding volume in MEvent. Perhaps it is because I am using only a MIDI backend which has a maximum volume setting of 7F (127). Firstly, crescendos seem to start at this volume level, although diminuendos are OK. Secondly, the Loudness implementation seems correctly to set the volume in the context but then to ignore it, taking the volume only of the original note.
The various articulations don't seem to work properly. Not sure yet if it's a bug in HSoM or in the translation to PureScript.