From c31a609399c2e05a50a5df8be10049903521c9e7 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Thu, 1 Nov 2012 21:10:31 +0000 Subject: initial commit --- vfg/src/main.cpp | 16 ++++++++++ vfg/src/music.cpp | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++ vfg/src/music.h | 55 ++++++++++++++++++++++++++++++++ vfg/src/testApp.cpp | 64 +++++++++++++++++++++++++++++++++++++ vfg/src/testApp.h | 56 +++++++++++++++++++++++++++++++++ 5 files changed, 282 insertions(+) create mode 100755 vfg/src/main.cpp create mode 100755 vfg/src/music.cpp create mode 100755 vfg/src/music.h create mode 100755 vfg/src/testApp.cpp create mode 100755 vfg/src/testApp.h (limited to 'vfg/src') diff --git a/vfg/src/main.cpp b/vfg/src/main.cpp new file mode 100755 index 0000000..6a32c6a --- /dev/null +++ b/vfg/src/main.cpp @@ -0,0 +1,16 @@ +#include "ofMain.h" +#include "testApp.h" +#include "ofAppGlutWindow.h" + +//======================================================================== +int main( ){ + + ofAppGlutWindow window; + ofSetupOpenGL(&window, 1024,768, OF_WINDOW); // <-------- setup the GL context + + // this kicks off the running of my app + // can be OF_WINDOW or OF_FULLSCREEN + // pass in width and height too: + ofRunApp( new testApp()); + +} diff --git a/vfg/src/music.cpp b/vfg/src/music.cpp new file mode 100755 index 0000000..82e953e --- /dev/null +++ b/vfg/src/music.cpp @@ -0,0 +1,91 @@ +#include "music.h" + +//event times & durations are absolute integer milliseconds + +note::note(int n,int v,int d){ + num=n; + velocity=v; + duration=d; +} +void musicscore::parseMidi(string filename){ + // millis = 60000 / (BPM * PPQ) + // BPM = 60000000 / MQPN (last 3 bytes of midi tempoSet) + // http://www.lastrayofhope.com/2009/12/23/midi-delta-time-ticks-to-seconds/ + // presume no change in time signature? + + //2 passes:: extract notes & set abs times, then scan for + + float wt=ofGetElapsedTimef(); + + float BPM=120.0f; + //input:: MPQN :: default 500000 + float MPQN=60000000.0f/BPM; + //unknown:: ticks per quarter note + int TPQN=96; + //want:: seconds per tick in float + float SPT =(MPQN/1000000.0f)/TPQN; + + float time=0; //counts up in float seconds but converts to millis for map index + + map events; + + if( !XML.loadFile(filename) ){ + printf("unable to load %s check data/ folder\n",filename.c_str()); + }else{ + if(XML.pushTag("MidiFile")) { + for (int i=0;i::iterator iter1; + map::iterator iter2; + + for (iter1 = events.begin(); iter1 != events.end(); ++iter1) { + if (iter1->second->duration==144) { + iter1->second->duration=0; + iter2=iter1; + while (++iter2 != events.end()) { + if ((iter1->second->num==iter2->second->num)&&(iter2->second->duration==128)) { + iter1->second->duration=iter2->first-iter1->first; + notes[iter1->first]=iter1->second; + //printf("%i: noteon %i %i\n",iter1->first,iter1->second->num,iter1->second->duration); + break; + } + } + } + } + printf("processed %s: %i notes in %f seconds\n",filename.c_str(),notes.size(),ofGetElapsedTimef()-wt); +} + +song::song(string backfile,string melfile,string notefile) { + backing.loadSound(backfile); + melody.loadSound(melfile); + notes.parseMidi(notefile); + bpm=bpm; //can be used to set tempo eventually? keeps everything simple to do it this way +} diff --git a/vfg/src/music.h b/vfg/src/music.h new file mode 100755 index 0000000..145538e --- /dev/null +++ b/vfg/src/music.h @@ -0,0 +1,55 @@ +#pragma once + +#include "ofMain.h" +#include "ofxXmlSettings.h" + +//event times are absolute integer milliseconds + +class note { + public: + note(int n,int v,int d=0); + int num; + int velocity; + int duration; //may be needed another time? +}; + +class score { + //implements basics of timelime, loading from xml, time, checking + public: + + protected: + ofxXmlSettings XML; +}; + +class lyricscore: public score { + //draws lyrics to screen for a certain time + public: +}; + +class musicscore: public score { + //draws notes to screen for a certain time and certain parameters, checks when they become ready + //how will it be played dictates how the data is stored + //play : start from beginning, schedule event at next delta + //end : clean up and start again + //you can set position of sound file, it will seek. will we want ffwd at any stage + //when it comes to drawing, we will want to repeatedly retrieve notes in a range of times + //lower_bound and upper_bound + public: + void parseMidi(string filename); + private: + map notes; +}; + +class song { + public: + song(string backfile,string melfile,string musfile); + private: + ofSoundPlayer backing; + ofSoundPlayer melody; + lyricscore lyrics; + musicscore notes; + int bpm; +}; + + + diff --git a/vfg/src/testApp.cpp b/vfg/src/testApp.cpp new file mode 100755 index 0000000..7710326 --- /dev/null +++ b/vfg/src/testApp.cpp @@ -0,0 +1,64 @@ +#include "testApp.h" + +//-------------------------------------------------------------- +void testApp::setup(){ + testsong=new song("VODA_MUS_DeckTheHalls-Backing_v.1.3.mp3","VODA_MUS_DeckTheHalls-Melody_v.1.3.mp3","MIDI_DeckTheHalls_Test.1.3.xml"); +} + +void testApp::exit(){ + delete testsong; +} + +//-------------------------------------------------------------- +void testApp::update(){ +} + +//-------------------------------------------------------------- +void testApp::draw(){ + +} + +//-------------------------------------------------------------- +void testApp::keyPressed(int key){ + +} + +//-------------------------------------------------------------- +void testApp::keyReleased(int key){ + +} + +//-------------------------------------------------------------- +void testApp::mouseMoved(int x, int y ){ + +} + +//-------------------------------------------------------------- +void testApp::mouseDragged(int x, int y, int button){ + +} + +//-------------------------------------------------------------- +void testApp::mousePressed(int x, int y, int button){ + +} + +//-------------------------------------------------------------- +void testApp::mouseReleased(int x, int y, int button){ + +} + +//-------------------------------------------------------------- +void testApp::windowResized(int w, int h){ + +} + +//-------------------------------------------------------------- +void testApp::gotMessage(ofMessage msg){ + +} + +//-------------------------------------------------------------- +void testApp::dragEvent(ofDragInfo dragInfo){ + +} diff --git a/vfg/src/testApp.h b/vfg/src/testApp.h new file mode 100755 index 0000000..94691a5 --- /dev/null +++ b/vfg/src/testApp.h @@ -0,0 +1,56 @@ +#pragma once + +#include "ofMain.h" +#include "music.h" + +/* +this library? + +https://github.com/micknoise/Maximilian + +Maximilian is an audio synthesis and signal processing library written in C++. It's cross-platform compatible with MacOS, Windows, Linux and IOS systems. The main features are: + +- sample playback, recording and looping +- read from WAV and OGG files. +- a selection of oscillators and filters +- enveloping +- multichannel mixing for 1, 2, 4 and 8 channel setups +- controller mapping functions +- effects including delay, distortion, chorus, flanging +- granular synthesis, including time and pitch stretching +- atom synthesis +- realtime music information retrieval functions: spectrum analysis, spectral features, octave analysis, and MFCCs +- example projects for Windows and MacOS, using command line and OpenFrameworks environments + +*/ + +class game { + vector songs; +}; + +class testApp : public ofBaseApp{ + + public: + void setup(); + void update(); + void draw(); + void exit(); + + void keyPressed (int key); + void keyReleased(int key); + void mouseMoved(int x, int y ); + void mouseDragged(int x, int y, int button); + void mousePressed(int x, int y, int button); + void mouseReleased(int x, int y, int button); + void windowResized(int w, int h); + void dragEvent(ofDragInfo dragInfo); + void gotMessage(ofMessage msg); + + song* testsong; + +}; + + + + + -- cgit v1.2.3