1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ 2 3 4 /* 5 Rosegarden 6 A sequencer and musical notation editor. 7 Copyright 2000-2010 the Rosegarden development team. 8 See the AUTHORS file for more details. 9 10 This program is free software; you can redistribute it and/or 11 modify it under the terms of the GNU General Public License as 12 published by the Free Software Foundation; either version 2 of the 13 License, or (at your option) any later version. See the file 14 COPYING included with this distribution for more information. 15 */ 16 17 #ifndef RG_SEGMENTLINKER_H 18 #define RG_SEGMENTLINKER_H 19 20 #include "Segment.h" 21 #include <QObject> 22 23 namespace Rosegarden 24 { 25 26 class Command; 27 class Event; txid_currentnull28 29 class SegmentLinker : public QObject 30 { 31 Q_OBJECT 32 33 public: 34 typedef unsigned int SegmentLinkerId; 35 36 SegmentLinker(); 37 SegmentLinker(SegmentLinkerId id); 38 ~SegmentLinker() override; 39 40 void addLinkedSegment(Segment *s); 41 void removeLinkedSegment(Segment *s); 42 int getNumberOfLinkedSegments() const { 43 return m_linkedSegmentParamsList.size(); } 44 int getNumberOfTmpSegments() const; 45 int getNumberOfOutOfCompSegments() const; 46 47 void clearRefreshStatuses(); 48 SegmentLinkerId getSegmentLinkerId() const { return m_id; } 49 50 ///re-read one segment from any of the others 51 void refreshSegment(Segment *segment); 52 53 //factory functions for dealing with linking/unlinking of segments 54 static Segment* createLinkedSegment(Segment *s); 55 static bool unlinkSegment(Segment *s); 56 57 Segment * setReference(Segment *s) { 58 Segment *oldRef = m_reference; 59 m_reference = s; 60 return oldRef; 61 } 62 63 Segment * getReference() const { 64 return m_reference; 65 } 66 67 /** 68 * Set the flag for using a segment in notation for each linked segment 69 */ 70 void setForNotation(bool f); 71 72 protected slots: 73 void slotUpdateLinkedSegments(Command* command); 74 75 private: 76 struct LinkedSegmentParams 77 { 78 LinkedSegmentParams(Segment *s); 79 Segment *m_linkedSegment; 80 uint m_refreshStatusId; 81 }; 82 83 typedef std::list<LinkedSegmentParams> LinkedSegmentParamsList; 84 85 void linkedSegmentChanged(Segment* s, const timeT from, const timeT to); 86 87 /** 88 * Return true if lyricsAlreadyErased is true or if some 89 * lyrics have been erased 90 */ 91 bool eraseNonIgnored(Segment *s, Segment::const_iterator itrFrom, 92 Segment::const_iterator itrTo, 93 bool lyricsAlreadyErased); 94 95 /** 96 * Return true if lyricsAlreadyInserted is true or if a lyric 97 * event has been inserted 98 */ 99 bool insertMappedEvent(Segment *seg, const Event *e, timeT t, timeT nt, 100 int semitones, int steps, 101 bool lyricsAlreadyInserted); 102 103 LinkedSegmentParamsList::iterator findParamsItrForSegment(Segment *s); 104 static void handleImpliedCMajor(Segment *s); 105 106 LinkedSegmentParamsList m_linkedSegmentParamsList; 107 108 static SegmentLinkerId m_count; 109 SegmentLinkerId m_id; 110 111 Segment * m_reference; 112 }; 113 114 } 115 116 #endif // RG_SEGMENTLINKER_H 117