// // Programmer: Craig Stuart Sapp // Creation Date: Mon Jan 12 21:40:35 GMT-0800 1998 // Last Modified: Mon Jan 12 21:40:39 GMT-0800 1998 // Filename: ...sig/code/control/MidiOutPort/unsupported/MidiOutPort_unsupported.cpp // Web Address: http://www-ccrma.stanford.edu/~craig/improv/src/MidiOutPort_unsupported.cpp // Syntax: C++ // // Description: Operating-System specific interface for basic MIDI output // capabilities in an unknown operating system. Privately // inherited by the MidiOutPort class. Used for compiling // and running MIDI programs on a computer with no // MIDI output. // #include "MidiOutPort_unsupported.h" #include #include #ifndef OLDCPP #include #include #define SSTREAM stringstream #define CSTRING str().c_str() using namespace std; #else #include #ifdef VISUAL #include #else #include #endif #define SSTREAM strstream #define CSTRING str() #endif // initialized static variables int MidiOutPort_unsupported::numDevices = 0; int MidiOutPort_unsupported::objectCount = 0; int* MidiOutPort_unsupported::openQ = NULL; int* MidiOutPort_unsupported::portObjectCount = NULL; int MidiOutPort_unsupported::channelOffset = 0; ////////////////////////////// // // MidiOutPort_unsupported::MidiOutPort_unsupported // default values: autoOpen = 1 // MidiOutPort_unsupported::MidiOutPort_unsupported(void) { if (objectCount == 0) { initialize(); } objectCount++; port = -1; setPort(0); } MidiOutPort_unsupported::MidiOutPort_unsupported(int aPort, int autoOpen) { if (objectCount == 0) { initialize(); } objectCount++; port = -1; setPort(aPort); if (autoOpen) { open(); } } ////////////////////////////// // // MidiOutPort_unsupported::~MidiOutPort_unsupported // MidiOutPort_unsupported::~MidiOutPort_unsupported() { objectCount--; if (objectCount == 0) { deinitialize(); } else if (objectCount < 0) { cerr << "Error: bad MidiOutPort object count!: " << objectCount << endl; exit(1); } } ////////////////////////////// // // MidiOutPort_unsupported::close // void MidiOutPort_unsupported::close(void) { if (getPortStatus() == 1) { setPortStatus(0); } } ////////////////////////////// // // MidiOutPort_unsupported::closeAll // void MidiOutPort_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]++; } ////////////////////////////// // // MidiOutPort_unsupported::setTrace -- if false, then won't print // Midi messages to standard output. // int MidiOutPort_unsupported::setTrace(int aState) { int oldtrace = trace; if (aState == 0) { trace = 0; } else { trace = 1; } return oldtrace; } ////////////////////////////// // // MidiOutPort_unsupported::sysex -- // int MidiOutPort_unsupported::sysex(uchar* array, int size) { return 1; } ////////////////////////////// // // MidiOutPort_unsupported::toggleTrace -- // void MidiOutPort_unsupported::toggleTrace(void) { trace = !trace; } /////////////////////////////////////////////////////////////////////////// // // Private functions // ////////////////////////////// // // MidiOutPort_unsupported::deinitialize -- sets up storage if necessary // This function should be called if the current object is // the first object to be created. // void MidiOutPort_unsupported::deinitialize(void) { closeAll(); if (openQ != NULL) delete [] openQ; openQ = NULL; if (portObjectCount != NULL) delete [] portObjectCount; portObjectCount = NULL; } ////////////////////////////// // // MidiOutPort_unsupported::initialize -- sets up storage if necessary // This function should be called if the current object is // the first object to be created. // void MidiOutPort_unsupported::initialize(void) { // get the number of ports numDevices = 16; if (getNumPorts() <= 0) { cerr << "Error: no MIDI output devices" << endl; exit(1); } // 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]; // initialize the static arrays for (int i=0; i