diff options
Diffstat (limited to 'muse2/muse/songfile.cpp')
-rw-r--r-- | muse2/muse/songfile.cpp | 420 |
1 files changed, 10 insertions, 410 deletions
diff --git a/muse2/muse/songfile.cpp b/muse2/muse/songfile.cpp index b07d1243..78338bac 100644 --- a/muse2/muse/songfile.cpp +++ b/muse2/muse/songfile.cpp @@ -56,49 +56,6 @@ MusECore::CloneList cloneList; namespace MusECore { -/* DELETETHIS 42 -//--------------------------------------------------------- -// updateCloneList -//--------------------------------------------------------- - -void updateCloneList(Part* oPart, Part* nPart) -{ - for(iClone i = MusEGlobal::cloneList.begin(); i != MusEGlobal::cloneList.end(); ++i) - { - if(i->cp == oPart) - { - i->cp = nPart; - break; - } - } -} - -void updateCloneList(PartList* oParts, PartList* nParts) -{ - for(iPart ip = oParts->begin(); ip != oParts->end(); ++ip) - { - for(iClone i = MusEGlobal::cloneList.begin(); i != MusEGlobal::cloneList.end(); ++i) - { - if(i->cp == oPart) - { - i->cp = nPart; - break; - } - } - } -} - -//--------------------------------------------------------- -// clearClipboardAndCloneList -//--------------------------------------------------------- - -void clearClipboardAndCloneList() -{ - //QApplication::clipboard()->clear(QClipboard::Clipboard); - MusEGlobal::cloneList.clear(); -} -*/ - //--------------------------------------------------------- // NKey::write //--------------------------------------------------------- @@ -167,10 +124,10 @@ void Scale::read(Xml& xml) } //--------------------------------------------------------- -// readXmlPart +// Part::readFromXml //--------------------------------------------------------- -Part* readXmlPart(Xml& xml, Track* track, bool doClone, bool toTrack) +Part* Part::readFromXml(Xml& xml, Track* track, bool doClone, bool toTrack) { int id = -1; Part* npart = 0; @@ -197,7 +154,7 @@ Part* readXmlPart(Xml& xml, Track* track, bool doClone, bool toTrack) { if(i->id == id) // Is a matching part found in the clone list? { - // This makes a clone, chains the part, and increases ref counts. + // Create a clone. It must still be added later in a operationgroup npart = track->newPart((Part*)i->cp, true); break; } @@ -242,7 +199,7 @@ Part* readXmlPart(Xml& xml, Track* track, bool doClone, bool toTrack) if(!doClone && !isclone) break; - // This makes a clone, chains the part, and increases ref counts. + // Create a clone. It must still be added later in a operationgroup npart = track->newPart((Part*)i->cp, true); break; } @@ -340,14 +297,6 @@ Part* readXmlPart(Xml& xml, Track* track, bool doClone, bool toTrack) e.move( -npart->tick() ); int tick = e.tick(); - // DELETETHIS 7 - // Do not discard events belonging to clone parts, - // at least not yet. A later clone might have a longer, - // fully accommodating part length! - //if ((tick < 0) || (tick >= (int) lenTick())) { - //if ((tick < 0) || ( id == -1 && !clone && (tick >= (int)lenTick()) )) - // No way to tell at the moment whether there will be clones referencing this... - // No choice but to accept all events past 0. if(tick < 0) { printf("readClone: warning: event at tick:%d not in part:%s, discarded\n", @@ -355,7 +304,7 @@ Part* readXmlPart(Xml& xml, Track* track, bool doClone, bool toTrack) } else { - npart->events()->add(e); + npart->_events.add(e); } } else // ...Otherwise a clone was created, so we don't need the events. @@ -373,25 +322,6 @@ Part* readXmlPart(Xml& xml, Track* track, bool doClone, bool toTrack) else if (tag == "cloneId") { id = xml.s2().toInt(); - //if(id != -1) DELETETHIS 19 - //{ - // for(iClone i = MusEGlobal::cloneList.begin(); i != MusEGlobal::cloneList.end(); ++i) - // { - // Is a matching part found in the clone list? - // if(i->id == id) - // { - // If it's a regular paste (not paste clone), and the original part is - // not a clone, defer so that a new copy is created in TagStart above. - //if(!doClone && i->cp->cevents()->arefCount() <= 1) - //if(!doClone && !isclone) - // break; - - // This makes a clone, chains the part, and increases ref counts. - // npart = track->newPart((Part*)i->cp, true); - // break; - // } - // } - //} } else if (tag == "uuid") { @@ -399,55 +329,6 @@ Part* readXmlPart(Xml& xml, Track* track, bool doClone, bool toTrack) if(!uuid_is_null(uuid)) { uuidvalid = true; - /* DELETETHIS 50 - for(iClone i = MusEGlobal::cloneList.begin(); i != MusEGlobal::cloneList.end(); ++i) - { - // Is a matching part found in the clone list? - if(uuid_compare(uuid, i->uuid) == 0) - { - Track* cpt = i->cp->track(); - // If we want to paste to the given track... - if(toTrack) - { - // If the given track type is not the same as the part's - // original track type, we can't continue. Just return. - if(!track || cpt->type() != track->type()) - { - xml.skip("part"); - return 0; - } - } - else - // ...else we want to paste to the part's original track. - { - // Make sure the track exists (has not been deleted). - if((cpt->isMidiTrack() && MusEGlobal::song->midis()->find(cpt) != MusEGlobal::song->midis()->end()) || - (cpt->type() == Track::WAVE && MusEGlobal::song->waves()->find(cpt) != MusEGlobal::song->waves()->end())) - track = cpt; - else - // Track was not found. Try pasting to the given track, as above... - { - if(!track || cpt->type() != track->type()) - { - // No luck. Just return. - xml.skip("part"); - return 0; - } - } - } - - // If it's a regular paste (not paste clone), and the original part is - // not a clone, defer so that a new copy is created in TagStart above. - //if(!doClone && i->cp->cevents()->arefCount() <= 1) - if(!doClone && !isclone) - break; - - // This makes a clone, chains the part, and increases ref counts. - npart = track->newPart((Part*)i->cp, true); - break; - } - } - */ } } else if(tag == "isclone") @@ -471,7 +352,6 @@ Part* readXmlPart(Xml& xml, Track* track, bool doClone, bool toTrack) void Part::write(int level, Xml& xml, bool isCopy, bool forceWavePaths) const { - const EventList* el = cevents(); int id = -1; uuid_t uuid; uuid_clear(uuid); @@ -482,7 +362,7 @@ void Part::write(int level, Xml& xml, bool isCopy, bool forceWavePaths) const { for(iClone i = MusEGlobal::cloneList.begin(); i != MusEGlobal::cloneList.end(); ++i) { - if(i->cp->cevents() == el) + if(i->cp->isCloneOf(this)) { uuid_copy(uuid, i->uuid); dumpEvents = false; @@ -498,11 +378,11 @@ void Part::write(int level, Xml& xml, bool isCopy, bool forceWavePaths) const } else { - if (el->arefCount() > 1) + if (this->hasClones()) { for (iClone i = MusEGlobal::cloneList.begin(); i != MusEGlobal::cloneList.end(); ++i) { - if (i->cp->cevents() == el) + if (i->cp->isCloneOf(this)) { id = i->id; dumpEvents = false; @@ -531,7 +411,7 @@ void Part::write(int level, Xml& xml, bool isCopy, bool forceWavePaths) const else xml.nput(level, "<part uuid=\"%s\"", sid); - if(el->arefCount() > 1) + if(hasClones()) xml.nput(" isclone=\"1\""); xml.put(">"); level++; @@ -552,292 +432,12 @@ void Part::write(int level, Xml& xml, bool isCopy, bool forceWavePaths) const if (_mute) xml.intTag(level, "mute", _mute); if (dumpEvents) { - for (ciEvent e = el->begin(); e != el->end(); ++e) + for (ciEvent e = events().begin(); e != events().end(); ++e) e->second.write(level, xml, *this, forceWavePaths); } xml.etag(level, "part"); } -// DELETETHIS 280! whoa! -/* -//--------------------------------------------------------- -// Part::read -//--------------------------------------------------------- - -void Part::read(Xml& xml, int, bool toTrack) // int newPartOffset - { - int id = -1; - bool containsEvents = false; - uuid_t uuid; - uuid_clear(uuid); - bool uuidvalid = false; - bool clone = false; - - for (;;) { - Xml::Token token = xml.parse(); - const QString& tag = xml.s1(); - switch (token) { - case Xml::Error: - case Xml::End: - return; - case Xml::TagStart: - if (tag == "name") - _name = xml.parse1(); - else if (tag == "poslen") { - PosLen::read(xml, "poslen"); - } - else if (tag == "pos") { - Pos pos; - pos.read(xml, "pos"); // obsolete - setTick(pos.tick()); - } - else if (tag == "len") { - Pos len; - len.read(xml, "len"); // obsolete - setLenTick(len.tick()); - } - else if (tag == "selected") - _selected = xml.parseInt(); - else if (tag == "color") - _colorIndex = xml.parseInt(); - else if (tag == "mute") - _mute = xml.parseInt(); - else if (tag == "event") { - containsEvents = true; - EventType type = Wave; - if (_track->isMidiTrack()) - type = Note; - Event e(type); - e.read(xml); - // stored tickpos for event has absolute value. However internally - // tickpos is relative to start of part, we substract tick(). - // TODO: better handling for wave event - e.move(-tick()); - int tick = e.tick(); - - // Changed by T356. Do not discard events belonging to clone parts, - // at least not yet. A later clone might have a longer, - // fully accommodating part length! - //if ((tick < 0) || (tick >= (int) lenTick())) { - if ((tick < 0) || ( id == -1 && !clone && (tick >= (int)lenTick()) )) - { - //printf("Part::read: warning: event not in part: %d - %d -%d, discarded\n", - printf("Part::read: warning: event at tick:%d not in part:%s, discarded\n", - tick, name().toLatin1().constData()); - } - else { - _events->add(e); -*/ - - - /* - // TODO: This should NOT be done here since the event list - // might be deleted below. Since after reading a part it - // likely (always?) that (msg)AddPart() or (msg)ChangePart() - // will be called (must check if they're ever called BEFORE - // Part::read), then those routines will take care of it, - // they are already coded to do so. - // Note the redundancy of doing it here AND (msg)Add/ChangePart ! - // Try to eliminate this section altogether by verifying that - // (msg)Add/ChangePart (or one of the other routines which add port - // controller values) is always called after Part::read... - if (e.type() == Controller) { - MidiTrack* mt = (MidiTrack*)_track; - int channel = mt->outChannel(); - MidiPort* mp = &MusEGlobal::midiPorts[mt->outPort()]; - // tick is relative to part, controller needs an absolute value hence - // part offset is added. If newPartOffset was given we use that instead of - // the recorded offset! - if (!newPartOffset) - newPartOffset=this->tick(); - - int ctl = e.dataA(); - if(mt->type() == Track::DRUM) - { - // Is it a drum controller event, according to the track port's instrument? - MidiController* mc = mp->drumController(ctl); - if(mc) - { - int note = ctl & 0x7f; - ctl &= ~0xff; - channel = drumMap[note].channel; - mp = &MusEGlobal::midiPorts[drumMap[note].port]; - ctl |= drumMap[note].anote; - } - } - - // Removed by T356 - // check if controller exists - //if (mp->hwCtrlState(channel, e.dataA()) == CTRL_VAL_UNKNOWN) { - // mp->addManagedController(channel, e.dataA()); - // } - - // Changed by T356 - // add controller value - //mp->setCtrl(channel, tick+newPartOffset, e.dataA(), e.dataB()); - mp->setControllerVal(channel, tick+newPartOffset, ctl, e.dataB(), this); - } - */ -/* - } - } - else - xml.unknown("Part::read"); - break; - case Xml::Attribut: - if (tag == "cloneId") - id = xml.s2().toInt(); - else if (tag == "uuid") - { - uuid_parse(xml.s2().toLatin1().constData(), uuid); - if(!uuid_is_null(uuid)) - uuidvalid = true; - } - else if (tag == "isclone") - clone = xml.s2().toInt(); - break; - case Xml::TagEnd: - if (tag == "part") - { -*/ - /* - if (id != -1) - { - - // clone part - if (containsEvents) { - // add to MusEGlobal::cloneList: - //ClonePart cp(_events, id); - ClonePart cp(this, id); - MusEGlobal::cloneList.push_back(cp); - } - else { - // replace event list with clone event - // list - for (iClone i = MusEGlobal::cloneList.begin(); - i != MusEGlobal::cloneList.end(); ++i) { - if (i->id == id) { - delete _events; - //_events = (EventList*)(i->el); - _events = (EventList*)(i->cp->cevents()); - _events->incRef(1); - _events->incARef(1); - //i->cp->chainClone(this); - chainClone((Part*)i->cp, this); - break; - } - } - } - */ - -/* - if(id != -1) - { - // See if the part exists in the clone list. - // The clone list is also the copy/paste clone list. - // Care must be taken to ensure the list is ALWAYS EMPTY - // before loading or dropping parts INTO muse, because the - // current song parts are NOT the same as when the imported parts - // were created, (even if they were created from the current session, - // we should NOT look them up). Always back up the list, clear it, - // read part(s), then restore the list so that paste works after. - Part* cp = 0; - for(iClone i = MusEGlobal::cloneList.begin(); i != MusEGlobal::cloneList.end(); ++i) - { - if(i->id == id) - { - cp = (Part*)i->cp; - break; - } - } - // Was a matching part found in the clone list? - if(cp) - { - // Make this part a clone of that part. Use its event list... - delete _events; - _events = (EventList*)(cp->cevents()); - _events->incRef(1); - _events->incARef(1); - chainClone(cp, this); - } - else - { - // No matching part to clone was found in the clone list. - // Does the part contain some events? - //if(containsEvents) - { - // Add the part to the clone list so that subsequent parts - // can look it up and clone from it... - ClonePart ncp(this, id); - MusEGlobal::cloneList.push_back(ncp); - } - // Otherwise this part has no matching part in the clone list - // and no events of its own. Nothing left to do, we now have - // a blank part with the original offset, colour etc. - } - } - else - // If a uuid was found, do the same as above. Using uuids - // allows foolproof rejection of copied parts not found - // in the clone list, particularly when copying parts from - // another instance of muse. - if(uuidvalid) - { - Part* cp = 0; - for(iClone i = MusEGlobal::cloneList.begin(); i != MusEGlobal::cloneList.end(); ++i) - { - if(uuid_compare(uuid, i->uuid) == 0) - { - cp = (Part*)i->cp; - break; - } - } - // If a matching part was found, and we want to paste to the original track... - if(cp && !toTrack) - { - // Make sure the track exists (has not been deleted). - if((cp->track()->isMidiTrack() && MusEGlobal::song->midis()->find(cp->track()) != MusEGlobal::song->midis()->end()) || - (cp->track()->type() == Track::WAVE && MusEGlobal::song->waves()->find(cp->track()) != MusEGlobal::song->waves()->end())) - setTrack(cp->track()); - } - // Was a matching part found in the clone list, and was it - // originally a clone part? - if(cp && clone) - { - // Make this part a clone of that part. Use its event list... - delete _events; - _events = (EventList*)(cp->cevents()); - _events->incRef(1); - _events->incARef(1); - // Chain the clone. - // Use the slower function which makes sure it chains to a part - // within a valid (non-deleted) track. - //chainClone(cp, this); - chainClone(this); - } - else - { - // No matching part to clone was found in the clone list. - // Does the part contain some events? - //if(containsEvents) - { - // Add the part to the clone list so that subsequent parts - // can look it up and clone from it... - ClonePart ncp(this); - // New ClonePart creates its own uuid, but we need to replace it. - uuid_copy(ncp.uuid, uuid); - MusEGlobal::cloneList.push_back(ncp); - } - } - } - return; - } - default: - break; - } - } - } -*/ //--------------------------------------------------------- // writeFont |