diff options
Diffstat (limited to 'client/lib')
| -rw-r--r-- | client/lib/midi.js | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/client/lib/midi.js b/client/lib/midi.js index 449abc0..b22f2fe 100644 --- a/client/lib/midi.js +++ b/client/lib/midi.js @@ -55,7 +55,7 @@ export function midi_init() { /* play a single note */ -export function play_note(index, duration, channel="all", exporting=false, rest=0, defer=0){ +export function play_note(index, duration, channel="all", exporting=false, defer=0){ // console.log(index) const scale = scales.current() const freq = scale.index(index + Math.round(nx.offset.value), nx.octave.value) @@ -70,10 +70,10 @@ export function play_note(index, duration, channel="all", exporting=false, rest= if ((midiDevice || exporting) && midi_note > 127) return 0 const note = Tone.Frequency(Math.floor(midi_note), "midi").toNote() const defer_time = 30000 / Tone.Transport.bpm.value * defer / 128 - console.log(defer, defer_time) if (exporting) { return note } + console.log('defer', defer, defer_time) if (midiDevice) { duration = duration || 60000 / Tone.Transport.bpm.value if (! exporting) { @@ -147,32 +147,46 @@ export function export_pattern_as_midi(datasetName, bounds, diff, tempo, timingI const { rows } = bounds // let count = behavior === 'sequence' ? rows[0].length * rows.length : rows.length max_i = max_i || rows[0].length - let notes, timings, wait + let notes, timings let note_time // let timing = note_values[timingIndex][2] + let pedal_note, next_i + let wait = 0 let midi_track = new MidiWriter.Track() - let next_i midi_track.setTempo(tempo) + let pedal_track = new MidiWriter.Track() + pedal_track.setTempo(tempo) for (let i = 0, len = max_i; i < len; i++) { - [next_i, notes, timings, wait] = play_fn(i, bounds, diff, note_time, "all", true) + [next_i, notes, timings, pedal_note] = 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) + if (!notes.length) wait += 128 for (let j = 0; j < notes.length; j++) { - console.log(i, j, notes[j], timings[j], wait) - midi_track.addEvent(new MidiWriter.NoteEvent({ + console.log(i, j, notes[j], timings[j], wait, pedal_note) + let e = { pitch: notes[j], duration: 't' + timings[j], - wait, - })) + velocity: 50, + } + if (wait) { + e.wait = 't' + wait + } + midi_track.addEvent(new MidiWriter.NoteEvent(e)) wait = 0 } + pedal_track.addEvent(new MidiWriter.NoteEvent({ + pitch: pedal_note, + duration: 't128', + velocity: 25, + })) } - const writer = new MidiWriter.Writer([midi_track]) + let tracks = [midi_track, pedal_track] + const writer = new MidiWriter.Writer(tracks) const blob = dataURItoBlob(writer.dataUri()) saveAs(blob, 'Recording - ' + datasetName + '.mid') } |
