├── example-ofxThreadedMidiPlayer-playback ├── addons.make ├── bin │ └── data │ │ ├── lady_gaga-alejandro.mid │ │ └── snoop_dogg-the_shiznit.mid ├── example-ofxThreadedMidiPlayer-playback.xcodeproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ └── example-ofxThreadedMidiPlayer-playback.xccheckout │ └── xcshareddata │ │ └── xcschemes │ │ ├── example-ofxThreadedMidiPlayer-playback Debug.xcscheme │ │ └── example-ofxThreadedMidiPlayer-playback Release.xcscheme ├── src │ ├── main.cpp │ ├── ofApp.h │ └── ofApp.cpp ├── Makefile ├── Project.xcconfig ├── openFrameworks-Info.plist └── config.make ├── libs └── jdksmidi │ ├── lib │ └── jdksmidi.a │ ├── src │ ├── jdksmidi_msg.cpp │ ├── jdksmidi_tick.cpp │ ├── jdksmidi_tempo.cpp │ ├── jdksmidi_driverdump.cpp │ ├── jdksmidi_queue.cpp │ ├── jdksmidi_sysex.cpp │ ├── jdksmidi_file.cpp │ ├── jdksmidi_midi.cpp │ ├── jdksmidi_filewritemultitrack.cpp │ ├── jdksmidi_process.cpp │ ├── jdksmidi_driver.cpp │ ├── jdksmidi_matrix.cpp │ ├── win32 │ │ └── jdksmidi_driverwin32.cpp │ ├── jdksmidi_filereadmultitrack.cpp │ ├── jdksmidi_keysig.cpp │ └── jdksmidi_manager.cpp │ ├── include │ └── jdksmidi │ │ ├── tick.h │ │ ├── driverdump.h │ │ ├── song.h │ │ ├── queue.h │ │ ├── filewritemultitrack.h │ │ ├── world.h │ │ ├── keysig.h │ │ ├── parser.h │ │ ├── matrix.h │ │ ├── driverwin32.h │ │ ├── manager.h │ │ ├── fileshow.h │ │ ├── utils.h │ │ ├── process.h │ │ ├── filereadmultitrack.h │ │ ├── edittrack.h │ │ ├── sysex.h │ │ ├── tempo.h │ │ ├── advancedsequencer.h │ │ ├── driver.h │ │ ├── file.h │ │ ├── showcontrolhandler.h │ │ ├── multitrack.h │ │ ├── filewrite.h │ │ └── fileread.h │ └── examples │ ├── jdksmidi_test_show.cpp │ ├── win32 │ └── jdksmidi_test_drvwin32.cpp │ ├── jdksmidi_test_drv.cpp │ ├── jdksmidi_test_multitrack1.cpp │ ├── jdksmidi_test_parse.cpp │ ├── jdksmidi_test_multitrack.cpp │ ├── rewrite_midifile.cpp │ ├── jdksmidi_rewrite_midifile.cpp │ └── vrm_music_gen_readme.txt ├── .gitignore ├── README.md ├── src └── ofxThreadedMidiPlayer.h └── addon_config.mk /example-ofxThreadedMidiPlayer-playback/addons.make: -------------------------------------------------------------------------------- 1 | ofxMidi 2 | ofxThreadedMidiPlayer 3 | -------------------------------------------------------------------------------- /libs/jdksmidi/lib/jdksmidi.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jvcleave/ofxThreadedMidiPlayer/HEAD/libs/jdksmidi/lib/jdksmidi.a -------------------------------------------------------------------------------- /libs/jdksmidi/src/jdksmidi_msg.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jvcleave/ofxThreadedMidiPlayer/HEAD/libs/jdksmidi/src/jdksmidi_msg.cpp -------------------------------------------------------------------------------- /example-ofxThreadedMidiPlayer-playback/bin/data/lady_gaga-alejandro.mid: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jvcleave/ofxThreadedMidiPlayer/HEAD/example-ofxThreadedMidiPlayer-playback/bin/data/lady_gaga-alejandro.mid -------------------------------------------------------------------------------- /example-ofxThreadedMidiPlayer-playback/bin/data/snoop_dogg-the_shiznit.mid: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jvcleave/ofxThreadedMidiPlayer/HEAD/example-ofxThreadedMidiPlayer-playback/bin/data/snoop_dogg-the_shiznit.mid -------------------------------------------------------------------------------- /example-ofxThreadedMidiPlayer-playback/example-ofxThreadedMidiPlayer-playback.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .svn/ 2 | build/ 3 | 4 | ipch/ 5 | 6 | # mac Finder index files 7 | .DS_* 8 | 9 | # mac apps 10 | *.app* 11 | 12 | # xcode user project files 13 | *.pbxuser 14 | *.perspectivev3 15 | xcuserdata 16 | *.mode1*v3 17 | 18 | # codeblocks project files 19 | *.depend 20 | *.layout 21 | 22 | # visual studio project files 23 | *.vcxproj.user 24 | *.suo 25 | *.sdf 26 | -------------------------------------------------------------------------------- /example-ofxThreadedMidiPlayer-playback/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include "ofMain.h" 2 | #include "ofApp.h" 3 | 4 | //======================================================================== 5 | int main( ){ 6 | 7 | 8 | ofSetupOpenGL( 200,200, OF_WINDOW); // <-------- setup the GL context 9 | 10 | // this kicks off the running of my app 11 | // can be OF_WINDOW or OF_FULLSCREEN 12 | // pass in width and height too: 13 | ofRunApp( new ofApp()); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /example-ofxThreadedMidiPlayer-playback/Makefile: -------------------------------------------------------------------------------- 1 | # Attempt to load a config.make file. 2 | # If none is found, project defaults in config.project.make will be used. 3 | ifneq ($(wildcard config.make),) 4 | include config.make 5 | endif 6 | 7 | # make sure the the OF_ROOT location is defined 8 | ifndef OF_ROOT 9 | OF_ROOT=$(realpath ../../..) 10 | endif 11 | 12 | # call the project makefile! 13 | include $(OF_ROOT)/libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk 14 | -------------------------------------------------------------------------------- /example-ofxThreadedMidiPlayer-playback/Project.xcconfig: -------------------------------------------------------------------------------- 1 | //THE PATH TO THE ROOT OF OUR OF PATH RELATIVE TO THIS PROJECT. 2 | //THIS NEEDS TO BE DEFINED BEFORE CoreOF.xcconfig IS INCLUDED 3 | OF_PATH = ../../.. 4 | 5 | //THIS HAS ALL THE HEADER AND LIBS FOR OF CORE 6 | #include "../../../libs/openFrameworksCompiled/project/osx/CoreOF.xcconfig" 7 | 8 | //ICONS - NEW IN 0072 9 | ICON_NAME_DEBUG = icon-debug.icns 10 | ICON_NAME_RELEASE = icon.icns 11 | ICON_FILE_PATH = $(OF_PATH)/libs/openFrameworksCompiled/project/osx/ 12 | 13 | //IF YOU WANT AN APP TO HAVE A CUSTOM ICON - PUT THEM IN YOUR DATA FOLDER AND CHANGE ICON_FILE_PATH to: 14 | //ICON_FILE_PATH = bin/data/ 15 | 16 | OTHER_LDFLAGS = $(OF_CORE_LIBS) $(OF_CORE_FRAMEWORKS) 17 | HEADER_SEARCH_PATHS = $(OF_CORE_HEADERS) 18 | -------------------------------------------------------------------------------- /example-ofxThreadedMidiPlayer-playback/src/ofApp.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ofMain.h" 4 | 5 | #include "ofxThreadedMidiPlayer.h" 6 | 7 | 8 | class ofApp : public ofBaseApp{ 9 | 10 | public: 11 | void setup(); 12 | void update(); 13 | void draw(); 14 | 15 | void exit(); 16 | 17 | void keyPressed (int key); 18 | void keyReleased(int key); 19 | void mouseMoved(int x, int y ); 20 | void mouseDragged(int x, int y, int button); 21 | void mousePressed(int x, int y, int button); 22 | void mouseReleased(int x, int y, int button); 23 | void windowResized(int w, int h); 24 | void dragEvent(ofDragInfo dragInfo); 25 | void gotMessage(ofMessage msg); 26 | 27 | ofxThreadedMidiPlayer player; 28 | 29 | 30 | void midiEvent(ofxMidiMessage& m); 31 | }; 32 | -------------------------------------------------------------------------------- /example-ofxThreadedMidiPlayer-playback/openFrameworks-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | cc.openFrameworks.ofapp 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | APPL 15 | CFBundleSignature 16 | ???? 17 | CFBundleVersion 18 | 1.0 19 | CFBundleIconFile 20 | ${ICON} 21 | 22 | 23 | -------------------------------------------------------------------------------- /libs/jdksmidi/src/jdksmidi_tick.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * libjdksmidi-2004 C++ Class Library for MIDI 3 | * 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 5 | * www.jdkoftinoff.com 6 | * jeffk@jdkoftinoff.com 7 | * 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | 25 | #include "jdksmidi/world.h" 26 | #include "jdksmidi/tick.h" 27 | 28 | namespace jdksmidi 29 | { 30 | 31 | MIDITick::~MIDITick() 32 | { 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /libs/jdksmidi/include/jdksmidi/tick.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjdksmidi-2004 C++ Class Library for MIDI 3 | * 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 5 | * www.jdkoftinoff.com 6 | * jeffk@jdkoftinoff.com 7 | * 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | 25 | #ifndef JDKSMIDI_TICK_H 26 | #define JDKSMIDI_TICK_H 27 | 28 | namespace jdksmidi 29 | { 30 | 31 | class MIDITick 32 | { 33 | public: 34 | MIDITick() 35 | { 36 | } 37 | 38 | virtual ~MIDITick(); 39 | 40 | virtual void TimeTick ( unsigned long sys_time ) = 0; 41 | }; 42 | 43 | } 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /libs/jdksmidi/src/jdksmidi_tempo.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * libjdksmidi-2004 C++ Class Library for MIDI 3 | * 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 5 | * www.jdkoftinoff.com 6 | * jeffk@jdkoftinoff.com 7 | * 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | /* 25 | ** Copyright 1986 to 1998 By J.D. Koftinoff Software, Ltd. 26 | ** 27 | ** All rights reserved. 28 | ** 29 | ** No one may duplicate this source code in any form for any reason 30 | ** without the written permission given by J.D. Koftinoff Software, Ltd. 31 | ** 32 | */ 33 | 34 | #include "jdksmidi/world.h" 35 | #include "jdksmidi/tempo.h" 36 | 37 | 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #ofxThreadedMidiPlayer 2 | Plays a midi file from disk in openFrameworks 0.9.3. 3 | 4 | The example project has everything setup for XCode. 5 | 6 | ###What's new? 7 | ####Updated by [Roy J. Macdonald](https://github.com/roymacdonald/ofxThreadedMidiPlayer/) 8 | * Updated to work with OF 0.9.3 (current stable release) 9 | * Removed dependency on ofxRuiThread and now works with OF's ofThread object. 10 | * Added ofEvent for each new midi event. This means you can easily set up any listener at any point in your app. 11 | This event uses the ofxMidiMessage form ofxMidi so it is very easy to deal with both addons together. 12 | * Updated example. 13 | * Restructured folder to conform with the ofxAddonTemplate 14 | * Renamed README to README.md and updated it (this file) 15 | * Rename testApp to ofApp 16 | * added addon_config.mk file so it works nicely with OF's Project Generator 17 | 18 | 19 | #####THANKS/REFERENCES 20 | Uses jdksmidi awesome library to read and parse midi files 21 | [https://github.com/jdkoftinoff/jdksmidi](https://github.com/jdkoftinoff/jdksmidi) 22 | 23 | Thanks to [https://github.com/gmarco/qthesia](https://github.com/gmarco/qthesia) for example of parsing jdksmidi messages 24 | Nice writeup on setting up a virtual midi port on a Mac (works well with GarageBand) 25 | http://fox-gieg.com/tutorials/2007/inter-application-midi/ 26 | 27 | Uses RtMidi (included in ofxMidi) to send data to MIDI ports 28 | [https://github.com/chrisoshea/ofxMidi](https://github.com/chrisoshea/ofxMidi) 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/ofxThreadedMidiPlayer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ofMain.h" 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include "ofxMidi.h" 14 | 15 | 16 | 17 | 18 | using namespace jdksmidi; 19 | 20 | class ofxThreadedMidiPlayer: public ofThread{ 21 | public: 22 | int count; 23 | bool isReady; 24 | string midiFileName; 25 | int midiPort; 26 | float currentTime; 27 | float nextEventTime; 28 | 29 | double musicDurationInSeconds; 30 | float max_time; 31 | long myTime; 32 | long initTime; 33 | bool doLoop; 34 | 35 | MIDIMultiTrack *tracks; 36 | MIDISequencer *sequencer; 37 | MIDITimedBigMessage lastTimedBigMessage; 38 | 39 | RtMidiOut *midiout; 40 | 41 | 42 | ofxThreadedMidiPlayer(); 43 | ~ofxThreadedMidiPlayer(); 44 | void stop(); 45 | void DumpMIDITimedBigMessage( const MIDITimedBigMessage& msg ); 46 | void start(); 47 | 48 | void setup(string fileName, int portNumber, bool shouldLoop = true); 49 | void threadedFunction(); 50 | void clean(); 51 | float getBpm(); 52 | bool setBpm(float bpm); 53 | 54 | ofxMidiEvent midiEvent; 55 | 56 | 57 | protected: 58 | void dispatchMidiEvent(float currentTime, float timeDelta, vector& message); 59 | bool bIsInited; 60 | 61 | void init(); 62 | }; 63 | -------------------------------------------------------------------------------- /libs/jdksmidi/include/jdksmidi/driverdump.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjdksmidi-2004 C++ Class Library for MIDI 3 | * 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 5 | * www.jdkoftinoff.com 6 | * jeffk@jdkoftinoff.com 7 | * 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | 25 | #ifndef JDKSMIDI_DRIVERDUMP_H 26 | #define JDKSMIDI_DRIVERDUMP_H 27 | 28 | #include "jdksmidi/driver.h" 29 | 30 | namespace jdksmidi 31 | { 32 | 33 | class MIDIDriverDump : public MIDIDriver 34 | { 35 | 36 | public: 37 | 38 | MIDIDriverDump ( int queue_size, FILE *outfile ); 39 | virtual ~MIDIDriverDump(); 40 | 41 | virtual bool HardwareMsgOut ( const MIDITimedBigMessage &msg ); 42 | 43 | virtual void TimeTick ( unsigned long sys_time ); 44 | 45 | protected: 46 | 47 | FILE *f; 48 | }; 49 | 50 | } 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /libs/jdksmidi/src/jdksmidi_driverdump.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * libjdksmidi-2004 C++ Class Library for MIDI 3 | * 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 5 | * www.jdkoftinoff.com 6 | * jeffk@jdkoftinoff.com 7 | * 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | 25 | #include "jdksmidi/world.h" 26 | #include "jdksmidi/driverdump.h" 27 | 28 | namespace jdksmidi 29 | { 30 | 31 | MIDIDriverDump::MIDIDriverDump ( int queue_size, FILE *outfile ) 32 | : 33 | MIDIDriver ( queue_size ), 34 | f ( outfile ) 35 | { 36 | } 37 | 38 | MIDIDriverDump::~MIDIDriverDump() 39 | { 40 | } 41 | 42 | 43 | bool MIDIDriverDump::HardwareMsgOut ( const MIDITimedBigMessage &msg ) 44 | { 45 | char buf[256]; 46 | fprintf ( f, "OUTPUT: %s\n", msg.MsgToText ( buf ) ); 47 | return true; 48 | } 49 | 50 | 51 | void MIDIDriverDump::TimeTick ( unsigned long sys_time ) 52 | { 53 | fprintf ( f, "TICK : %8ld\n", sys_time ); 54 | MIDIDriver::TimeTick ( sys_time ); 55 | } 56 | 57 | 58 | } 59 | -------------------------------------------------------------------------------- /libs/jdksmidi/src/jdksmidi_queue.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * libjdksmidi-2004 C++ Class Library for MIDI 3 | * 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 5 | * www.jdkoftinoff.com 6 | * jeffk@jdkoftinoff.com 7 | * 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | // 25 | // Copyright (C) 2010 V.R.Madgazin 26 | // www.vmgames.com vrm@vmgames.com 27 | // 28 | 29 | #include "jdksmidi/world.h" 30 | #include "jdksmidi/queue.h" 31 | 32 | namespace jdksmidi 33 | { 34 | 35 | MIDIQueue::MIDIQueue ( int num_msgs ) 36 | : 37 | buf ( new MIDITimedBigMessage[ num_msgs ] ), 38 | bufsize ( num_msgs ), 39 | next_in ( 0 ), 40 | next_out ( 0 ) 41 | { 42 | } 43 | 44 | 45 | MIDIQueue::~MIDIQueue() 46 | { 47 | jdks_safe_delete_array( buf ); 48 | } 49 | 50 | void MIDIQueue::Clear() 51 | { 52 | next_in = 0; 53 | next_out = 0; 54 | } 55 | 56 | bool MIDIQueue::CanPut() const 57 | { 58 | return next_out != ( ( next_in + 1 ) % bufsize ); 59 | } 60 | 61 | bool MIDIQueue::CanGet() const 62 | { 63 | return next_in != next_out; 64 | } 65 | 66 | 67 | 68 | } 69 | -------------------------------------------------------------------------------- /libs/jdksmidi/include/jdksmidi/song.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjdksmidi-2004 C++ Class Library for MIDI 3 | * 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 5 | * www.jdkoftinoff.com 6 | * jeffk@jdkoftinoff.com 7 | * 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | 25 | #ifndef JDKSMIDI_SONG_H 26 | #define JDKSMIDI_SONG_H 27 | 28 | #include "jdksmidi/multitrack.h" 29 | #include "jdksmidi/sequencer.h" 30 | #include "jdksmidi/filereadmultitrack.h" 31 | 32 | namespace jdksmidi 33 | { 34 | 35 | class MIDISong 36 | { 37 | public: 38 | MIDISong ( int max_tracks ); 39 | virtual ~MIDISong(); 40 | 41 | bool Load ( const char *fname ); 42 | 43 | // bool Save( const char *fname ); 44 | 45 | MIDIMultiTrack *GetMultiTrack() 46 | { 47 | return multitrack; 48 | } 49 | 50 | const MIDIMultiTrack *GetMultiTrack() const 51 | { 52 | return multitrack; 53 | } 54 | 55 | MIDISequencer *GetSeq() 56 | { 57 | return sequencer; 58 | } 59 | 60 | const MIDISequencer *GetSeq() const 61 | { 62 | return sequencer; 63 | } 64 | 65 | protected: 66 | 67 | MIDIMultiTrack track; 68 | MIDISequencer seq; 69 | 70 | char title; 71 | }; 72 | } 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /libs/jdksmidi/include/jdksmidi/queue.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjdksmidi-2004 C++ Class Library for MIDI 3 | * 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 5 | * www.jdkoftinoff.com 6 | * jeffk@jdkoftinoff.com 7 | * 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | 25 | #ifndef JDKSMIDI_QUEUE_H 26 | #define JDKSMIDI_QUEUE_H 27 | 28 | #include "jdksmidi/msg.h" 29 | #include "jdksmidi/sysex.h" 30 | 31 | namespace jdksmidi 32 | { 33 | 34 | class MIDIQueue 35 | { 36 | public: 37 | MIDIQueue ( int num_msgs ); 38 | virtual ~MIDIQueue(); 39 | 40 | void Clear(); 41 | 42 | bool CanPut() const; 43 | 44 | bool CanGet() const; 45 | 46 | bool IsFull() const 47 | { 48 | return !CanPut(); 49 | } 50 | 51 | 52 | void Put ( const MIDITimedBigMessage &msg ) 53 | { 54 | buf[next_in] = msg; 55 | next_in = ( next_in + 1 ) % bufsize; 56 | } 57 | 58 | MIDITimedBigMessage Get() const 59 | { 60 | return MIDITimedBigMessage ( buf[next_out] ); 61 | } 62 | 63 | void Next() 64 | { 65 | next_out = ( next_out + 1 ) % bufsize; 66 | } 67 | 68 | const MIDITimedBigMessage *Peek() const 69 | { 70 | return &buf[next_out]; 71 | } 72 | 73 | protected: 74 | MIDITimedBigMessage *buf; 75 | int bufsize; 76 | volatile int next_in; 77 | volatile int next_out; 78 | }; 79 | 80 | } 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /libs/jdksmidi/examples/jdksmidi_test_show.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * libjdksmidi-2004 C++ Class Library for MIDI 3 | * 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 5 | * www.jdkoftinoff.com 6 | * jeffk@jdkoftinoff.com 7 | * 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | // 25 | // Copyright (C) 2010 V.R.Madgazin 26 | // www.vmgames.com vrm@vmgames.com 27 | // 28 | 29 | #include "jdksmidi/world.h" 30 | #include "jdksmidi/fileread.h" 31 | #include "jdksmidi/fileshow.h" 32 | using namespace jdksmidi; 33 | 34 | #include 35 | using namespace std; 36 | 37 | int main ( int argc, char **argv ) 38 | { 39 | if ( argc > 1 ) 40 | { 41 | const char *infile_name = argv[1]; 42 | 43 | MIDIFileReadStreamFile rs ( infile_name ); 44 | if ( !rs.IsValid() ) 45 | { 46 | cerr << "\nError opening file " << infile_name << endl; 47 | return -1; 48 | } 49 | 50 | // if true print META_SEQUENCER_SPECIFIC events as text string 51 | bool sqspecific_as_text = true; 52 | 53 | MIDIFileShow shower ( stdout, sqspecific_as_text ); 54 | MIDIFileRead reader ( &rs, &shower ); 55 | 56 | if ( !reader.Parse() ) 57 | { 58 | cerr << "\nError parse file " << infile_name << endl; 59 | return -1; 60 | } 61 | } 62 | else 63 | { 64 | cerr << "usage:\n\tjdkmidi_test_show INFILE.mid\n"; 65 | return -1; 66 | } 67 | 68 | return 0; 69 | } 70 | -------------------------------------------------------------------------------- /libs/jdksmidi/include/jdksmidi/filewritemultitrack.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjdksmidi-2004 C++ Class Library for MIDI 3 | * 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 5 | * www.jdkoftinoff.com 6 | * jeffk@jdkoftinoff.com 7 | * 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | // 25 | // Copyright (C) 2010 V.R.Madgazin 26 | // www.vmgames.com vrm@vmgames.com 27 | // 28 | 29 | #ifndef JDKSMIDI_FILEWRITEMULTITRACK_H 30 | #define JDKSMIDI_FILEWRITEMULTITRACK_H 31 | 32 | #include "jdksmidi/filewrite.h" 33 | #include "jdksmidi/multitrack.h" 34 | 35 | namespace jdksmidi 36 | { 37 | 38 | class MIDIFileWriteMultiTrack 39 | { 40 | public: 41 | 42 | MIDIFileWriteMultiTrack ( 43 | const MIDIMultiTrack *mlt_, 44 | MIDIFileWriteStream *strm_ 45 | ); 46 | 47 | virtual ~MIDIFileWriteMultiTrack(); 48 | 49 | bool Write ( int num_tracks, int division ); 50 | 51 | bool Write ( int num_tracks ) 52 | { 53 | return Write ( num_tracks, multitrack->GetClksPerBeat() ); 54 | } 55 | bool Write() 56 | { 57 | return Write ( multitrack->GetNumTracks(), multitrack->GetClksPerBeat() ); 58 | } 59 | 60 | // false argument disable use running status in midi file (true on default) 61 | void UseRunningStatus( bool use ) 62 | { 63 | writer.UseRunningStatus( use ); 64 | } 65 | 66 | private: 67 | virtual bool PreWrite(); 68 | virtual bool PostWrite(); 69 | 70 | const MIDIMultiTrack *multitrack; 71 | MIDIFileWrite writer; 72 | }; 73 | 74 | } 75 | 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /libs/jdksmidi/examples/win32/jdksmidi_test_drvwin32.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * libjdksmidi-2004 C++ Class Library for MIDI 3 | * 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 5 | * www.jdkoftinoff.com 6 | * jeffk@jdkoftinoff.com 7 | * 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | 25 | 26 | #include "jdksmidi/world.h" 27 | #include "jdksmidi/track.h" 28 | #include "jdksmidi/multitrack.h" 29 | #include "jdksmidi/filereadmultitrack.h" 30 | #include "jdksmidi/fileread.h" 31 | #include "jdksmidi/fileshow.h" 32 | #include "jdksmidi/sequencer.h" 33 | #include "jdksmidi/manager.h" 34 | #include "jdksmidi/driver.h" 35 | #include "jdksmidi/driverwin32.h" 36 | 37 | using namespace jdksmidi; 38 | 39 | int main ( int argc, char **argv ) 40 | { 41 | #ifdef WIN32 42 | 43 | if ( argc > 1 ) 44 | { 45 | MIDIFileReadStreamFile rs ( argv[1] ); 46 | MIDIMultiTrack tracks ( 64 ); 47 | MIDIFileReadMultiTrack track_loader ( &tracks ); 48 | MIDIFileRead reader ( &rs, &track_loader ); 49 | MIDISequencerGUIEventNotifierText gui ( stdout ); 50 | MIDISequencer seq ( &tracks, &gui ); 51 | MIDIDriverWin32 driver ( 128 ); 52 | MIDIManager mgr ( &driver, &gui ); 53 | reader.Parse(); 54 | driver.StartTimer ( 20 ); 55 | driver.OpenMIDIOutPort ( MIDI_MAPPER ); 56 | seq.GoToZero(); 57 | mgr.SetSeq ( &seq ); 58 | mgr.SetTimeOffset ( timeGetTime() ); 59 | mgr.SeqPlay(); 60 | getchar(); 61 | mgr.SeqStop(); 62 | } 63 | 64 | return 0; 65 | #endif 66 | } 67 | 68 | 69 | -------------------------------------------------------------------------------- /example-ofxThreadedMidiPlayer-playback/example-ofxThreadedMidiPlayer-playback.xcodeproj/project.xcworkspace/xcshareddata/example-ofxThreadedMidiPlayer-playback.xccheckout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDESourceControlProjectFavoriteDictionaryKey 6 | 7 | IDESourceControlProjectIdentifier 8 | 768FA66B-94DB-49B6-B020-6D79C2EED0A8 9 | IDESourceControlProjectName 10 | example-ofxThreadedMidiPlayer-playback 11 | IDESourceControlProjectOriginsDictionary 12 | 13 | 8C4C6F40B92FB9BF6B911F36ED937FECD7CB225D 14 | git://github.com/jvcleave/ofxThreadedMidiPlayer.git 15 | 90E2F969A762FB62C413A0C44D1F334E6EC3F531 16 | https://github.com/danomatika/ofxMidi.git 17 | 18 | IDESourceControlProjectPath 19 | example-ofxThreadedMidiPlayer-playback/example-ofxThreadedMidiPlayer-playback.xcodeproj 20 | IDESourceControlProjectRelativeInstallPathDictionary 21 | 22 | 8C4C6F40B92FB9BF6B911F36ED937FECD7CB225D 23 | ../../.. 24 | 90E2F969A762FB62C413A0C44D1F334E6EC3F531 25 | ../../../../ofxMidi 26 | 27 | IDESourceControlProjectURL 28 | git://github.com/jvcleave/ofxThreadedMidiPlayer.git 29 | IDESourceControlProjectVersion 30 | 111 31 | IDESourceControlProjectWCCIdentifier 32 | 8C4C6F40B92FB9BF6B911F36ED937FECD7CB225D 33 | IDESourceControlProjectWCConfigurations 34 | 35 | 36 | IDESourceControlRepositoryExtensionIdentifierKey 37 | public.vcs.git 38 | IDESourceControlWCCIdentifierKey 39 | 90E2F969A762FB62C413A0C44D1F334E6EC3F531 40 | IDESourceControlWCCName 41 | ofxMidi 42 | 43 | 44 | IDESourceControlRepositoryExtensionIdentifierKey 45 | public.vcs.git 46 | IDESourceControlWCCIdentifierKey 47 | 8C4C6F40B92FB9BF6B911F36ED937FECD7CB225D 48 | IDESourceControlWCCName 49 | ofxThreadedMidiPlayer 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /example-ofxThreadedMidiPlayer-playback/src/ofApp.cpp: -------------------------------------------------------------------------------- 1 | #include "ofApp.h" 2 | 3 | //-------------------------------------------------------------- 4 | void ofApp::setup() 5 | { 6 | ofSetLogLevel(OF_LOG_VERBOSE); 7 | 8 | bool shouldSequenceLoop = false; 9 | int midiPortNumber = 0; 10 | 11 | player.setup("snoop_dogg-the_shiznit.mid", midiPortNumber, shouldSequenceLoop); 12 | 13 | ofAddListener(player.midiEvent, this, &ofApp::midiEvent); 14 | 15 | } 16 | 17 | //-------------------------------------------------------------- 18 | void ofApp::exit(){ 19 | player.stop(); 20 | } 21 | //-------------------------------------------------------------- 22 | void ofApp::update(){ 23 | 24 | ofSetWindowTitle(ofToString(ofGetFrameRate())); 25 | } 26 | //-------------------------------------------------------------- 27 | void ofApp::midiEvent(ofxMidiMessage& m){ 28 | // ofLog << " Evento Midi" << m.status << '\n'; 29 | // ofLog << "midiMessage status: " << ofxMidiMessage::getStatusString(m.status) << '\n'; 30 | 31 | } 32 | //-------------------------------------------------------------- 33 | void ofApp::draw(){ 34 | } 35 | 36 | //-------------------------------------------------------------- 37 | void ofApp::keyPressed(int key){ 38 | 39 | } 40 | 41 | //-------------------------------------------------------------- 42 | void ofApp::keyReleased(int key){ 43 | if (key == 'a'){ 44 | player.start(); 45 | }else if (key == 's'){ 46 | player.stop(); 47 | } 48 | else if (key == 'd'){ 49 | player.clean(); 50 | } 51 | } 52 | 53 | //-------------------------------------------------------------- 54 | void ofApp::mouseMoved(int x, int y ){ 55 | 56 | } 57 | 58 | //-------------------------------------------------------------- 59 | void ofApp::mouseDragged(int x, int y, int button){ 60 | 61 | } 62 | 63 | //-------------------------------------------------------------- 64 | void ofApp::mousePressed(int x, int y, int button){ 65 | 66 | } 67 | 68 | //-------------------------------------------------------------- 69 | void ofApp::mouseReleased(int x, int y, int button){ 70 | 71 | } 72 | 73 | //-------------------------------------------------------------- 74 | void ofApp::windowResized(int w, int h){ 75 | 76 | } 77 | 78 | //-------------------------------------------------------------- 79 | void ofApp::gotMessage(ofMessage msg){ 80 | 81 | } 82 | 83 | //-------------------------------------------------------------- 84 | void ofApp::dragEvent(ofDragInfo dragInfo){ 85 | 86 | } 87 | -------------------------------------------------------------------------------- /libs/jdksmidi/include/jdksmidi/world.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjdksmidi-2004 C++ Class Library for MIDI 3 | * 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 5 | * www.jdkoftinoff.com 6 | * jeffk@jdkoftinoff.com 7 | * 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | /* 25 | ** Copyright 1986 to 1998 By J.D. Koftinoff Software, Ltd. 26 | ** 27 | ** All rights reserved. 28 | ** 29 | ** No one may duplicate this source code in any form for any reason 30 | ** without the written permission given by J.D. Koftinoff Software, Ltd. 31 | ** 32 | */ 33 | // 34 | // Copyright (C) 2010 V.R.Madgazin 35 | // www.vmgames.com vrm@vmgames.com 36 | // 37 | 38 | #ifndef JDKSMIDI_WORLD_H 39 | #define JDKSMIDI_WORLD_H 40 | 41 | #include 42 | #include 43 | #include 44 | 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | 51 | namespace jdksmidi 52 | { 53 | 54 | #define ENTER(a) 55 | 56 | #define DBG(a) 57 | #define OSTYPE( a,b,c,d ) ((a)*0x1000000 + (b)*0x10000 + (c)*0x100 + (d) ) 58 | 59 | typedef unsigned char uchar; 60 | typedef unsigned long ulong; 61 | typedef unsigned int uint; 62 | typedef unsigned short ushort; 63 | 64 | /*! \mainpage libjdksmidi, a MIDI C++ Library 65 | 66 | \section overview Overview 67 | 68 | This is the Overview section. The MIDI Library allows one to parse, generate MIDI and Standard 69 | MIDI Files easily. 70 | 71 | \section history History 72 | 73 | 74 | 75 | \section theory Theory of Operation 76 | 77 | \section limitations Limitations 78 | 79 | \section future The Future 80 | 81 | */ 82 | 83 | #ifdef WIN32 84 | #pragma warning(disable: 4996) // to take away "function was declared deprecated" warnings 85 | #pragma warning(disable: 4355) // 'this' used in base member initializer list 86 | #endif 87 | 88 | } 89 | 90 | #include "jdksmidi/utils.h" 91 | 92 | #endif 93 | 94 | -------------------------------------------------------------------------------- /libs/jdksmidi/include/jdksmidi/keysig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjdksmidi-2004 C++ Class Library for MIDI 3 | * 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 5 | * www.jdkoftinoff.com 6 | * jeffk@jdkoftinoff.com 7 | * 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | /* 25 | ** Copyright 1986 to 1998 By J.D. Koftinoff Software, Ltd. 26 | ** 27 | ** All rights reserved. 28 | ** 29 | ** No one may duplicate this source code in any form for any reason 30 | ** without the written permission given by J.D. Koftinoff Software, Ltd. 31 | ** 32 | */ 33 | 34 | #ifndef JDKSMIDI_KEYSIG_H 35 | #define JDKSMIDI_KEYSIG_H 36 | 37 | #include "jdksmidi/midi.h" 38 | 39 | namespace jdksmidi 40 | { 41 | 42 | enum MIDIAccidentalType 43 | { 44 | ACCFlat = 0, 45 | ACCNatural, 46 | ACCSharp 47 | }; 48 | 49 | class MIDIKeySignature 50 | { 51 | public: 52 | 53 | MIDIKeySignature(); 54 | MIDIKeySignature ( const MIDIKeySignature &k ); 55 | 56 | void Reset(); 57 | 58 | 59 | bool IsMajor() 60 | { 61 | return major; 62 | } 63 | 64 | void SetSharpFlats ( int sf, bool maj = true ) 65 | { 66 | sharp_flat = sf; 67 | major = maj; 68 | Reset(); 69 | } 70 | 71 | int GetSharpFlats() 72 | { 73 | return sharp_flat; 74 | } 75 | 76 | MIDIAccidentalType GetNoteStatus ( int white_note ) 77 | { 78 | return state[white_note%7]; 79 | } 80 | 81 | 82 | bool ConvertMIDINote ( int in_note, int *out_note ); 83 | 84 | protected: 85 | 86 | bool ProcessWhiteNote ( int in_note, int *out_note ); 87 | bool ProcessBlackNote ( int in_note, int *out_note ); 88 | 89 | MIDIAccidentalType state[7]; 90 | bool use_sharps; 91 | int sharp_flat; 92 | bool major; 93 | 94 | static int sharp_list[7]; 95 | static int flat_list[7]; 96 | 97 | 98 | }; 99 | } 100 | 101 | #endif 102 | 103 | 104 | -------------------------------------------------------------------------------- /libs/jdksmidi/include/jdksmidi/parser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjdksmidi-2004 C++ Class Library for MIDI 3 | * 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 5 | * www.jdkoftinoff.com 6 | * jeffk@jdkoftinoff.com 7 | * 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | /* 25 | ** Copyright 1986 to 1998 By J.D. Koftinoff Software, Ltd. 26 | ** 27 | ** All rights reserved. 28 | ** 29 | ** No one may duplicate this source code in any form for any reason 30 | ** without the written permission given by J.D. Koftinoff Software, Ltd. 31 | ** 32 | */ 33 | 34 | #ifndef JDKSMIDI_PARSER_H 35 | #define JDKSMIDI_PARSER_H 36 | 37 | #include "jdksmidi/midi.h" 38 | #include "jdksmidi/msg.h" 39 | #include "jdksmidi/sysex.h" 40 | 41 | namespace jdksmidi 42 | { 43 | 44 | class MIDIParser 45 | { 46 | public: 47 | MIDIParser ( ushort max_sysex_size = 384 ); 48 | virtual ~MIDIParser(); 49 | 50 | void Clear() 51 | { 52 | state = FIND_STATUS; 53 | } 54 | 55 | virtual bool Parse ( uchar b, MIDIMessage *msg ); 56 | 57 | MIDISystemExclusive *GetSystemExclusive() const 58 | { 59 | return sysex; 60 | } 61 | 62 | protected: 63 | 64 | // 65 | // The states used for parsing messages. 66 | // 67 | 68 | enum State 69 | { 70 | FIND_STATUS, // ignore data bytes 71 | FIRST_OF_ONE, // read first data byte of a one data byte msg 72 | FIRST_OF_TWO, // read first data byte of two data byte msg 73 | SECOND_OF_TWO, // read second data byte of two data byte msg 74 | FIRST_OF_ONE_NORUN, // read one byte message, do not allow 75 | // running status (for MTC) 76 | SYSEX_DATA // read sysex data byte 77 | }; 78 | 79 | MIDIMessage tmp_msg; 80 | MIDISystemExclusive *sysex; 81 | State state; 82 | 83 | bool ParseSystemByte ( uchar b, MIDIMessage *msg ); 84 | bool ParseDataByte ( uchar b, MIDIMessage *msg ); 85 | void ParseStatusByte ( uchar b ); 86 | }; 87 | 88 | 89 | } 90 | 91 | #endif 92 | 93 | 94 | -------------------------------------------------------------------------------- /libs/jdksmidi/src/jdksmidi_sysex.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * libjdksmidi-2004 C++ Class Library for MIDI 3 | * 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 5 | * www.jdkoftinoff.com 6 | * jeffk@jdkoftinoff.com 7 | * 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | /* 25 | ** Copyright 1986 to 1998 By J.D. Koftinoff Software, Ltd. 26 | ** 27 | ** All rights reserved. 28 | ** 29 | ** No one may duplicate this source code in any form for any reason 30 | ** without the written permission given by J.D. Koftinoff Software, Ltd. 31 | ** 32 | */ 33 | // 34 | // Copyright (C) 2010 V.R.Madgazin 35 | // www.vmgames.com vrm@vmgames.com 36 | // 37 | 38 | #include "jdksmidi/world.h" 39 | #include "jdksmidi/sysex.h" 40 | 41 | #ifndef DEBUG_MDSYSEX 42 | # define DEBUG_MDSYSEX 0 43 | #endif 44 | 45 | #if DEBUG_MDSYSEX 46 | # undef DBG 47 | # define DBG(a) a 48 | #endif 49 | 50 | namespace jdksmidi 51 | { 52 | 53 | MIDISystemExclusive::MIDISystemExclusive ( int size_ ) 54 | { 55 | ENTER ( "MIDISystemExclusive::MIDISystemExclusive" ); 56 | buf = new uchar[size_]; 57 | 58 | if ( buf ) 59 | max_len = size_; 60 | 61 | else 62 | max_len = 0; 63 | 64 | cur_len = 0; 65 | chk_sum = 0; 66 | deletable = true; 67 | } 68 | 69 | MIDISystemExclusive::MIDISystemExclusive ( const MIDISystemExclusive &e ) 70 | { 71 | buf = new unsigned char [e.max_len]; 72 | max_len = e.max_len; 73 | cur_len = e.cur_len; 74 | chk_sum = e.chk_sum; 75 | deletable = true; 76 | 77 | for ( int i = 0; i < cur_len; ++i ) 78 | { 79 | buf[i] = e.buf[i]; 80 | } 81 | } 82 | 83 | MIDISystemExclusive::~MIDISystemExclusive() 84 | { 85 | ENTER ( "MIDISystemExclusive::~MIDISystemExclusive" ); 86 | 87 | if ( deletable ) 88 | { 89 | jdks_safe_delete_array( buf ); 90 | } 91 | } 92 | 93 | bool operator == ( const MIDISystemExclusive &e1, const MIDISystemExclusive &e2 ) 94 | { 95 | if ( e1.cur_len != e2.cur_len ) 96 | return false; 97 | 98 | if ( e1.cur_len == 0 ) 99 | return true; 100 | 101 | return memcmp( e1.buf, e2.buf, e1.cur_len ) == 0 ; 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /libs/jdksmidi/include/jdksmidi/matrix.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjdksmidi-2004 C++ Class Library for MIDI 3 | * 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 5 | * www.jdkoftinoff.com 6 | * jeffk@jdkoftinoff.com 7 | * 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | /* 25 | ** Copyright 1986 to 1998 By J.D. Koftinoff Software, Ltd. 26 | ** 27 | ** All rights reserved. 28 | ** 29 | ** No one may duplicate this source code in any form for any reason 30 | ** without the written permission given by J.D. Koftinoff Software, Ltd. 31 | ** 32 | */ 33 | 34 | #ifndef JDKSMIDI_MATRIX_H 35 | #define JDKSMIDI_MATRIX_H 36 | 37 | 38 | #include "jdksmidi/midi.h" 39 | #include "jdksmidi/msg.h" 40 | 41 | namespace jdksmidi 42 | { 43 | 44 | class MIDIMatrix 45 | { 46 | public: 47 | MIDIMatrix(); 48 | virtual ~MIDIMatrix(); 49 | 50 | virtual bool Process ( const MIDIMessage &m ); 51 | 52 | virtual void Clear(); 53 | 54 | int GetTotalCount() const 55 | { 56 | return total_count; 57 | } 58 | int GetChannelCount ( int channel ) const 59 | { 60 | return channel_count[channel]; 61 | } 62 | 63 | int GetNoteCount ( int channel, int note ) const 64 | { 65 | return note_on_count[channel][note]; 66 | } 67 | 68 | bool GetHoldPedal ( int channel ) const 69 | { 70 | return hold_pedal[channel]; 71 | } 72 | 73 | 74 | protected: 75 | virtual void DecNoteCount ( const MIDIMessage &m, int channel, int note ); 76 | virtual void IncNoteCount ( const MIDIMessage &m, int channel, int note ); 77 | virtual void ClearChannel ( int channel ); 78 | virtual void OtherMessage ( const MIDIMessage &m ); 79 | 80 | void SetNoteCount ( unsigned char chan, unsigned char note, unsigned char val ) 81 | { 82 | note_on_count[chan][note] = val; 83 | } 84 | void SetChannelCount ( unsigned char chan, int val ) 85 | { 86 | channel_count[chan] = val; 87 | } 88 | 89 | private: 90 | unsigned char note_on_count[16][128]; 91 | int channel_count[16]; 92 | bool hold_pedal[16]; 93 | int total_count; 94 | }; 95 | 96 | } 97 | 98 | 99 | #endif 100 | 101 | 102 | -------------------------------------------------------------------------------- /addon_config.mk: -------------------------------------------------------------------------------- 1 | # All variables and this file are optional, if they are not present the PG and the 2 | # makefiles will try to parse the correct values from the file system. 3 | # 4 | # Variables that specify exclusions can use % as a wildcard to specify that anything in 5 | # that position will match. A partial path can also be specified to, for example, exclude 6 | # a whole folder from the parsed paths from the file system 7 | # 8 | # Variables can be specified using = or += 9 | # = will clear the contents of that variable both specified from the file or the ones parsed 10 | # from the file system 11 | # += will add the values to the previous ones in the file or the ones parsed from the file 12 | # system 13 | # 14 | # The PG can be used to detect errors in this file, just create a new project with this addon 15 | # and the PG will write to the console the kind of error and in which line it is 16 | 17 | meta: 18 | ADDON_NAME = ofxThreadedMidiPlayer 19 | ADDON_DESCRIPTION = Plays a midi file from disk in openFrameworks 20 | ADDON_AUTHOR = Jason Van Cleave. Reworked and updated by Roy J. Macdonald 21 | ADDON_TAGS = "midi" "sound" 22 | ADDON_URL = http://github.com/roymacdonald/ofxThreadedMidiPlayer 23 | 24 | common: 25 | # dependencies with other addons, a list of them separated by spaces 26 | # or use += in several lines 27 | ADDON_DEPENDENCIES = ofxMidi 28 | 29 | # include search paths, this will be usually parsed from the file system 30 | # but if the addon or addon libraries need special search paths they can be 31 | # specified here separated by spaces or one per line using += 32 | #ADDON_INCLUDES = 33 | 34 | # any special flag that should be passed to the compiler when using this 35 | # addon 36 | # ADDON_CFLAGS = 37 | 38 | # any special flag that should be passed to the linker when using this 39 | # addon, also used for system libraries with -lname 40 | # ADDON_LDFLAGS = 41 | 42 | # linux only, any library that should be included in the project using 43 | # pkg-config 44 | # ADDON_PKG_CONFIG_LIBRARIES = 45 | 46 | # osx/iOS only, any framework that should be included in the project 47 | # ADDON_FRAMEWORKS = 48 | 49 | # source files, these will be usually parsed from the file system looking 50 | # in the src folders in libs and the root of the addon. if your addon needs 51 | # to include files in different places or a different set of files per platform 52 | # they can be specified here 53 | # ADDON_SOURCES = 54 | 55 | # some addons need resources to be copied to the bin/data folder of the project 56 | # specify here any files that need to be copied, you can use wildcards like * and ? 57 | # ADDON_DATA = 58 | 59 | # when parsing the file system looking for libraries exclude this for all or 60 | # a specific platform 61 | # ADDON_LIBS_EXCLUDE = 62 | 63 | # when parsing the file system looking for sources exclude this for all or 64 | # a specific platform 65 | ADDON_SOURCES_EXCLUDE = libs/jdksmidi/examples/% 66 | 67 | # when parsing the file system looking for include paths exclude this for all or 68 | # a specific platform 69 | ADDON_INCLUDES_EXCLUDE = libs/jdksmidi/examples/% 70 | 71 | 72 | -------------------------------------------------------------------------------- /libs/jdksmidi/src/jdksmidi_file.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * libjdksmidi-2004 C++ Class Library for MIDI 3 | * 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 5 | * www.jdkoftinoff.com 6 | * jeffk@jdkoftinoff.com 7 | * 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | /* 25 | ** Copyright 1986 to 1998 By J.D. Koftinoff Software, Ltd. 26 | ** 27 | ** All rights reserved. 28 | ** 29 | ** No one may duplicate this source code in any form for any reason 30 | ** without the written permission given by J.D. Koftinoff Software, Ltd. 31 | ** 32 | */ 33 | 34 | #include "jdksmidi/world.h" 35 | 36 | #include "jdksmidi/file.h" 37 | 38 | #if DEBUG_MDFILE 39 | # undef DBG 40 | # define DBG(a) a 41 | #endif 42 | 43 | namespace jdksmidi 44 | { 45 | 46 | MIDIFile::MIDIFile() 47 | { 48 | } 49 | 50 | MIDIFile::~MIDIFile() 51 | { 52 | } 53 | 54 | unsigned long MIDIFile::ConvertTempoToFreq ( 55 | short division, 56 | MIDITempo &tempo 57 | ) 58 | { 59 | if ( division > 0 ) 60 | { 61 | long clocks_per_beat = ( long ) division * 1000; 62 | long micro_sec_per_beat = tempo.GetMIDIFileTempo() / 1000; 63 | return ( unsigned long ) clocks_per_beat / micro_sec_per_beat; 64 | } 65 | 66 | else 67 | { 68 | // TO DO: handle smpte frame rate references 69 | return 120; 70 | } 71 | } 72 | 73 | 74 | unsigned long MIDIFile::ReadVariableLengthNumber ( unsigned char **in ) 75 | { 76 | unsigned long num = 0; 77 | unsigned char *t = *in; 78 | 79 | do 80 | { 81 | num <<= 7; 82 | num |= ( *t ); 83 | } 84 | while ( ( *t++ ) & 0x80 ); 85 | 86 | *in = t; 87 | return num; 88 | } 89 | 90 | unsigned char * MIDIFile::WriteVariableLengthNumber ( unsigned long num, unsigned char *out ) 91 | { 92 | register unsigned long buffer; 93 | buffer = num & 0x7f; 94 | 95 | while ( ( num >>= 7 ) > 0 ) 96 | { 97 | buffer <<= 8; 98 | buffer |= 0x80; 99 | buffer += ( num & 0x7f ); 100 | } 101 | 102 | do 103 | { 104 | *out++ = ( unsigned char ) buffer; 105 | 106 | if ( buffer & 0x80 ) 107 | buffer >>= 8; 108 | 109 | else 110 | break; 111 | } 112 | while ( true ); 113 | 114 | return out; 115 | } 116 | 117 | } 118 | -------------------------------------------------------------------------------- /libs/jdksmidi/examples/jdksmidi_test_drv.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * libjdksmidi-2004 C++ Class Library for MIDI 3 | * 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 5 | * www.jdkoftinoff.com 6 | * jeffk@jdkoftinoff.com 7 | * 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | 25 | #include "jdksmidi/world.h" 26 | #include "jdksmidi/track.h" 27 | #include "jdksmidi/multitrack.h" 28 | #include "jdksmidi/filereadmultitrack.h" 29 | #include "jdksmidi/fileread.h" 30 | #include "jdksmidi/fileshow.h" 31 | #include "jdksmidi/sequencer.h" 32 | #include "jdksmidi/manager.h" 33 | #include "jdksmidi/driverdump.h" 34 | 35 | using namespace jdksmidi; 36 | 37 | void DumpTrackNames ( MIDISequencer *seq ) 38 | { 39 | fprintf ( stdout, "TEMPO = %f\n", 40 | seq->GetTrackState ( 0 )->tempobpm 41 | ); 42 | 43 | for ( int i = 0; i < seq->GetNumTracks(); ++i ) 44 | { 45 | fprintf ( stdout, "TRK #%2d : NAME = '%s'\n", 46 | i, 47 | seq->GetTrackState ( i )->track_name 48 | ); 49 | } 50 | } 51 | 52 | 53 | void PlayDumpManager ( MIDIManager *mgr ) 54 | { 55 | MIDISequencer *seq = mgr->GetSeq(); 56 | double pretend_clock_time = 0.0; 57 | seq->GoToTime ( ( unsigned long ) pretend_clock_time ); 58 | mgr->SeqPlay(); 59 | // simulate a clock going forward with 10ms resolution for 1 minute 60 | 61 | for ( pretend_clock_time = 0.0; pretend_clock_time < 60.0 * 1000.0; pretend_clock_time += 100 ) 62 | { 63 | mgr->GetDriver()->TimeTick ( ( unsigned long ) pretend_clock_time ); 64 | } 65 | 66 | mgr->SeqStop(); 67 | mgr->GetDriver()->AllNotesOff(); 68 | } 69 | 70 | 71 | int main ( int argc, char **argv ) 72 | { 73 | if ( argc > 1 ) 74 | { 75 | MIDIFileReadStreamFile rs ( argv[1] ); 76 | MIDIMultiTrack tracks ( 64 ); 77 | MIDIFileReadMultiTrack track_loader ( &tracks ); 78 | MIDIFileRead reader ( &rs, &track_loader ); 79 | MIDISequencerGUIEventNotifierText gui ( stdout ); 80 | MIDISequencer seq ( &tracks, &gui ); 81 | MIDIDriverDump driver ( 128, stdout ); 82 | MIDIManager mgr ( &driver, &gui ); 83 | reader.Parse(); 84 | seq.GoToZero(); 85 | mgr.SetSeq ( &seq ); 86 | DumpTrackNames ( &seq ); 87 | PlayDumpManager ( &mgr ); 88 | } 89 | 90 | return 0; 91 | } 92 | -------------------------------------------------------------------------------- /libs/jdksmidi/src/jdksmidi_midi.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * libjdksmidi-2004 C++ Class Library for MIDI 3 | * 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 5 | * www.jdkoftinoff.com 6 | * jeffk@jdkoftinoff.com 7 | * 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | /* 25 | ** Copyright 1986 to 1998 By J.D. Koftinoff Software, Ltd. 26 | ** 27 | ** All rights reserved. 28 | ** 29 | ** No one may duplicate this source code in any form for any reason 30 | ** without the written permission given by J.D. Koftinoff Software, Ltd. 31 | ** 32 | */ 33 | // 34 | // Copyright (C) 2010 V.R.Madgazin 35 | // www.vmgames.com vrm@vmgames.com 36 | // 37 | 38 | #include "jdksmidi/world.h" 39 | 40 | #include "jdksmidi/midi.h" 41 | 42 | namespace jdksmidi 43 | { 44 | 45 | const int lut_msglen[16] = 46 | { 47 | 0, 0, 0, 0, 0, 0, 0, 0, 48 | 3, // 0x80=note off, 3 bytes 49 | 3, // 0x90=note on, 3 bytes 50 | 3, // 0xA0=poly pressure, 3 bytes 51 | 3, // 0xB0=control change, 3 bytes 52 | 2, // 0xC0=program change, 2 bytes 53 | 2, // 0xD0=channel pressure, 2 bytes 54 | 3, // 0xE0=pitch bend, 3 bytes 55 | -1 // 0xF0=other things. may vary. 56 | }; 57 | 58 | const int lut_sysmsglen[16] = 59 | { 60 | // System Common Messages 61 | -1, // 0xF0=Normal SysEx Events start. may vary 62 | 2, // 0xF1=MIDI Time Code. 2 bytes 63 | 3, // 0xF2=MIDI Song position. 3 bytes 64 | 2, // 0xF3=MIDI Song Select. 2 bytes. 65 | 0, // 0xF4=undefined. (Reserved) 66 | 0, // 0xF5=undefined. (Reserved) 67 | 1, // 0xF6=TUNE Request. 1 byte 68 | 0, // 0xF7=Normal or Divided SysEx Events end. 69 | // -1, // 0xF7=Divided or Authorization SysEx Events. may vary 70 | 71 | // System Real-Time Messages 72 | 1, // 0xF8=timing clock. 1 byte 73 | 1, // 0xF9=proposed measure end? (Reserved) 74 | 1, // 0xFA=start. 1 byte 75 | 1, // 0xFB=continue. 1 byte 76 | 1, // 0xFC=stop. 1 byte 77 | 0, // 0xFD=undefined. (Reserved) 78 | 1, // 0xFE=active sensing. 1 byte 79 | // 1, // 0xFF=reset. 1 byte 80 | 81 | 3 // 0xFF=not reset, but a META-EVENT, which is always 3 bytes 82 | // TODO@VRM // not valid jet? see comment to midi.h function: 83 | // inline int GetSystemMessageLength ( unsigned char stat ) 84 | }; 85 | 86 | 87 | const bool lut_is_white[12] = 88 | { 89 | // C C# D D# E F F# G G# A A# B 90 | 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1 91 | }; 92 | 93 | 94 | 95 | } 96 | -------------------------------------------------------------------------------- /libs/jdksmidi/include/jdksmidi/driverwin32.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjdksmidi-2004 C++ Class Library for MIDI 3 | * 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 5 | * www.jdkoftinoff.com 6 | * jeffk@jdkoftinoff.com 7 | * 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | 25 | #ifndef JDKSMIDI_DRIVERWIN32_H 26 | #define JDKSMIDI_DRIVERWIN32_H 27 | 28 | #include "jdksmidi/driver.h" 29 | #include "jdksmidi/sequencer.h" 30 | 31 | #ifdef WIN32 32 | #include "windows.h" 33 | #include "mmsystem.h" 34 | 35 | namespace jdksmidi 36 | { 37 | 38 | class MIDISequencerGUIEventNotifierWin32 : 39 | public MIDISequencerGUIEventNotifier 40 | { 41 | 42 | public: 43 | 44 | MIDISequencerGUIEventNotifierWin32 ( 45 | HWND w, 46 | DWORD wmmsg, 47 | WPARAM wparam_value_ = 0 48 | ); 49 | 50 | virtual ~MIDISequencerGUIEventNotifierWin32(); 51 | 52 | virtual void Notify ( const MIDISequencer *seq, MIDISequencerGUIEvent e ); 53 | virtual bool GetEnable() const; 54 | virtual void SetEnable ( bool f ); 55 | 56 | private: 57 | 58 | HWND dest_window; 59 | DWORD window_msg; 60 | WPARAM wparam_value; 61 | bool en; 62 | }; 63 | 64 | 65 | 66 | class MIDIDriverWin32 : public MIDIDriver 67 | { 68 | 69 | public: 70 | 71 | MIDIDriverWin32 ( int queue_size ); 72 | virtual ~MIDIDriverWin32(); 73 | 74 | void ResetMIDIOut(); 75 | 76 | bool StartTimer ( int resolution_ms ); 77 | bool OpenMIDIInPort ( int id ); 78 | bool OpenMIDIOutPort ( int id ); 79 | 80 | void StopTimer(); 81 | void CloseMIDIInPort(); 82 | void CloseMIDIOutPort(); 83 | 84 | 85 | bool HardwareMsgOut ( const MIDITimedBigMessage &msg ); 86 | 87 | protected: 88 | 89 | static void CALLBACK win32_timer ( 90 | UINT wTimerID, 91 | UINT msg, 92 | DWORD dwUser, 93 | DWORD dw1, 94 | DWORD dw2 95 | ); 96 | 97 | static void CALLBACK win32_midi_in ( 98 | HMIDIIN hMidiIn, 99 | UINT wMsg, 100 | DWORD dwInstance, 101 | DWORD dwParam1, 102 | DWORD dwParam2 103 | ); 104 | 105 | HMIDIIN in_handle; 106 | HMIDIOUT out_handle; 107 | int timer_id; 108 | int timer_res; 109 | 110 | bool in_open; 111 | bool out_open; 112 | bool timer_open; 113 | }; 114 | 115 | 116 | } 117 | #endif 118 | 119 | #endif 120 | -------------------------------------------------------------------------------- /libs/jdksmidi/include/jdksmidi/manager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjdksmidi-2004 C++ Class Library for MIDI 3 | * 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 5 | * www.jdkoftinoff.com 6 | * jeffk@jdkoftinoff.com 7 | * 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | 25 | #ifndef JDKSMIDI_MANAGER_H 26 | #define JDKSMIDI_MANAGER_H 27 | 28 | #include "jdksmidi/msg.h" 29 | #include "jdksmidi/sysex.h" 30 | #include "jdksmidi/driver.h" 31 | #include "jdksmidi/sequencer.h" 32 | #include "jdksmidi/tick.h" 33 | 34 | namespace jdksmidi 35 | { 36 | 37 | class MIDIManager : public MIDITick 38 | { 39 | public: 40 | MIDIManager ( 41 | MIDIDriver *drv, 42 | MIDISequencerGUIEventNotifier *n = 0, 43 | MIDISequencer *seq_ = 0 44 | ); 45 | 46 | virtual ~MIDIManager(); 47 | 48 | void Reset(); 49 | 50 | // to set and get the current sequencer 51 | void SetSeq ( MIDISequencer *seq ); 52 | MIDISequencer *GetSeq(); 53 | const MIDISequencer *GetSeq() const; 54 | 55 | // to get the driver that we use 56 | MIDIDriver *GetDriver() 57 | { 58 | return driver; 59 | } 60 | 61 | 62 | // to set and get the system time offset 63 | void SetTimeOffset ( unsigned long off ); 64 | unsigned long GetTimeOffset(); 65 | 66 | // to set and get the sequencer time offset 67 | void SetSeqOffset ( unsigned long seqoff ); 68 | unsigned long GetSeqOffset(); 69 | 70 | 71 | // to manage the playback of the sequencer 72 | void SeqPlay(); 73 | void SeqStop(); 74 | void SetRepeatPlay ( 75 | bool flag, 76 | unsigned long start_measure, 77 | unsigned long end_measure 78 | ); 79 | 80 | 81 | // status request functions 82 | bool IsSeqPlay() const; 83 | bool IsSeqStop() const; 84 | bool IsSeqRepeat() const; 85 | 86 | // inherited from MIDITick 87 | virtual void TimeTick ( unsigned long sys_time ); 88 | 89 | protected: 90 | 91 | virtual void TimeTickPlayMode ( unsigned long sys_time_ ); 92 | virtual void TimeTickStopMode ( unsigned long sys_time_ ); 93 | 94 | MIDIDriver *driver; 95 | 96 | MIDISequencer *sequencer; 97 | 98 | unsigned long sys_time_offset; 99 | unsigned long seq_time_offset; 100 | 101 | volatile bool play_mode; 102 | volatile bool stop_mode; 103 | 104 | MIDISequencerGUIEventNotifier *notifier; 105 | 106 | volatile bool repeat_play_mode; 107 | long repeat_start_measure; 108 | long repeat_end_measure; 109 | 110 | 111 | }; 112 | 113 | 114 | } 115 | 116 | #endif 117 | -------------------------------------------------------------------------------- /libs/jdksmidi/include/jdksmidi/fileshow.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjdksmidi-2004 C++ Class Library for MIDI 3 | * 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 5 | * www.jdkoftinoff.com 6 | * jeffk@jdkoftinoff.com 7 | * 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | /* 25 | ** Copyright 1986 to 1998 By J.D. Koftinoff Software, Ltd. 26 | ** 27 | ** All rights reserved. 28 | ** 29 | ** No one may duplicate this source code in any form for any reason 30 | ** without the written permission given by J.D. Koftinoff Software, Ltd. 31 | ** 32 | */ 33 | // 34 | // Copyright (C) 2010 V.R.Madgazin 35 | // www.vmgames.com vrm@vmgames.com 36 | // 37 | 38 | #ifndef JDKSMIDI_FILESHOW_H 39 | #define JDKSMIDI_FILESHOW_H 40 | 41 | #include "jdksmidi/fileread.h" 42 | 43 | namespace jdksmidi 44 | { 45 | 46 | class MIDIFileShow : public MIDIFileEvents 47 | { 48 | public: 49 | MIDIFileShow ( FILE *out_, bool sqspecific_as_text_ = false ); 50 | virtual ~MIDIFileShow(); 51 | 52 | protected: 53 | 54 | virtual void show_time ( MIDIClockTime time ); 55 | 56 | virtual void mf_error ( const char * ); 57 | 58 | virtual void mf_starttrack ( int trk ); 59 | virtual void mf_endtrack ( int trk ); 60 | virtual void mf_header ( int, int, int ); 61 | 62 | 63 | // 64 | // The possible events in a MIDI Files 65 | // 66 | 67 | virtual void mf_system_mode ( const MIDITimedMessage &msg ); 68 | virtual void mf_note_on ( const MIDITimedMessage &msg ); 69 | virtual void mf_note_off ( const MIDITimedMessage &msg ); 70 | virtual void mf_poly_after ( const MIDITimedMessage &msg ); 71 | virtual void mf_bender ( const MIDITimedMessage &msg ); 72 | virtual void mf_program ( const MIDITimedMessage &msg ); 73 | virtual void mf_chan_after ( const MIDITimedMessage &msg ); 74 | virtual void mf_control ( const MIDITimedMessage &msg ); 75 | 76 | virtual bool mf_metamisc ( MIDIClockTime time, int type, int len, unsigned char *data ); 77 | virtual bool mf_timesig ( MIDIClockTime time, int, int, int, int ); 78 | virtual bool mf_tempo ( MIDIClockTime time, unsigned char a, unsigned char b, unsigned char c ); 79 | virtual bool mf_keysig ( MIDIClockTime time, int, int ); 80 | virtual bool mf_sqspecific ( MIDIClockTime time, int, unsigned char * ); 81 | virtual bool mf_text ( MIDIClockTime time, int, int, unsigned char * ); 82 | virtual bool mf_eot ( MIDIClockTime time ); 83 | virtual bool mf_sysex ( MIDIClockTime time, int type, int len, unsigned char *s ); 84 | 85 | FILE *out; 86 | int division; 87 | 88 | private: 89 | bool sqspecific_as_text; // if true print META_SEQUENCER_SPECIFIC events as text string 90 | 91 | }; 92 | 93 | } 94 | #endif 95 | 96 | -------------------------------------------------------------------------------- /libs/jdksmidi/examples/jdksmidi_test_multitrack1.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * libjdksmidi-2004 C++ Class Library for MIDI 3 | * 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 5 | * www.jdkoftinoff.com 6 | * jeffk@jdkoftinoff.com 7 | * 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | // 25 | // Copyright (C) 2010 V.R.Madgazin 26 | // www.vmgames.com vrm@vmgames.com 27 | // 28 | 29 | #include "jdksmidi/world.h" 30 | #include "jdksmidi/track.h" 31 | #include "jdksmidi/multitrack.h" 32 | #include "jdksmidi/filereadmultitrack.h" 33 | #include "jdksmidi/fileread.h" 34 | #include "jdksmidi/fileshow.h" 35 | 36 | using namespace jdksmidi; 37 | 38 | 39 | void DumpMIDITimedBigMessage ( const MIDITimedBigMessage *msg ) 40 | { 41 | if ( msg ) 42 | { 43 | char msgbuf[1024]; 44 | fprintf ( stdout, "%8ld : %s\n", msg->GetTime(), msg->MsgToText ( msgbuf ) ); 45 | 46 | if ( msg->IsSystemExclusive() ) 47 | { 48 | fprintf ( stdout, "\tSYSEX length: %d\n", msg->GetSysEx()->GetLength() ); 49 | } 50 | } 51 | } 52 | 53 | void DumpMIDITrack ( MIDITrack *t ) 54 | { 55 | MIDITimedBigMessage *msg; 56 | 57 | for ( int i = 0; i < t->GetNumEvents(); ++i ) 58 | { 59 | msg = t->GetEventAddress ( i ); 60 | DumpMIDITimedBigMessage ( msg ); 61 | } 62 | } 63 | 64 | void DumpAllTracks ( MIDIMultiTrack *mlt ) 65 | { 66 | for ( int i = 0; i < mlt->GetNumTracks(); ++i ) 67 | { 68 | if ( mlt->GetTrack ( i )->GetNumEvents() > 0 ) 69 | { 70 | fprintf ( stdout, "DUMP OF TRACK #%2d:\n", i ); 71 | DumpMIDITrack ( mlt->GetTrack ( i ) ); 72 | fprintf ( stdout, "\n" ); 73 | } 74 | } 75 | } 76 | 77 | 78 | void DumpMIDIMultiTrack ( MIDIMultiTrack *mlt ) 79 | { 80 | MIDIMultiTrackIterator i ( mlt ); 81 | const MIDITimedBigMessage *msg; 82 | i.GoToTime ( 0 ); 83 | 84 | do 85 | { 86 | int trk_num; 87 | 88 | if ( i.GetCurEvent ( &trk_num, &msg ) ) 89 | { 90 | fprintf ( stdout, "#%2d - ", trk_num ); 91 | DumpMIDITimedBigMessage ( msg ); 92 | } 93 | } 94 | while ( i.GoToNextEvent() ); 95 | } 96 | 97 | 98 | 99 | int main ( int argc, char **argv ) 100 | { 101 | if ( argc > 1 ) 102 | { 103 | MIDIFileReadStreamFile rs ( argv[1] ); 104 | MIDIMultiTrack tracks; 105 | MIDIFileReadMultiTrack track_loader ( &tracks ); 106 | MIDIFileRead reader ( &rs, &track_loader ); 107 | reader.Parse(); 108 | DumpMIDIMultiTrack ( &tracks ); 109 | } 110 | 111 | return 0; 112 | } 113 | -------------------------------------------------------------------------------- /libs/jdksmidi/examples/jdksmidi_test_parse.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * libjdksmidi-2004 C++ Class Library for MIDI 3 | * 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 5 | * www.jdkoftinoff.com 6 | * jeffk@jdkoftinoff.com 7 | * 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | // 25 | // Copyright (C) 2010 V.R.Madgazin 26 | // www.vmgames.com vrm@vmgames.com 27 | // 28 | 29 | #include "jdksmidi/world.h" 30 | #include "jdksmidi/midi.h" 31 | #include "jdksmidi/msg.h" 32 | #include "jdksmidi/sysex.h" 33 | #include "jdksmidi/parser.h" 34 | 35 | using namespace jdksmidi; 36 | 37 | 38 | void PrintSysEx ( FILE *f, MIDISystemExclusive *ex, bool normal_sysex) 39 | { 40 | int l = ex->GetLength(); 41 | 42 | if ( normal_sysex ) 43 | { 44 | fprintf ( f, "Normal System-Exclusive message Len=%d", l ); 45 | } 46 | else 47 | { 48 | fprintf ( f, "Authorization System-Exclusive message Len=%d", l ); 49 | } 50 | 51 | for ( int i = 0; i < l; ++i ) 52 | { 53 | if ( ( ( i ) % 20 ) == 0 ) 54 | { 55 | fprintf ( f, "\n" ); 56 | } 57 | 58 | fprintf ( f, "%02x ", ( int ) ex->GetData ( i ) ); 59 | } 60 | 61 | fprintf ( f, "\n" ); 62 | fflush ( f ); 63 | } 64 | 65 | 66 | void PrintMsg ( FILE *f, MIDIMessage *m ) 67 | { 68 | int l = m->GetLength(); 69 | fprintf ( f, "Msg : " ); 70 | 71 | if ( l == 1 ) 72 | { 73 | fprintf ( f, " %02x \t=", m->GetStatus() ); 74 | } 75 | 76 | else if ( l == 2 ) 77 | { 78 | fprintf ( f, " %02x %02x \t=", m->GetStatus(), m->GetByte1() ); 79 | } 80 | 81 | else if ( l == 3 ) 82 | { 83 | fprintf ( f, " %02x %02x %02x \t=", m->GetStatus(), m->GetByte1(), m->GetByte2() ); 84 | } 85 | 86 | char buf[129]; 87 | m->MsgToText ( buf ); 88 | fprintf ( f, "%s\n", buf ); 89 | fflush ( f ); 90 | } 91 | 92 | 93 | int main ( int argc, char ** argv ) 94 | { 95 | fprintf ( stdout, "mdparse:\n" ); 96 | MIDIParser p ( 32 * 1024 ); 97 | MIDIMessage m; 98 | FILE *f = stdin; 99 | 100 | while ( !feof ( f ) ) 101 | { 102 | int c = fgetc ( f ); 103 | 104 | if ( c == EOF ) 105 | break; 106 | 107 | if ( p.Parse ( ( uchar ) c, &m ) ) 108 | { 109 | if ( m.IsSystemExclusive() ) 110 | { 111 | PrintSysEx ( stdout, p.GetSystemExclusive(), m.IsSysExN() ); 112 | } 113 | 114 | else 115 | { 116 | PrintMsg ( stdout, &m ); 117 | } 118 | } 119 | } 120 | 121 | return 0; 122 | } 123 | 124 | -------------------------------------------------------------------------------- /libs/jdksmidi/src/jdksmidi_filewritemultitrack.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * libjdksmidi-2004 C++ Class Library for MIDI 3 | * 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 5 | * www.jdkoftinoff.com 6 | * jeffk@jdkoftinoff.com 7 | * 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | // 25 | // Copyright (C) 2010 V.R.Madgazin 26 | // www.vmgames.com vrm@vmgames.com 27 | // 28 | 29 | #include "jdksmidi/world.h" 30 | #include "jdksmidi/filewritemultitrack.h" 31 | 32 | namespace jdksmidi 33 | { 34 | 35 | MIDIFileWriteMultiTrack::MIDIFileWriteMultiTrack ( 36 | const MIDIMultiTrack *mlt_, 37 | MIDIFileWriteStream *strm_ 38 | ) 39 | : 40 | multitrack ( mlt_ ), 41 | writer ( strm_ ) 42 | { 43 | } 44 | 45 | MIDIFileWriteMultiTrack::~MIDIFileWriteMultiTrack() 46 | { 47 | } 48 | 49 | bool MIDIFileWriteMultiTrack::Write ( int num_tracks, int division ) 50 | { 51 | if ( !PreWrite() ) 52 | return false; 53 | 54 | // first, write the header. 55 | writer.WriteFileHeader ( ( num_tracks > 1 )? 1:0, num_tracks, division ); 56 | // now write each track 57 | 58 | for ( int i = 0; i < num_tracks; ++i ) 59 | { 60 | const MIDITrack *t = multitrack->GetTrack ( i ); 61 | 62 | if ( !t || !t->EventsOrderOK() ) // time of events out of order: t->SortEventsOrder() must be done externally 63 | return false; 64 | 65 | writer.WriteTrackHeader ( 0 ); // will be rewritten later 66 | 67 | const MIDITimedBigMessage *ev; 68 | MIDIClockTime ev_time = 0; 69 | 70 | for ( int event_num = 0; event_num < t->GetNumEvents(); ++event_num ) 71 | { 72 | ev = t->GetEventAddress ( event_num ); 73 | if ( !ev ) 74 | return false; 75 | 76 | // don't write to midifile NoOp msgs 77 | if ( ev->IsNoOp() ) 78 | continue; 79 | 80 | ev_time = ev->GetTime(); 81 | 82 | // ignore all msgs after EndOfTrack 83 | if ( ev->IsDataEnd() ) 84 | break; 85 | 86 | // write all other msgs 87 | writer.WriteEvent ( *ev ); 88 | 89 | if ( writer.ErrorOccurred() ) 90 | return false; 91 | } 92 | 93 | writer.WriteEndOfTrack ( ev_time ); 94 | writer.RewriteTrackLength(); 95 | } 96 | 97 | if ( !PostWrite() ) 98 | return false; 99 | 100 | return true; 101 | } 102 | 103 | 104 | bool MIDIFileWriteMultiTrack::PreWrite() 105 | { 106 | return true; 107 | } 108 | 109 | bool MIDIFileWriteMultiTrack::PostWrite() 110 | { 111 | return true; 112 | } 113 | 114 | 115 | 116 | } 117 | -------------------------------------------------------------------------------- /libs/jdksmidi/include/jdksmidi/utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | libjdksmidi C++ Class Library for MIDI addendum 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; 16 | if not, write to the Free Software Foundation, Inc., 17 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | // 20 | // Copyright (C) 2010 V.R.Madgazin 21 | // www.vmgames.com 22 | // vrm@vmgames.com 23 | // 24 | 25 | #ifndef JDKSMIDI_UTILS_H 26 | #define JDKSMIDI_UTILS_H 27 | 28 | #include "jdksmidi/multitrack.h" 29 | 30 | namespace jdksmidi 31 | { 32 | 33 | // copy events from src to dst multitrack for time interval from 0 to max_time_sec seconds 34 | void ClipMultiTrack( const MIDIMultiTrack &src, MIDIMultiTrack &dst, double max_time_sec ); 35 | 36 | // copy src to dst without all ignore_channel events 37 | void CopyWithoutChannel( const MIDIMultiTrack &src, MIDIMultiTrack &dst, int ignore_channel ); 38 | 39 | // skip pause before really start of music, ignore channel 0...15 events (9 for percussion) 40 | void CompressStartPause( const MIDIMultiTrack &src, MIDIMultiTrack &dst, int ignore_channel = -1 ); 41 | 42 | // convert src music to dst solo melody, ignore channel 0...15 events (9 for percussion) 43 | // this simple code works better for src MultiTrack with 1 track, 44 | // if not, we can make before the call of CollapseMultiTrack() 45 | void SoloMelodyConverter( const MIDIMultiTrack &src, MIDIMultiTrack &dst, int ignore_channel = -1 ); 46 | 47 | // collapse all tracks from src to dst track 0 48 | void CollapseMultiTrack( const MIDIMultiTrack &src, MIDIMultiTrack &dst ); 49 | 50 | // collapse all src tracks to track 0 and than expand it to dst tracks 0-17: 51 | // midi channel events to tracks 1-16, and all other types of events to track 0 52 | void CollapseAndExpandMultiTrack( const MIDIMultiTrack &src, MIDIMultiTrack &dst ); 53 | 54 | bool ReadMidiFile(const char *file, MIDIMultiTrack &dst); 55 | 56 | // write multitrack to midi file; note that src must contain right clks_per_beat value 57 | bool WriteMidiFile(const MIDIMultiTrack &src, const char *file, bool use_running_status = true); 58 | 59 | double GetMusicDurationInSeconds(const MIDIMultiTrack &mt); 60 | 61 | std::string MultiTrackAsText(const MIDIMultiTrack &mt); 62 | 63 | std::string EventAsText(const MIDITimedBigMessage &ev); 64 | 65 | // add ticks time to all last track events (i.e. to all events with max time value) 66 | void LastEventsProlongation( MIDIMultiTrack &tracks, int track_num, MIDIClockTime add_ticks ); 67 | 68 | // add "pause" after last track event 69 | bool AddEndingPause( MIDIMultiTrack &tracks, int track_num, MIDIClockTime pause_ticks ); 70 | 71 | template inline void jdks_safe_delete_object(I *&obj) 72 | { 73 | delete obj; 74 | obj = 0; 75 | } 76 | 77 | template inline void jdks_safe_delete_array(I *&arr) 78 | { 79 | delete [] arr; 80 | arr = 0; 81 | } 82 | 83 | template inline int jdks_float2int(D d) 84 | { 85 | return int( d >= D(0.) ? ( d + D(0.5) ):( d - D(0.5) ) ); 86 | } 87 | 88 | } 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /libs/jdksmidi/include/jdksmidi/process.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjdksmidi-2004 C++ Class Library for MIDI 3 | * 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 5 | * www.jdkoftinoff.com 6 | * jeffk@jdkoftinoff.com 7 | * 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | 25 | #ifndef JDKSMIDI_PROCESS_H 26 | #define JDKSMIDI_PROCESS_H 27 | 28 | #include "jdksmidi/msg.h" 29 | #include "jdksmidi/sysex.h" 30 | 31 | namespace jdksmidi 32 | { 33 | 34 | class MIDIProcessor; 35 | class MIDIMultiProcessor; 36 | class MIDIProcessorTransposer; 37 | class MIDIProcessor; 38 | 39 | 40 | class MIDIProcessor 41 | { 42 | public: 43 | MIDIProcessor(); 44 | virtual ~MIDIProcessor(); 45 | 46 | virtual bool Process ( MIDITimedBigMessage *msg ) = 0; 47 | }; 48 | 49 | class MIDIMultiProcessor : public MIDIProcessor 50 | { 51 | public: 52 | MIDIMultiProcessor ( int num_processors ); 53 | virtual ~MIDIMultiProcessor(); 54 | 55 | // MIDIProcessors given to a MIDIMultiProcessor are NOT owned 56 | // by MIDIMultiProcessor. 57 | 58 | void SetProcessor ( int position, MIDIProcessor *proc ) 59 | { 60 | processors[position] = proc; 61 | } 62 | 63 | MIDIProcessor *GetProcessor ( int position ) 64 | { 65 | return processors[position]; 66 | } 67 | 68 | const MIDIProcessor *GetProcessor ( int position ) const 69 | { 70 | return processors[position]; 71 | } 72 | 73 | virtual bool Process ( MIDITimedBigMessage *msg ); 74 | 75 | private: 76 | MIDIProcessor **processors; 77 | int num_processors; 78 | }; 79 | 80 | class MIDIProcessorTransposer : public MIDIProcessor 81 | { 82 | public: 83 | MIDIProcessorTransposer(); 84 | virtual ~MIDIProcessorTransposer(); 85 | 86 | void SetTransposeChannel ( int chan, int trans ) 87 | { 88 | trans_amount[chan] = trans; 89 | } 90 | 91 | int GetTransposeChannel ( int chan ) const 92 | { 93 | return trans_amount[chan]; 94 | } 95 | 96 | void SetAllTranspose ( int trans ); 97 | 98 | virtual bool Process ( MIDITimedBigMessage *msg ); 99 | private: 100 | int trans_amount[16]; 101 | }; 102 | 103 | class MIDIProcessorRechannelizer : public MIDIProcessor 104 | { 105 | public: 106 | MIDIProcessorRechannelizer(); 107 | virtual ~MIDIProcessorRechannelizer(); 108 | 109 | void SetRechanMap ( int src_chan, int dest_chan ) 110 | { 111 | rechan_map[src_chan] = dest_chan; 112 | } 113 | 114 | int GetRechanMap ( int src_chan ) const 115 | { 116 | return rechan_map[src_chan]; 117 | } 118 | 119 | void SetAllRechan ( int dest_chan ); 120 | 121 | virtual bool Process ( MIDITimedBigMessage *msg ); 122 | 123 | private: 124 | 125 | int rechan_map[16]; 126 | }; 127 | } 128 | 129 | #endif 130 | -------------------------------------------------------------------------------- /libs/jdksmidi/include/jdksmidi/filereadmultitrack.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjdksmidi-2004 C++ Class Library for MIDI 3 | * 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 5 | * www.jdkoftinoff.com 6 | * jeffk@jdkoftinoff.com 7 | * 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | /* 25 | ** Copyright 1986 to 1998 By J.D. Koftinoff Software, Ltd. 26 | ** 27 | ** All rights reserved. 28 | ** 29 | ** No one may duplicate this source code in any form for any reason 30 | ** without the written permission given by J.D. Koftinoff Software, Ltd. 31 | ** 32 | */ 33 | // 34 | // Copyright (C) 2010 V.R.Madgazin 35 | // www.vmgames.com vrm@vmgames.com 36 | // 37 | 38 | #ifndef JDKSMIDI_FILEREADMULTITRACK_H 39 | #define JDKSMIDI_FILEREADMULTITRACK_H 40 | 41 | #include "jdksmidi/midi.h" 42 | #include "jdksmidi/msg.h" 43 | #include "jdksmidi/sysex.h" 44 | #include "jdksmidi/file.h" 45 | #include "jdksmidi/fileread.h" 46 | #include "jdksmidi/multitrack.h" 47 | 48 | namespace jdksmidi 49 | { 50 | 51 | class MIDIFileReadMultiTrack : public MIDIFileEvents 52 | { 53 | public: 54 | MIDIFileReadMultiTrack ( MIDIMultiTrack *mlttrk ); 55 | 56 | virtual ~MIDIFileReadMultiTrack(); 57 | 58 | 59 | // 60 | // The possible events in a MIDI Files 61 | // 62 | 63 | virtual bool mf_metamisc ( MIDIClockTime time, int type, int len, unsigned char *data ); 64 | virtual bool mf_timesig ( MIDIClockTime time, int, int, int, int ); 65 | virtual bool mf_tempo ( MIDIClockTime time, unsigned char a, unsigned char b, unsigned char c ); 66 | virtual bool mf_keysig ( MIDIClockTime time, int, int ); 67 | virtual bool mf_sqspecific ( MIDIClockTime time, int, unsigned char * ); 68 | virtual bool mf_text ( MIDIClockTime time, int, int, unsigned char * ); 69 | virtual bool mf_eot ( MIDIClockTime time ); 70 | virtual bool mf_sysex ( MIDIClockTime time, int type, int len, unsigned char *s ); 71 | 72 | // 73 | // the following methods are to be overridden for your specific purpose 74 | // 75 | 76 | virtual void mf_error ( const char * ); 77 | virtual void mf_starttrack ( int trk ); 78 | virtual void mf_endtrack ( int trk ); 79 | virtual void mf_header ( int, int, int ); 80 | 81 | // 82 | // Higher level dispatch functions 83 | // 84 | 85 | virtual bool ChanMessage ( const MIDITimedMessage &msg ); 86 | // test and sort events temporal order in all tracks 87 | virtual void SortEventsOrder(); 88 | 89 | protected: 90 | 91 | // return false if dest_track absent or no space for event 92 | bool AddEventToMultiTrack ( const MIDITimedMessage &msg, MIDISystemExclusive *sysex, int dest_track ); 93 | 94 | MIDIMultiTrack *multitrack; 95 | int cur_track; 96 | 97 | int the_format; 98 | int num_tracks; 99 | int division; 100 | 101 | }; 102 | 103 | } 104 | 105 | 106 | #endif 107 | -------------------------------------------------------------------------------- /libs/jdksmidi/examples/jdksmidi_test_multitrack.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * libjdksmidi-2004 C++ Class Library for MIDI 3 | * 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 5 | * www.jdkoftinoff.com 6 | * jeffk@jdkoftinoff.com 7 | * 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | // 25 | // Copyright (C) 2010 V.R.Madgazin 26 | // www.vmgames.com vrm@vmgames.com 27 | // 28 | 29 | #ifdef WIN32 30 | #include 31 | #endif 32 | 33 | #include "jdksmidi/world.h" 34 | #include "jdksmidi/track.h" 35 | #include "jdksmidi/multitrack.h" 36 | #include "jdksmidi/filereadmultitrack.h" 37 | #include "jdksmidi/fileread.h" 38 | #include "jdksmidi/fileshow.h" 39 | 40 | using namespace jdksmidi; 41 | 42 | void DumpMIDITimedBigMessage ( const MIDITimedBigMessage *msg ) 43 | { 44 | if ( msg ) 45 | { 46 | char msgbuf[1024]; 47 | fprintf ( stdout, "%8ld : %s\n", msg->GetTime(), msg->MsgToText ( msgbuf ) ); 48 | 49 | if ( msg->IsSystemExclusive() ) 50 | { 51 | fprintf ( stdout, "\tSYSEX length: %d\n", msg->GetSysEx()->GetLength() ); 52 | } 53 | } 54 | } 55 | 56 | void DumpMIDITrack ( MIDITrack *t ) 57 | { 58 | MIDITimedBigMessage *msg; 59 | 60 | for ( int i = 0; i < t->GetNumEvents(); ++i ) 61 | { 62 | msg = t->GetEventAddress ( i ); 63 | DumpMIDITimedBigMessage ( msg ); 64 | } 65 | } 66 | 67 | void DumpAllTracks ( MIDIMultiTrack *mlt ) 68 | { 69 | fprintf ( stdout , "Clocks per beat: %d\n\n", mlt->GetClksPerBeat() ); 70 | 71 | for ( int i = 0; i < mlt->GetNumTracks(); ++i ) 72 | { 73 | if ( mlt->GetTrack ( i )->GetNumEvents() > 0 ) 74 | { 75 | fprintf ( stdout, "DUMP OF TRACK #%2d:\n", i ); 76 | DumpMIDITrack ( mlt->GetTrack ( i ) ); 77 | fprintf ( stdout, "\n" ); 78 | } 79 | } 80 | } 81 | 82 | 83 | void DumpMIDIMultiTrack ( MIDIMultiTrack *mlt ) 84 | { 85 | MIDIMultiTrackIterator i ( mlt ); 86 | const MIDITimedBigMessage *msg; 87 | fprintf ( stdout , "Clocks per beat: %d\n\n", mlt->GetClksPerBeat() ); 88 | i.GoToTime ( 0 ); 89 | 90 | do 91 | { 92 | int trk_num; 93 | 94 | if ( i.GetCurEvent ( &trk_num, &msg ) ) 95 | { 96 | fprintf ( stdout, "#%2d - ", trk_num ); 97 | DumpMIDITimedBigMessage ( msg ); 98 | } 99 | } 100 | while ( i.GoToNextEvent() ); 101 | } 102 | 103 | 104 | 105 | int main ( int argc, char **argv ) 106 | { 107 | if ( argc > 1 ) 108 | { 109 | MIDIFileReadStreamFile rs ( argv[1] ); 110 | MIDIMultiTrack tracks; 111 | MIDIFileReadMultiTrack track_loader ( &tracks ); 112 | MIDIFileRead reader ( &rs, &track_loader ); 113 | reader.Parse(); 114 | DumpMIDIMultiTrack ( &tracks ); 115 | } 116 | 117 | return 0; 118 | } 119 | -------------------------------------------------------------------------------- /example-ofxThreadedMidiPlayer-playback/example-ofxThreadedMidiPlayer-playback.xcodeproj/xcshareddata/xcschemes/example-ofxThreadedMidiPlayer-playback Debug.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 51 | 52 | 58 | 59 | 60 | 61 | 62 | 63 | 69 | 70 | 76 | 77 | 78 | 79 | 81 | 82 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /example-ofxThreadedMidiPlayer-playback/example-ofxThreadedMidiPlayer-playback.xcodeproj/xcshareddata/xcschemes/example-ofxThreadedMidiPlayer-playback Release.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 51 | 52 | 58 | 59 | 60 | 61 | 62 | 63 | 69 | 70 | 76 | 77 | 78 | 79 | 81 | 82 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /libs/jdksmidi/include/jdksmidi/edittrack.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjdksmidi-2004 C++ Class Library for MIDI 3 | * 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 5 | * www.jdkoftinoff.com 6 | * jeffk@jdkoftinoff.com 7 | * 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | /* 25 | ** Copyright 1986 to 1998 By J.D. Koftinoff Software, Ltd. 26 | ** 27 | ** All rights reserved. 28 | ** 29 | ** No one may duplicate this source code in any form for any reason 30 | ** without the written permission given by J.D. Koftinoff Software, Ltd. 31 | ** 32 | */ 33 | 34 | #ifndef JDKSMIDI_EDITTRACK_H 35 | #define JDKSMIDI_EDITTRACK_H 36 | 37 | #include "jdksmidi/track.h" 38 | #include "jdksmidi/matrix.h" 39 | #include "jdksmidi/process.h" 40 | 41 | namespace jdksmidi 42 | { 43 | 44 | class MIDIEditTrackEventMatcher 45 | { 46 | public: 47 | MIDIEditTrackEventMatcher(); 48 | virtual ~MIDIEditTrackEventMatcher(); 49 | 50 | virtual bool Match ( const MIDITimedBigMessage &ev ) = 0; 51 | }; 52 | 53 | 54 | class MIDIEditTrack 55 | { 56 | public: 57 | MIDIEditTrack ( MIDITrack *track_ ); 58 | virtual ~MIDIEditTrack(); 59 | 60 | // 61 | // Process applies a MIDI process to all events that are matched 62 | // 63 | 64 | void Process ( 65 | MIDIClockTime start_time, 66 | MIDIClockTime end_time, 67 | MIDIProcessor *process, 68 | MIDIEditTrackEventMatcher *match 69 | ); 70 | 71 | // 72 | // Truncate erases all events after a certain time. then 73 | // adds appropriate note off's 74 | // 75 | void Truncate ( MIDIClockTime start_time ); 76 | 77 | 78 | // 79 | // this merge function merges two other tracks into this track. 80 | // this is the faster form of merge 81 | // 82 | void Merge ( 83 | MIDITrack *trk1, MIDITrack *trk2, 84 | MIDIEditTrackEventMatcher *match1, 85 | MIDIEditTrackEventMatcher *match2 ); 86 | 87 | 88 | // 89 | // this erase function will erase all events from start to end time 90 | // and can be jagged or not. 91 | // 92 | void Erase ( 93 | MIDIClockTime start, 94 | MIDIClockTime end, 95 | bool jagged = true, 96 | MIDIEditTrackEventMatcher *match = 0 97 | ); 98 | 99 | 100 | 101 | // 102 | // this delete function will delete all events like erase and then 103 | // shift the events over 104 | // 105 | void Delete ( 106 | MIDIClockTime start, 107 | MIDIClockTime end, 108 | bool jagged = true, 109 | MIDIEditTrackEventMatcher *match = 0 110 | ); 111 | 112 | 113 | // 114 | // this insert function will insert 'length' clicks starting at 115 | // the events at start time. 116 | // 117 | void Insert ( 118 | MIDIClockTime start, 119 | MIDIClockTime length 120 | ); 121 | 122 | 123 | // 124 | // this shift function will shift all event times by an offset. 125 | // 126 | void Shift ( 127 | signed long offset, 128 | MIDIEditTrackEventMatcher *match = 0 129 | ); 130 | 131 | protected: 132 | 133 | MIDIMatrix matrix; 134 | MIDITrack *track; 135 | 136 | private: 137 | 138 | }; 139 | 140 | 141 | } 142 | 143 | #endif 144 | 145 | 146 | -------------------------------------------------------------------------------- /libs/jdksmidi/examples/rewrite_midifile.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Rewrite Midifile example for libJDKSmidi C++ MIDI Library 4 | 5 | Copyright (C) 2010 V.R.Madgazin 6 | www.vmgames.com 7 | vrm@vmgames.com 8 | 9 | This program is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU General Public License 11 | as published by the Free Software Foundation; either version 2 12 | of the License, or (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this program; 21 | if not, write to the Free Software Foundation, Inc., 22 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 23 | 24 | */ 25 | 26 | #ifdef WIN32 27 | #include 28 | #endif 29 | 30 | #include "jdksmidi/world.h" 31 | using namespace jdksmidi; 32 | 33 | #include 34 | using namespace std; 35 | 36 | // delete all text events from multitrack object 37 | bool DeleteAllTracksText( MIDIMultiTrack &tracks ) 38 | { 39 | bool text_deleted = false; 40 | int num_tracks = tracks.GetNumTracksWithEvents(); 41 | 42 | for ( int nt = 0; nt < num_tracks; ++nt ) 43 | { 44 | MIDITrack &trk = *tracks.GetTrack( nt ); 45 | int num_events = trk.GetNumEvents(); 46 | 47 | for ( int ne = 0; ne < num_events; ++ne ) 48 | { 49 | MIDITimedBigMessage *msg = trk.GetEvent( ne ); 50 | // convert any text midi event to NoOp event 51 | if ( msg->IsTextEvent() ) 52 | { 53 | trk.MakeEventNoOp( ne ); 54 | text_deleted = true; 55 | } 56 | } 57 | } 58 | 59 | return text_deleted; 60 | } 61 | 62 | void args_err() 63 | { 64 | cerr << "\nusage: jdkmidi_rewrite_midifile INFILE.mid OUTFILE.mid ['1' for reduce outfile size]\n"; 65 | cerr << " ['2' for delete start pause]\n\n"; 66 | } 67 | 68 | int main ( int argc, char **argv ) 69 | { 70 | int retcode = -1; 71 | 72 | if ( argc <= 2 ) 73 | { 74 | args_err(); 75 | return retcode; 76 | } 77 | 78 | const char *infile = argv[1]; 79 | const char *outfile = argv[2]; 80 | 81 | int mode = 0; 82 | if ( argc > 3 ) 83 | mode = abs ( atol( argv[3] ) ); 84 | 85 | MIDIMultiTrack tracks, tracks2; 86 | 87 | if ( !ReadMidiFile( infile, tracks ) ) 88 | { 89 | cerr << "\nError reading file " << infile << endl; 90 | return retcode; 91 | } 92 | 93 | if ( mode%2 == 1 ) // need to reduce outfile size 94 | { 95 | // delete all text events from all tracks 96 | if ( DeleteAllTracksText( tracks ) ) 97 | { 98 | cout << "\nAll midi text events deleted." << endl; 99 | } 100 | 101 | if ( tracks.GetNumTracksWithEvents() == 1 ) 102 | { 103 | // remake multitrack object and optimize new tracks content: 104 | // move all channal events to tracks 1-16, and all other types of events to track 0 105 | // and reduce midifile size because of increase number of events with running status 106 | tracks.AssignEventsToTracks( 0 ); 107 | cout << "\nAll midi channal events moved to tracks 1-16." << endl; 108 | } 109 | } 110 | 111 | MIDIMultiTrack *outtracks = &tracks; 112 | if ( mode >= 2 ) // need to delete start pause 113 | { 114 | CompressStartPause( tracks, tracks2 ); 115 | outtracks = &tracks2; 116 | cout << "\nStart pause deleted (decreased)." << endl; 117 | } 118 | 119 | if ( WriteMidiFile( *outtracks, outfile) ) 120 | { 121 | int num_tracks = outtracks->GetNumTracksWithEvents(); 122 | cout << "\nAll OK. Number of tracks with events " << num_tracks << endl; 123 | retcode = 0; 124 | } 125 | else 126 | { 127 | cerr << "\nError writing file " << outfile << endl; 128 | } 129 | 130 | return retcode; 131 | } 132 | 133 | -------------------------------------------------------------------------------- /libs/jdksmidi/include/jdksmidi/sysex.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjdksmidi-2004 C++ Class Library for MIDI 3 | * 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 5 | * www.jdkoftinoff.com 6 | * jeffk@jdkoftinoff.com 7 | * 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | /* 25 | ** Copyright 1986 to 1998 By J.D. Koftinoff Software, Ltd. 26 | ** 27 | ** All rights reserved. 28 | ** 29 | ** No one may duplicate this source code in any form for any reason 30 | ** without the written permission given by J.D. Koftinoff Software, Ltd. 31 | ** 32 | */ 33 | // 34 | // Copyright (C) 2010 V.R.Madgazin 35 | // www.vmgames.com vrm@vmgames.com 36 | // 37 | 38 | #ifndef JDKSMIDI_SYSEX_H 39 | #define JDKSMIDI_SYSEX_H 40 | 41 | #include "jdksmidi/midi.h" 42 | 43 | namespace jdksmidi 44 | { 45 | 46 | class MIDISystemExclusive 47 | { 48 | public: 49 | MIDISystemExclusive ( int size = 384 ); 50 | 51 | MIDISystemExclusive ( const MIDISystemExclusive &e ); 52 | 53 | 54 | MIDISystemExclusive ( 55 | unsigned char *buf_, 56 | int max_len_, 57 | int cur_len_, 58 | bool deletable_ 59 | ) 60 | { 61 | buf = buf_; 62 | max_len = max_len_; 63 | cur_len = cur_len_; 64 | chk_sum = 0; 65 | deletable = deletable_; 66 | } 67 | 68 | virtual ~MIDISystemExclusive(); 69 | 70 | friend bool operator == ( const MIDISystemExclusive &e1, const MIDISystemExclusive &e2 ); 71 | 72 | void Clear() 73 | { 74 | cur_len = 0; 75 | chk_sum = 0; 76 | } 77 | void ClearChecksum() 78 | { 79 | chk_sum = 0; 80 | } 81 | 82 | void PutSysByte ( unsigned char b ) // does not add to chksum 83 | { 84 | if ( cur_len < max_len ) 85 | buf[cur_len++] = b; 86 | } 87 | 88 | void PutByte ( unsigned char b ) 89 | { 90 | PutSysByte ( b ); 91 | chk_sum += b; 92 | } 93 | 94 | void PutEXC() 95 | { 96 | PutSysByte ( SYSEX_START_N ); 97 | } 98 | void PutEOX() 99 | { 100 | PutSysByte ( SYSEX_END ); 101 | } 102 | 103 | // low nibble first 104 | void PutNibblizedByte ( unsigned char b ) 105 | { 106 | PutByte ( ( unsigned char ) ( b & 0xf ) ); 107 | PutByte ( ( unsigned char ) ( b >> 4 ) ); 108 | } 109 | 110 | // high nibble first 111 | void PutNibblizedByte2 ( unsigned char b ) 112 | { 113 | PutByte ( ( unsigned char ) ( b >> 4 ) ); 114 | PutByte ( ( unsigned char ) ( b & 0xf ) ); 115 | } 116 | 117 | void PutChecksum() 118 | { 119 | PutByte ( ( unsigned char ) ( chk_sum & 0x7f ) ); 120 | } 121 | 122 | unsigned char GetChecksum() const 123 | { 124 | return ( unsigned char ) ( chk_sum & 0x7f ); 125 | } 126 | 127 | int GetLengthSE() const 128 | { 129 | return cur_len; 130 | } 131 | 132 | int GetLength() const 133 | { 134 | return GetLengthSE(); 135 | } 136 | 137 | unsigned char GetData ( int i ) const 138 | { 139 | return buf[i]; 140 | } 141 | 142 | bool IsFull() const 143 | { 144 | return cur_len >= max_len; 145 | } 146 | 147 | unsigned char *GetBuf() 148 | { 149 | return buf; 150 | } 151 | 152 | const unsigned char *GetBuf() const 153 | { 154 | return buf; 155 | } 156 | 157 | private: 158 | 159 | unsigned char *buf; 160 | int max_len; 161 | int cur_len; 162 | unsigned char chk_sum; 163 | bool deletable; 164 | }; 165 | } 166 | 167 | #endif 168 | 169 | 170 | -------------------------------------------------------------------------------- /libs/jdksmidi/src/jdksmidi_process.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * libjdksmidi-2004 C++ Class Library for MIDI 3 | * 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 5 | * www.jdkoftinoff.com 6 | * jeffk@jdkoftinoff.com 7 | * 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | // 25 | // Copyright (C) 2010 V.R.Madgazin 26 | // www.vmgames.com vrm@vmgames.com 27 | // 28 | 29 | #include "jdksmidi/world.h" 30 | #include "jdksmidi/process.h" 31 | 32 | namespace jdksmidi 33 | { 34 | 35 | MIDIProcessor::MIDIProcessor() 36 | { 37 | } 38 | 39 | MIDIProcessor::~MIDIProcessor() 40 | { 41 | } 42 | 43 | 44 | 45 | MIDIMultiProcessor::MIDIMultiProcessor ( int num ) 46 | : 47 | processors ( new MIDIProcessor *[num] ), 48 | num_processors ( num ) 49 | { 50 | for ( int i = 0; i < num_processors; ++i ) 51 | { 52 | processors[i] = 0; 53 | } 54 | } 55 | 56 | MIDIMultiProcessor::~MIDIMultiProcessor() 57 | { 58 | jdks_safe_delete_array( processors ); 59 | } 60 | 61 | 62 | 63 | bool MIDIMultiProcessor::Process ( MIDITimedBigMessage *msg ) 64 | { 65 | for ( int i = 0; i < num_processors; ++i ) 66 | { 67 | if ( processors[i] ) 68 | { 69 | if ( processors[i]->Process ( msg ) == false ) 70 | { 71 | return false; 72 | } 73 | } 74 | } 75 | 76 | return true; 77 | } 78 | 79 | 80 | 81 | 82 | 83 | MIDIProcessorTransposer::MIDIProcessorTransposer() 84 | { 85 | for ( int i = 0; i < 16; ++i ) 86 | { 87 | trans_amount[i] = 0; 88 | } 89 | } 90 | 91 | MIDIProcessorTransposer::~MIDIProcessorTransposer() 92 | { 93 | } 94 | 95 | 96 | void MIDIProcessorTransposer::SetAllTranspose ( int val ) 97 | { 98 | for ( int chan = 0; chan < 16; ++chan ) 99 | { 100 | trans_amount[chan] = val; 101 | } 102 | } 103 | 104 | bool MIDIProcessorTransposer::Process ( MIDITimedBigMessage *msg ) 105 | { 106 | if ( msg->IsChannelMsg() ) 107 | { 108 | if ( msg->IsNoteOn() || msg->IsNoteOff() || msg->IsPolyPressure() ) 109 | { 110 | int trans = trans_amount[ msg->GetChannel() ]; 111 | int new_note = ( ( int ) msg->GetNote() ) + trans; 112 | 113 | if ( trans > 127 || trans < 0 ) 114 | { 115 | // delete event if out of range 116 | return false; 117 | } 118 | 119 | else 120 | { 121 | // set new note number 122 | msg->SetNote ( ( unsigned char ) new_note ); 123 | } 124 | } 125 | } 126 | 127 | return true; 128 | } 129 | 130 | 131 | 132 | 133 | 134 | MIDIProcessorRechannelizer::MIDIProcessorRechannelizer() 135 | { 136 | for ( int i = 0; i < 16; ++i ) 137 | { 138 | rechan_map[i] = i; 139 | } 140 | } 141 | 142 | MIDIProcessorRechannelizer::~MIDIProcessorRechannelizer() 143 | { 144 | } 145 | 146 | 147 | void MIDIProcessorRechannelizer::SetAllRechan ( int dest_chan ) 148 | { 149 | for ( int i = 0; i < 16; ++i ) 150 | { 151 | rechan_map[i] = dest_chan; 152 | } 153 | } 154 | 155 | bool MIDIProcessorRechannelizer::Process ( MIDITimedBigMessage *msg ) 156 | { 157 | if ( msg->IsChannelMsg() ) 158 | { 159 | int new_chan = rechan_map[ msg->GetChannel() ]; 160 | 161 | if ( new_chan == -1 ) 162 | { 163 | // this channel is to be deleted! return false 164 | return false; 165 | } 166 | 167 | msg->SetChannel ( ( unsigned char ) new_chan ); 168 | } 169 | 170 | return true; 171 | } 172 | 173 | 174 | 175 | 176 | 177 | } 178 | -------------------------------------------------------------------------------- /libs/jdksmidi/include/jdksmidi/tempo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjdksmidi-2004 C++ Class Library for MIDI 3 | * 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 5 | * www.jdkoftinoff.com 6 | * jeffk@jdkoftinoff.com 7 | * 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | /* 25 | ** Copyright 1986 to 1998 By J.D. Koftinoff Software, Ltd. 26 | ** 27 | ** All rights reserved. 28 | ** 29 | ** No one may duplicate this source code in any form for any reason 30 | ** without the written permission given by J.D. Koftinoff Software, Ltd. 31 | ** 32 | */ 33 | 34 | #ifndef JDKSMIDI_TEMPO_H 35 | #define JDKSMIDI_TEMPO_H 36 | 37 | // 38 | // This class makes it easy to deal with Tempos as fixed point numbers. 39 | // 40 | // The actual tempo is stored times 256 for 1/256 bpm accuracy. 41 | // 42 | // The default operator int() etc., automatically convert the 43 | // fixed point number so the value is in normal beats per minutes. 44 | // 45 | // 46 | 47 | #include "jdksmidi/midi.h" 48 | 49 | namespace jdksmidi 50 | { 51 | 52 | class MIDITempo 53 | { 54 | public: 55 | MIDITempo() 56 | { 57 | tempo = 120 << 8; 58 | } 59 | MIDITempo ( int a ) 60 | { 61 | tempo = ( unsigned long ) a << 8; 62 | } 63 | MIDITempo ( unsigned int a ) 64 | { 65 | tempo = ( unsigned long ) a << 8; 66 | } 67 | MIDITempo ( long a ) 68 | { 69 | tempo = ( unsigned long ) a << 8; 70 | } 71 | MIDITempo ( unsigned long a ) 72 | { 73 | tempo = a << 8; 74 | } 75 | MIDITempo ( float a ) 76 | { 77 | tempo = ( unsigned long ) ( a * 256.0 ); 78 | } 79 | MIDITempo ( const MIDITempo &a ) 80 | { 81 | tempo = a.GetFullTempo(); 82 | } 83 | 84 | operator short () 85 | { 86 | return ( short ) ( ( tempo + 0x80 ) >> 8 ); 87 | } 88 | operator unsigned short () 89 | { 90 | return ( unsigned short ) ( ( tempo + 0x80 ) >> 8 ); 91 | } 92 | 93 | operator int () 94 | { 95 | return ( int ) ( ( tempo + 0x80 ) >> 8 ); 96 | } 97 | operator unsigned int () 98 | { 99 | return ( unsigned int ) ( ( tempo + 0x80 ) >> 8 ); 100 | } 101 | operator long () 102 | { 103 | return ( long ) ( ( tempo + 0x80 ) >> 8 ); 104 | } 105 | operator unsigned long () 106 | { 107 | return ( unsigned long ) ( ( tempo + 0x80 ) >> 8 ); 108 | } 109 | operator float () 110 | { 111 | return ( float ) tempo / 256.0f; 112 | } 113 | void operator = ( unsigned short a ) 114 | { 115 | tempo = ( unsigned long ) a << 8; 116 | } 117 | void operator = ( short a ) 118 | { 119 | tempo = ( unsigned long ) a << 8; 120 | } 121 | 122 | void operator = ( unsigned int a ) 123 | { 124 | tempo = ( unsigned long ) a << 8; 125 | } 126 | void operator = ( int a ) 127 | { 128 | tempo = ( unsigned long ) a << 8; 129 | } 130 | void operator = ( unsigned long a ) 131 | { 132 | tempo = ( unsigned long ) a << 8; 133 | } 134 | void operator = ( long a ) 135 | { 136 | tempo = ( unsigned long ) a << 8; 137 | } 138 | 139 | void operator = ( float a ) 140 | { 141 | tempo = ( unsigned long ) ( a * 256.0 ); 142 | } 143 | 144 | unsigned long GetFullTempo() const 145 | { 146 | return tempo; 147 | } 148 | void SetFullTempo ( unsigned long v ) 149 | { 150 | tempo = v; 151 | } 152 | 153 | unsigned long GetMIDIFileTempo() 154 | { 155 | if ( tempo ) 156 | return ( 60000000L / 256 ) / tempo; 157 | 158 | else 159 | return ( 60000000L / 256 ) / ( 120 * 256 ); 160 | } 161 | 162 | protected: 163 | unsigned long tempo; 164 | }; 165 | 166 | } 167 | 168 | #endif 169 | 170 | 171 | -------------------------------------------------------------------------------- /libs/jdksmidi/src/jdksmidi_driver.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * libjdksmidi-2004 C++ Class Library for MIDI 3 | * 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 5 | * www.jdkoftinoff.com 6 | * jeffk@jdkoftinoff.com 7 | * 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | 25 | #include "jdksmidi/world.h" 26 | #include "jdksmidi/driver.h" 27 | 28 | namespace jdksmidi 29 | { 30 | 31 | MIDIDriver::MIDIDriver ( int queue_size ) 32 | : 33 | in_queue ( queue_size ), 34 | out_queue ( queue_size ), 35 | in_proc ( 0 ), 36 | out_proc ( 0 ), 37 | thru_proc ( 0 ), 38 | thru_enable ( false ), 39 | tick_proc ( 0 ) 40 | { 41 | } 42 | 43 | MIDIDriver::~MIDIDriver() 44 | { 45 | } 46 | 47 | void MIDIDriver::Reset() 48 | { 49 | in_queue.Clear(); 50 | out_queue.Clear(); 51 | out_matrix.Clear(); 52 | } 53 | 54 | void MIDIDriver::AllNotesOff ( int chan ) 55 | { 56 | MIDITimedBigMessage msg; 57 | // send a note off for every note on in the out_matrix 58 | 59 | if ( out_matrix.GetChannelCount ( chan ) > 0 ) 60 | { 61 | for ( int note = 0; note < 128; ++note ) 62 | { 63 | while ( out_matrix.GetNoteCount ( chan, note ) > 0 ) 64 | { 65 | // make a note off with note on msg, velocity 0 66 | msg.SetNoteOn ( ( unsigned char ) chan, 67 | ( unsigned char ) note, 0 ); 68 | OutputMessage ( msg ); 69 | } 70 | } 71 | } 72 | 73 | msg.SetControlChange ( chan, C_DAMPER, 0 ); 74 | OutputMessage ( msg ); 75 | msg.SetAllNotesOff ( ( unsigned char ) chan ); 76 | OutputMessage ( msg ); 77 | } 78 | 79 | void MIDIDriver::AllNotesOff() 80 | { 81 | for ( int i = 0; i < 16; ++i ) 82 | { 83 | AllNotesOff ( i ); 84 | } 85 | } 86 | 87 | bool MIDIDriver::HardwareMsgIn ( MIDITimedBigMessage &msg ) 88 | { 89 | // put input midi messages thru the in processor 90 | if ( in_proc ) 91 | { 92 | if ( in_proc->Process ( &msg ) == false ) 93 | { 94 | // message was deleted, so ignore it. 95 | return true; 96 | } 97 | } 98 | 99 | // stick input into in queue 100 | 101 | if ( in_queue.CanPut() ) 102 | { 103 | in_queue.Put ( msg ); 104 | } 105 | 106 | else 107 | { 108 | return false; 109 | } 110 | 111 | // now stick it through the THRU processor 112 | 113 | if ( thru_proc ) 114 | { 115 | if ( thru_proc->Process ( &msg ) == false ) 116 | { 117 | // message was deleted, so ignore it. 118 | return true; 119 | } 120 | } 121 | 122 | if ( thru_enable ) 123 | { 124 | // stick this message into the out queue so the tick procedure 125 | // will play it out asap 126 | if ( out_queue.CanPut() ) 127 | { 128 | out_queue.Put ( msg ); 129 | } 130 | 131 | else 132 | { 133 | return false; 134 | } 135 | } 136 | 137 | return true; 138 | } 139 | 140 | void MIDIDriver::TimeTick ( unsigned long sys_time ) 141 | { 142 | // run the additional tick procedure if we need to 143 | if ( tick_proc ) 144 | { 145 | tick_proc->TimeTick ( sys_time ); 146 | } 147 | 148 | // feed as many midi messages from out_queu to the hardware out port 149 | // as we can 150 | 151 | while ( out_queue.CanGet() ) 152 | { 153 | // use the Peek() function to avoid allocating memory for 154 | // a duplicate sysex 155 | if ( HardwareMsgOut ( * ( out_queue.Peek() ) ) == true ) 156 | { 157 | // ok, got and sent a message - update our out_queue now 158 | out_queue.Next(); 159 | } 160 | 161 | else 162 | { 163 | // cant send any more, stop now. 164 | break; 165 | } 166 | } 167 | } 168 | 169 | } 170 | -------------------------------------------------------------------------------- /libs/jdksmidi/src/jdksmidi_matrix.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * libjdksmidi-2004 C++ Class Library for MIDI 3 | * 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 5 | * www.jdkoftinoff.com 6 | * jeffk@jdkoftinoff.com 7 | * 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | /* 25 | ** Copyright 1986 to 1998 By J.D. Koftinoff Software, Ltd. 26 | ** 27 | ** All rights reserved. 28 | ** 29 | ** No one may duplicate this source code in any form for any reason 30 | ** without the written permission given by J.D. Koftinoff Software, Ltd. 31 | ** 32 | */ 33 | 34 | 35 | #include "jdksmidi/world.h" 36 | 37 | #include "jdksmidi/matrix.h" 38 | 39 | #ifndef DEBUG_MDMATRIX 40 | # define DEBUG_MDMATRIX 0 41 | #endif 42 | 43 | #if DEBUG_MDMATRIX 44 | # undef DBG 45 | # define DBG(a) a 46 | #endif 47 | 48 | 49 | namespace jdksmidi 50 | { 51 | 52 | MIDIMatrix::MIDIMatrix() 53 | { 54 | ENTER ( "MIDIMatrix::MIDIMatrix()" ); 55 | 56 | for ( int channel = 0; channel < 16; channel++ ) 57 | { 58 | channel_count[channel] = 0; 59 | hold_pedal[channel] = false; 60 | 61 | for ( unsigned char note = 0; note < 128; note++ ) 62 | note_on_count[channel][note] = 0; 63 | } 64 | 65 | total_count = 0; 66 | } 67 | 68 | MIDIMatrix::~MIDIMatrix() 69 | { 70 | ENTER ( "MIDIMatrix::~MIDIMatrix()" ); 71 | } 72 | 73 | 74 | void MIDIMatrix::DecNoteCount ( const MIDIMessage &, int channel, int note ) 75 | { 76 | ENTER ( "MIDIMatrix::DecNoteCount()" ); 77 | 78 | if ( note_on_count[channel][note] > 0 ) 79 | { 80 | --note_on_count[channel][note]; 81 | --channel_count[channel]; 82 | --total_count; 83 | } 84 | } 85 | 86 | void MIDIMatrix::IncNoteCount ( const MIDIMessage &, int channel, int note ) 87 | { 88 | ENTER ( "MIDIMatrix::IncNoteCount()" ); 89 | ++note_on_count[channel][note]; 90 | ++channel_count[channel]; 91 | ++total_count; 92 | } 93 | 94 | void MIDIMatrix::OtherMessage ( const MIDIMessage & ) 95 | { 96 | ENTER ( "MIDIMatrix::OtherMessage()" ); 97 | } 98 | 99 | 100 | bool MIDIMatrix::Process ( const MIDIMessage &m ) 101 | { 102 | ENTER ( "MIDIMatrix::Process()" ); 103 | bool status = false; 104 | 105 | if ( m.IsChannelMsg() ) 106 | { 107 | int channel = m.GetChannel(); 108 | int note = m.GetNote(); 109 | 110 | if ( m.IsAllNotesOff() ) 111 | { 112 | ClearChannel ( channel ); 113 | status = true; 114 | } 115 | 116 | else if ( m.IsNoteOn() ) 117 | { 118 | if ( m.GetVelocity() != 0 ) 119 | IncNoteCount ( m, channel, note ); 120 | 121 | else 122 | DecNoteCount ( m, channel, note ); 123 | 124 | status = true; 125 | } 126 | 127 | else if ( m.IsNoteOff() ) 128 | { 129 | DecNoteCount ( m, channel, note ); 130 | status = true; 131 | } 132 | 133 | else if ( m.IsControlChange() && m.GetController() == C_DAMPER ) 134 | { 135 | if ( m.GetControllerValue() & 0x40 ) 136 | { 137 | hold_pedal[channel] = true; 138 | } 139 | 140 | else 141 | { 142 | hold_pedal[channel] = false; 143 | } 144 | } 145 | 146 | else 147 | OtherMessage ( m ); 148 | } 149 | 150 | return status; 151 | } 152 | 153 | void MIDIMatrix::Clear() 154 | { 155 | ENTER ( "MIDIMatrix::Clear()" ); 156 | 157 | for ( int channel = 0; channel < 16; ++channel ) 158 | { 159 | ClearChannel ( channel ); 160 | } 161 | 162 | total_count = 0; 163 | } 164 | 165 | void MIDIMatrix::ClearChannel ( int channel ) 166 | { 167 | ENTER ( "MIDIMatrix::ClearChannel()" ); 168 | 169 | for ( int note = 0; note < 128; ++note ) 170 | { 171 | total_count -= note_on_count[channel][note]; 172 | note_on_count[channel][note] = 0; 173 | } 174 | 175 | channel_count[channel] = 0; 176 | hold_pedal[channel] = 0; 177 | } 178 | 179 | 180 | 181 | } 182 | -------------------------------------------------------------------------------- /libs/jdksmidi/include/jdksmidi/advancedsequencer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjdksmidi-2004 C++ Class Library for MIDI 3 | * 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 5 | * www.jdkoftinoff.com 6 | * jeffk@jdkoftinoff.com 7 | * 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | /* 25 | ** Copyright 1986 to 1998 By J.D. Koftinoff Software, Ltd. 26 | ** 27 | ** All rights reserved. 28 | ** 29 | ** No one may duplicate this source code in any form for any reason 30 | ** without the written permission given by J.D. Koftinoff Software, Ltd. 31 | ** 32 | */ 33 | 34 | #ifndef JDKSMIDI_ADVANCEDSEQUENCER_H 35 | #define JDKSMIDI_ADVANCEDSEQUENCER_H 36 | 37 | #include "jdksmidi/midi.h" 38 | #include "jdksmidi/msg.h" 39 | #include "jdksmidi/sysex.h" 40 | #include "jdksmidi/multitrack.h" 41 | #include "jdksmidi/filereadmultitrack.h" 42 | #include "jdksmidi/sequencer.h" 43 | #include "jdksmidi/manager.h" 44 | #include "jdksmidi/driver.h" 45 | 46 | 47 | #include "jdksmidi/driverdump.h" 48 | 49 | #include 50 | #include 51 | 52 | #define MAX_WARP_POSITIONS (128) 53 | #define MEASURES_PER_WARP (4) 54 | 55 | namespace jdksmidi 56 | { 57 | 58 | class AdvancedSequencer 59 | { 60 | public: 61 | AdvancedSequencer(); 62 | virtual ~AdvancedSequencer(); 63 | 64 | bool OpenMIDI ( int in_port, int out_port, int timer_resolution = 5 ); 65 | void CloseMIDI(); 66 | 67 | void SetMIDIThruEnable ( bool f ); 68 | bool GetMIDIThruEnable() const; 69 | 70 | void SetMIDIThruChannel ( int chan ); 71 | int GetMIDIThruChannel() const; 72 | 73 | void SetMIDIThruTranspose ( int val ); 74 | int GetMIDIThruTranspose() const; 75 | 76 | bool Load ( const char *fname ); 77 | void Reset(); 78 | 79 | void GoToMeasure ( int measure, int beat = 0 ); 80 | void GoToTime ( MIDIClockTime t ); 81 | void Play ( int clock_offset = 0 ); 82 | void RepeatPlay ( bool enable, int start_measure, int end_measure ); 83 | void Pause(); 84 | void Stop(); 85 | 86 | bool IsPlay() 87 | { 88 | return mgr.IsSeqPlay(); 89 | } 90 | 91 | void UnmuteAllTracks(); 92 | void SoloTrack ( int trk ); 93 | void UnSoloTrack(); 94 | void SetTrackMute ( int trk, bool f ); 95 | 96 | void SetTempoScale ( double scale ); 97 | double GetTempoWithoutScale() const; 98 | double GetTempoWithScale() const; 99 | 100 | int GetMeasure() const; 101 | int GetBeat() const; 102 | 103 | int GetTimeSigNumerator() const; 104 | int GetTimeSigDenominator() const; 105 | 106 | int GetTrackNoteCount ( int trk ) const; 107 | const char *GetTrackName ( int trk ) const; 108 | int GetTrackVolume ( int trk ) const; 109 | 110 | void SetTrackVelocityScale ( int trk, int scale ); 111 | int GetTrackVelocityScale ( int trk ) const; 112 | 113 | void SetTrackRechannelize ( int trk, int chan ); 114 | int GetTrackRechannelize ( int trk ) const; 115 | 116 | void SetTrackTranspose ( int trk, int trans ); 117 | int GetTrackTranspose ( int trk ) const; 118 | 119 | void ExtractMarkers ( std::vector< std::string > *list ); 120 | int GetCurrentMarker() const; 121 | 122 | int FindFirstChannelOnTrack ( int trk ); 123 | 124 | void ExtractWarpPositions(); 125 | 126 | bool IsChainMode() const 127 | { 128 | return chain_mode; 129 | } 130 | 131 | MIDIMultiProcessor thru_processor; 132 | MIDIProcessorTransposer thru_transposer; 133 | MIDIProcessorRechannelizer thru_rechannelizer; 134 | 135 | MIDIDriverDump driver; 136 | 137 | MIDIMultiTrack tracks; 138 | 139 | 140 | MIDISequencerGUIEventNotifierText notifier; 141 | 142 | MIDISequencer seq; 143 | 144 | MIDIClockTime marker_times[1024]; 145 | int num_markers; 146 | 147 | MIDIManager mgr; 148 | 149 | long repeat_start_measure; 150 | long repeat_end_measure; 151 | bool repeat_play_mode; 152 | 153 | int num_warp_positions; 154 | MIDISequencerState *warp_positions[MAX_WARP_POSITIONS]; 155 | 156 | bool file_loaded; 157 | bool chain_mode; 158 | }; 159 | 160 | } 161 | 162 | #endif 163 | -------------------------------------------------------------------------------- /libs/jdksmidi/include/jdksmidi/driver.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjdksmidi-2004 C++ Class Library for MIDI 3 | * 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 5 | * www.jdkoftinoff.com 6 | * jeffk@jdkoftinoff.com 7 | * 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | 25 | #ifndef JDKSMIDI_DRIVER_H 26 | #define JDKSMIDI_DRIVER_H 27 | 28 | #include "jdksmidi/msg.h" 29 | #include "jdksmidi/sysex.h" 30 | #include "jdksmidi/matrix.h" 31 | #include "jdksmidi/process.h" 32 | #include "jdksmidi/queue.h" 33 | #include "jdksmidi/tick.h" 34 | 35 | namespace jdksmidi 36 | { 37 | 38 | class MIDIDriver : public MIDITick 39 | { 40 | 41 | public: 42 | 43 | MIDIDriver ( int queue_size ); 44 | virtual ~MIDIDriver(); 45 | 46 | virtual void Reset(); 47 | 48 | // to get the midi in queue 49 | MIDIQueue * InputQueue() 50 | { 51 | return &in_queue; 52 | } 53 | 54 | const MIDIQueue * InputQueue() const 55 | { 56 | return &in_queue; 57 | } 58 | 59 | // to get the midi out queue 60 | MIDIQueue * OutputQueue() 61 | { 62 | return &out_queue; 63 | } 64 | 65 | const MIDIQueue * OutputQueue() const 66 | { 67 | return &out_queue; 68 | } 69 | 70 | 71 | // 72 | // returns true if the output queue is not full 73 | bool CanOutputMessage() const 74 | { 75 | return out_queue.CanPut(); 76 | } 77 | 78 | 79 | // processes message with the OutProcessor and then 80 | // puts the message in the out_queue 81 | void OutputMessage ( MIDITimedBigMessage &msg ) 82 | { 83 | if ( ( out_proc && out_proc->Process ( &msg ) ) || !out_proc ) 84 | { 85 | out_matrix.Process ( msg ); 86 | out_queue.Put ( msg ); 87 | } 88 | } 89 | 90 | void SetThruEnable ( bool f ) 91 | { 92 | thru_enable = f; 93 | } 94 | 95 | bool GetThruEnable() const 96 | { 97 | return thru_enable; 98 | } 99 | 100 | // to set the midi processors used for thru, out, and in 101 | void SetThruProcessor ( MIDIProcessor *proc ) 102 | { 103 | thru_proc = proc; 104 | } 105 | 106 | void SetOutProcessor ( MIDIProcessor *proc ) 107 | { 108 | out_proc = proc; 109 | } 110 | 111 | void SetInProcessor ( MIDIProcessor *proc ) 112 | { 113 | in_proc = proc; 114 | } 115 | 116 | void SetTickProc ( MIDITick *tick ) 117 | { 118 | tick_proc = tick; 119 | } 120 | 121 | // to send all notes off on selected midi chanel 122 | void AllNotesOff ( int chan ); 123 | 124 | // to send all notes off on all midi channels 125 | void AllNotesOff(); 126 | 127 | // call handle midi in when a parsed midi message 128 | // comes in to the system. Can be called by a callback function 129 | // or by your TimeTick() function. 130 | 131 | virtual bool HardwareMsgIn ( MIDITimedBigMessage &msg ); 132 | 133 | // HardwareMsgOut() must be overriden by a subclass - It must 134 | // take 135 | 136 | virtual bool HardwareMsgOut ( const MIDITimedBigMessage &msg ) = 0; 137 | 138 | // the time tick procedure: 139 | // manages in/out/thru to hardware 140 | // inherited from MIDITick. 141 | // 142 | // if you need to poll midi in hardware, 143 | // you can override this method - Call MIDIDriver::TimeTick(t) 144 | // first, You may then poll the midi in 145 | // hardware, parse the bytes, form a message, and give the 146 | // resulting message to HandleMsgIn to process it and put it in 147 | // the in_queue. 148 | 149 | virtual void TimeTick ( unsigned long sys_time ); 150 | 151 | 152 | protected: 153 | 154 | 155 | // the in and out queues 156 | MIDIQueue in_queue; 157 | MIDIQueue out_queue; 158 | 159 | // the processors 160 | MIDIProcessor *in_proc; 161 | MIDIProcessor *out_proc; 162 | MIDIProcessor *thru_proc; 163 | 164 | bool thru_enable; 165 | 166 | // additional TimeTick procedure 167 | 168 | MIDITick *tick_proc; 169 | 170 | // to keep track of notes on going to MIDI out 171 | 172 | MIDIMatrix out_matrix; 173 | }; 174 | 175 | 176 | } 177 | 178 | #endif 179 | -------------------------------------------------------------------------------- /libs/jdksmidi/include/jdksmidi/file.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjdksmidi-2004 C++ Class Library for MIDI 3 | * 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 5 | * www.jdkoftinoff.com 6 | * jeffk@jdkoftinoff.com 7 | * 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | /* 25 | ** Copyright 1986 to 1998 By J.D. Koftinoff Software, Ltd. 26 | ** 27 | ** All rights reserved. 28 | ** 29 | ** No one may duplicate this source code in any form for any reason 30 | ** without the written permission given by J.D. Koftinoff Software, Ltd. 31 | ** 32 | */ 33 | // 34 | // Copyright (C) 2010 V.R.Madgazin 35 | // www.vmgames.com vrm@vmgames.com 36 | // 37 | 38 | #ifndef JDKSMIDI_FILE_H 39 | #define JDKSMIDI_FILE_H 40 | 41 | #include "jdksmidi/midi.h" 42 | #include "jdksmidi/msg.h" 43 | #include "jdksmidi/sysex.h" 44 | #include "jdksmidi/tempo.h" 45 | 46 | namespace jdksmidi 47 | { 48 | 49 | // 50 | // The MIDIFile class contains definitions and utilities to deal with 51 | // reading and writing midi files. 52 | // 53 | 54 | const unsigned long _MThd = OSTYPE ( 'M', 'T', 'h', 'd' ); 55 | const unsigned long _MTrk = OSTYPE ( 'M', 'T', 'r', 'k' ); 56 | 57 | class MIDIFile 58 | { 59 | public: 60 | 61 | MIDIFile(); 62 | virtual ~MIDIFile(); 63 | 64 | struct MIDIFileChunk 65 | { 66 | unsigned long id; 67 | unsigned long length; 68 | }; 69 | 70 | struct MIDIFileHeader 71 | { 72 | short format; 73 | short ntrks; 74 | short division; 75 | }; 76 | 77 | // 78 | // define all the different meta event message types. 79 | // 80 | 81 | enum 82 | { 83 | MF_META_SEQUENCE_NUMBER = META_SEQUENCE_NUMBER, 84 | 85 | MF_META_GENERIC_TEXT = META_GENERIC_TEXT, 86 | MF_META_COPYRIGHT = META_COPYRIGHT, 87 | MF_META_TRACK_NAME = META_TRACK_NAME, 88 | MF_META_INSTRUMENT_NAME = META_INSTRUMENT_NAME, 89 | MF_META_LYRIC_TEXT = META_LYRIC_TEXT, 90 | MF_META_MARKER_TEXT = META_MARKER_TEXT, 91 | MF_META_CUE_POINT = META_CUE_POINT, 92 | MF_META_GENERIC_TEXT_8 = META_PROGRAM_NAME, 93 | MF_META_GENERIC_TEXT_9 = META_DEVICE_NAME, 94 | MF_META_GENERIC_TEXT_A = META_GENERIC_TEXT_A, 95 | MF_META_GENERIC_TEXT_B = META_GENERIC_TEXT_B, 96 | MF_META_GENERIC_TEXT_C = META_GENERIC_TEXT_C, 97 | MF_META_GENERIC_TEXT_D = META_GENERIC_TEXT_D, 98 | MF_META_GENERIC_TEXT_E = META_GENERIC_TEXT_E, 99 | MF_META_GENERIC_TEXT_F = META_GENERIC_TEXT_F, 100 | 101 | MF_META_CHANNEL_PREFIX = META_CHANNEL_PREFIX, 102 | MF_META_OUTPUT_CABLE = META_OUTPUT_CABLE, 103 | MF_META_TRACK_LOOP = META_TRACK_LOOP, 104 | MF_META_END_OF_TRACK = META_END_OF_TRACK, 105 | 106 | MF_META_TEMPO = META_TEMPO, 107 | MF_META_SMPTE = META_SMPTE, 108 | MF_META_TIMESIG = META_TIMESIG, 109 | MF_META_KEYSIG = META_KEYSIG, 110 | 111 | MF_META_SEQUENCER_SPECIFIC = META_SEQUENCER_SPECIFIC 112 | }; 113 | 114 | 115 | // 116 | // ConvertTempoToFreq() returns the frequency of the required 117 | // tempo clock 118 | // 119 | 120 | static unsigned long ConvertTempoToFreq ( short division, MIDITempo &tempo ); 121 | 122 | // 123 | // Convert a four byte number to an unsigned long. 124 | // 125 | 126 | static unsigned long To32Bit ( unsigned char a, unsigned char b, unsigned char c, unsigned char d ) 127 | { 128 | return ( static_cast ( a ) << 24 ) | 129 | ( static_cast ( b ) << 16 ) | 130 | ( static_cast ( c ) << 8 ) | 131 | ( static_cast ( d ) ); 132 | } 133 | 134 | // 135 | // Convert a two byte number to an unsigned short 136 | // 137 | 138 | static unsigned short To16Bit ( unsigned char a, unsigned char b ) 139 | { 140 | return ( static_cast ( a ) << 8 ) | 141 | ( static_cast ( b ) ); 142 | } 143 | 144 | static unsigned long ReadVariableLengthNumber ( unsigned char **in ); 145 | static unsigned char * WriteVariableLengthNumber ( unsigned long num, unsigned char *out ); 146 | }; 147 | 148 | } 149 | 150 | #endif 151 | 152 | -------------------------------------------------------------------------------- /libs/jdksmidi/include/jdksmidi/showcontrolhandler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjdksmidi-2004 C++ Class Library for MIDI 3 | * 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 5 | * www.jdkoftinoff.com 6 | * jeffk@jdkoftinoff.com 7 | * 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | 25 | #ifndef JDKSMIDI_SHOWCONTROLHANDLER_H 26 | #define JDKSMIDI_SHOWCONTROLHANDLER_H 27 | 28 | #include "jdksmidi/showcontrol.h" 29 | 30 | namespace jdksmidi 31 | { 32 | 33 | class MIDISCHandle 34 | { 35 | public: 36 | MIDISCHandle(); 37 | virtual ~MIDISCHandle(); 38 | 39 | virtual bool Dispatch ( const MIDIShowControlPacket &p ); 40 | 41 | virtual bool Go(); 42 | virtual bool Go ( const MIDICue & q_number ); 43 | virtual bool Go ( const MIDICue & q_number, const MIDICue & q_list ); 44 | virtual bool Go ( const MIDICue & q_number, const MIDICue & q_list, const MIDICue & q_path ); 45 | virtual bool Stop(); 46 | virtual bool Stop ( const MIDICue & q_number ); 47 | virtual bool Stop ( const MIDICue & q_number, const MIDICue & q_list ); 48 | virtual bool Stop ( const MIDICue & q_number, const MIDICue & q_list, const MIDICue & q_path ); 49 | virtual bool Resume(); 50 | virtual bool Resume ( const MIDICue & q_number ); 51 | virtual bool Resume ( const MIDICue & q_number, const MIDICue & q_list ); 52 | virtual bool Resume ( const MIDICue & q_number, const MIDICue & q_list, const MIDICue & q_path ); 53 | virtual bool TimedGo ( 54 | uchar hr, uchar mn, uchar sc, uchar fr, uchar ff 55 | ); 56 | virtual bool TimedGo ( 57 | uchar hr, uchar mn, uchar sc, uchar fr, uchar ff, 58 | const MIDICue & q_number 59 | ); 60 | virtual bool TimedGo ( 61 | uchar hr, uchar mn, uchar sc, uchar fr, uchar ff, 62 | const MIDICue & q_number, const MIDICue & q_list 63 | ); 64 | 65 | virtual bool TimedGo ( 66 | uchar hr, uchar mn, uchar sc, uchar fr, uchar ff, 67 | const MIDICue & q_number, const MIDICue & q_list, const MIDICue & q_path 68 | ); 69 | 70 | virtual bool Load ( const MIDICue & q_number ); 71 | virtual bool Load ( const MIDICue & q_number, const MIDICue & q_list ); 72 | virtual bool Load ( const MIDICue & q_number, const MIDICue & q_list, const MIDICue & q_path ); 73 | virtual bool Set ( ulong ctrl_num, ulong ctrl_val ); 74 | 75 | virtual bool Set ( 76 | ulong ctrl_num, 77 | ulong ctrl_val, 78 | uchar hr, uchar mn, uchar sc, uchar fr, uchar ff 79 | ); 80 | 81 | virtual bool Fire ( uchar macro_num ); 82 | virtual bool AllOff(); 83 | virtual bool Restore(); 84 | virtual bool Reset(); 85 | virtual bool GoOff(); 86 | virtual bool GoOff ( const MIDICue & q_number ); 87 | virtual bool GoOff ( const MIDICue & q_number, const MIDICue & q_list ); 88 | virtual bool GoOff ( const MIDICue & q_number, const MIDICue & q_list, const MIDICue & q_path ); 89 | virtual bool GoJam(); 90 | virtual bool GoJam ( const MIDICue & q_number ); 91 | virtual bool GoJam ( const MIDICue & q_number, const MIDICue & q_list ); 92 | virtual bool GoJam ( const MIDICue & q_number, const MIDICue & q_list, const MIDICue & q_path ); 93 | virtual bool StandbyPlus(); 94 | virtual bool StandbyPlus ( const MIDICue & q_list ); 95 | virtual bool StandbyMinus(); 96 | virtual bool StandbyMinus ( const MIDICue & q_list ); 97 | virtual bool SequencePlus(); 98 | virtual bool SequencePlus ( const MIDICue & q_list ); 99 | virtual bool SequenceMinus(); 100 | virtual bool SequenceMinus ( const MIDICue & q_list ); 101 | virtual bool StartClock(); 102 | virtual bool StartClock ( const MIDICue & q_list ); 103 | virtual bool StopClock(); 104 | virtual bool StopClock ( const MIDICue & q_list ); 105 | virtual bool ZeroClock(); 106 | virtual bool ZeroClock ( const MIDICue & q_list ); 107 | virtual bool SetClock ( 108 | uchar hr, uchar mn, uchar sc, uchar fr, uchar ff 109 | ); 110 | virtual bool SetClock ( 111 | uchar hr, uchar mn, uchar sc, uchar fr, uchar ff, 112 | const MIDICue & q_list 113 | ); 114 | virtual bool MTCChaseOn(); 115 | virtual bool MTCChaseOn ( const MIDICue & q_list ); 116 | virtual bool MTCChaseOff(); 117 | virtual bool MTCChaseOff ( const MIDICue & q_list ); 118 | virtual bool OpenQList ( const MIDICue & q_list ); 119 | virtual bool CloseQList ( const MIDICue & q_list ); 120 | virtual bool OpenQPath ( const MIDICue & q_path ); 121 | virtual bool CloseQPath ( const MIDICue & q_path ); 122 | 123 | }; 124 | 125 | } 126 | 127 | #endif 128 | -------------------------------------------------------------------------------- /libs/jdksmidi/include/jdksmidi/multitrack.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjdksmidi-2004 C++ Class Library for MIDI 3 | * 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 5 | * www.jdkoftinoff.com 6 | * jeffk@jdkoftinoff.com 7 | * 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | /* 25 | ** Copyright 1986 to 1998 By J.D. Koftinoff Software, Ltd. 26 | ** 27 | ** All rights reserved. 28 | ** 29 | ** No one may duplicate this source code in any form for any reason 30 | ** without the written permission given by J.D. Koftinoff Software, Ltd. 31 | ** 32 | */ 33 | // 34 | // Copyright (C) 2010 V.R.Madgazin 35 | // www.vmgames.com vrm@vmgames.com 36 | // 37 | 38 | #ifndef JDKSMIDI_MULTITRACK_H 39 | #define JDKSMIDI_MULTITRACK_H 40 | 41 | #include "jdksmidi/track.h" 42 | 43 | namespace jdksmidi 44 | { 45 | 46 | class MIDIMultiTrack; 47 | class MIDIMultiTrackIteratorState; 48 | class MIDIMultiTrackIterator; 49 | 50 | class MIDIMultiTrack 51 | { 52 | private: 53 | 54 | // delete old multitrack, construct new 55 | bool CreateObject ( int num_tracks_, bool deletable_ ); 56 | 57 | public: 58 | 59 | MIDIMultiTrack ( int max_num_tracks_ = 64, bool deletable_ = true ); 60 | virtual ~MIDIMultiTrack(); 61 | 62 | void SetTrack ( int track_num, MIDITrack *track ) 63 | { 64 | tracks[track_num] = track; 65 | } 66 | 67 | MIDITrack *GetTrack ( int track_num ) 68 | { 69 | return tracks[track_num]; 70 | } 71 | const MIDITrack *GetTrack ( int track_num ) const 72 | { 73 | return tracks[track_num]; 74 | } 75 | 76 | int GetNumTracks() const 77 | { 78 | return number_of_tracks; 79 | } 80 | 81 | // return number of tracks with events, last tracks have no events 82 | int GetNumTracksWithEvents() const; 83 | 84 | // test and sort events temporal order in all tracks 85 | void SortEventsOrder(); 86 | 87 | // delete all tracks and remake multitrack with new amount of empty tracks 88 | bool ClearAndResize ( int num_tracks ); 89 | 90 | // store src track and remake multitrack object with 17 tracks (src track can be a member of multitrack obiect), 91 | // move src track channel events to tracks 1-16, and all other types of events to track 0 92 | bool AssignEventsToTracks ( const MIDITrack *src ); 93 | 94 | // the same as previous, but argument is track number of multitrack object himself 95 | bool AssignEventsToTracks ( int track_num = 0 ) 96 | { 97 | return AssignEventsToTracks( GetTrack( track_num ) ); 98 | } 99 | 100 | void Clear(); 101 | 102 | int GetClksPerBeat() const 103 | { 104 | return clks_per_beat; 105 | } 106 | void SetClksPerBeat ( int cpb ) 107 | { 108 | clks_per_beat = cpb; 109 | } 110 | 111 | int GetNumEvents() const 112 | { 113 | int num_events = 0; 114 | for ( int i = 0; i < number_of_tracks; ++i ) 115 | num_events += tracks[i]->GetNumEvents(); 116 | return num_events; 117 | } 118 | 119 | protected: 120 | 121 | MIDITrack **tracks; 122 | int number_of_tracks; 123 | bool deletable; 124 | 125 | int clks_per_beat; 126 | }; 127 | 128 | class MIDIMultiTrackIteratorState 129 | { 130 | public: 131 | 132 | MIDIMultiTrackIteratorState ( int num_tracks_ = 64 ); 133 | MIDIMultiTrackIteratorState ( const MIDIMultiTrackIteratorState &m ); 134 | virtual ~MIDIMultiTrackIteratorState(); 135 | 136 | const MIDIMultiTrackIteratorState & operator = ( const MIDIMultiTrackIteratorState &m ); 137 | 138 | int GetNumTracks() const 139 | { 140 | return num_tracks; 141 | } 142 | int GetCurEventTrack() const 143 | { 144 | return cur_event_track; 145 | } 146 | MIDIClockTime GetCurrentTime() const 147 | { 148 | return cur_time; 149 | } 150 | 151 | void Reset(); 152 | int FindTrackOfFirstEvent(); 153 | 154 | MIDIClockTime cur_time; 155 | int cur_event_track; 156 | int num_tracks; 157 | int *next_event_number; 158 | MIDIClockTime *next_event_time; 159 | }; 160 | 161 | class MIDIMultiTrackIterator 162 | { 163 | public: 164 | 165 | MIDIMultiTrackIterator ( const MIDIMultiTrack *mlt ); 166 | virtual ~MIDIMultiTrackIterator(); 167 | 168 | 169 | void GoToTime ( MIDIClockTime time ); 170 | 171 | bool GetCurEventTime ( MIDIClockTime *t ) const; 172 | bool GetCurEvent ( int *track, const MIDITimedBigMessage **msg ) const; 173 | bool GoToNextEvent(); 174 | 175 | bool GoToNextEventOnTrack ( int track ); 176 | 177 | const MIDIMultiTrackIteratorState &GetState() const 178 | { 179 | return state; 180 | } 181 | 182 | MIDIMultiTrackIteratorState &GetState() 183 | { 184 | return state; 185 | } 186 | 187 | void SetState ( const MIDIMultiTrackIteratorState &s ) 188 | { 189 | state = s; 190 | } 191 | 192 | const MIDIMultiTrack * GetMultiTrack() const 193 | { 194 | return multitrack; 195 | } 196 | 197 | protected: 198 | 199 | const MIDIMultiTrack *multitrack; 200 | MIDIMultiTrackIteratorState state; 201 | }; 202 | 203 | } 204 | 205 | #endif 206 | 207 | 208 | -------------------------------------------------------------------------------- /libs/jdksmidi/include/jdksmidi/filewrite.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjdksmidi-2004 C++ Class Library for MIDI 3 | * 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 5 | * www.jdkoftinoff.com 6 | * jeffk@jdkoftinoff.com 7 | * 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | /* 25 | ** Copyright 1986 to 1998 By J.D. Koftinoff Software, Ltd. 26 | ** 27 | ** All rights reserved. 28 | ** 29 | ** No one may duplicate this source code in any form for any reason 30 | ** without the written permission given by J.D. Koftinoff Software, Ltd. 31 | ** 32 | */ 33 | // 34 | // Copyright (C) 2010 V.R.Madgazin 35 | // www.vmgames.com vrm@vmgames.com 36 | // 37 | 38 | #ifndef JDKSMIDI_FILEWRITE_H 39 | #define JDKSMIDI_FILEWRITE_H 40 | 41 | #include "jdksmidi/midi.h" 42 | #include "jdksmidi/msg.h" 43 | #include "jdksmidi/sysex.h" 44 | #include "jdksmidi/file.h" 45 | 46 | namespace jdksmidi 47 | { 48 | 49 | class MIDIFileWriteStream; 50 | class MIDIFileWriteStreamFile; 51 | class MIDIFileWrite; 52 | 53 | class MIDIFileWriteStream 54 | { 55 | public: 56 | MIDIFileWriteStream(); 57 | virtual ~MIDIFileWriteStream(); 58 | 59 | virtual long Seek ( long pos, int whence = SEEK_SET ) = 0; 60 | virtual int WriteChar ( int c ) = 0; 61 | }; 62 | 63 | class MIDIFileWriteStreamFile : public MIDIFileWriteStream 64 | { 65 | public: 66 | MIDIFileWriteStreamFile ( FILE *f_ ); 67 | virtual ~MIDIFileWriteStreamFile(); 68 | 69 | long Seek ( long pos, int whence = SEEK_SET ); 70 | int WriteChar ( int c ); 71 | protected: 72 | FILE *f; 73 | }; 74 | 75 | class MIDIFileWriteStreamFileName : public MIDIFileWriteStreamFile 76 | { 77 | public: 78 | MIDIFileWriteStreamFileName ( const char *fname ) : MIDIFileWriteStreamFile ( fopen ( fname, "wb" ) ) 79 | { 80 | } 81 | 82 | #ifdef WIN32 83 | MIDIFileWriteStreamFileName ( const wchar_t *fname ) : MIDIFileWriteStreamFile ( _wfopen ( fname, L"wb" ) ) 84 | { 85 | } 86 | #endif 87 | 88 | bool IsValid() 89 | { 90 | return f != 0; 91 | } 92 | 93 | virtual ~MIDIFileWriteStreamFileName() 94 | { 95 | if ( f ) 96 | { 97 | fclose ( f ); 98 | } 99 | } 100 | 101 | }; 102 | 103 | class MIDIFileWrite : protected MIDIFile 104 | { 105 | public: 106 | MIDIFileWrite ( MIDIFileWriteStream *out_stream_ ); 107 | virtual ~MIDIFileWrite(); 108 | 109 | bool ErrorOccurred() 110 | { 111 | return error; 112 | } 113 | unsigned long GetFileLength() 114 | { 115 | return file_length; 116 | } 117 | unsigned long GetTrackLength() 118 | { 119 | return track_length; 120 | } 121 | void ResetTrackLength() 122 | { 123 | track_length = 0; 124 | } 125 | void ResetTrackTime() 126 | { 127 | track_time = 0; 128 | } 129 | 130 | void WriteFileHeader ( int format, int ntrks, int division ); 131 | void WriteTrackHeader ( unsigned long length ); 132 | 133 | void WriteEvent ( const MIDITimedBigMessage &m ); 134 | 135 | void WriteSystemExclusiveEvent ( const MIDITimedBigMessage &m ); 136 | void WriteTextEvent ( unsigned long time, unsigned char type, const char *text ); 137 | void WriteMetaEvent ( unsigned long time, unsigned char type, const unsigned char *data, long length ); 138 | void WriteMetaMisc ( const MIDITimedBigMessage &m ); 139 | void WriteTempo ( const MIDITimedBigMessage &m ); 140 | 141 | void WriteKeySignature ( unsigned long time, char sharp_flat, char minor ); 142 | void WriteTimeSignature ( 143 | unsigned long time, 144 | unsigned char numerator = 4, 145 | unsigned char denominator_power = 2, 146 | unsigned char midi_clocks_per_metronome = 24, 147 | unsigned char num_32nd_per_midi_quarter_note = 8 ); 148 | 149 | void WriteEndOfTrack ( unsigned long time ); 150 | virtual void RewriteTrackLength(); 151 | // false argument disable use running status in midi file (true on default) 152 | void UseRunningStatus( bool use ) 153 | { 154 | use_running_status = use; 155 | } 156 | 157 | protected: 158 | virtual void Error ( const char *s ); 159 | 160 | void WriteCharacter ( uchar c ) 161 | { 162 | if ( out_stream->WriteChar ( c ) < 0 ) 163 | error = true; 164 | } 165 | 166 | void Seek ( long pos ) 167 | { 168 | if ( out_stream->Seek ( pos ) < 0 ) 169 | error = true; 170 | } 171 | 172 | void IncrementCounters ( int c ) 173 | { 174 | track_length += c; 175 | file_length += c; 176 | } 177 | 178 | void WriteShort ( unsigned short c ); 179 | void Write3Char ( long c ); 180 | void WriteLong ( unsigned long c ); 181 | int WriteVariableNum ( unsigned long n ); 182 | void WriteDeltaTime ( unsigned long time ); 183 | 184 | private: 185 | bool use_running_status; // true on default 186 | bool error; 187 | bool within_track; 188 | unsigned long file_length; 189 | unsigned long track_length; 190 | unsigned long track_time; 191 | unsigned long track_position; 192 | uchar running_status; 193 | 194 | MIDIFileWriteStream *out_stream; 195 | }; 196 | } 197 | 198 | #endif 199 | 200 | 201 | -------------------------------------------------------------------------------- /libs/jdksmidi/examples/jdksmidi_rewrite_midifile.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * libjdksmidi-2004 C++ Class Library for MIDI 3 | * 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 5 | * www.jdkoftinoff.com 6 | * jeffk@jdkoftinoff.com 7 | * 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | // 25 | // jdksmidi_rewrite_midifile.cpp 26 | // Copyright (C) 2010 V.R.Madgazin 27 | // www.vmgames.com vrm@vmgames.com 28 | // 29 | 30 | #ifdef WIN32 31 | #include 32 | #endif 33 | 34 | #include "jdksmidi/world.h" 35 | #include "jdksmidi/track.h" 36 | #include "jdksmidi/multitrack.h" 37 | #include "jdksmidi/filereadmultitrack.h" 38 | #include "jdksmidi/fileread.h" 39 | #include "jdksmidi/fileshow.h" 40 | #include "jdksmidi/filewritemultitrack.h" 41 | using namespace jdksmidi; 42 | 43 | #include 44 | using namespace std; 45 | 46 | // delete all text events from multitrack object 47 | void DeleteAllTracksText( MIDIMultiTrack &tracks ) 48 | { 49 | int num_tracks = tracks.GetNumTracksWithEvents(); 50 | 51 | for ( int nt = 0; nt < num_tracks; ++nt ) 52 | { 53 | MIDITrack &trk = *tracks.GetTrack( nt ); 54 | int num_events = trk.GetNumEvents(); 55 | 56 | for ( int ne = 0; ne < num_events; ++ne ) 57 | { 58 | MIDITimedBigMessage *msg = trk.GetEvent( ne ); 59 | // convert any text midi event to NoOp event 60 | if ( msg->IsTextEvent() ) 61 | trk.MakeEventNoOp( ne ); 62 | } 63 | } 64 | } 65 | 66 | void args_err() 67 | { 68 | cerr << "usage:\n\tjdkmidi_rewrite_midifile INFILE.mid OUTFILE.mid ['1' for reduce outfile size]\n"; 69 | } 70 | 71 | int main ( int argc, char **argv ) 72 | { 73 | int return_code = -1; 74 | 75 | if ( argc > 1 ) 76 | { 77 | const char *infile_name = argv[1]; 78 | 79 | // the stream used to read the input file 80 | MIDIFileReadStreamFile rs ( infile_name ); 81 | if ( !rs.IsValid() ) 82 | { 83 | cerr << "\nError opening file " << infile_name << endl; 84 | return return_code; 85 | } 86 | 87 | if ( argc <= 2 ) 88 | { 89 | args_err(); 90 | return return_code; 91 | } 92 | 93 | const char *outfile_name = argv[2]; 94 | 95 | // the multitrack object which will hold all the tracks 96 | MIDIMultiTrack tracks( 1 ); // only 1 track in multitrack object - not enough for midifile format 1 97 | 98 | // the object which loads the tracks into the tracks object 99 | MIDIFileReadMultiTrack track_loader ( &tracks ); 100 | 101 | // the object which parses the midifile and gives it to the multitrack loader 102 | MIDIFileRead reader ( &rs, &track_loader ); 103 | 104 | // make amount of of tracks equal to midifile_num_tracks 105 | int midifile_num_tracks = reader.ReadNumTracks(); 106 | tracks.ClearAndResize( midifile_num_tracks ); 107 | 108 | // load the midifile into the multitrack object 109 | if ( !reader.Parse() ) 110 | { 111 | cerr << "\nError Parse file " << infile_name << endl; 112 | return return_code; 113 | } 114 | else 115 | { 116 | // ok Parse(), get UsedRunningStatus() low level midi info 117 | // cout << "\nUsed Running Status: " << reader.UsedRunningStatus() << " In file: " << infile_name << endl; 118 | } 119 | 120 | // if exist any of argv[3]: delete all text events and optimize tracks if possible 121 | if ( argc > 3 ) 122 | { 123 | // delete all text events from all tracks 124 | DeleteAllTracksText( tracks ); 125 | 126 | // remake multitrack object with 17 tracks and optimize new tracks content: 127 | // move old track 0 channal events to new tracks 1-16, and all other types of events to new track 0 128 | if ( midifile_num_tracks == 1 ) tracks.AssignEventsToTracks( 0 ); 129 | // this function can reduce midifile size because of increase number of events with running status 130 | } 131 | 132 | // create the output stream 133 | MIDIFileWriteStreamFileName out_stream ( outfile_name ); 134 | 135 | if ( out_stream.IsValid() ) 136 | { 137 | // the object which takes the midi tracks and writes the midifile to the output stream 138 | MIDIFileWriteMultiTrack writer ( &tracks, &out_stream ); 139 | 140 | // uncomment this string for output midifile without running status usage 141 | // writer.UseRunningStatus( false ); 142 | 143 | // extract the original multitrack division 144 | int division = reader.GetDivision(); 145 | 146 | // get really number of track, used in reader.Parse() process 147 | int num_tracks = tracks.GetNumTracksWithEvents(); 148 | 149 | // write the output midi file 150 | if ( writer.Write ( num_tracks, division ) ) 151 | { 152 | cout << "\nAll OK. Number of tracks with events " << num_tracks << endl; 153 | return_code = 0; 154 | } 155 | else 156 | { 157 | cerr << "\nError writing file " << outfile_name << endl; 158 | } 159 | } 160 | else 161 | { 162 | cerr << "\nError opening file " << outfile_name << endl; 163 | } 164 | } 165 | else 166 | { 167 | args_err(); 168 | } 169 | 170 | return return_code; 171 | } 172 | 173 | -------------------------------------------------------------------------------- /example-ofxThreadedMidiPlayer-playback/config.make: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # CONFIGURE PROJECT MAKEFILE (optional) 3 | # This file is where we make project specific configurations. 4 | ################################################################################ 5 | 6 | ################################################################################ 7 | # OF ROOT 8 | # The location of your root openFrameworks installation 9 | # (default) OF_ROOT = ../../.. 10 | ################################################################################ 11 | # OF_ROOT = ../../.. 12 | 13 | ################################################################################ 14 | # PROJECT ROOT 15 | # The location of the project - a starting place for searching for files 16 | # (default) PROJECT_ROOT = . (this directory) 17 | # 18 | ################################################################################ 19 | # PROJECT_ROOT = . 20 | 21 | ################################################################################ 22 | # PROJECT SPECIFIC CHECKS 23 | # This is a project defined section to create internal makefile flags to 24 | # conditionally enable or disable the addition of various features within 25 | # this makefile. For instance, if you want to make changes based on whether 26 | # GTK is installed, one might test that here and create a variable to check. 27 | ################################################################################ 28 | # None 29 | 30 | ################################################################################ 31 | # PROJECT EXTERNAL SOURCE PATHS 32 | # These are fully qualified paths that are not within the PROJECT_ROOT folder. 33 | # Like source folders in the PROJECT_ROOT, these paths are subject to 34 | # exlclusion via the PROJECT_EXLCUSIONS list. 35 | # 36 | # (default) PROJECT_EXTERNAL_SOURCE_PATHS = (blank) 37 | # 38 | # Note: Leave a leading space when adding list items with the += operator 39 | ################################################################################ 40 | # PROJECT_EXTERNAL_SOURCE_PATHS = 41 | 42 | ################################################################################ 43 | # PROJECT EXCLUSIONS 44 | # These makefiles assume that all folders in your current project directory 45 | # and any listed in the PROJECT_EXTERNAL_SOURCH_PATHS are are valid locations 46 | # to look for source code. The any folders or files that match any of the 47 | # items in the PROJECT_EXCLUSIONS list below will be ignored. 48 | # 49 | # Each item in the PROJECT_EXCLUSIONS list will be treated as a complete 50 | # string unless teh user adds a wildcard (%) operator to match subdirectories. 51 | # GNU make only allows one wildcard for matching. The second wildcard (%) is 52 | # treated literally. 53 | # 54 | # (default) PROJECT_EXCLUSIONS = (blank) 55 | # 56 | # Will automatically exclude the following: 57 | # 58 | # $(PROJECT_ROOT)/bin% 59 | # $(PROJECT_ROOT)/obj% 60 | # $(PROJECT_ROOT)/%.xcodeproj 61 | # 62 | # Note: Leave a leading space when adding list items with the += operator 63 | ################################################################################ 64 | # PROJECT_EXCLUSIONS = 65 | 66 | ################################################################################ 67 | # PROJECT LINKER FLAGS 68 | # These flags will be sent to the linker when compiling the executable. 69 | # 70 | # (default) PROJECT_LDFLAGS = -Wl,-rpath=./libs 71 | # 72 | # Note: Leave a leading space when adding list items with the += operator 73 | ################################################################################ 74 | 75 | # Currently, shared libraries that are needed are copied to the 76 | # $(PROJECT_ROOT)/bin/libs directory. The following LDFLAGS tell the linker to 77 | # add a runtime path to search for those shared libraries, since they aren't 78 | # incorporated directly into the final executable application binary. 79 | # TODO: should this be a default setting? 80 | # PROJECT_LDFLAGS=-Wl,-rpath=./libs 81 | 82 | ################################################################################ 83 | # PROJECT DEFINES 84 | # Create a space-delimited list of DEFINES. The list will be converted into 85 | # CFLAGS with the "-D" flag later in the makefile. 86 | # 87 | # (default) PROJECT_DEFINES = (blank) 88 | # 89 | # Note: Leave a leading space when adding list items with the += operator 90 | ################################################################################ 91 | # PROJECT_DEFINES = 92 | 93 | ################################################################################ 94 | # PROJECT CFLAGS 95 | # This is a list of fully qualified CFLAGS required when compiling for this 96 | # project. These CFLAGS will be used IN ADDITION TO the PLATFORM_CFLAGS 97 | # defined in your platform specific core configuration files. These flags are 98 | # presented to the compiler BEFORE the PROJECT_OPTIMIZATION_CFLAGS below. 99 | # 100 | # (default) PROJECT_CFLAGS = (blank) 101 | # 102 | # Note: Before adding PROJECT_CFLAGS, note that the PLATFORM_CFLAGS defined in 103 | # your platform specific configuration file will be applied by default and 104 | # further flags here may not be needed. 105 | # 106 | # Note: Leave a leading space when adding list items with the += operator 107 | ################################################################################ 108 | # PROJECT_CFLAGS = 109 | 110 | ################################################################################ 111 | # PROJECT OPTIMIZATION CFLAGS 112 | # These are lists of CFLAGS that are target-specific. While any flags could 113 | # be conditionally added, they are usually limited to optimization flags. 114 | # These flags are added BEFORE the PROJECT_CFLAGS. 115 | # 116 | # PROJECT_OPTIMIZATION_CFLAGS_RELEASE flags are only applied to RELEASE targets. 117 | # 118 | # (default) PROJECT_OPTIMIZATION_CFLAGS_RELEASE = (blank) 119 | # 120 | # PROJECT_OPTIMIZATION_CFLAGS_DEBUG flags are only applied to DEBUG targets. 121 | # 122 | # (default) PROJECT_OPTIMIZATION_CFLAGS_DEBUG = (blank) 123 | # 124 | # Note: Before adding PROJECT_OPTIMIZATION_CFLAGS, please note that the 125 | # PLATFORM_OPTIMIZATION_CFLAGS defined in your platform specific configuration 126 | # file will be applied by default and further optimization flags here may not 127 | # be needed. 128 | # 129 | # Note: Leave a leading space when adding list items with the += operator 130 | ################################################################################ 131 | # PROJECT_OPTIMIZATION_CFLAGS_RELEASE = 132 | # PROJECT_OPTIMIZATION_CFLAGS_DEBUG = 133 | 134 | ################################################################################ 135 | # PROJECT COMPILERS 136 | # Custom compilers can be set for CC and CXX 137 | # (default) PROJECT_CXX = (blank) 138 | # (default) PROJECT_CC = (blank) 139 | # Note: Leave a leading space when adding list items with the += operator 140 | ################################################################################ 141 | # PROJECT_CXX = 142 | # PROJECT_CC = 143 | -------------------------------------------------------------------------------- /libs/jdksmidi/src/win32/jdksmidi_driverwin32.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * libjdksmidi-2004 C++ Class Library for MIDI 3 | * 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 5 | * www.jdkoftinoff.com 6 | * jeffk@jdkoftinoff.com 7 | * 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | // 25 | // Copyright (C) 2010 V.R.Madgazin 26 | // www.vmgames.com vrm@vmgames.com 27 | // 28 | 29 | #include "jdksmidi/world.h" 30 | 31 | #ifdef WIN32 32 | #include "jdksmidi/driverwin32.h" 33 | 34 | namespace jdksmidi 35 | { 36 | 37 | MIDISequencerGUIEventNotifierWin32::MIDISequencerGUIEventNotifierWin32 ( 38 | HWND w, 39 | DWORD msg, 40 | WPARAM wparam_value_ 41 | ) 42 | : 43 | dest_window ( w ), 44 | window_msg ( msg ), 45 | wparam_value ( wparam_value_ ), 46 | en ( true ) 47 | { 48 | } 49 | 50 | MIDISequencerGUIEventNotifierWin32::~MIDISequencerGUIEventNotifierWin32() 51 | { 52 | } 53 | 54 | 55 | void MIDISequencerGUIEventNotifierWin32::Notify ( 56 | const MIDISequencer *seq, 57 | MIDISequencerGUIEvent e 58 | ) 59 | { 60 | if ( en ) 61 | { 62 | PostMessage ( 63 | dest_window, 64 | window_msg, 65 | wparam_value, 66 | ( unsigned long ) e 67 | ); 68 | } 69 | } 70 | 71 | bool MIDISequencerGUIEventNotifierWin32::GetEnable() const 72 | { 73 | return en; 74 | } 75 | 76 | void MIDISequencerGUIEventNotifierWin32::SetEnable ( bool f ) 77 | { 78 | en = f; 79 | } 80 | 81 | 82 | 83 | MIDIDriverWin32::MIDIDriverWin32 ( int queue_size ) 84 | : 85 | MIDIDriver ( queue_size ), 86 | in_handle ( 0 ), 87 | out_handle ( 0 ), 88 | in_open ( false ), 89 | out_open ( false ), 90 | timer_open ( false ) 91 | { 92 | } 93 | 94 | MIDIDriverWin32::~MIDIDriverWin32() 95 | { 96 | StopTimer(); 97 | CloseMIDIInPort(); 98 | CloseMIDIOutPort(); 99 | } 100 | 101 | void MIDIDriverWin32::ResetMIDIOut() 102 | { 103 | if ( out_open ) 104 | { 105 | midiOutReset ( out_handle ); 106 | } 107 | } 108 | 109 | bool MIDIDriverWin32::StartTimer ( int res ) 110 | { 111 | if ( !timer_open ) 112 | { 113 | TIMECAPS tc; 114 | 115 | if ( timeGetDevCaps ( &tc, sizeof ( TIMECAPS ) ) != TIMERR_NOERROR ) 116 | { 117 | return false; 118 | } 119 | 120 | timer_res = res; 121 | 122 | if ( timer_res < ( int ) tc.wPeriodMin ) 123 | timer_res = ( int ) tc.wPeriodMin; 124 | 125 | if ( timer_res > ( int ) tc.wPeriodMax ) 126 | timer_res = ( int ) tc.wPeriodMax; 127 | 128 | timeBeginPeriod ( timer_res ); 129 | timer_id = timeSetEvent ( 130 | res, 131 | res, 132 | win32_timer, 133 | ( DWORD ) this, 134 | TIME_PERIODIC 135 | ); 136 | 137 | if ( timer_id ) 138 | { 139 | timer_open = true; 140 | } 141 | } 142 | 143 | return true; 144 | } 145 | 146 | void MIDIDriverWin32::StopTimer() 147 | { 148 | if ( timer_open ) 149 | { 150 | timeKillEvent ( timer_id ); 151 | timeEndPeriod ( timer_res ); 152 | timer_open = false; 153 | } 154 | } 155 | 156 | bool MIDIDriverWin32::OpenMIDIInPort ( int id ) 157 | { 158 | if ( !in_open ) 159 | { 160 | if ( midiInOpen ( 161 | &in_handle, 162 | id, 163 | ( DWORD ) win32_midi_in, 164 | ( DWORD ) this, 165 | CALLBACK_FUNCTION ) != 0 166 | ) 167 | { 168 | return false; 169 | } 170 | 171 | midiInStart ( in_handle ); 172 | in_open = true; 173 | } 174 | 175 | return true; 176 | } 177 | 178 | bool MIDIDriverWin32::OpenMIDIOutPort ( int id ) 179 | { 180 | if ( !out_open ) 181 | { 182 | int e = midiOutOpen ( 183 | &out_handle, 184 | id, 185 | 0, 186 | 0, 187 | CALLBACK_NULL 188 | ); 189 | 190 | if ( e != 0 ) 191 | { 192 | return false; 193 | } 194 | 195 | out_open = true; 196 | } 197 | 198 | return true; 199 | } 200 | 201 | void MIDIDriverWin32::CloseMIDIInPort() 202 | { 203 | if ( in_open ) 204 | { 205 | midiInStop ( in_handle ); 206 | midiInClose ( in_handle ); 207 | in_open = false; 208 | } 209 | } 210 | 211 | void MIDIDriverWin32::CloseMIDIOutPort() 212 | { 213 | if ( out_open ) 214 | { 215 | midiOutClose ( out_handle ); 216 | out_open = false; 217 | Reset(); 218 | } 219 | } 220 | 221 | bool MIDIDriverWin32::HardwareMsgOut ( const MIDITimedBigMessage &msg ) 222 | { 223 | if ( out_open ) 224 | { 225 | // dont send sysex or meta-events 226 | // if ( msg.GetStatus() < 0xff && !msg.IsSysEx() ) 227 | if ( msg.IsChannelEvent() ) 228 | { 229 | DWORD winmsg; 230 | winmsg = 231 | ( ( ( DWORD ) msg.GetStatus() & 0xFF ) ) 232 | | ( ( ( DWORD ) msg.GetByte1() & 0xFF ) << 8 ) 233 | | ( ( ( DWORD ) msg.GetByte2() & 0xFF ) << 16 ); 234 | 235 | if ( midiOutShortMsg ( out_handle, winmsg ) != 0 ) 236 | { 237 | return false; 238 | } 239 | } 240 | 241 | return true; 242 | } 243 | 244 | return false; 245 | } 246 | 247 | void CALLBACK MIDIDriverWin32::win32_timer ( 248 | UINT wTimerID, 249 | UINT msg, 250 | DWORD dwUser, 251 | DWORD dw1, 252 | DWORD dw2 253 | ) 254 | { 255 | MIDIDriverWin32 *self = ( MIDIDriverWin32 * ) dwUser; 256 | self->TimeTick ( timeGetTime() ); 257 | } 258 | 259 | void CALLBACK MIDIDriverWin32::win32_midi_in ( 260 | HMIDIIN hMidiIn, 261 | UINT wMsg, 262 | DWORD dwInstance, 263 | DWORD dwParam1, 264 | DWORD dwParam2 265 | ) 266 | { 267 | MIDIDriverWin32 *self = ( MIDIDriverWin32 * ) dwInstance; 268 | 269 | if ( wMsg == MIM_DATA ) 270 | { 271 | MIDITimedBigMessage msg; 272 | msg.SetStatus ( ( unsigned char ) ( dwParam1 & 0xff ) ); 273 | msg.SetByte1 ( ( unsigned char ) ( ( dwParam1 >> 8 ) & 0xff ) ); 274 | msg.SetByte2 ( ( unsigned char ) ( ( dwParam1 >> 16 ) & 0xff ) ); 275 | msg.SetTime ( timeGetTime() ); 276 | self->HardwareMsgIn ( msg ); 277 | } 278 | } 279 | 280 | } 281 | #endif 282 | 283 | -------------------------------------------------------------------------------- /libs/jdksmidi/include/jdksmidi/fileread.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjdksmidi-2004 C++ Class Library for MIDI 3 | * 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 5 | * www.jdkoftinoff.com 6 | * jeffk@jdkoftinoff.com 7 | * 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | /* 25 | ** Copyright 1986 to 1998 By J.D. Koftinoff Software, Ltd. 26 | ** 27 | ** All rights reserved. 28 | ** 29 | ** No one may duplicate this source code in any form for any reason 30 | ** without the written permission given by J.D. Koftinoff Software, Ltd. 31 | ** 32 | */ 33 | // 34 | // Copyright (C) 2010 V.R.Madgazin 35 | // www.vmgames.com vrm@vmgames.com 36 | // 37 | 38 | #ifndef JDKSMIDI_FILEREAD_H 39 | #define JDKSMIDI_FILEREAD_H 40 | 41 | #include "jdksmidi/midi.h" 42 | #include "jdksmidi/msg.h" 43 | #include "jdksmidi/sysex.h" 44 | #include "jdksmidi/file.h" 45 | 46 | namespace jdksmidi 47 | { 48 | 49 | class MIDIFileReadStream; 50 | class MIDIFileReadStreamFile; 51 | class MIDIFileEvents; 52 | class MIDIFileRead; 53 | 54 | 55 | class MIDIFileReadStream 56 | { 57 | public: 58 | MIDIFileReadStream() 59 | { 60 | } 61 | 62 | virtual ~MIDIFileReadStream() 63 | { 64 | } 65 | 66 | virtual void Rewind() = 0; 67 | 68 | virtual int ReadChar() = 0; 69 | }; 70 | 71 | class MIDIFileReadStreamFile : public MIDIFileReadStream 72 | { 73 | public: 74 | explicit MIDIFileReadStreamFile ( const char *fname ) 75 | { 76 | f = fopen ( fname, "rb" ); 77 | } 78 | 79 | #ifdef WIN32 80 | explicit MIDIFileReadStreamFile ( const wchar_t *fname ) 81 | { 82 | f = _wfopen ( fname, L"rb" ); 83 | } 84 | #endif 85 | 86 | explicit MIDIFileReadStreamFile ( FILE *f_ ) : f ( f_ ) 87 | { 88 | } 89 | 90 | virtual ~MIDIFileReadStreamFile() 91 | { 92 | if ( f ) fclose ( f ); 93 | } 94 | 95 | virtual void Rewind() 96 | { 97 | if ( f ) rewind ( f ); 98 | } 99 | 100 | bool IsValid() 101 | { 102 | return f != 0; 103 | } 104 | 105 | virtual int ReadChar() 106 | { 107 | int r = -1; 108 | 109 | if ( f && !feof ( f ) && !ferror ( f ) ) 110 | { 111 | r = fgetc ( f ); 112 | } 113 | 114 | return r; 115 | } 116 | 117 | 118 | private: 119 | FILE *f; 120 | }; 121 | 122 | class MIDIFileEvents : protected MIDIFile 123 | { 124 | public: 125 | MIDIFileEvents() 126 | { 127 | } 128 | 129 | virtual ~MIDIFileEvents() 130 | { 131 | } 132 | 133 | 134 | // 135 | // The possible events in a MIDI Files 136 | // 137 | 138 | virtual void mf_system_mode ( const MIDITimedMessage &msg ); 139 | virtual void mf_note_on ( const MIDITimedMessage &msg ); 140 | virtual void mf_note_off ( const MIDITimedMessage &msg ); 141 | virtual void mf_poly_after ( const MIDITimedMessage &msg ); 142 | virtual void mf_bender ( const MIDITimedMessage &msg ); 143 | virtual void mf_program ( const MIDITimedMessage &msg ); 144 | virtual void mf_chan_after ( const MIDITimedMessage &msg ); 145 | virtual void mf_control ( const MIDITimedMessage &msg ); 146 | 147 | virtual bool mf_metamisc ( MIDIClockTime time, int type, int len, unsigned char *data ); 148 | virtual bool mf_timesig ( MIDIClockTime time, int, int, int, int ); 149 | virtual bool mf_tempo ( MIDIClockTime time, unsigned char a, unsigned char b, unsigned char c ); 150 | 151 | virtual bool mf_keysig ( MIDIClockTime time, int, int ); 152 | virtual bool mf_sqspecific ( MIDIClockTime time, int, unsigned char * ); 153 | virtual bool mf_text ( MIDIClockTime time, int, int, unsigned char * ); 154 | virtual bool mf_eot ( MIDIClockTime time ); 155 | virtual bool mf_sysex ( MIDIClockTime time, int type, int len, unsigned char *s ); 156 | 157 | // 158 | // the following methods are to be overridden for your specific purpose 159 | // 160 | 161 | virtual void mf_error ( const char * ); 162 | 163 | virtual void mf_starttrack ( int trk ); 164 | virtual void mf_endtrack ( int trk ); 165 | virtual void mf_header ( int, int, int ); 166 | 167 | // 168 | // Higher level dispatch functions 169 | // 170 | virtual void UpdateTime ( MIDIClockTime delta_time ); 171 | virtual bool MetaEvent ( MIDIClockTime time, int type, int len, unsigned char *buf ); 172 | virtual bool ChanMessage ( const MIDITimedMessage &msg); 173 | virtual void SortEventsOrder() {} 174 | 175 | }; 176 | 177 | class MIDIFileRead : protected MIDIFile 178 | { 179 | public: 180 | MIDIFileRead ( 181 | MIDIFileReadStream *input_stream_, 182 | MIDIFileEvents *event_handler_, 183 | unsigned long max_msg_len = 8192 184 | ); 185 | virtual ~MIDIFileRead(); 186 | 187 | // return false if not enough number of tracks or events in any track 188 | virtual bool Parse(); 189 | 190 | // read midifile header, return number of tracks 191 | int ReadNumTracks(); 192 | 193 | int GetFormat() const 194 | { 195 | return header_format; 196 | } 197 | int GetNumTracks() const 198 | { 199 | return header_ntrks; 200 | } 201 | // call it after Parse(): return true if file contain event(s) with running status 202 | bool UsedRunningStatus() const 203 | { 204 | return used_running_status; 205 | } 206 | // return header_division = clock per beat value for range 1...32767 207 | int GetDivision() const 208 | { 209 | return header_division; 210 | } 211 | 212 | protected: 213 | virtual int ReadHeader(); 214 | virtual void mf_error ( const char * ); 215 | 216 | MIDIClockTime cur_time; 217 | int skip_init; 218 | unsigned long to_be_read; 219 | int cur_track; 220 | int abort_parse; 221 | 222 | unsigned char *the_msg; 223 | int max_msg_len; 224 | int act_msg_len; // actual msg length 225 | 226 | private: 227 | unsigned long ReadVariableNum(); 228 | unsigned long Read32Bit(); 229 | int Read16Bit(); 230 | 231 | void ReadTrack(); 232 | 233 | void MsgAdd ( int ); 234 | void MsgInit(); 235 | 236 | int EGetC(); 237 | 238 | int ReadMT ( unsigned long, int ); 239 | 240 | bool FormChanMessage ( unsigned char st, unsigned char b1, unsigned char b2 ); 241 | // reset data for multiple parse 242 | void Reset(); 243 | 244 | bool used_running_status; 245 | 246 | int header_format; 247 | int header_ntrks; 248 | int header_division; 249 | 250 | MIDIFileReadStream *input_stream; 251 | MIDIFileEvents *event_handler; 252 | }; 253 | } 254 | 255 | #endif 256 | 257 | -------------------------------------------------------------------------------- /libs/jdksmidi/src/jdksmidi_filereadmultitrack.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * libjdksmidi-2004 C++ Class Library for MIDI 3 | * 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 5 | * www.jdkoftinoff.com 6 | * jeffk@jdkoftinoff.com 7 | * 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | /* 25 | ** Copyright 1986 to 1998 By J.D. Koftinoff Software, Ltd. 26 | ** 27 | ** All rights reserved. 28 | ** 29 | ** No one may duplicate this source code in any form for any reason 30 | ** without the written permission given by J.D. Koftinoff Software, Ltd. 31 | ** 32 | */ 33 | // 34 | // Copyright (C) 2010 V.R.Madgazin 35 | // www.vmgames.com vrm@vmgames.com 36 | // 37 | 38 | #include "jdksmidi/world.h" 39 | #include "jdksmidi/filereadmultitrack.h" 40 | 41 | namespace jdksmidi 42 | { 43 | 44 | MIDIFileReadMultiTrack::MIDIFileReadMultiTrack ( MIDIMultiTrack *mlttrk ) 45 | : multitrack ( mlttrk ), cur_track ( -1 ) 46 | { 47 | } 48 | 49 | MIDIFileReadMultiTrack::~MIDIFileReadMultiTrack() 50 | { 51 | } 52 | 53 | void MIDIFileReadMultiTrack::mf_error ( const char * ) 54 | { 55 | } 56 | 57 | void MIDIFileReadMultiTrack::mf_starttrack ( int trk ) 58 | { 59 | cur_track = trk; 60 | } 61 | 62 | void MIDIFileReadMultiTrack::mf_endtrack ( int trk ) 63 | { 64 | cur_track = -1; 65 | } 66 | 67 | bool MIDIFileReadMultiTrack::AddEventToMultiTrack ( const MIDITimedMessage &msg, MIDISystemExclusive *sysex, int dest_track ) 68 | { 69 | bool result = false; 70 | 71 | if ( dest_track != -1 && dest_track < multitrack->GetNumTracks() ) 72 | { 73 | MIDITrack *t = multitrack->GetTrack ( dest_track ); 74 | 75 | if ( t ) 76 | { 77 | result = t->PutEvent ( msg, sysex ); 78 | } 79 | } 80 | 81 | return result; 82 | } 83 | 84 | void MIDIFileReadMultiTrack::mf_header (int the_format_, int ntrks_, int division_ ) 85 | { 86 | the_format = the_format_; 87 | num_tracks = ntrks_; 88 | division = division_; 89 | multitrack->SetClksPerBeat ( division ); 90 | } 91 | 92 | bool MIDIFileReadMultiTrack::ChanMessage ( const MIDITimedMessage &msg ) 93 | { 94 | return AddEventToMultiTrack ( msg, 0, cur_track ); 95 | } 96 | 97 | void MIDIFileReadMultiTrack::SortEventsOrder() 98 | { 99 | multitrack->SortEventsOrder(); 100 | } 101 | 102 | bool MIDIFileReadMultiTrack::mf_metamisc ( MIDIClockTime time, int type, int len, unsigned char *data ) 103 | { 104 | // code for all miscellaneous meta events 105 | 106 | MIDITimedMessage msg; 107 | msg.SetTime ( time ); 108 | 109 | msg.SetStatus( META_EVENT ); 110 | msg.SetByte1( type ); 111 | 112 | if ( len <= 5 ) 113 | { 114 | if ( len > 0 ) 115 | msg.SetByte2( data[0] ); 116 | 117 | if ( len > 1 ) 118 | msg.SetByte3( data[1] ); 119 | 120 | if ( len > 2 ) 121 | msg.SetByte4( data[2] ); 122 | 123 | if ( len > 3 ) 124 | msg.SetByte5( data[3] ); 125 | 126 | if ( len > 4 ) 127 | msg.SetByte6( data[4] ); 128 | } 129 | // else msg add to track, but do'nt write to output midifile! 130 | 131 | msg.SetDataLength( len ); 132 | return AddEventToMultiTrack ( msg, 0, cur_track ); 133 | } 134 | 135 | bool MIDIFileReadMultiTrack::mf_timesig ( MIDIClockTime time, int num, int den_pow, int clks_per_metro, int notated_32nd_per_quarter ) 136 | { 137 | MIDITimedMessage msg; 138 | msg.SetTime ( time ); 139 | msg.SetTimeSig ( num, den_pow, clks_per_metro, notated_32nd_per_quarter ); 140 | msg.SetDataLength( 5 ); // source 4 bytes + 1 byte for denominator 141 | return AddEventToMultiTrack ( msg, 0, cur_track ); 142 | } 143 | 144 | bool MIDIFileReadMultiTrack::mf_tempo ( MIDIClockTime time, unsigned char a, unsigned char b, unsigned char c ) 145 | { 146 | MIDITimedMessage msg; 147 | msg.SetTime ( time ); 148 | msg.SetMetaEvent ( MF_META_TEMPO, a, b ); 149 | msg.SetByte4( c ); 150 | msg.SetDataLength( 3 ); 151 | return AddEventToMultiTrack ( msg, 0, cur_track ); 152 | } 153 | 154 | bool MIDIFileReadMultiTrack::mf_keysig ( MIDIClockTime time, int c, int v ) 155 | { 156 | MIDITimedMessage msg; 157 | msg.SetTime ( time ); 158 | msg.SetKeySig ( ( unsigned char ) c, ( unsigned char ) v ); 159 | msg.SetDataLength( 2 ); 160 | return AddEventToMultiTrack ( msg, 0, cur_track ); 161 | } 162 | 163 | bool MIDIFileReadMultiTrack::mf_sqspecific ( MIDIClockTime time, int len, unsigned char *s ) 164 | { 165 | // read sequencer specific message as pseudo-text message 166 | return mf_text ( time, MF_META_SEQUENCER_SPECIFIC, len, s ); 167 | } 168 | 169 | bool MIDIFileReadMultiTrack::mf_text ( MIDIClockTime time, int type, int len, unsigned char *s ) 170 | { 171 | MIDITimedMessage msg; 172 | msg.SetStatus ( META_EVENT ); 173 | msg.SetMetaType ( ( uchar ) type ); // remember - MF_META_* id codes match META_* codes 174 | msg.SetTime ( time ); 175 | 176 | MIDISystemExclusive sysex( len ); 177 | 178 | for ( int i = 0; i < len; ++i ) 179 | { 180 | sysex.PutSysByte ( s[i] ); 181 | } 182 | 183 | msg.SetDataLength( 0 ); // variable data length don't saved to data_length 184 | return AddEventToMultiTrack ( msg, &sysex, cur_track ); 185 | } 186 | 187 | bool MIDIFileReadMultiTrack::mf_sysex ( MIDIClockTime time, int type, int len, unsigned char *s ) 188 | { 189 | MIDITimedMessage msg; 190 | msg.SetSysEx( type ); // set msg status byte (0xF0 or 0xF7) 191 | 192 | int num = len; // number of possible SysExURT header data bytes in msg, 0...5 193 | if ( num > 5 ) 194 | num = 5; 195 | 196 | // add up to 5 starting bytes for SysExURT functions 197 | if ( num > 0 ) 198 | msg.SetByte2( s[0] ); 199 | if ( num > 1 ) 200 | msg.SetByte3( s[1] ); 201 | if ( num > 2 ) 202 | msg.SetByte4( s[2] ); 203 | if ( num > 3 ) 204 | msg.SetByte5( s[3] ); 205 | if ( num > 4 ) 206 | msg.SetByte6( s[4] ); 207 | 208 | msg.SetTime ( time ); 209 | MIDISystemExclusive sysex( len ); 210 | 211 | for ( int i = 0; i < len; ++i ) 212 | { 213 | sysex.PutSysByte ( s[i] ); 214 | } 215 | 216 | msg.SetDataLength( num ); 217 | return AddEventToMultiTrack ( msg, &sysex, cur_track ); 218 | } 219 | 220 | bool MIDIFileReadMultiTrack::mf_eot ( MIDIClockTime time ) 221 | { 222 | MIDITimedMessage msg; 223 | msg.SetStatus ( META_EVENT ); 224 | msg.SetMetaType ( META_END_OF_TRACK ); 225 | msg.SetTime ( time ); 226 | msg.SetDataLength( 0 ); 227 | return AddEventToMultiTrack ( msg, 0, cur_track ); 228 | } 229 | 230 | } 231 | -------------------------------------------------------------------------------- /libs/jdksmidi/src/jdksmidi_keysig.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * libjdksmidi-2004 C++ Class Library for MIDI 3 | * 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 5 | * www.jdkoftinoff.com 6 | * jeffk@jdkoftinoff.com 7 | * 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | /* 25 | ** Copyright 1986 to 1998 By J.D. Koftinoff Software, Ltd. 26 | ** 27 | ** All rights reserved. 28 | ** 29 | ** No one may duplicate this source code in any form for any reason 30 | ** without the written permission given by J.D. Koftinoff Software, Ltd. 31 | ** 32 | */ 33 | 34 | 35 | #include "jdksmidi/world.h" 36 | 37 | #include "jdksmidi/keysig.h" 38 | 39 | 40 | #ifndef DEBUG_MDKEYSIG 41 | # define DEBUG_MDKEYSIG 0 42 | #endif 43 | 44 | #if DEBUG_MDKEYSIG 45 | # undef DBG 46 | # define DBG(a) a 47 | #endif 48 | 49 | namespace jdksmidi 50 | { 51 | 52 | int MIDIKeySignature::sharp_list[7] = { 3, 0, 4, 1, 5, 2, 6 }; 53 | int MIDIKeySignature::flat_list[7] = { 6, 2, 5, 1, 4, 0, 3 }; 54 | 55 | 56 | MIDIKeySignature::MIDIKeySignature() 57 | { 58 | ENTER ( "MIDIKeySignature::MIDIKeySignature()" ); 59 | use_sharps = true; 60 | sharp_flat = 0; 61 | major = true; 62 | Reset(); 63 | } 64 | 65 | MIDIKeySignature::MIDIKeySignature ( const MIDIKeySignature &k ) 66 | { 67 | ENTER ( "MIDIKeySignature::MIDIKeySignature()" ); 68 | use_sharps = k.use_sharps; 69 | sharp_flat = k.sharp_flat; 70 | major = k.major; 71 | Reset(); 72 | } 73 | 74 | 75 | // 76 | // Reset() generates the sharp/flat list based on sharp_flat, major, 77 | // and use_sharps. 78 | // 79 | 80 | void MIDIKeySignature::Reset() 81 | { 82 | ENTER ( "MIDIKeySignature::Reset()" ); 83 | 84 | if ( sharp_flat < -7 ) 85 | sharp_flat = -7; 86 | 87 | if ( sharp_flat > 7 ) 88 | sharp_flat = 7; 89 | 90 | for ( int note = 0; note < 7; ++note ) 91 | state[note] = ACCNatural; 92 | 93 | if ( sharp_flat == 0 ) 94 | { 95 | // Key of C has no sharps or flats. 96 | // and any accidentals will be sharp 97 | use_sharps = true; 98 | } 99 | 100 | else if ( sharp_flat > 0 ) 101 | { 102 | // 103 | // this key has a number of sharps in it. 104 | // 105 | use_sharps = true; 106 | 107 | for ( short i = 0; i < sharp_flat; ++i ) 108 | { 109 | state[sharp_list[i]] = ACCSharp; 110 | } 111 | } 112 | 113 | else if ( sharp_flat < 0 ) 114 | { 115 | // 116 | // this key has flats in it. 117 | // -sharp_flat is how many flats. 118 | // 119 | int flats = -sharp_flat; 120 | use_sharps = false; 121 | 122 | for ( int i = 0; i < flats; ++i ) 123 | { 124 | state[ flat_list[i] ] = ACCFlat; 125 | } 126 | } 127 | } 128 | 129 | 130 | 131 | 132 | bool MIDIKeySignature::ProcessWhiteNote ( int in_note, int *out_note ) 133 | { 134 | ENTER ( "MIDIKeySignature::ProcessWhiteNote()" ); 135 | // 136 | // check to see if this white note is allowed in the current 137 | // state. 138 | // 139 | 140 | if ( state[in_note] == ACCNatural ) 141 | { 142 | // 143 | // yes it is allowed, return it. 144 | // 145 | *out_note = in_note; 146 | // 147 | // return false to signify that this note doesn't need 148 | // an accidental. 149 | // 150 | return false; 151 | } 152 | 153 | else 154 | { 155 | // 156 | // no it was not allowed. We must change our state. 157 | // to allow it. return it. 158 | // 159 | *out_note = in_note; 160 | // 161 | // change the desired note to a natural 162 | // 163 | state[in_note] = ACCNatural; 164 | // 165 | // return true because it needed an accidental 166 | // 167 | return true; 168 | } 169 | } 170 | 171 | 172 | bool MIDIKeySignature::ProcessBlackNote ( int in_note, int *out_note ) 173 | { 174 | ENTER ( "MIDIKeySignature::ProcessBlackNote()" ); 175 | // 176 | // if this note is already sharped, 177 | // return the note unchanged and return false 178 | // because no accidental was required 179 | 180 | if ( state[in_note] == ACCSharp ) 181 | { 182 | *out_note = in_note; 183 | return false; 184 | } 185 | 186 | // 187 | // if the next note is flatted, then we could use it 188 | // instead. 189 | // 190 | 191 | if ( state[in_note+1] == ACCFlat ) 192 | { 193 | *out_note = in_note + 1; 194 | return false; 195 | } 196 | 197 | // 198 | // Couldn't find a black note. we gotta make one. 199 | // make a sharp if use_sharps==1 200 | 201 | if ( use_sharps ) 202 | { 203 | // 204 | // make this white note a sharp. 205 | // 206 | state[in_note] = ACCSharp; 207 | *out_note = in_note; 208 | // 209 | // Accidental required. return true. 210 | // 211 | return true; 212 | } 213 | 214 | else 215 | { 216 | // 217 | // make the next white note a flat. 218 | // 219 | state[in_note+1] = ACCFlat; 220 | *out_note = in_note + 1; 221 | // 222 | // Accidental required. Return true. 223 | // 224 | return true; 225 | } 226 | } 227 | 228 | 229 | 230 | // 231 | // ConvertMIDINote() takes a real MIDI note number and converts it to a 232 | // white-key note number. it returns true if an Accidental is required. 233 | // 234 | 235 | bool MIDIKeySignature::ConvertMIDINote ( 236 | int in_note, 237 | int *out_note 238 | ) 239 | { 240 | ENTER ( "MIDIKeySignature::ConvertMIDINote()" ); 241 | int octave = in_note / 12; 242 | int midi_note = in_note % 12; 243 | int actual_note = 0; 244 | bool changed = false; 245 | 246 | switch ( midi_note ) 247 | { 248 | case 0: // C 249 | changed = ProcessWhiteNote ( 0, &actual_note ); 250 | break; 251 | case 2: // D 252 | changed = ProcessWhiteNote ( 1, &actual_note ); 253 | break; 254 | case 4: // E 255 | changed = ProcessWhiteNote ( 2, &actual_note ); 256 | break; 257 | case 5: // F 258 | changed = ProcessWhiteNote ( 3, &actual_note ); 259 | break; 260 | case 7: // G 261 | changed = ProcessWhiteNote ( 4, &actual_note ); 262 | break; 263 | case 9: // A 264 | changed = ProcessWhiteNote ( 5, &actual_note ); 265 | break; 266 | case 11: // B 267 | changed = ProcessWhiteNote ( 6, &actual_note ); 268 | break; 269 | case 1: // C# 270 | changed = ProcessBlackNote ( 0, &actual_note ); 271 | break; 272 | case 3: // D# 273 | changed = ProcessBlackNote ( 1, &actual_note ); 274 | break; 275 | case 6: // F# 276 | changed = ProcessBlackNote ( 3, &actual_note ); 277 | break; 278 | case 8: // G# 279 | changed = ProcessBlackNote ( 4, &actual_note ); 280 | break; 281 | case 10: // A# 282 | changed = ProcessBlackNote ( 5, &actual_note ); 283 | break; 284 | }; 285 | 286 | *out_note = ( octave * 7 ) + actual_note; 287 | 288 | return changed; 289 | } 290 | 291 | } 292 | -------------------------------------------------------------------------------- /libs/jdksmidi/examples/vrm_music_gen_readme.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | VRM Music Generator based on libJDKSmidi C++ MIDI Library 4 | 5 | version 1.23 from February 2011 6 | 7 | Copyright (C) 2010 V.R.Madgazin 8 | www.vmgames.com 9 | vrm@vmgames.com 10 | 11 | 12 | 1. Launching. 13 | 14 | 15 | "vrm_music_gen" 16 | 17 | or with equivalent default arguments 18 | 19 | "vrm_music_gen -se 3 -in 25 -n0 0 -n1 14 -tr 48 -di 1 -ch 1 -md 43 -sd 1 -nd 0.5 -de 1.5 -pr 4" 20 | 21 | 22 | 2. Arguments. 23 | 24 | 25 | "-key key_value", key_value "I" = Integer number, "F" = Float number 26 | 27 | 28 | "-se I" random seed value (default 3); any of 32 bit integer 29 | 30 | "-in I" midi melodic instrument number (25), see section 4; 0...127 31 | 32 | "-n0 I" min index of notes array (0), see section 3; 0 for C-dur, 5 for A-moll; 0...70 33 | 34 | "-n1 I" max index of notes array (14); add N*7 to min index for N octaves diapason; 0...70 35 | 36 | "-tr I" notes transposition (48); 0...127 37 | abs. note number is calculated on formula ( notes_table[index] + transposition ) 38 | 39 | "-di I" switch for discretization of all time intervals in note duration unit (1); 0...1 40 | 41 | "-ch I" channel number (1 for melodic instruments); 1...16 42 | channel number 10 for percussion instruments, which correspond to abs. note number 43 | 44 | "-md F" total music duration in seconds (43); 0.001...3600... 45 | 46 | "-sd F" temporal section of music in seconds (1); 0.001...3600... 47 | 48 | "-nd F" note duration in seconds (0.5); 0.001...10... 49 | 50 | "-de F" average notes number per note duration (1.5); 0.1...10... 51 | 52 | "-pr I" last note prolongation time in note duration time (4); 0...4... 53 | 54 | 55 | 3. Notes array. 56 | 57 | 58 | const int MAX_INDEX = 70; 59 | int notes_table[MAX_INDEX+1] = // notes number array: all "white" notes in 10 octaves 60 | { 0, 2, 4, 5, 7, 9,11, 12,14,16,17,19,21,23, 24,26,28,29,31,33,35, 36,38,40,41,43,45,47, ... }; 61 | // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 index 62 | // C D E F G A B C D E F G A B C D E F G A B C D E F G A B notes 63 | 64 | 65 | 4. General Midi melodic instruments numbers and names. 66 | 67 | 68 | 0 Acoustic Grand Piano 69 | 1 Bright Acoustic Piano 70 | 2 Electric Grand Piano 71 | 3 Honky-tonk Piano 72 | 4 Electric Piano 1 73 | 5 Electric Piano 2 74 | 6 Harpsichord 75 | 7 Clavinet 76 | 8 Celesta 77 | 9 Glockenspiel 78 | 10 Music Box 79 | 11 Vibraphone 80 | 12 Marimba 81 | 13 Xylophone 82 | 14 Tubular Bells 83 | 15 Dulcimer 84 | 16 Drawbar Organ 85 | 17 Percussive Organ 86 | 18 Rock Organ 87 | 19 Church Organ 88 | 20 Reed Organ 89 | 21 Accordion 90 | 22 Harmonica 91 | 23 Tango Accordion 92 | 24 Acoustic Guitar (nylon) 93 | 25 Acoustic Guitar (steel) 94 | 26 Electric Guitar (jazz) 95 | 27 Electric Guitar (clean) 96 | 28 Electric Guitar (muted) 97 | 29 Overdriven Guitar 98 | 30 Distortion Guitar 99 | 31 Guitar Harmonics 100 | 32 Acoustic Bass 101 | 33 Electric Bass (finger) 102 | 34 Electric Bass (pick) 103 | 35 Fretless Bass 104 | 36 Slap Bass 1 105 | 37 Slap Bass 2 106 | 38 Synth Bass 1 107 | 39 Synth Bass 2 108 | 40 Violin 109 | 41 Viola 110 | 42 Cello 111 | 43 Contrabass 112 | 44 Tremolo Strings 113 | 45 Pizzicato Strings 114 | 46 Orchestral Harp 115 | 47 Timpani 116 | 48 String Ensemble 1 117 | 49 String Ensemble 2 118 | 50 Synth Strings 1 119 | 51 Synth Strings 2 120 | 52 Choir Aahs 121 | 53 Voice Oohs 122 | 54 Synth Voice 123 | 55 Orchestra Hit 124 | 56 Trumpet 125 | 57 Trombone 126 | 58 Tuba 127 | 59 Muted Trumpet 128 | 60 French Horn 129 | 61 Brass Section 130 | 62 Synth Brass 1 131 | 63 Synth Brass 2 132 | 64 Soprano Sax 133 | 65 Alto Sax 134 | 66 Tenor Sax 135 | 67 Baritone Sax 136 | 68 Oboe 137 | 69 English Horn 138 | 70 Bassoon 139 | 71 Clarinet 140 | 72 Piccolo 141 | 73 Flute 142 | 74 Recorder 143 | 75 Pan Flute 144 | 76 Bottle Blow 145 | 77 Shakuhachi 146 | 78 Whistle 147 | 79 Ocarina 148 | 80 Lead 1 (square) 149 | 81 Lead 2 (sawtooth) 150 | 82 Lead 3 (calliope) 151 | 83 Lead 4 (chiff) 152 | 84 Lead 5 (charang) 153 | 85 Lead 6 (voice) 154 | 86 Lead 7 (fifths) 155 | 87 Lead 8 (bass + lead) 156 | 88 Pad 1 (new age) 157 | 89 Pad 2 (warm) 158 | 90 Pad 3 (polysynth) 159 | 91 Pad 4 (choir) 160 | 92 Pad 5 (bowed) 161 | 93 Pad 6 (metallic) 162 | 94 Pad 7 (halo) 163 | 95 Pad 8 (sweep) 164 | 96 FX 1 (rain) 165 | 97 FX 2 (soundtrack) 166 | 98 FX 3 (crystal) 167 | 99 FX 4 (atmosphere) 168 | 100 FX 5 (brightness) 169 | 101 FX 6 (goblins) 170 | 102 FX 7 (echoes) 171 | 103 FX 8 (sci-fi) 172 | 104 Sitar 173 | 105 Banjo 174 | 106 Shamisen 175 | 107 Koto 176 | 108 Kalimba 177 | 109 Bagpipe 178 | 110 Fiddle 179 | 111 Shanai 180 | 112 Tinkle Bell 181 | 113 Agogo 182 | 114 Steel Drums 183 | 115 Woodblock 184 | 116 Taiko Drum 185 | 117 Melodic Tom 186 | 118 Synth Drum 187 | 119 Reverse Cymbal 188 | 120 Guitar Fret Noise 189 | 121 Breath Noise 190 | 122 Seashore 191 | 123 Bird Tweet 192 | 124 Telephone Ring 193 | 125 Helicopter 194 | 126 Applause 195 | 127 Gunshot 196 | 197 | 198 | 5. General Midi percussion instruments numbers and names. 199 | 200 | 201 | 35 Acoustic Bass Drum 202 | 36 Bass Drum 1 203 | 37 Side Kick 204 | 38 Acoustic Snare 205 | 39 Hand Clap 206 | 40 Electric Snare 207 | 41 Low Floor Tom 208 | 42 Closed High-Hat 209 | 43 High Floor Tom 210 | 44 Pedal High Hat 211 | 45 Low Tom 212 | 46 Open High Hat 213 | 47 Low-Mid Tom 214 | 48 High-Mid Tom 215 | 49 Crash Cymbal 1 216 | 50 High Tom 217 | 51 Ride Cymbal 1 218 | 52 Chinese Cymbal 219 | 53 Ride Bell 220 | 54 Tambourine 221 | 55 Splash Cymbal 222 | 56 Cowbell 223 | 57 Crash Cymbal 2 224 | 58 Vibraslap 225 | 59 Ride Cymbal 2 226 | 60 High Bongo 227 | 61 Low Bongo 228 | 62 Mute High Conga 229 | 63 Open High Conga 230 | 64 Low Conga 231 | 65 High Timbale 232 | 66 Low Timbale 233 | 67 High Agogo 234 | 68 Low Agogo 235 | 69 Cabasa 236 | 70 Maracas 237 | 71 Short Whistle 238 | 72 Long Whistle 239 | 73 Short Guiro 240 | 74 Long Guiro 241 | 75 Claves 242 | 76 High Wood Block 243 | 77 Low Wood Block 244 | 78 Mute Cuica 245 | 79 Open Cuica 246 | 80 Mute Triangle 247 | 81 Open Triangle 248 | 249 | 250 | 6. License. 251 | 252 | 253 | This program is free software; you can redistribute it and/or 254 | modify it under the terms of the GNU General Public License 255 | as published by the Free Software Foundation; either version 2 256 | of the License, or (at your option) any later version. 257 | 258 | This program is distributed in the hope that it will be useful, 259 | but WITHOUT ANY WARRANTY; without even the implied warranty of 260 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 261 | GNU General Public License for more details. 262 | 263 | You should have received a copy of the GNU General Public License 264 | along with this program; 265 | if not, write to the Free Software Foundation, Inc., 266 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 267 | 268 | 269 | 7. Project pages. 270 | 271 | 272 | http://www.vmgames.com 273 | 274 | http://www.vmgames.com/music/ 275 | 276 | http://github.com/vadimrm/jdksmidi 277 | 278 | http://github.com/jdkoftinoff/jdksmidi 279 | 280 | 281 | Vadim R. Madgazin vrm@vmgames.com 282 | 283 | -------------------------------------------------------------------------------- /libs/jdksmidi/src/jdksmidi_manager.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * libjdksmidi-2004 C++ Class Library for MIDI 3 | * 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 5 | * www.jdkoftinoff.com 6 | * jeffk@jdkoftinoff.com 7 | * 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | 25 | #include "jdksmidi/world.h" 26 | #include "jdksmidi/manager.h" 27 | 28 | namespace jdksmidi 29 | { 30 | 31 | MIDIManager::MIDIManager ( 32 | MIDIDriver *drv, 33 | MIDISequencerGUIEventNotifier *n, 34 | MIDISequencer *seq_ 35 | ) 36 | : 37 | driver ( drv ), 38 | sequencer ( seq_ ), 39 | sys_time_offset ( 0 ), 40 | seq_time_offset ( 0 ), 41 | play_mode ( false ), 42 | stop_mode ( true ), 43 | notifier ( n ), 44 | repeat_play_mode ( false ), 45 | repeat_start_measure ( 0 ), 46 | repeat_end_measure ( 0 ) 47 | { 48 | driver->SetTickProc ( this ); 49 | } 50 | 51 | MIDIManager::~MIDIManager() 52 | { 53 | } 54 | 55 | 56 | void MIDIManager::Reset() 57 | { 58 | SeqStop(); 59 | sys_time_offset = 0; 60 | seq_time_offset = 0; 61 | play_mode = false; 62 | stop_mode = true; 63 | 64 | if ( notifier ) 65 | { 66 | notifier->Notify ( sequencer, MIDISequencerGUIEvent ( MIDISequencerGUIEvent::GROUP_ALL ) ); 67 | } 68 | } 69 | 70 | 71 | // to set and get the current sequencer 72 | void MIDIManager::SetSeq ( MIDISequencer *seq ) 73 | { 74 | if ( notifier ) 75 | { 76 | notifier->Notify ( sequencer, MIDISequencerGUIEvent ( MIDISequencerGUIEvent::GROUP_ALL ) ); 77 | } 78 | 79 | sequencer = seq; 80 | } 81 | 82 | 83 | MIDISequencer *MIDIManager::GetSeq() 84 | { 85 | return sequencer; 86 | } 87 | 88 | const MIDISequencer *MIDIManager::GetSeq() const 89 | { 90 | return sequencer; 91 | } 92 | 93 | 94 | // to set and get the system time offset 95 | void MIDIManager::SetTimeOffset ( unsigned long off ) 96 | { 97 | sys_time_offset = off; 98 | } 99 | 100 | unsigned long MIDIManager::GetTimeOffset() 101 | { 102 | return sys_time_offset; 103 | } 104 | 105 | // to set and get the sequencer time offset 106 | void MIDIManager::SetSeqOffset ( unsigned long seqoff ) 107 | { 108 | seq_time_offset = seqoff; 109 | } 110 | 111 | unsigned long MIDIManager::GetSeqOffset() 112 | { 113 | return seq_time_offset; 114 | } 115 | 116 | // to manage the playback of the sequencer 117 | void MIDIManager::SeqPlay() 118 | { 119 | stop_mode = false; 120 | play_mode = true; 121 | 122 | if ( notifier ) 123 | { 124 | notifier->Notify ( sequencer, 125 | MIDISequencerGUIEvent ( 126 | MIDISequencerGUIEvent::GROUP_TRANSPORT, 127 | 0, 128 | MIDISequencerGUIEvent::GROUP_TRANSPORT_MODE 129 | ) ); 130 | } 131 | } 132 | 133 | // to manage the repeat playback of the sequencer 134 | void MIDIManager::SetRepeatPlay ( 135 | bool flag, 136 | unsigned long start_measure, 137 | unsigned long end_measure 138 | ) 139 | { 140 | // shut off repeat play while we muck with values 141 | repeat_play_mode = false; 142 | repeat_start_measure = start_measure; 143 | repeat_end_measure = end_measure; 144 | // set repeat mode flag to how we want it. 145 | repeat_play_mode = flag; 146 | } 147 | 148 | void MIDIManager::SeqStop() 149 | { 150 | play_mode = false; 151 | stop_mode = true; 152 | 153 | if ( notifier ) 154 | { 155 | notifier->Notify ( sequencer, 156 | MIDISequencerGUIEvent ( 157 | MIDISequencerGUIEvent::GROUP_TRANSPORT, 158 | 0, 159 | MIDISequencerGUIEvent::GROUP_TRANSPORT_MODE 160 | ) ); 161 | } 162 | } 163 | 164 | // status request functions 165 | bool MIDIManager::IsSeqPlay() const 166 | { 167 | return play_mode; 168 | } 169 | 170 | bool MIDIManager::IsSeqStop() const 171 | { 172 | return stop_mode; 173 | } 174 | 175 | bool MIDIManager::IsSeqRepeat() const 176 | { 177 | return repeat_play_mode && play_mode; 178 | } 179 | 180 | void MIDIManager::TimeTick ( unsigned long sys_time_ ) 181 | { 182 | if ( play_mode ) 183 | { 184 | TimeTickPlayMode ( sys_time_ ); 185 | } 186 | 187 | else if ( stop_mode ) 188 | { 189 | TimeTickStopMode ( sys_time_ ); 190 | } 191 | } 192 | 193 | void MIDIManager::TimeTickPlayMode ( unsigned long sys_time_ ) 194 | { 195 | double sys_time = ( double ) sys_time_ - ( double ) sys_time_offset; 196 | float next_event_time = 0.0; 197 | int ev_track; 198 | MIDITimedBigMessage ev; 199 | 200 | // if we are in repeat mode, repeat if we hit end of the repeat region 201 | if ( repeat_play_mode && 202 | sequencer->GetCurrentMeasure() >= repeat_end_measure ) 203 | { 204 | // yes we hit the end of our repeat block 205 | // shut off all notes on 206 | driver->AllNotesOff(); 207 | // now move the sequencer to our start position 208 | sequencer->GoToMeasure ( repeat_start_measure ); 209 | // our current raw system time is now the new system time offset 210 | sys_time_offset = sys_time_; 211 | sys_time = 0; 212 | // the sequencer time offset now must be reset to the 213 | // time in milliseconds of the sequence start point 214 | seq_time_offset = ( unsigned long ) sequencer->GetCurrentTimeInMs(); 215 | } 216 | 217 | // find all events that exist before or at this time, 218 | // but only if we have space in the output queue to do so! 219 | // also limit ourselves to 100 midi events max. 220 | int output_count = 100; 221 | 222 | while ( sequencer->GetNextEventTimeMs ( &next_event_time ) && 223 | ( next_event_time - seq_time_offset ) <= sys_time && 224 | driver->CanOutputMessage() && 225 | ( --output_count ) > 0 ) 226 | { 227 | // found an event! get it! 228 | if ( sequencer->GetNextEvent ( &ev_track, &ev ) ) 229 | { 230 | // ok, tell the driver the send this message now 231 | driver->OutputMessage ( ev ); 232 | } 233 | } 234 | 235 | // auto stop at end of sequence 236 | 237 | if ( !sequencer->GetNextEventTimeMs ( &next_event_time ) ) 238 | { 239 | // no events left 240 | stop_mode = true; 241 | play_mode = false; 242 | 243 | if ( notifier ) 244 | { 245 | notifier->Notify ( sequencer, 246 | MIDISequencerGUIEvent ( 247 | MIDISequencerGUIEvent::GROUP_TRANSPORT, 248 | 0, 249 | MIDISequencerGUIEvent::GROUP_TRANSPORT_MODE 250 | ) ); 251 | notifier->Notify ( sequencer, 252 | MIDISequencerGUIEvent ( 253 | MIDISequencerGUIEvent::GROUP_TRANSPORT, 254 | 0, 255 | MIDISequencerGUIEvent::GROUP_TRANSPORT_ENDOFSONG 256 | ) ); 257 | } 258 | } 259 | } 260 | 261 | void MIDIManager::TimeTickStopMode ( unsigned long sys_time_ ) 262 | { 263 | } 264 | } 265 | --------------------------------------------------------------------------------