diff options
Diffstat (limited to 'muse2/muse/track.cpp')
-rw-r--r-- | muse2/muse/track.cpp | 158 |
1 files changed, 28 insertions, 130 deletions
diff --git a/muse2/muse/track.cpp b/muse2/muse/track.cpp index cc1e56ac..8d30fccb 100644 --- a/muse2/muse/track.cpp +++ b/muse2/muse/track.cpp @@ -66,9 +66,9 @@ void addPortCtrlEvents(MidiTrack* t) for(ciPart ip = pl->begin(); ip != pl->end(); ++ip) { Part* part = ip->second; - const EventList* el = part->cevents(); + const EventList& el = part->events(); unsigned len = part->lenTick(); - for(ciEvent ie = el->begin(); ie != el->end(); ++ie) + for(ciEvent ie = el.begin(); ie != el.end(); ++ie) { const Event& ev = ie->second; // Added by T356. Do not add events which are past the end of the part. @@ -116,8 +116,8 @@ void removePortCtrlEvents(MidiTrack* t) for(ciPart ip = pl->begin(); ip != pl->end(); ++ip) { Part* part = ip->second; - const EventList* el = part->cevents(); - for(ciEvent ie = el->begin(); ie != el->end(); ++ie) + const EventList& el = part->events(); + for(ciEvent ie = el.begin(); ie != el.end(); ++ie) { const Event& ev = ie->second; @@ -468,8 +468,6 @@ MidiTrack::MidiTrack() : Track(MIDI) { init(); - _events = new EventList; - _mpevents = new MPEventList; clefType=trebleClef; _drummap=new DrumMap[128]; @@ -481,9 +479,6 @@ MidiTrack::MidiTrack() MidiTrack::MidiTrack(const MidiTrack& mt, int flags) : Track(mt, flags) { - _events = new EventList; - _mpevents = new MPEventList; - _drummap=new DrumMap[128]; _drummap_hidden=new bool[128]; @@ -592,27 +587,11 @@ void MidiTrack::internal_assign(const Track& t, int flags) const PartList* pl = t.cparts(); for (ciPart ip = pl->begin(); ip != pl->end(); ++ip) { Part* spart = ip->second; - bool clone = spart->events()->arefCount() > 1; - // This increments aref count if cloned, and chains clones. - // It also gives the new part a new serial number. - Part* dpart = newPart(spart, clone); - if(!clone) { - // Copy Events - MusECore::EventList* se = spart->events(); - MusECore::EventList* de = dpart->events(); - for (MusECore::iEvent i = se->begin(); i != se->end(); ++i) { - MusECore::Event oldEvent = i->second; - MusECore::Event ev = oldEvent.clone(); - de->add(ev); - } - } - - // TODO: Should we include the parts in the undo? - // dpart->events()->incARef(-1); // the later MusEGlobal::song->applyOperationGroup() will increment it - // // so we must decrement it first :/ - // // These will not increment ref count, and will not chain clones... - // // DELETETHIS: is the above comment still correct (by flo93)? i doubt it! - // operations.push_back(MusECore::UndoOp(MusECore::UndoOp::AddPart,dpart)); + Part* dpart; + if (spart->hasClones()) + dpart = spart->createNewClone(); + else + dpart = spart->duplicate(); parts()->add(dpart); } @@ -628,8 +607,6 @@ void MidiTrack::assign(const Track& t, int flags) MidiTrack::~MidiTrack() { - delete _events; - delete _mpevents; delete [] _drummap; delete [] _drummap_hidden; @@ -803,90 +780,6 @@ void MidiTrack::setInPortAndChannelMask(unsigned int portmask, int chanmask) } } -/* DELETETHIS 84 -//--------------------------------------------------------- -// addPortCtrlEvents -//--------------------------------------------------------- - -void MidiTrack::addPortCtrlEvents() -{ - const PartList* pl = cparts(); - for(ciPart ip = pl->begin(); ip != pl->end(); ++ip) - { - Part* part = ip->second; - const EventList* el = part->cevents(); - for(ciEvent ie = el->begin(); ie != el->end(); ++ie) - { - const Event& ev = ie->second; - if(ev.type() == Controller) - { - int tick = ev.tick() + part->tick(); - int cntrl = ev.dataA(); - int val = ev.dataB(); - int ch = _outChannel; - - MidiPort* mp = &MusEGlobal::midiPorts[_outPort]; - // Is it a drum controller event, according to the track port's instrument? - if(type() == DRUM) - { - MidiController* mc = mp->drumController(cntrl); - if(mc) - { - int note = cntrl & 0x7f; - cntrl &= ~0xff; - ch = MusEGlobal::drumMap[note].channel; - mp = &MusEGlobal::midiPorts[MusEGlobal::drumMap[note].port]; - cntrl |= MusEGlobal::drumMap[note].anote; - } - } - - mp->setControllerVal(ch, tick, cntrl, val, part); - } - } - } -} - -//--------------------------------------------------------- -// removePortCtrlEvents -//--------------------------------------------------------- - -void MidiTrack::removePortCtrlEvents() -{ - const PartList* pl = cparts(); - for(ciPart ip = pl->begin(); ip != pl->end(); ++ip) - { - Part* part = ip->second; - const EventList* el = part->cevents(); - for(ciEvent ie = el->begin(); ie != el->end(); ++ie) - { - const Event& ev = ie->second; - if(ev.type() == Controller) - { - int tick = ev.tick() + part->tick(); - int cntrl = ev.dataA(); - int ch = _outChannel; - - MidiPort* mp = &MusEGlobal::midiPorts[_outPort]; - // Is it a drum controller event, according to the track port's instrument? - if(type() == DRUM) - { - MidiController* mc = mp->drumController(cntrl); - if(mc) - { - int note = cntrl & 0x7f; - cntrl &= ~0xff; - ch = MusEGlobal::drumMap[note].channel; - mp = &MusEGlobal::midiPorts[MusEGlobal::drumMap[note].port]; - cntrl |= MusEGlobal::drumMap[note].anote; - } - } - - mp->deleteController(ch, tick, cntrl, part); - } - } - } -} -*/ //--------------------------------------------------------- // newPart @@ -894,7 +787,16 @@ void MidiTrack::removePortCtrlEvents() Part* MidiTrack::newPart(Part*p, bool clone) { - MidiPart* part = clone ? new MidiPart(this, p->events()) : new MidiPart(this); + MidiPart* part; + if (clone) + { + part = (MidiPart*)p->createNewClone(); + part->setTrack(this); + } + else + part= new MidiPart(this); + + if (p) { part->setName(p->name()); part->setColorIndex(p->colorIndex()); @@ -903,10 +805,6 @@ Part* MidiTrack::newPart(Part*p, bool clone) part->setMute(p->mute()); } - if(clone) - //p->chainClone(part); - chainClone(p, part); - return part; } @@ -1004,7 +902,7 @@ void MidiTrack::read(Xml& xml) switch (token) { case Xml::Error: case Xml::End: - return; + goto out_of_MidiTrackRead_forloop; case Xml::TagStart: if (tag == "transposition") transposition = xml.parseInt(); @@ -1017,10 +915,7 @@ void MidiTrack::read(Xml& xml) else if (tag == "compression") compression = xml.parseInt(); else if (tag == "part") { - //Part* p = newPart(); - //p->read(xml); - Part* p = 0; - p = readXmlPart(xml, this); + Part* p = Part::readFromXml(xml, this); if(p) parts()->add(p); } @@ -1094,12 +989,15 @@ void MidiTrack::read(Xml& xml) if (tag == "miditrack" || tag == "drumtrack" || tag == "newdrumtrack") { setInPortAndChannelMask(portmask, chanmask); // Support old files. - return; + goto out_of_MidiTrackRead_forloop; } default: break; } } + +out_of_MidiTrackRead_forloop: + chainTrackParts(this); } void MidiTrack::readOurDrumSettings(Xml& xml) @@ -1335,7 +1233,7 @@ int MidiTrack::getFirstControllerValue(int ctrl, int def) { Part* part=pit->second; if (part->tick() > tick) break; // ignore this and the rest. we won't find anything new. - for (iEvent eit=part->events()->begin(); eit!=part->events()->end(); eit++) + for (ciEvent eit=part->events().begin(); eit!=part->events().end(); eit++) { if (eit->first+part->tick() >= tick) break; if (eit->first > part->lenTick()) break; // ignore events past the end of the part @@ -1359,7 +1257,7 @@ int MidiTrack::getControllerChangeAtTick(unsigned tick, int ctrl, int def) Part* part=pit->second; if (part->tick() > tick) break; // ignore this and the rest. we'd find nothing any more if (part->endTick() < tick) continue; // ignore only this. - for (iEvent eit=part->events()->begin(); eit!=part->events()->end(); eit++) + for (ciEvent eit=part->events().begin(); eit!=part->events().end(); eit++) { if (eit->first+part->tick() > tick) break; // we won't find anything in this part from now on. if (eit->first > part->lenTick()) break; // ignore events past the end of the part @@ -1385,7 +1283,7 @@ unsigned MidiTrack::getControllerValueLifetime(unsigned tick, int ctrl) Part* part=pit->second; if (part->tick() > result) break; // ignore this and the rest. we won't find anything new. if (part->endTick() < tick) continue; // ignore only this part, we won't find anything there. - for (iEvent eit=part->events()->begin(); eit!=part->events()->end(); eit++) + for (ciEvent eit=part->events().begin(); eit!=part->events().end(); eit++) { if (eit->first+part->tick() >= result) break; if (eit->first > part->lenTick()) break; // ignore events past the end of the part |