From 9e824cc6d358fc902b27e00e5a1e8f88e3610823 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 8 Oct 2018 01:05:13 +0200 Subject: group and midi stuff --- client/index.js | 85 ++++++++------------------------------------------------- 1 file changed, 12 insertions(+), 73 deletions(-) (limited to 'client/index.js') diff --git a/client/index.js b/client/index.js index 65b15d3..74c9252 100644 --- a/client/index.js +++ b/client/index.js @@ -9,8 +9,10 @@ import { play_note, play_sequence, play_interval_sequence, + export_pattern_as_midi, note_values, MidiWriter, + transpose, } from './lib/midi' import { requestAudioContext, ftom, norm, dataURItoBlob, @@ -19,18 +21,16 @@ import { import { update_value_on_change, update_radio_value_on_change, - build_options + build_options, + nx } from './lib/ui' import * as data from './data' const DEFAULT_BPM = 60 -const nx = window.nx = {} - let recorder = null let recording = false -let sendPitchBend = false midi_init() @@ -39,81 +39,20 @@ midi_init() let i = 0, datasets = {}, dataset = {}, bounds = {}, diff = [] let play_fn = play_sequence data.load().then(lists => { - console.log(lists) - datasets = lists.map(list => { - list.shift() - switch(list.name) { - case 'gun_violence': - return gun_violence_melody(list) - case 'mass_shootings': - return { - ...list, - lines: list.lines.map(line => { - // 0 case name - // 1 location - // 2 date - // 3 summary - // 4 fatalities - // 5 injured - // 6 total_victims - // 7 location - // 8 age_of_shooter - // 9 prior_signs_mental_health_issues - // 10 mental_health_details - // 11 weapons_obtained_legally - // 12 where_obtained - // 13 weapon_type - // 14 weapon_details - // 15 race - // 16 gender - // 17 sources - // 18 mental_health_sources - // 19 sources_additional_age - // 20 latitude - // 21 longitude - // 22 type (Spree / Mass) - // 23 year - }) - } - break - } - }) - pick_dataset('mass shootings') - requestAudioContext(ready) + // pick_dataset('mass shootings') + // requestAudioContext(ready) + console.log(lists) + transpose(lists.gun_violence_by_month.lines) }) -function gun_violence_melody(list){ - let melody = [] - let lookup = {} - let last = Date.now() - let last_y = 2018 - let last_m = 3 - list.lines.forEach(line => { - let [ - incident_id, date, state, city_or_county, address, n_killed, n_injured, - incident_url, source_url, incident_url_fields_missing, congressional_district, - gun_stolen, gun_type, incident_characteristics, latitude, location_description, longitude, - n_guns_involved, notes, - participant_age, participant_age_group, participant_gender, - participant_name, participant_relationship, participant_status, - participant_type, - sources, - state_house_district, state_senate_district - ] = line - let [ y, m, d ] = date.split('-') - }) - return { - ...list, - lines: melody, - } -} +// /* play next note according to sonification */ function play_next(){ let note_time = 120000 / Tone.Transport.bpm.value * note_values[nx.timing.active][0] * nx.duration.value setTimeout(play_next, note_time) - let [new_i, notes] = play_fn(i, bounds, note_time) + let [new_i, notes] = play_fn(i, bounds, diff, note_time) i = new_i if (recording) { let timing = note_values[nx.timing.active][2] @@ -141,7 +80,7 @@ function pick_behavior(name){ /* build and bind the UI */ -function ready () { +function ready() { scales.build_options(document.querySelector('#scale')) build_options(document.querySelector('#dataset'), datasets, pick_dataset) build_options(document.querySelector('#behavior'), behaviors, pick_behavior) @@ -205,7 +144,7 @@ function ready () { const export_midi_button = document.querySelector('#export_midi') export_midi_button.addEventListener('click', () => { - export_pattern_as_midi(dataset.name, bounds, nx.tempo.value, nx.timing.active, play_fn) + export_pattern_as_midi(dataset.name, bounds, diff, nx.tempo.value, nx.timing.active, play_fn) }) const record_midi_button = document.querySelector('#record_midi') -- cgit v1.2.3-70-g09d2