Index
MidiInput
MyParser
CSV_Scanner
CSV_Parser
This functor defines MIDI import for Strasheela. Similar to the MIDI output functor, this functor relies on midicsv (see http://www.fourmilab.ch/webtools/midicsv/). A MIDI file is transformed into a midicsv text file with the procedure RenderCSVFile. This text file is read into a list of Oz values (MIDI events) with the function ParseCSVFile. The format of this event list is exactly the same as the format supported and documented by the MIDI output functor.

You may use this list of MIDI events directly. Alternatively, it can be transformed into a Strasheela score using the functions EventsToNestedEvents and NestedEventsToScore. Examples for both approaches are provided in the test file (../testing/MidiInput-test.oz).

This functor is provided as a contribution (i.e. not as part of the Strasheela core), because its compilation requires a C++ compiler, which is not necessarily available on all systems (especially not on Windows).

Functor

Import

Export

Define

fun{PairNoteEvents Events}
Expects a list of CSV Events. All note-on events and their corresponding note-off events are grouped into matching pairs NoteOn#NoteOff. All other events are passed unaltered.
PairNoteEvents finds for every note-on event the first following note-off event with the same pitch and channel. Note that in case there is no corresponding note-off event, the returned note pair is NoteOn#nil.


fun{EventsToNestedEvents Events}
Expects a list of CSV events and returns a nested record. The top-level record (label tracks) sorts the events by their track number. The features of this record are the different track numbers, and their values are a list of records which (nested) contain only events of that track number. These records and the second nesting level (label channels) sort events by channel numbers. The features of the record are the different channel numbers and their values are lists of events of that channel. Events without channel number are placed at the record feature nil. Finally, note events are grouped into pairs NoteOn#NoteOff.


fun{NestedEventsToScore NestedEvents Args}
Expects a nested CSV event list as returned by EventsToNestedEvents, and returns a textual Strasheela score. The optional arg clauses (in Args) expects a list of Test#Process pairs, where Test is a boolean function and Process is a transformation function. Test expects an element in the hierarchy of the result of EventsToNestedEvents, and if it returns true then Process expects this element as argument and returns a transformation (a textual Strasheela score object). If it returns nil, then the next clause is tried. When process returns nil, then its output is omitted from the result. Note that the score transformation happens from the inside to the outside, i.e., when a container datum is transformed its elements are transformed already.
The default clauses (see source) result in a hierarchic score whose elements are the MIDI notes (i.e., all other MIDI events are skipped by default). Support for additional MIDI events is added simply by adding further Test#Process clauses. The score topology follows the hierarchic nesting returned by EventsToNestedEvents (see below). Whether the channel container is a simultaneous container or a sequential container depends on whether the notes in the container overlap in time (in that case a sim is created, a seq otherwise).

sim(info:score
items:[sim(info:track
items:[seq(info:channel
items:[Note1 Note2 ..])
...])
...])





End