//------------------------------------------------------------------------- // Filename: channel2channel.cc // Version: $Id: channel2channel.cc,v 1.1.2.2 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: Remap channels. // Created at: Mon May 24 16:13:29 1999 // Modified by: Erik Mouw // Modified at: Wed Jun 9 12:02:13 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" #ifdef HAVE_CONFIG_H # include "config.h" #endif #ifdef MUSICA_DEBUG # include #endif #include #include "channel2channel.hh" static const char *deviceType = "channel-to-channel"; midiChannel2Channel::midiChannel2Channel(const char *theName) : midiDevice(theName) { #ifdef MUSICA_DEBUG cerr<< __PRETTY_FUNCTION__<< endl; #endif setDevice(0); setDefaultChannels(); type = deviceType; } midiChannel2Channel::~midiChannel2Channel(void) { #ifdef MUSICA_DEBUG cerr<< __PRETTY_FUNCTION__<< endl; #endif // don't delete the device! } void midiChannel2Channel::setDevice(midiDevice *d) { #ifdef MUSICA_DEBUG cerr<< __PRETTY_FUNCTION__<< endl; #endif device = d; } midiDevice *midiChannel2Channel::getDevice(void) { #ifdef MUSICA_DEBUG cerr<< __PRETTY_FUNCTION__<< endl; #endif return(device); } void midiChannel2Channel::setChannel(int from, int to) { #ifdef MUSICA_DEBUG cerr<< __PRETTY_FUNCTION__<< endl; #endif assert(from >= minMidiChannel && from <= maxMidiChannel); assert((to != invalidMidiChannel) || (to >= minMidiChannel && to <= maxMidiChannel)); channelMap[from] = to; } void midiChannel2Channel::setDefaultChannels(void) { int i; #ifdef MUSICA_DEBUG cerr<< __PRETTY_FUNCTION__<< endl; #endif for(i = 0; i < numMidiChannels; i++) channelMap[i] = i; } int midiChannel2Channel::getChannel(int from) { #ifdef MUSICA_DEBUG cerr<< __PRETTY_FUNCTION__<< endl; #endif assert(from >= minMidiChannel && from <= maxMidiChannel); return(channelMap[from]); } bool midiChannel2Channel::open(void) { #ifdef MUSICA_DEBUG cerr<< __PRETTY_FUNCTION__<< endl; #endif // do nothing return(true); } bool midiChannel2Channel::close(void) { #ifdef MUSICA_DEBUG cerr<< __PRETTY_FUNCTION__<< endl; #endif // do nothing return(true); } void midiChannel2Channel::noteOn(int channel, int key, int velocity) { if((device != 0) && (channelMap[channel] != invalidMidiChannel)) device->noteOn(channelMap[channel], key, velocity); } void midiChannel2Channel::noteOff(int channel, int key, int velocity) { if((device != 0) && (channelMap[channel] != invalidMidiChannel)) device->noteOff(channelMap[channel], key, velocity); } void midiChannel2Channel::keyPressure(int channel, int key, int pressure) { if((device != 0) && (channelMap[channel] != invalidMidiChannel)) device->keyPressure(channelMap[channel], key, pressure); } void midiChannel2Channel::channelPressure(int channel, int pressure) { if((device != 0) && (channelMap[channel] != invalidMidiChannel)) device->channelPressure(channelMap[channel], pressure); } void midiChannel2Channel::pitchBend(int channel, int fine, int coarse) { if((device != 0) && (channelMap[channel] != invalidMidiChannel)) device->pitchBend(channelMap[channel], fine, coarse); } void midiChannel2Channel::controlChange(int channel, int controller, int value) { if((device != 0) && (channelMap[channel] != invalidMidiChannel)) device->controlChange(channelMap[channel], controller, value); } void midiChannel2Channel::programChange(int channel, int program) { if((device != 0) && (channelMap[channel] != invalidMidiChannel)) { #ifdef MUSICA_DEBUG cerr<< __FUNCTION__<< ": "<< getType()<< "("<< getName()<< ") ch# "<< channel<< " prgm# "<< program<< " --> "<< device->getType()<< "("<< device->getName()<< ") ch # "<< channelMap[channel]<< endl; #endif device->programChange(channelMap[channel], program); } } void midiChannel2Channel::allNoteOff(void) { if(device != 0) device->allNoteOff(); } void midiChannel2Channel::systemReset(void) { if(device != 0) device->systemReset(); }