~ubuntu-branches/ubuntu/karmic/rosegarden/karmic

« back to all changes in this revision

Viewing changes to src/base/Segment.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Ebner
  • Date: 2008-05-02 00:33:44 UTC
  • mfrom: (1.1.7 upstream) (6.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080502003344-67vbfhgqx2yl0ksi
Tags: 1:1.7.0-1ubuntu1
* Merge from Debian unstable. (LP: #225849) Remaining Ubuntu changes:
  - Add usr/share/doc/kde/HTML to rosegarden-data, to provide online
    help documentation.
  - Change fftw3-dev to libfftw3-dev.
  - Update maintainer field as per spec.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
    Rosegarden
5
5
    A sequencer and musical notation editor.
6
6
 
7
 
    This program is Copyright 2000-2007
 
7
    This program is Copyright 2000-2008
8
8
        Guillaume Laurent   <glaurent@telegraph-road.org>,
9
9
        Chris Cannam        <cannam@all-day-breakfast.com>,
10
10
        Richard Bown        <bownie@bownie.com>
242
242
    for (int i = 0; i < events.size(); ++i) {
243
243
        insert(events[i]);
244
244
    }
 
245
 
 
246
    notifyStartChanged(m_startTime);
 
247
    updateRefreshStatuses(m_startTime, m_endTime);
245
248
}
246
249
 
247
250
void
366
369
 
367
370
        if (m_composition) m_composition->setSegmentStartTime(this, t0);
368
371
        else m_startTime = t0;
 
372
        notifyStartChanged(m_startTime);
369
373
    }
370
374
 
371
375
    if (t1 > m_endTime ||
372
376
        begin() == end()) {
 
377
        timeT oldTime = m_endTime;
373
378
        m_endTime = t1;
 
379
        notifyEndMarkerChange(m_endTime < oldTime);
374
380
    }
375
381
 
376
382
    iterator i = std::multiset<Event*, Event::EventCmp>::insert(e);
411
417
        timeT startTime = (*begin())->getAbsoluteTime();
412
418
        if (m_composition) m_composition->setSegmentStartTime(this, startTime);
413
419
        else m_startTime = startTime;
 
420
        notifyStartChanged(m_startTime);
414
421
    }
415
422
    if (t1 == m_endTime) {
416
423
        updateEndTime();
447
454
        timeT startTime = (*begin())->getAbsoluteTime();
448
455
        if (m_composition) m_composition->setSegmentStartTime(this, startTime);
449
456
        else m_startTime = startTime;
 
457
        notifyStartChanged(m_startTime);
450
458
    }
451
459
 
452
460
    if (endTime == m_endTime) {
543
551
    if (startTime < m_startTime) {
544
552
        if (m_composition) m_composition->setSegmentStartTime(this, startTime);
545
553
        else m_startTime = startTime;
 
554
        notifyStartChanged(m_startTime);
546
555
    }
547
556
 
548
557
    TimeSignature ts;
590
599
#endif
591
600
        if (m_composition) m_composition->setSegmentStartTime(this, startTime);
592
601
        else m_startTime = startTime;
 
602
        notifyStartChanged(m_startTime);
593
603
    }
594
604
 
595
605
    //!!! Need to remove the rests then relocate the start time
742
752
 
743
753
    for (; i != ib && i != end(); ++i) {
744
754
 
745
 
        // if we have any rests remaining in this area, treat them
746
 
        // as "hard" rests (they had tuplet data, so we don't want to
747
 
        // disturb them)
748
 
        if (!((*i)->isa(Note::EventType) || (*i)->isa(Note::EventRestType))) {
 
755
        // Boundary events for sets of rests may be notes (obviously),
 
756
        // text events (because they need to be "attached" to
 
757
        // something that has the correct timing), or rests (any
 
758
        // remaining rests in this area have tuplet data so should be
 
759
        // treated as "hard" rests);
 
760
        if (!((*i)->isa(Note::EventType) ||
 
761
              (*i)->isa(Text::EventType) ||
 
762
              (*i)->isa(Note::EventRestType))) {
749
763
            continue;
750
764
        }
751
765
 
1063
1077
    }
1064
1078
}
1065
1079
 
 
1080
void
 
1081
Segment::getFirstClefAndKey(Clef &clef, Key &key)
 
1082
{
 
1083
    bool keyFound = false;
 
1084
    bool clefFound = false;
 
1085
    clef = Clef();          // Default clef
 
1086
    key = Key();            // Default key signature
 
1087
 
 
1088
    iterator i = begin();
 
1089
    while (i!=end()) {
 
1090
        // Keep current clef and key as soon as a note or rest event is found
 
1091
        if ((*i)->isa(Note::EventRestType) || (*i)->isa(Note::EventType)) return;
 
1092
 
 
1093
        // Remember the first clef event found
 
1094
        if ((*i)->isa(Clef::EventType)) {
 
1095
            clef = Clef(*(*i));
 
1096
            // and return if a key has already been found
 
1097
            if (keyFound) return;
 
1098
            clefFound = true;
 
1099
        }
 
1100
 
 
1101
        // Remember the first key event found
 
1102
        if ((*i)->isa(Key::EventType)) {
 
1103
            key = Key(*(*i));
 
1104
            // and return if a clef has already been found
 
1105
            if (clefFound) return;
 
1106
            keyFound = true;
 
1107
        }
 
1108
 
 
1109
        ++i;
 
1110
    }
 
1111
}
 
1112
 
1066
1113
timeT
1067
1114
Segment::getRepeatEndTime() const
1068
1115
{
 
1116
    timeT endMarker = getEndMarkerTime();
 
1117
 
1069
1118
    if (m_repeating && m_composition) {
1070
1119
        Composition::iterator i(m_composition->findSegment(this));
1071
1120
        assert(i != m_composition->end());
1072
1121
        ++i;
1073
1122
        if (i != m_composition->end() && (*i)->getTrack() == getTrack()) {
1074
 
            return (*i)->getStartTime();
 
1123
            timeT t = (*i)->getStartTime();
 
1124
            if (t < endMarker) return endMarker;
 
1125
            else return t;
1075
1126
        } else {
1076
1127
            return m_composition->getEndMarker();
1077
1128
        }
1078
1129
    }
1079
 
    return getEndMarkerTime();
 
1130
 
 
1131
    return endMarker;
1080
1132
}
1081
1133
 
1082
1134
 
1126
1178
}
1127
1179
 
1128
1180
void
 
1181
Segment::notifyStartChanged(timeT newTime)
 
1182
{
 
1183
    for (ObserverSet::const_iterator i = m_observers.begin();
 
1184
         i != m_observers.end(); ++i) {
 
1185
        (*i)->startChanged(this, newTime);
 
1186
    }
 
1187
    if (m_composition) {
 
1188
        m_composition->notifySegmentStartChanged(this, newTime);
 
1189
    }
 
1190
}
 
1191
    
 
1192
 
 
1193
void
1129
1194
Segment::notifyEndMarkerChange(bool shorten)
1130
1195
{
1131
1196
    for (ObserverSet::const_iterator i = m_observers.begin();