# HG changeset patch # User Andrew N Robertson # Date 1323009033 0 # Node ID fa1890efa044aaaa653042216b2614f246808e77 # Parent 179365726f07087cc09d053f3325b6304502f0d5 close to final version on HackDay diff -r 179365726f07 -r fa1890efa044 hackday/CannamMidiFileLoader.cpp --- a/hackday/CannamMidiFileLoader.cpp Sun Dec 04 00:02:26 2011 +0000 +++ b/hackday/CannamMidiFileLoader.cpp Sun Dec 04 14:30:33 2011 +0000 @@ -336,8 +336,8 @@ //update lastMeasurePosition += ticksPerMeasure; myMidiEvents.measureVector.push_back(lastMeasurePosition); - cout << "MEASURE " << myMidiEvents.measureVector.size()-1 << " is " << lastMeasurePosition << endl; - printf("MEASURE %i is %i \n", (int)myMidiEvents.measureVector.size()-1 , lastMeasurePosition); +// cout << "MEASURE " << myMidiEvents.measureVector.size()-1 << " is " << lastMeasurePosition << endl; +// printf("MEASURE %i is %i \n", (int)myMidiEvents.measureVector.size()-1 , lastMeasurePosition); } } diff -r 179365726f07 -r fa1890efa044 hackday/testApp.cpp --- a/hackday/testApp.cpp Sun Dec 04 00:02:26 2011 +0000 +++ b/hackday/testApp.cpp Sun Dec 04 14:30:33 2011 +0000 @@ -1,17 +1,34 @@ #include "testApp.h" + +testApp::testApp(ofxArgs* args){ + this->args = args; +} + //-------------------------------------------------------------- void testApp::setup(){ + + + this->args->printArgs(); + this->args->printOpts(); midiFileName = "../../../data/frerejacques.mid"; + + if (this->args->getCount() > 0){ + museScoreFilename = this->args->getString(1); + //printf("MUSESCORE FILENAME IS %s\n", museScoreFilename); + cout << "running!! " << museScoreFilename << endl; + midiFileName = museScoreFilename; + } + int retVal = cannamMainFunction(); - cout << "MIDI INPUT EXAMPLE" << endl; - printf("midi in in in"); ofSetVerticalSync(true); //ofBackground(255,255,255); - + midiPort = 2; midiIn.listPorts(); - midiIn.openPort(2); + midiIn.openPort(midiPort); + midiPortName = ""; + //midiPortName = midiIn.portNames(midiPort); transpose = 12; noteInStream.transposeVal = &transpose; @@ -29,7 +46,10 @@ //midiIn.addListener(this); ofAddListener(midiIn.newMessageEvent, this, &testApp::newMessage); - + + verdana30.loadFont("verdana.ttf", 50, true, true); + verdana30.setLineHeight(48.0f); + verdana30.setLetterSpacing(1.035); playing = false; @@ -47,7 +67,11 @@ midiEvents.ticksPerScreen += 4000; lastScoreIndexSent = 0; - performanceRating = 1.0; + performanceRating = 0.0; + + liveInputPlaying = false; + lastScoreIndexSent = 0; + midiEvents.bestMatchIndex = 0; } @@ -157,7 +181,7 @@ lastMeasureSent++; } if (lastMeasureSent != tmpMeasure){ - sendMeasureToMuseScore(); + //sendMeasureToMuseScore(); performanceRating = noteInStream.calculateTotalScore(midiEvents); } @@ -186,7 +210,12 @@ m.addStringArg( noteString); sender.sendMessage( m ); */ - + sendNoteDataByOsc(pitch, ticks); + +// /color-note 60,3440 + + //crappy javascript message + /* ofxOscMessage m; m.setAddress( "/plugin" ); string noteString; @@ -194,19 +223,21 @@ noteString += ",myTick,"+ofToString(ticks)+",myPitch,"+ofToString(pitch); // printf("%s\n", noteString); m.addStringArg( noteString); - sender.sendMessage( m ); - /* - m.addStringArg( "coloronenote.js" ); - m.addStringArg("mytick"); - m.addIntArg( ticks ); - m.addStringArg("mypitch"); - m.addIntArg( pitch); - */ + sender.sendMessage( m ); */ + // /plugin coloronenote.js mytick 100 mypitch 56; } - +void testApp::sendNoteDataByOsc(const int& pitch, const int& ticks){ + ofxOscMessage m; + m.setAddress( "/color-note" ); + string noteString; + noteString = ofToString(ticks); + noteString += ","+ofToString(pitch); + m.addStringArg( noteString); + sender.sendMessage( m ); +} void testApp::sendMeasureToMuseScore(){ @@ -264,16 +295,44 @@ info += " Last note "; info += ofToString(lastScoreIndexSent); - ofSetHexColor(0x000000); - ofDrawBitmapString(info, 20, 20); + ofSetHexColor(0xFF0000); +// ofDrawBitmapString(info, 20, 20); midiEvents.drawMidiFile(noteInStream.midiInputEvents); - ofDrawBitmapString("Rating "+ofToString(performanceRating*100), 20, 50); +// ofDrawBitmapString("Rating "+ofToString(performanceRating*100), 60, 50); + //ofDrawBitmapString("filename "+museScoreFilename, 20, 80); + string ratingString = ofToString(performanceRating*100,0)+"%"; + if (performanceRating > 0.84) + ratingString += "!* *"; + string extraText = ""; + if (performanceRating > 0.9){ + extraText += " pretty good, huh?"; + } + if (performanceRating > 0.95) + extraText = " blimey! "; + if (performanceRating > 0.97) + extraText = " maestro!"; + + ratingString += extraText; + verdana30.drawString(ratingString, 20, 60); + + ofSetHexColor(0x000000); + ofDrawBitmapString(midiPortName, 20, ofGetHeight() - 20); + } //-------------------------------------------------------------- void testApp::keyPressed(int key){ + if (key == '.'){ + midiPort++; + midiIn.openPort(midiPort); + } + + if (key == ',' && midiPort > 0){ + midiPort--; + midiIn.openPort(midiPort); + } // if (key == ' '){ // startPlaying(); @@ -292,6 +351,9 @@ printf("CROSS UPDATE TOOK %f", timenow); } + if (key == 'x') + sendNoteDataByOsc(60, 0); + if (key == OF_KEY_LEFT){ } @@ -354,7 +416,7 @@ } - if (key == 'o'){ + if (key == 'o' || key == 'O'){ //open audio file string *filePtr; filePtr = &midiFileName; @@ -476,212 +538,3 @@ - //trying to port to new class - /* - MIDIFileReader fr(filename); - - if (!fr.isOK()) { - std::cerr << "Error: " << fr.getError().c_str() << std::endl; - return 1; - } - - MIDIComposition c = fr.load(); - - switch (fr.getFormat()) { - case MIDI_SINGLE_TRACK_FILE: cout << "Format: MIDI Single Track File" << endl; break; - case MIDI_SIMULTANEOUS_TRACK_FILE: cout << "Format: MIDI Simultaneous Track File" << endl; break; - case MIDI_SEQUENTIAL_TRACK_FILE: cout << "Format: MIDI Sequential Track File" << endl; break; - default: cout << "Format: Unknown MIDI file format?" << endl; break; - } - - cout << "Tracks: " << c.size() << endl; - - int td = fr.getTimingDivision(); - if (td < 32768) { - cout << "Timing division: " << fr.getTimingDivision() << " ppq" << endl; - - midiEvents.pulsesPerQuarternote = fr.getTimingDivision(); - } else { - int frames = 256 - (td >> 8); - int subframes = td & 0xff; - cout << "SMPTE timing: " << frames << " fps, " << subframes << " subframes" << endl; - } - - for (MIDIComposition::const_iterator i = c.begin(); i != c.end(); ++i) { - - cout << "Start of track: " << i->first+1 << endl; - - for (MIDITrack::const_iterator j = i->second.begin(); j != i->second.end(); ++j) { - - unsigned int t = j->getTime(); - int ch = j->getChannelNumber(); - - if (j->isMeta()) { - int code = j->getMetaEventCode(); - string name; - bool printable = true; - switch (code) { - - case MIDI_END_OF_TRACK: - cout << t << ": End of track" << endl; - break; - - case MIDI_TEXT_EVENT: name = "Text"; break; - case MIDI_COPYRIGHT_NOTICE: name = "Copyright"; break; - case MIDI_TRACK_NAME: name = "Track name"; break; - case MIDI_INSTRUMENT_NAME: name = "Instrument name"; break; - case MIDI_LYRIC: name = "Lyric"; break; - case MIDI_TEXT_MARKER: name = "Text marker"; break; - case MIDI_SEQUENCE_NUMBER: name = "Sequence number"; printable = false; break; - case MIDI_CHANNEL_PREFIX_OR_PORT: name = "Channel prefix or port"; printable = false; break; - case MIDI_CUE_POINT: name = "Cue point"; break; - case MIDI_CHANNEL_PREFIX: name = "Channel prefix"; printable = false; break; - case MIDI_SEQUENCER_SPECIFIC: name = "Sequencer specific"; printable = false; break; - case MIDI_SMPTE_OFFSET: name = "SMPTE offset"; printable = false; break; - - case MIDI_SET_TEMPO: - { - int m0 = j->getMetaMessage()[0]; - int m1 = j->getMetaMessage()[1]; - int m2 = j->getMetaMessage()[2]; - long tempo = (((m0 << 8) + m1) << 8) + m2; - - cout << t << ": Tempo: " << 60000000.0 / double(tempo) << endl; - midiEvents.tempo = 60000000.0 / double(tempo); - midiEvents.period = double(tempo)/1000.0; - - printf("period double is %f\n", midiEvents.period); - } - break; - - case MIDI_TIME_SIGNATURE: - { - int numerator = j->getMetaMessage()[0]; - int denominator = 1 << (int)j->getMetaMessage()[1]; - - cout << t << ": Time signature: " << numerator << "/" << denominator << endl; - } - - case MIDI_KEY_SIGNATURE: - { - int accidentals = j->getMetaMessage()[0]; - int isMinor = j->getMetaMessage()[1]; - bool isSharp = accidentals < 0 ? false : true; - accidentals = accidentals < 0 ? -accidentals : accidentals; - cout << t << ": Key signature: " << accidentals << " " - << (isSharp ? - (accidentals > 1 ? "sharps" : "sharp") : - (accidentals > 1 ? "flats" : "flat")) - << (isMinor ? ", minor" : ", major") << endl; - } - - } - - - if (name != "") { - if (printable) { - cout << t << ": File meta event: code " << code - << ": " << name << ": \"" << j->getMetaMessage() - << "\"" << endl; - } else { - cout << t << ": File meta event: code " << code - << ": " << name << ": "; - for (int k = 0; k < j->getMetaMessage().length(); ++k) { - cout << (int)j->getMetaMessage()[k] << " "; - } - } - } - continue; - } - - switch (j->getMessageType()) { - - case MIDI_NOTE_ON: - cout << t << ": Note: channel " << ch - << " duration " << j->getDuration() - << " pitch " << j->getPitch() - << " velocity " << j->getVelocity() - << "event time " << midiEvents.getEventTimeMillis(t) << endl; - v.clear(); - v.push_back(t); - v.push_back(j->getPitch()); - v.push_back(j->getVelocity()); - v.push_back(j->getDuration()); - midiEvents.recordedNoteOnMatrix.push_back(v); - midiEvents.recordedEventTimes.push_back(midiEvents.getEventTimeMillis(t)); - break; - - case MIDI_POLY_AFTERTOUCH: - cout << t << ": Polyphonic aftertouch: channel " << ch - << " pitch " << j->getPitch() - << " pressure " << j->getData2() << endl; - break; - - case MIDI_CTRL_CHANGE: - { - int controller = j->getData1(); - string name; - switch (controller) { - case MIDI_CONTROLLER_BANK_MSB: name = "Bank select MSB"; break; - case MIDI_CONTROLLER_VOLUME: name = "Volume"; break; - case MIDI_CONTROLLER_BANK_LSB: name = "Bank select LSB"; break; - case MIDI_CONTROLLER_MODULATION: name = "Modulation wheel"; break; - case MIDI_CONTROLLER_PAN: name = "Pan"; break; - case MIDI_CONTROLLER_SUSTAIN: name = "Sustain"; break; - case MIDI_CONTROLLER_RESONANCE: name = "Resonance"; break; - case MIDI_CONTROLLER_RELEASE: name = "Release"; break; - case MIDI_CONTROLLER_ATTACK: name = "Attack"; break; - case MIDI_CONTROLLER_FILTER: name = "Filter"; break; - case MIDI_CONTROLLER_REVERB: name = "Reverb"; break; - case MIDI_CONTROLLER_CHORUS: name = "Chorus"; break; - case MIDI_CONTROLLER_NRPN_1: name = "NRPN 1"; break; - case MIDI_CONTROLLER_NRPN_2: name = "NRPN 2"; break; - case MIDI_CONTROLLER_RPN_1: name = "RPN 1"; break; - case MIDI_CONTROLLER_RPN_2: name = "RPN 2"; break; - case MIDI_CONTROLLER_SOUNDS_OFF: name = "All sounds off"; break; - case MIDI_CONTROLLER_RESET: name = "Reset"; break; - case MIDI_CONTROLLER_LOCAL: name = "Local"; break; - case MIDI_CONTROLLER_ALL_NOTES_OFF: name = "All notes off"; break; - } - cout << t << ": Controller change: channel " << ch - << " controller " << j->getData1(); - if (name != "") cout << " (" << name << ")"; - cout << " value " << j->getData2() << endl; - } - break; - - case MIDI_PROG_CHANGE: - cout << t << ": Program change: channel " << ch - << " program " << j->getData1() << endl; - break; - - case MIDI_CHNL_AFTERTOUCH: - cout << t << ": Channel aftertouch: channel " << ch - << " pressure " << j->getData1() << endl; - break; - - case MIDI_PITCH_BEND: - cout << t << ": Pitch bend: channel " << ch - << " value " << (int)j->getData2() * 128 + (int)j->getData1() << endl; - break; - - case MIDI_SYSTEM_EXCLUSIVE: - cout << t << ": System exclusive: code " - << (int)j->getMessageType() << " message length " << - j->getMetaMessage().length() << endl; - break; - - - } - - - } - - - } - -}//end cannam midi main - -*/ - - diff -r 179365726f07 -r fa1890efa044 hackday/testApp.h --- a/hackday/testApp.h Sun Dec 04 00:02:26 2011 +0000 +++ b/hackday/testApp.h Sun Dec 04 14:30:33 2011 +0000 @@ -29,7 +29,7 @@ #include "ofxMidiIn.h" #include "ofxOsc.h" #include "MidiInputStream.h" - +#include "ofxArgs.h" #define PORT 12121 #define SEND_PORT 5282 @@ -40,8 +40,16 @@ using namespace MIDIConstants; class testApp : public ofBaseApp{ +private: + ofxArgs* args; + string option1, option2; + bool flag1; + ofxOscReceiver receiver; + ofxOscSender sender; + +public: + testApp(ofxArgs* args); - public: void setup(); void update(); void draw(); @@ -67,7 +75,8 @@ int cannamMainFunction(); string midiFileName; - + std::string museScoreFilename; + bool playing; //drawMidiNotes drawer; @@ -105,10 +114,11 @@ int lastScoreIndexSent; int lastMeasureSent; double performanceRating; -private: - ofxOscReceiver receiver; - ofxOscSender sender; + void sendNoteDataByOsc(const int& pitch, const int& ticks); + ofTrueTypeFont verdana30; + int midiPort; + std::string midiPortName; }; diff -r 179365726f07 -r fa1890efa044 src/untitled.h --- a/src/untitled.h Sun Dec 04 00:02:26 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -/* - * untitled.h - * midiCannamReader - * - * Created by Andrew on 18/07/2011. - * Copyright 2011 QMUL. All rights reserved. - * - */ - -#include "ofMain.h" - -class Double \ No newline at end of file