diff options
Diffstat (limited to 'client/lib/midi.js')
| -rw-r--r-- | client/lib/midi.js | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/client/lib/midi.js b/client/lib/midi.js index d51aeff..449abc0 100644 --- a/client/lib/midi.js +++ b/client/lib/midi.js @@ -142,31 +142,34 @@ export function play_interval_sequence(i, bounds, diff, note_time, channel="all" /* generate a 1-track midi file by calling the play function repeatedly */ -export function export_pattern_as_midi(datasetName, bounds, diff, tempo, timingIndex, play_fn) { +export function export_pattern_as_midi(datasetName, bounds, diff, tempo, timingIndex, play_fn, max_i) { // const behavior = document.querySelector('#behavior').value const { rows } = bounds // let count = behavior === 'sequence' ? rows[0].length * rows.length : rows.length - let count = rows[0].length + max_i = max_i || rows[0].length let notes, timings, wait let note_time // let timing = note_values[timingIndex][2] let midi_track = new MidiWriter.Track() + let next_i midi_track.setTempo(tempo) - for (let i = 0, len = count; i < len; i++) { - [i, notes, timings, wait] = play_fn(i, bounds, note_time, "all", true) + for (let i = 0, len = max_i; i < len; i++) { + [next_i, notes, timings, wait] = play_fn(i, bounds, diff, note_time, "all", true) // if (timing.length) { // note_time = timing[i % timing.length] // } else { // note_time = timing // } // midi_track.addEvent(new MidiWriter.NoteEvent({ pitch: notes, duration: 't' + note_time })) - console.log(i, notes, timings, wait) + // console.log(i, notes, timings, wait) for (let j = 0; j < notes.length; j++) { + console.log(i, j, notes[j], timings[j], wait) midi_track.addEvent(new MidiWriter.NoteEvent({ pitch: notes[j], duration: 't' + timings[j], - wait: (j === 0) ? wait : 0, + wait, })) + wait = 0 } } const writer = new MidiWriter.Writer([midi_track]) |
