//------------------------------------------------------------------------- // Filename: track.cc // Version: $Id: track.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: MIDI track class // Created at: Sat May 15 14:25:43 1999 // Modified by: Erik Mouw // Modified at: Wed May 26 23:50:59 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: track.cc,v 1.1.2.2 1999/06/09 10:14:05 erik Exp $" #ifdef HAVE_CONFIG_H # include #endif #include #include "track.hh" midiTrack::midiTrack(void) { events = 0; lastEvent = 0; currentEvent = 0; currentTime = -1L; nextTime = -1L; } midiTrack::~midiTrack(void) { midiEvent *nextEvent; rewind(); // delete all events if(currentEvent != 0) { do { nextEvent = currentEvent->getNextEvent(); delete currentEvent; currentEvent = nextEvent; } while(currentEvent != 0); } } void midiTrack::addEvent(midiEvent *event) { // sanity check assert(event != 0); if(events == 0) { events = currentEvent = lastEvent = event; } else { lastEvent->setNextEvent(event); lastEvent = event; } lastEvent->setNextEvent(0); rewind(); } midiEvent *midiTrack::getNextEvent(void) { long int deltaTime; if(currentEvent != 0) { currentEvent = currentEvent->getNextEvent(); if(currentEvent != 0) { currentTime = nextTime; deltaTime = currentEvent->getDeltaTime(); if(deltaTime >= 0L) nextTime = currentTime + currentEvent->getDeltaTime(); else nextTime = -1L; } else { currentTime = nextTime = -1L; } } else { currentTime = nextTime = -1L; } return(currentEvent); } midiEvent *midiTrack::rewind(void) { currentEvent = events; if(currentEvent == 0) { currentTime = -1L; nextTime = -1L; } else { currentTime = 0L; nextTime = currentEvent->getDeltaTime(); } return(currentEvent); } void midiTrack::play(midiDevice *device, midiPlayer *player) { assert(device != 0); assert(player != 0); if(currentEvent != 0) { currentEvent->play(device, player); getNextEvent(); } }