// // Programmer: Craig Stuart Sapp // Creation Date: Wed Jan 21 22:46:30 GMT-0800 1998 // Last Modified: Thu Jan 22 22:53:53 GMT-0800 1998 // Last Modified: Wed Jun 30 11:42:59 PDT 1999 (added sysex capability) // Filename: ...sig/code/control/MidiInPort/unsupported/MidiInPort_unsupported.cpp // Web Address: http://www-ccrma.stanford.edu/~craig/improv/src/MidiInPort_unsupported.cpp // Syntax: C++ // // Description: An interface for MIDI input capabilities of // an unknown sound driver's specific MIDI input methods. // This class is inherited privately by the MidiInPort class. // This class is used when there is no MIDI input, so // that MIDI programs can otherwise be compiled and run. // This file can also serve as a template for creating // an OS specific class for MIDI input. // #include "MidiInPort_unsupported.h" #include #ifndef OLDCPP #include using namespace std; #else #include #endif #define DEFAULT_INPUT_BUFFER_SIZE (1024) // initialized static variables int MidiInPort_unsupported::numDevices = 0; int MidiInPort_unsupported::objectCount = 0; int* MidiInPort_unsupported::openQ = NULL; int* MidiInPort_unsupported::portObjectCount = NULL; CircularBuffer* MidiInPort_unsupported::midiBuffer = NULL; int MidiInPort_unsupported::channelOffset = 0; int* MidiInPort_unsupported::sysexWriteBuffer = NULL; Array** MidiInPort_unsupported::sysexBuffers = NULL; ////////////////////////////// // // MidiInPort_unsupported::MidiInPort_unsupported // default values: autoOpen = 1 // MidiInPort_unsupported::MidiInPort_unsupported(void) { if (objectCount == 0) { initialize(); } objectCount++; port = -1; setPort(0); } MidiInPort_unsupported::MidiInPort_unsupported(int aPort, int autoOpen) { if (objectCount == 0) { initialize(); } objectCount++; port = -1; setPort(aPort); if (autoOpen) { open(); } } ////////////////////////////// // // MidiInPort_unsupported::~MidiInPort_unsupported // MidiInPort_unsupported::~MidiInPort_unsupported() { objectCount--; if (objectCount == 0) { deinitialize(); } else if (objectCount < 0) { cerr << "Error: bad MidiInPort_unsupported object count!: " << objectCount << endl; exit(1); } } ////////////////////////////// // // MidiInPort_unsupported::close // void MidiInPort_unsupported::close(void) { if (getPortStatus() == 1) { openQ[getPort()] = 0; } } ////////////////////////////// // // MidiInPort_unsupported::closeAll // void MidiInPort_unsupported::closeAll(void) { for (int i=0; i= getNumPorts()) { cerr << "Error: maximum port number is: " << getNumPorts()-1 << ", but you tried to access port: " << aPort << endl; exit(1); } if (port != -1) { portObjectCount[port]--; } port = aPort; portObjectCount[port]++; } ////////////////////////////// // // MidiInPort_unsupported::setTrace -- if false, then don't print MIDI messages // to the screen. // int MidiInPort_unsupported::setTrace(int aState) { int oldtrace = trace; if (aState == 0) { trace = 0; } else { trace = 1; } return oldtrace; } ////////////////////////////// // // MidiInPort_unsupported::toggleTrace -- switches the state of trace // Returns the previous value of the trace variable. // void MidiInPort_unsupported::toggleTrace(void) { trace = !trace; } ////////////////////////////// // // MidiInPort_unsupported::unpause -- enables the Midi input port // to inserting MIDI messages into the buffer after the // port is already open. // void MidiInPort_unsupported::unpause(void) { // nothing } /////////////////////////////////////////////////////////////////////////// // // Private functions // ////////////////////////////// // // MidiInPort_unsupported::deinitialize -- sets up storage if necessary // This function should be called if the current object is // the first object to be created. // void MidiInPort_unsupported::deinitialize(void) { int deviceCount = numDevices; closeAll(); if (sysexBuffers != NULL) { for (int i=0; i*[numDevices]; // allocate space for sysexWriteBuffer, the port open/close status if (sysexWriteBuffer != NULL) delete [] sysexWriteBuffer; sysexWriteBuffer = new int[numDevices]; // allocate space for openQ, the port open/close status if (openQ != NULL) delete [] openQ; openQ = new int[numDevices]; // allocate space for object count on each port: if (portObjectCount != NULL) delete [] portObjectCount; portObjectCount = new int[numDevices]; // allocate space for the Midi input buffers if (midiBuffer != NULL) delete [] midiBuffer; midiBuffer = new CircularBuffer[numDevices]; // initialize the static arrays for (int i=0; i[128]; for (int n=0; n<128; n++) { sysexBuffers[i][n].allowGrowth(0); // shouldn't need to grow sysexBuffers[i][n].setAllocSize(32); sysexBuffers[i][n].setSize(0); sysexBuffers[i][n].setGrowth(32); // in case it will ever grow } } } ////////////////////////////// // // MidiInPort_unsupported::setPortStatus // void MidiInPort_unsupported::setPortStatus(int aStatus) { if (aStatus) { openQ[getPort()] = 1; } else { openQ[getPort()] = 0; } } // md5sum: 2d78831da29de2b0efcddbb25004bbf0 MidiInPort_unsupported.cpp [20050403]