//------------------------------------------------------------------------- // Filename: events.cc // Version: $Id: events.cc,v 1.1.4.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: MIDI event classes // Created at: Sun Mar 28 17:55:22 1999 // Modified by: Erik Mouw // Modified at: Wed May 26 23:34:53 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: events.cc,v 1.1.4.2 1999/06/09 10:14:04 erik Exp $" #ifdef HAVE_CONFIG_H # include #endif #include using namespace std; #ifdef STDC_HEADERS # include #endif #include "events.hh" #include "player.hh" //------------------------------------------------------------------------- // // class midiUnknownEvent // //------------------------------------------------------------------------- void midiUnknownEvent::play(midiDevice *device, midiPlayer *player) { // do nothing, but it is convenient for timing #ifdef MIDI_DEBUG cout<< "unknown event"<< endl; #endif } //------------------------------------------------------------------------- // // class midiNoteOnEvent // //------------------------------------------------------------------------- void midiNoteOnEvent::play(midiDevice *device, midiPlayer *player) { if((key >= 0) && (velocity >= 0) && (channel >= 0)) device->noteOn(channel, key, velocity); } //------------------------------------------------------------------------- // // class midiNoteOffEvent // //------------------------------------------------------------------------- void midiNoteOffEvent::play(midiDevice *device, midiPlayer *player) { if((key >= 0) && (velocity >= 0) && (channel >= 0)) device->noteOff(channel, key, velocity); } //------------------------------------------------------------------------- // // class midiKeyPressureEvent // //------------------------------------------------------------------------- void midiKeyPressureEvent::play(midiDevice *device, midiPlayer *player) { if((key >= 0) && (pressure >= 0) && (channel >= 0)) device->keyPressure(channel, key, pressure); } //------------------------------------------------------------------------- // // class midiChannelPressureEvent // //------------------------------------------------------------------------- void midiChannelPressureEvent::play(midiDevice *device, midiPlayer *player) { if((pressure >= 0) && (channel >= 0)) device->channelPressure(channel, pressure); } //------------------------------------------------------------------------- // // class midiPitchWheelEvent // //------------------------------------------------------------------------- void midiPitchWheelEvent::play(midiDevice *device, midiPlayer *player) { if((fine >= 0) && (coarse >= 0) && (channel >= 0)) device->pitchBend(channel, fine, coarse); } //------------------------------------------------------------------------- // // class midiControlChangeEvent // //------------------------------------------------------------------------- void midiControlChangeEvent::play(midiDevice *device, midiPlayer *player) { if((controller >= 0) && (value >= 0) && (channel >= 0)) device->controlChange(channel, controller, value); } //------------------------------------------------------------------------- // // class midiProgramChangeEvent // //------------------------------------------------------------------------- void midiProgramChangeEvent::play(midiDevice *device, midiPlayer *player) { if((program >= 0) && (channel >= 0)) device->programChange(channel, program); } //------------------------------------------------------------------------- // // class midiDivisionEvent // //------------------------------------------------------------------------- void midiDivisionEvent::play(midiDevice *device, midiPlayer *player) { if(division >= 0) { #ifdef MIDI_DEBUG cout<< "setDivision(division) = ("<< division<< ")"<< endl; #endif player->setDivision(division); } } //------------------------------------------------------------------------- // // class midiSequenceNumberEvent // //------------------------------------------------------------------------- void midiSequenceNumberEvent::play(midiDevice *device, midiPlayer *player) { if(number >= 0) { #ifdef MIDI_DEBUG cout<< "sequenceNumber(number) = ("<< number<< ")"<< endl; #endif player->sequenceNumber(number); } } //------------------------------------------------------------------------- // // class midiMetaTextEvent // //------------------------------------------------------------------------- midiMetaTextEvent::midiMetaTextEvent(long int dT, midiEvent *n, char *t) : midiEvent(dT, n) { if(t == 0) { text = 0; } else { text = new char[strlen(t) + 1]; strcpy(text, t); } } midiMetaTextEvent::~midiMetaTextEvent(void) { if(text != 0) delete[] text; } void midiMetaTextEvent::setText(char *t) { if(text != 0) delete[] text; if(t == 0) { text = 0; } else { text = new char[strlen(t) + 1]; strcpy(text, t); } } char *midiMetaTextEvent::getText(void) const { return(text); } //------------------------------------------------------------------------- // // class midiTextEvent // //------------------------------------------------------------------------- void midiTextEvent::play(midiDevice *device, midiPlayer *player) { cout<< "Text: "<< text<< endl; } //------------------------------------------------------------------------- // // class midiCopyrightNoticeEvent // //------------------------------------------------------------------------- void midiCopyrightNoticeEvent::play(midiDevice *device, midiPlayer *player) { cout<< "Copyright notice: "<< text<< endl; } //------------------------------------------------------------------------- // // class midiTracknameEvent // //------------------------------------------------------------------------- void midiTrackNameEvent::play(midiDevice *device, midiPlayer *player) { cout<< "Track name: "<< text<< endl; } //------------------------------------------------------------------------- // // class midiIntrumentNameEvent // //------------------------------------------------------------------------- void midiIntrumentNameEvent::play(midiDevice *device, midiPlayer *player) { cout<< "Intrument name: "<< text<< endl; } //------------------------------------------------------------------------- // // class midiLyricEvent // //------------------------------------------------------------------------- void midiLyricEvent::play(midiDevice *device, midiPlayer *player) { cout<< "Lyric: "<< text<< endl; } //------------------------------------------------------------------------- // // class midiMarkerEvent // //------------------------------------------------------------------------- void midiMarkerEvent::play(midiDevice *device, midiPlayer *player) { cout<< "Marker: "<< text<< endl; } //------------------------------------------------------------------------- // // class midiCuePointEvent // //------------------------------------------------------------------------- void midiCuePointEvent::play(midiDevice *device, midiPlayer *player) { cout<< "Cue point: "<< text<< endl; } //------------------------------------------------------------------------- // // class midiReservedTextEvent // //------------------------------------------------------------------------- void midiReservedTextEvent::play(midiDevice *device, midiPlayer *player) { cout<< "Reserved text: "<< text<< endl; } //------------------------------------------------------------------------- // // class midiEndOfTrackEvent // //------------------------------------------------------------------------- void midiEndOfTrackEvent::play(midiDevice *device, midiPlayer *player) { player->endOfTrack(); } //------------------------------------------------------------------------- // // class midiTempoEvent // //------------------------------------------------------------------------- void midiTempoEvent::play(midiDevice *device, midiPlayer *player) { if(tempo >= 0) { #ifdef MIDI_DEBUG cout<< "setTempo(tempo) = ("<< tempo<< ")"<< endl; #endif player->setTempo(tempo); } } //------------------------------------------------------------------------- // // class midiSmpteOffsetEvent // //------------------------------------------------------------------------- void midiSmpteOffsetEvent::play(midiDevice *device, midiPlayer *player) { if((hours >= 0) && (minutes >= 0) && (seconds >= 0) && (frames >= 0) && (fraction >= 0)) { #ifdef MIDI_DEBUG cout<< "smpteOffset(hours, minutes, seconds, frames, fraction) = ("<< hours<< ", "<< minutes<< ", "<< seconds<< ", "<< frames<< ", "<< fraction<< ")"<< endl; #endif player->smpteOffset(hours, minutes, seconds, frames, fraction); } } //------------------------------------------------------------------------- // // class midiTimeSignatureEvent // //------------------------------------------------------------------------- void midiTimeSignatureEvent::play(midiDevice *device, midiPlayer *player) { if((numerator >= 0) && (denominator >= 0) && (clocks >= 0) && (bb >= 0)) { #ifdef MIDI_DEBUG cout<< "timeSignature(numerator, denominator, clocks, bb) = ("<< numerator<< ", "<< denominator<< ", "<< clocks<< ", "<< bb<< ")"<< endl; #endif player->timeSignature(numerator, denominator, clocks, bb); } } //------------------------------------------------------------------------- // // class midiKeySignatureEvent // //------------------------------------------------------------------------- void midiKeySignatureEvent::play(midiDevice *device, midiPlayer *player) { #ifdef MIDI_DEBUG cout<< "keySignature(key, signature) = ("<< key<< ", "<< signature<< ")"<< endl; #endif player->keySignature(key, signature); } //------------------------------------------------------------------------- // // class midiSequencerSpecificEvent // //------------------------------------------------------------------------- midiSequencerSpecificEvent::midiSequencerSpecificEvent(long int dT, midiEvent *n, unsigned char *d, int l) : midiEvent(dT, n) { if(d == 0) { data = 0; len = 0; } else { len = l; data = new unsigned char[l]; bcopy(d, data, l); } } midiSequencerSpecificEvent::~midiSequencerSpecificEvent(void) { if(data != 0) delete[] data; } void midiSequencerSpecificEvent::setData(unsigned char *d, int l) { if(data != 0) delete[] data; if(d == 0) { data = 0; len = 0; } else { len = l; data = new unsigned char[l]; bcopy(d, data, l); } } unsigned char *midiSequencerSpecificEvent::getData(void) const { return(data); } void midiSequencerSpecificEvent::play(midiDevice *device, midiPlayer *player) { #ifdef MUSICA_DEBUG cerr<< "Ignoring sequencer specific event"<< endl; #endif } //------------------------------------------------------------------------- // // class midiSysexEvent // //------------------------------------------------------------------------- void midiSysexEvent::play(midiDevice *device, midiPlayer *player) { #ifdef MUSICA_DEBUG cerr<< "Ignoring sysex event"<< endl; #endif }