Mercurial > hg > midi-score-follower
view hackday/MidiInputStream.cpp @ 24:5a11b19906c7
hackday code is added.
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Sat, 03 Dec 2011 17:19:43 +0000 |
parents | |
children | 2a025ea7c793 |
line wrap: on
line source
/* * MidiInputStream.cpp * MuseScoreMidiFollower * * Created by Andrew on 03/12/2011. * Copyright 2011 QMUL. All rights reserved. * */ #include "MidiInputStream.h" MidiInputStream::MidiInputStream(){ reset(); } void MidiInputStream::reset(){ midiInputEvents.clear(); eventTimesForNote.clear(); eventTimesForNote.assign (127, 0.0); midiInputTimes.clear(); } bool MidiInputStream::noteInReceived(ofxMidiEventArgs &args){ // printf("midi input received port %i, channel %i status %i, byteOne %i, byteTwo %i\n", args.port,args.channel, args.status, newPitch, args.byteTwo); bool noteOn = false; int newPitch; switch (args.status) { case 144: newPitch = (int)args.byteOne; newPitch += (*transposeVal); printf("note on %i", args.byteOne); if (args.byteTwo){ printf("volume is %i\n", args.byteTwo); double time = ofGetElapsedTimeMillis(); eventTimesForNote[newPitch] = time; noteOn = true; }else{ double time = ofGetElapsedTimeMillis(); time -= eventTimesForNote[newPitch]; printf(", OFF after %f millis %f ticks\n", time, time * (*factor)); int index = endNote(newPitch); midiInputEvents[index].push_back(time * (*factor)); } break; default: break; } return noteOn; //cout << "MIDI message [port: " << args.port << ", channel: " << args.channel << ", status: " << args.status << ", byteOne: " << newPitch << ", byteTwo: " << args.byteTwo << ", timestamp: " << args.timestamp << "]" << endl; } int MidiInputStream::endNote(int notePitch){ int index = midiInputEvents.size()-1; while (index > 0 && midiInputEvents[index][1] != notePitch){ index--; } printf("found index %i\n", index); return index; } void MidiInputStream::printNotes(){ printf("live input \n"); for (int i = 0;i < midiInputEvents.size();i++){ printf("ticktime %i :: pitch %i @ millis %f\n", midiInputEvents[i][0], midiInputEvents[i][1], midiInputTimes[i]); } }