//------------------------------------------------------------------------- // Filename: channel2device.cc // Version: $Id: channel2device.cc,v 1.1.2.1 1999/06/09 10:14:04 erik Exp $ // Copyright: Copyright (C) 1999, Erik Mouw (J.A.K.Mouw@its.tudelft.nl) // Author: Erik Mouw // Description: Map channels to devices (drum channel 9 --> SB AWE) // Created at: Sat Jun 5 13:29:18 1999 // Modified by: Erik Mouw // Modified at: Wed Jun 9 12:00:44 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: channel2device.cc,v 1.1.2.1 1999/06/09 10:14:04 erik Exp $" #ifdef HAVE_CONFIG_H # include "config.h" #endif #ifdef MUSICA_DEBUG # include #endif #include #include "channel2device.hh" static char deviceType[] = "channel-to-device"; midiChannel2Device::midiChannel2Device(const char *theName) : midiDevice(theName) { #ifdef MUSICA_DEBUG cerr<< __PRETTY_FUNCTION__<< endl; #endif setAllDevices(0); type = deviceType; } midiChannel2Device::~midiChannel2Device(void) { #ifdef MUSICA_DEBUG cerr<< __PRETTY_FUNCTION__<< endl; #endif // do not delete devices! } void midiChannel2Device::setDevice(int channel, midiDevice *device) { #ifdef MUSICA_DEBUG cerr<< __PRETTY_FUNCTION__<< endl; #endif assert(channel >= 0 && channel < numMidiChannels); deviceMap[channel] = device; } void midiChannel2Device::setAllDevices(midiDevice *device) { int i; #ifdef MUSICA_DEBUG cerr<< __PRETTY_FUNCTION__<< endl; #endif for(i = 0; i < numMidiChannels; i++) deviceMap[i] = device; } midiDevice *midiChannel2Device::getDevice(int channel) { #ifdef MUSICA_DEBUG cerr<< __PRETTY_FUNCTION__<< endl; #endif assert(channel >= 0 && channel < numMidiChannels); return(deviceMap[channel]); } bool midiChannel2Device::open(void) { #ifdef MUSICA_DEBUG cerr<< __PRETTY_FUNCTION__<< endl; #endif // do nothing return(true); } bool midiChannel2Device::close(void) { #ifdef MUSICA_DEBUG cerr<< __PRETTY_FUNCTION__<< endl; #endif // do nothing return(true); } void midiChannel2Device::noteOn(int channel, int key, int velocity) { if(deviceMap[channel] != 0) deviceMap[channel]->noteOn(channel, key, velocity); } void midiChannel2Device::noteOff(int channel, int key, int velocity) { if(deviceMap[channel] != 0) deviceMap[channel]->noteOff(channel, key, velocity); } void midiChannel2Device::keyPressure(int channel, int key, int pressure) { if(deviceMap[channel] != 0) deviceMap[channel]->keyPressure(channel, key, pressure); } void midiChannel2Device::channelPressure(int channel, int pressure) { if(deviceMap[channel] != 0) deviceMap[channel]->channelPressure(channel, pressure); } void midiChannel2Device::pitchBend(int channel, int fine, int coarse) { if(deviceMap[channel] != 0) deviceMap[channel]->pitchBend(channel, fine, coarse); } void midiChannel2Device::controlChange(int channel, int controller, int value) { if(deviceMap[channel] != 0) deviceMap[channel]->controlChange(channel, controller, value); } void midiChannel2Device::programChange(int channel, int program) { if(deviceMap[channel] != 0) { #ifdef MUSICA_DEBUG cerr<< __FUNCTION__<< ": "<< getType()<< "("<< getName()<< ") ch# "<< channel<< " prgm# "<< program<< " --> "<< deviceMap[channel]->getType()<< "("<< deviceMap[channel]->getName()<< ")"<< endl; #endif deviceMap[channel]->programChange(channel, program); } } void midiChannel2Device::allNoteOff(void) { int i; for(i = 0; i < numMidiChannels; i++) if(deviceMap[i] != 0) deviceMap[i]->allNoteOff(); } void midiChannel2Device::systemReset(void) { int i; for(i = 0; i < numMidiChannels; i++) if(deviceMap[i] != 0) deviceMap[i]->systemReset(); }