summaryrefslogtreecommitdiff
path: root/bundle.js
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2018-10-09 00:30:43 +0200
committerJules Laplace <julescarbon@gmail.com>2018-10-09 00:30:43 +0200
commit8848bc387d62e1667cdfa684f36c058d2619e6b3 (patch)
tree89c790f4bd6aa21fd12d3c943f4d5566a46bab28 /bundle.js
parenta411f4822a0b2fc72308bcd4af1bc3593aabd4ad (diff)
mass shooting sonification
Diffstat (limited to 'bundle.js')
-rw-r--r--bundle.js239
1 files changed, 222 insertions, 17 deletions
diff --git a/bundle.js b/bundle.js
index 9043b0a..2c09ced 100644
--- a/bundle.js
+++ b/bundle.js
@@ -30366,7 +30366,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
var files = [
// "gun_violence",
-"mass_shootings", "gun_violence_by_month"];
+"mass_shootings_lite", "gun_violence_by_month"];
var parse = __webpack_require__(133);
var dataPromises = files.map(function (name) {
@@ -30465,6 +30465,7 @@ Object.defineProperty(exports, "__esModule", {
exports.note_values = exports.MidiWriter = undefined;
exports.midi_init = midi_init;
exports.play_note = play_note;
+exports.play_midi_note = play_midi_note;
exports.play_sequence = play_sequence;
exports.play_interval_sequence = play_interval_sequence;
exports.export_pattern_as_midi = export_pattern_as_midi;
@@ -30529,6 +30530,7 @@ function midi_init() {
function play_note(index, duration) {
var channel = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "all";
var exporting = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
+ var defer = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
// console.log(index)
var scale = _scales2.default.current();
@@ -30546,9 +30548,12 @@ function play_note(index, duration) {
if (exporting || midiDevice) {
duration = duration || 60000 / _tone2.default.Transport.bpm.value;
if (!exporting) {
- midiDevice.playNote(note, channel, { duration: duration });
- if (sendPitchBend) {
- midiDevice.sendPitchBend(cents, channel);
+ if (defer) {
+ setTimeout(function () {
+ play_midi_note(note, cents, channel, duration);
+ }, defer);
+ } else {
+ play_midi_note(note, cents, channel, duration);
}
}
} else {
@@ -30557,6 +30562,13 @@ function play_note(index, duration) {
return note;
}
+function play_midi_note(note, cents, channel, duration) {
+ midiDevice.playNote(note, channel, { duration: duration });
+ if (sendPitchBend) {
+ midiDevice.sendPitchBend(cents, channel);
+ }
+}
+
/* play the next note in sequence */
function play_sequence(i, bounds, diff, note_time) {
@@ -30570,7 +30582,7 @@ function play_sequence(i, bounds, diff, note_time) {
if (i >= count) i = 0;
var y = Math.floor(i / rows[0].length);
var x = i % rows[0].length;
- if (!x) console.log(y);
+ // if (!x) console.log(y)
var n = rows[y][x];
i += 1;
if (i >= count) i = 0;
@@ -40517,6 +40529,10 @@ var _slicedToArray2 = __webpack_require__(73);
var _slicedToArray3 = _interopRequireDefault(_slicedToArray2);
+var _toArray2 = __webpack_require__(154);
+
+var _toArray3 = _interopRequireDefault(_toArray2);
+
var _tone = __webpack_require__(21);
var _tone2 = _interopRequireDefault(_tone);
@@ -40558,7 +40574,13 @@ var recording = false;
/* initialization */
+var mass_fields = ["date", "timestamp", "fatalities", "injured", "total_victims", "age", "case", "weapon_type", "weapon_details"].reduce(function (a, b, i) {
+ a[b] = i;
+ return a;
+}, {});
+
var i = 0,
+ mass_i = 0,
datasets = {},
dataset = {},
bounds = {},
@@ -40575,13 +40597,111 @@ data.load().then(function (lists) {
h: [name],
lines: [row.map(function (n) {
return parseInt(n);
- })]
+ })],
+ play_fn: _midi.play_sequence
};
});
+ datasets["Mass Shootings"] = lists.mass_shootings_lite;
+ datasets["Mass Shootings"].name = "Mass Shootings";
+ datasets["Mass Shootings"].play_fn = play_mass_shootings;
+ var lines = datasets["Mass Shootings"].lines.reverse();
+
+ var _lines$0$mass_fields$ = lines[0][mass_fields.date].split('/'),
+ _lines$0$mass_fields$2 = (0, _toArray3.default)(_lines$0$mass_fields$),
+ min_y = _lines$0$mass_fields$2[0],
+ rest = _lines$0$mass_fields$2.slice(1);
+
+ datasets["Mass Shootings"].dates = lines.map(function (row) {
+ var _row$mass_fields$date = row[mass_fields.date].split('/'),
+ _row$mass_fields$date2 = (0, _slicedToArray3.default)(_row$mass_fields$date, 3),
+ y = _row$mass_fields$date2[0],
+ m = _row$mass_fields$date2[1],
+ d = _row$mass_fields$date2[2];
+
+ return (parseInt(y) - parseInt(min_y)) * 12 + parseInt(m);
+ });
+ datasets["Mass Shootings"].lines = [lines.map(function (row) {
+ return Math.log(row[mass_fields.total_victims]);
+ })];
(0, _util.requestAudioContext)(ready);
});
-//
+/* play function for mass shooting data w/ custom timing */
+
+var mass_rest = 0;
+
+// export const note_values = [
+// [8, '8 measures', 8 * 512],
+// [4, '4 measures', 4 * 512],
+// [2, '2 measures', 2 * 512],
+// [1, 'whole note', 512],
+// [1/2, 'half note', 256],
+// [1/3, 'third note', [170, 170, 171]],
+// [1/4, 'quarter note', 128],
+// [1/5, 'fifth note', [51,51,51,51,52]],
+// [1/6, 'sixth note', [85, 85, 86, 85, 85, 86]],
+// [1/8, 'eighth note', 64],
+// [1/10, 'tenth note', [25,26,26,25,26,25,26,26,25,26]],
+// [1/12, 'twelfth note', [21,21,22, 21,21,22, 21,21,22, 21,21,22]],
+// [1/16, 'sixteenth note', 32],
+// [1/32, 'thirtysecond note', 16],
+// ]
+
+function play_mass_shootings(i, bounds, diff, note_time) {
+ var channel = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : "all";
+ var exporting = arguments[5];
+ var rows = bounds.rows,
+ min = bounds.min,
+ max = bounds.max;
+
+ var y = 0;
+ var x = i % rows[0].length;
+ var n = rows[y][x];
+ var notes = [],
+ midi_notes = [];
+ console.log(i, mass_i, dataset.dates[mass_i]);
+ while (i === dataset.dates[mass_i]) {
+ notes.push(dataset.lines[mass_i]);
+ mass_i += 1;
+ }
+ switch (notes.length) {
+ default:
+ case 0:
+ mass_rest += 1;
+ break;
+ case 1:
+ midi_notes.push((0, _midi.play_note)((0, _util.norm)(n, min, max) * _ui.nx.multiply.value, 128, channel, exporting, mass_rest, 0));
+ break;
+ case 2:
+ midi_notes.push((0, _midi.play_note)((0, _util.norm)(n, min, max) * _ui.nx.multiply.value, 64, channel, exporting, mass_rest, 0));
+ midi_notes.push((0, _midi.play_note)((0, _util.norm)(n, min, max) * _ui.nx.multiply.value, 64, channel, exporting, 0, 64));
+ break;
+ case 3:
+ midi_notes.push((0, _midi.play_note)((0, _util.norm)(n, min, max) * _ui.nx.multiply.value, 43, channel, exporting, mass_rest));
+ midi_notes.push((0, _midi.play_note)((0, _util.norm)(n, min, max) * _ui.nx.multiply.value, 43, channel, exporting, 0, 43));
+ midi_notes.push((0, _midi.play_note)((0, _util.norm)(n, min, max) * _ui.nx.multiply.value, 42, channel, exporting, 0, 85));
+ break;
+ case 4:
+ midi_notes.push((0, _midi.play_note)((0, _util.norm)(n, min, max) * _ui.nx.multiply.value, 32, channel, exporting, mass_rest));
+ midi_notes.push((0, _midi.play_note)((0, _util.norm)(n, min, max) * _ui.nx.multiply.value, 32, channel, exporting, 0, 32));
+ midi_notes.push((0, _midi.play_note)((0, _util.norm)(n, min, max) * _ui.nx.multiply.value, 32, channel, exporting, 0, 64));
+ midi_notes.push((0, _midi.play_note)((0, _util.norm)(n, min, max) * _ui.nx.multiply.value, 32, channel, exporting, 0, 96));
+ break;
+ }
+ if (mass_i > dataset.dates.length - 1) {
+ mass_rest = 0;
+ mass_i = 0;
+ i = 0;
+ } else {
+ i += 1;
+ }
+ if (notes.length) {
+ mass_rest = 0;
+ return [i, midi_notes];
+ }
+ mass_rest += 128;
+ return [i, []];
+}
/* play next note according to sonification */
@@ -40607,16 +40727,12 @@ function play_next() {
function pick_dataset(key) {
console.log('pick dataset:', key, datasets[key]);
i = 0;
+ mass_i = 0;
+ mass_rest = 0;
dataset = datasets[key];
bounds = (0, _util.get_bounds)(dataset);
diff = (0, _util.get_diff_bounds)(bounds.rows);
-}
-var behaviors = {
- sequence: { name: 'Sequence', fn: _midi.play_sequence },
- interval: { name: 'Intervals', fn: _midi.play_interval_sequence }
-};
-function pick_behavior(name) {
- play_fn = behaviors[name].fn;
+ play_fn = dataset.play_fn;
}
/* build and bind the UI */
@@ -40624,9 +40740,7 @@ function pick_behavior(name) {
function ready() {
_scales2.default.build_options(document.querySelector('#scale'));
(0, _ui.build_options)(document.querySelector('#dataset'), datasets, pick_dataset);
- (0, _ui.build_options)(document.querySelector('#behavior'), behaviors, pick_behavior);
- console.log(_nexusui2.default);
var dial_size = [50, 50];
_tone2.default.Transport.bpm.value = DEFAULT_BPM;
@@ -40719,7 +40833,7 @@ function ready() {
document.querySelector('.loading').classList.remove('loading');
document.querySelector('#dataset').value = 'Surrenders';
- pick_dataset('Surrenders');
+ pick_dataset('Mass Shootings');
play_next();
}
@@ -46011,6 +46125,97 @@ module.exports = __webpack_amd_options__;
/* (ignored) */
+/***/ }),
+/* 154 */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+exports.__esModule = true;
+
+var _from = __webpack_require__(155);
+
+var _from2 = _interopRequireDefault(_from);
+
+function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
+
+exports.default = function (arr) {
+ return Array.isArray(arr) ? arr : (0, _from2.default)(arr);
+};
+
+/***/ }),
+/* 155 */
+/***/ (function(module, exports, __webpack_require__) {
+
+module.exports = { "default": __webpack_require__(156), __esModule: true };
+
+/***/ }),
+/* 156 */
+/***/ (function(module, exports, __webpack_require__) {
+
+__webpack_require__(28);
+__webpack_require__(158);
+module.exports = __webpack_require__(1).Array.from;
+
+/***/ }),
+/* 157 */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+var $defineProperty = __webpack_require__(8)
+ , createDesc = __webpack_require__(25);
+
+module.exports = function(object, index, value){
+ if(index in object)$defineProperty.f(object, index, createDesc(0, value));
+ else object[index] = value;
+};
+
+/***/ }),
+/* 158 */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+var ctx = __webpack_require__(22)
+ , $export = __webpack_require__(12)
+ , toObject = __webpack_require__(41)
+ , call = __webpack_require__(105)
+ , isArrayIter = __webpack_require__(103)
+ , toLength = __webpack_require__(62)
+ , createProperty = __webpack_require__(157)
+ , getIterFn = __webpack_require__(63);
+
+$export($export.S + $export.F * !__webpack_require__(107)(function(iter){ Array.from(iter); }), 'Array', {
+ // 22.1.2.1 Array.from(arrayLike, mapfn = undefined, thisArg = undefined)
+ from: function from(arrayLike/*, mapfn = undefined, thisArg = undefined*/){
+ var O = toObject(arrayLike)
+ , C = typeof this == 'function' ? this : Array
+ , aLen = arguments.length
+ , mapfn = aLen > 1 ? arguments[1] : undefined
+ , mapping = mapfn !== undefined
+ , index = 0
+ , iterFn = getIterFn(O)
+ , length, result, step, iterator;
+ if(mapping)mapfn = ctx(mapfn, aLen > 2 ? arguments[2] : undefined, 2);
+ // if object isn't iterable or it's array with default iterator - use simple case
+ if(iterFn != undefined && !(C == Array && isArrayIter(iterFn))){
+ for(iterator = iterFn.call(O), result = new C; !(step = iterator.next()).done; index++){
+ createProperty(result, index, mapping ? call(iterator, mapfn, [step.value, index], true) : step.value);
+ }
+ } else {
+ length = toLength(O.length);
+ for(result = new C(length); length > index; index++){
+ createProperty(result, index, mapping ? mapfn(O[index], index) : O[index]);
+ }
+ }
+ result.length = index;
+ return result;
+ }
+});
+
+
/***/ })
/******/ ]);
//# sourceMappingURL=bundle.js.map \ No newline at end of file