Go on with hacking midi: load all messages for all rooms. So that, we have the full midi partition with the notes for computing the tempo.

This commit is contained in:
manuroe 2014-10-19 08:44:03 +02:00
parent e09dd47f4d
commit bc9350dbb5
4 changed files with 36 additions and 22 deletions

View File

@ -483,10 +483,7 @@ function(matrixService, $rootScope, $q, $timeout, mPresence) {
break; break;
case 'org.matrix.midi': case 'org.matrix.midi':
//if (isLiveEvent) MidiEventHandler.handleEvent(event, isLiveEvent);
{
MidiEventHandler.handleEvent(event);
}
break; break;

View File

@ -107,7 +107,7 @@ angular.module('eventStreamService', [])
// Initial sync: get all information and the last 30 messages of all rooms of the user // Initial sync: get all information and the last 30 messages of all rooms of the user
// 30 messages should be enough to display a full page of messages in a room // 30 messages should be enough to display a full page of messages in a room
// without requiring to make an additional request // without requiring to make an additional request
matrixService.initialSync(30, false).then( matrixService.initialSync(10000, false).then(
function(response) { function(response) {
var rooms = response.data.rooms; var rooms = response.data.rooms;
for (var i = 0; i < rooms.length; ++i) { for (var i = 0; i < rooms.length; ++i) {

View File

@ -28,22 +28,20 @@ var MidiEventHandler = {
currentMeasureTime: 0, currentMeasureTime: 0,
perLine: -1, perLine: -1,
init: function () { pastMidiEventsInWrongOrder: [],
MIDI.loadPlugin({
soundfontUrl: "./soundfont/", init: function (eventHandlerService) {
instrument: "acoustic_grand_piano",
callback: function () { // During initialSync, handleEvent is called for each event from latest events to the past.
/* // Need to reorder them.
var delay = 0; // play one note every quarter second var self = this;
var note = 50; // the MIDI note eventHandlerService.waitForInitialSyncCompletion().then(
var velocity = 127; // how hard the note hits function() {
// play the note for (var i = self.pastMidiEventsInWrongOrder.length - 1; i >= 0; i--) {
MIDI.setVolume(0, 127); self.handleEvent(self.pastMidiEventsInWrongOrder[i], true);
MIDI.noteOn(0, note, velocity, delay);
MIDI.noteOff(0, note, delay + 0.75);
*/
} }
}); }
);
}, },
reset: function() { reset: function() {
@ -81,7 +79,12 @@ notes C-D-E/4 #0# =:: C-D-E-F/4 =|=");
this.render(); this.render();
}, },
handleEvent: function(event) { handleEvent: function(event, isLiveEvent) {
if(!isLiveEvent) {
this.pastMidiEventsInWrongOrder.push(event);
return;
}
if (0 === this.beat) if (0 === this.beat)
{ {
@ -120,6 +123,8 @@ notes C-D-E/4 #0# =:: C-D-E-F/4 =|=");
var musicFraction; var musicFraction;
// Flag to ignore artefact(???)
var trashIt = false;
var duration = Math.floor(Math.log2(1 / fraction)) - 1; var duration = Math.floor(Math.log2(1 / fraction)) - 1;
switch (duration) { switch (duration) {
@ -142,7 +147,18 @@ notes C-D-E/4 #0# =:: C-D-E-F/4 =|=");
musicFraction = "32"; musicFraction = "32";
break; break;
default :
console.log("## Ignored note");
// Too short, ignore it
trashIt = true;
break;
} }
// Matthew is about to fix it
if (trashIt) return;
this.currentMeasureTime += duration; this.currentMeasureTime += duration;

View File

@ -650,6 +650,7 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
$scope.onInit = function() { $scope.onInit = function() {
console.log("onInit"); console.log("onInit");
MidiEventHandler.init(eventHandlerService);
MidiEventHandler.reset(); MidiEventHandler.reset();