//------------------------------------------------------------------------- // Filename: program2device.cc // Version: $Id: program2device.cc,v 1.1.2.2 1999/06/09 10:14:05 erik Exp $ // Copyright: Copyright (C) 1999, Erik Mouw (J.A.K.Mouw@its.tudelft.nl) // Author: Erik Mouw // Description: Map a program to a certain device // Created at: Sun May 23 15:57:11 1999 // Modified by: Erik Mouw // Modified at: Wed Jun 9 12:10:27 1999 //------------------------------------------------------------------------- // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // #ident "$Id: program2device.cc,v 1.1.2.2 1999/06/09 10:14:05 erik Exp $" #ifdef HAVE_CONFIG_H # include "config.h" #endif #ifdef MUSICA_DEBUG # include #endif #include #include "program2device.hh" static char deviceType[] = "program-to-device"; midiProgram2Device::midiProgram2Device(const char *theName) : midiDevice(theName) { int i; #ifdef MUSICA_DEBUG cerr<< __PRETTY_FUNCTION__<< endl; #endif setAllDevices(0); for(i = 0; i < numMidiChannels; i++) channelMap[i] = invalidMidiChannel; type = deviceType; } midiProgram2Device::~midiProgram2Device(void) { #ifdef MUSICA_DEBUG cerr<< __PRETTY_FUNCTION__<< endl; #endif // do not delete devices! } void midiProgram2Device::setDevice(int program, midiDevice *device) { #ifdef MUSICA_DEBUG cerr<< __PRETTY_FUNCTION__<< endl; #endif assert(program >= 0 && program < numMaxMidiPrograms); deviceMap[program] = device; } void midiProgram2Device::setAllDevices(midiDevice *device) { int i; #ifdef MUSICA_DEBUG cerr<< __PRETTY_FUNCTION__<< endl; #endif for(i = 0; i < numMaxMidiPrograms; i++) deviceMap[i] = device; } midiDevice *midiProgram2Device::getDevice(int program) { #ifdef MUSICA_DEBUG cerr<< __PRETTY_FUNCTION__<< endl; #endif assert(program >= 0 && program < numMaxMidiPrograms); return(deviceMap[program]); } bool midiProgram2Device::open(void) { #ifdef MUSICA_DEBUG cerr<< __PRETTY_FUNCTION__<< endl; #endif // do nothing return(true); } bool midiProgram2Device::close(void) { #ifdef MUSICA_DEBUG cerr<< __PRETTY_FUNCTION__<< endl; #endif // do nothing return(true); } void midiProgram2Device::noteOn(int channel, int key, int velocity) { if(deviceMap[channelMap[channel]] != 0) deviceMap[channelMap[channel]]->noteOn(channel, key, velocity); } void midiProgram2Device::noteOff(int channel, int key, int velocity) { if(deviceMap[channelMap[channel]] != 0) deviceMap[channelMap[channel]]->noteOff(channel, key, velocity); } void midiProgram2Device::keyPressure(int channel, int key, int pressure) { if(deviceMap[channelMap[channel]] != 0) deviceMap[channelMap[channel]]->keyPressure(channel, key, pressure); } void midiProgram2Device::channelPressure(int channel, int pressure) { if(deviceMap[channelMap[channel]] != 0) deviceMap[channelMap[channel]]->channelPressure(channel, pressure); } void midiProgram2Device::pitchBend(int channel, int fine, int coarse) { if(deviceMap[channelMap[channel]] != 0) deviceMap[channelMap[channel]]->pitchBend(channel, fine, coarse); } void midiProgram2Device::controlChange(int channel, int controller, int value) { if(deviceMap[channelMap[channel]] != 0) deviceMap[channelMap[channel]]->controlChange(channel, controller, value); } void midiProgram2Device::programChange(int channel, int program) { channelMap[channel] = program; if(deviceMap[program] != 0) { #ifdef MUSICA_DEBUG cerr<< __FUNCTION__<< ": "<< getType()<< "("<< getName()<< ") ch# "<< channel<< " prgm# "<< program<< " --> "<< deviceMap[program]->getType()<< "("<< deviceMap[program]->getName()<< ")"<< endl; #endif deviceMap[program]->programChange(channel, program); } } void midiProgram2Device::allNoteOff(void) { int i; for(i = 0; i < numMaxMidiPrograms; i++) if(deviceMap[i] != 0) deviceMap[i]->allNoteOff(); } void midiProgram2Device::systemReset(void) { int i; for(i = 0; i < numMaxMidiPrograms; i++) if(deviceMap[i] != 0) deviceMap[i]->systemReset(); }