diff options
Diffstat (limited to 'client/lib/midi.js')
| -rw-r--r-- | client/lib/midi.js | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/client/lib/midi.js b/client/lib/midi.js index f4b479b..3b07cb0 100644 --- a/client/lib/midi.js +++ b/client/lib/midi.js @@ -1,8 +1,9 @@ import Tone from 'tone' import WebMidi from 'webmidi' import scales from './scales' -import { ftom, norm } from './util' +import { ftom, norm, dataURItoBlob } from './util' import kalimba from './kalimba' +import { saveAs } from 'file-saver/FileSaver' import { nx } from './ui' @@ -139,22 +140,27 @@ 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) { - const behavior = document.querySelector('#behavior').value + // const behavior = document.querySelector('#behavior').value const { rows } = bounds - let count = behavior === 'sequence' ? rows[0].length * rows.length : rows.length - let notes + // let count = behavior === 'sequence' ? rows[0].length * rows.length : rows.length + let count = rows[0].length + let notes, timings, wait let note_time - let timing = note_values[timingIndex][2] + // let timing = note_values[timingIndex][2] let midi_track = new MidiWriter.Track() midi_track.setTempo(tempo) for (let i = 0, len = count; i < len; i++) { - notes = play_fn(i, bounds, note_time, "all", true)[1] - if (timing.length) { - note_time = timing[i % timing.length] - } else { - note_time = timing + [i, notes, timings, wait] = play_fn(i, bounds, 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) + for (let j = 0; j < notes.length; j++) { + midi_track.addEvent(new MidiWriter.NoteEvent({ pitch: notes[j], duration: 't' + timings[j], wait })) } - midi_track.addEvent(new MidiWriter.NoteEvent({ pitch: notes, duration: 't' + note_time })) } const writer = new MidiWriter.Writer([midi_track]) const blob = dataURItoBlob(writer.dataUri()) |
