diff options
Diffstat (limited to 'client')
| -rw-r--r-- | client/index.js | 13 | ||||
| -rw-r--r-- | client/lib/midi.js | 28 |
2 files changed, 25 insertions, 16 deletions
diff --git a/client/index.js b/client/index.js index 4740db0..527fb64 100644 --- a/client/index.js +++ b/client/index.js @@ -1,6 +1,5 @@ import Tone from 'tone' import Nexus from 'nexusui' -import { saveAs } from 'file-saver/FileSaver' import keys from './lib/keys' import scales from './lib/scales' @@ -102,7 +101,7 @@ function play_mass_shootings(i, bounds, diff, note_time, channel="all", exportin const x = i % rows[0].length const n = rows[y][x] const total = dataset.dates.length - let notes = [], midi_notes = [], cases = [] + let notes = [], midi_notes = [], cases = [], timings console.log(i, mass_i, dataset.dates[mass_i]) while (i >= dataset.dates[mass_i] && mass_i < total) { notes.push(dataset.lines[0][mass_i]) @@ -118,21 +117,25 @@ function play_mass_shootings(i, bounds, diff, note_time, channel="all", exportin break case 1: midi_notes.push(play_note( norm(notes[0], min, max) * nx.multiply.value, 128, channel, exporting, mass_rest, 0)) + timings = [128] break case 2: midi_notes.push(play_note( norm(notes[0], min, max) * nx.multiply.value, 64, channel, exporting, mass_rest, 0)) midi_notes.push(play_note( norm(notes[1], min, max) * nx.multiply.value, 64, channel, exporting, 0, 64)) + timings = [64, 64] break case 3: midi_notes.push(play_note( norm(notes[0], min, max) * nx.multiply.value, 43, channel, exporting, mass_rest)) midi_notes.push(play_note( norm(notes[1], min, max) * nx.multiply.value, 43, channel, exporting, 0, 43)) midi_notes.push(play_note( norm(notes[2], min, max) * nx.multiply.value, 42, channel, exporting, 0, 85)) + timings = [43, 43 ,42] break case 4: midi_notes.push(play_note( norm(notes[0], min, max) * nx.multiply.value, 32, channel, exporting, mass_rest)) midi_notes.push(play_note( norm(notes[1], min, max) * nx.multiply.value, 32, channel, exporting, 0, 32)) midi_notes.push(play_note( norm(notes[2], min, max) * nx.multiply.value, 32, channel, exporting, 0, 64)) midi_notes.push(play_note( norm(notes[3], min, max) * nx.multiply.value, 32, channel, exporting, 0, 96)) + timings = [32, 32, 32, 32] break } if (cases.length) { @@ -148,10 +151,10 @@ function play_mass_shootings(i, bounds, diff, note_time, channel="all", exportin kalimba.play(220, -12) if (notes.length) { mass_rest = 0 - return [i, midi_notes] + return [i, midi_notes, timings, mass_rest] } mass_rest += 128 - return [i, []] + return [i, [], [], 0] } /* play next note according to sonification */ @@ -159,7 +162,7 @@ function play_mass_shootings(i, bounds, diff, note_time, channel="all", exportin function play_next(){ let note_time = 120000 / Tone.Transport.bpm.value * note_values[nx.timing.active][0] setTimeout(play_next, note_time) - let [new_i, notes] = play_fn(i, bounds, diff, note_time) + let [new_i, notes, timings] = play_fn(i, bounds, diff, note_time) i = new_i if (recording) { let timing = note_values[nx.timing.active][2] 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()) |
