summaryrefslogtreecommitdiffstats
path: root/src/commands/segment
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-03-01 18:37:05 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-03-01 18:37:05 +0000
commit145364a8af6a1fec06556221e66d4b724a62fc9a (patch)
tree53bd71a544008c518034f208d64c932dc2883f50 /src/commands/segment
downloadrosegarden-145364a8af6a1fec06556221e66d4b724a62fc9a.tar.gz
rosegarden-145364a8af6a1fec06556221e66d4b724a62fc9a.zip
Added old abandoned KDE3 version of the RoseGarden MIDI tool
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/rosegarden@1097595 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/commands/segment')
-rw-r--r--src/commands/segment/AddTempoChangeCommand.cpp66
-rw-r--r--src/commands/segment/AddTempoChangeCommand.h76
-rw-r--r--src/commands/segment/AddTimeSignatureAndNormalizeCommand.cpp78
-rw-r--r--src/commands/segment/AddTimeSignatureAndNormalizeCommand.h53
-rw-r--r--src/commands/segment/AddTimeSignatureCommand.cpp78
-rw-r--r--src/commands/segment/AddTimeSignatureCommand.h71
-rw-r--r--src/commands/segment/AddTracksCommand.cpp137
-rw-r--r--src/commands/segment/AddTracksCommand.h77
-rw-r--r--src/commands/segment/AddTriggerSegmentCommand.cpp90
-rw-r--r--src/commands/segment/AddTriggerSegmentCommand.h72
-rw-r--r--src/commands/segment/AudioSegmentAutoSplitCommand.cpp191
-rw-r--r--src/commands/segment/AudioSegmentAutoSplitCommand.h71
-rw-r--r--src/commands/segment/AudioSegmentDistributeCommand.cpp156
-rw-r--r--src/commands/segment/AudioSegmentDistributeCommand.h86
-rw-r--r--src/commands/segment/AudioSegmentInsertCommand.cpp136
-rw-r--r--src/commands/segment/AudioSegmentInsertCommand.h77
-rw-r--r--src/commands/segment/AudioSegmentRescaleCommand.cpp210
-rw-r--r--src/commands/segment/AudioSegmentRescaleCommand.h81
-rw-r--r--src/commands/segment/AudioSegmentResizeFromStartCommand.cpp87
-rw-r--r--src/commands/segment/AudioSegmentResizeFromStartCommand.h66
-rw-r--r--src/commands/segment/AudioSegmentSplitCommand.cpp155
-rw-r--r--src/commands/segment/AudioSegmentSplitCommand.h65
-rw-r--r--src/commands/segment/ChangeCompositionLengthCommand.cpp64
-rw-r--r--src/commands/segment/ChangeCompositionLengthCommand.h70
-rw-r--r--src/commands/segment/CreateTempoMapFromSegmentCommand.cpp166
-rw-r--r--src/commands/segment/CreateTempoMapFromSegmentCommand.h69
-rw-r--r--src/commands/segment/CutRangeCommand.cpp47
-rw-r--r--src/commands/segment/CutRangeCommand.h53
-rw-r--r--src/commands/segment/DeleteRangeCommand.cpp127
-rw-r--r--src/commands/segment/DeleteRangeCommand.h84
-rw-r--r--src/commands/segment/DeleteTracksCommand.cpp161
-rw-r--r--src/commands/segment/DeleteTracksCommand.h68
-rw-r--r--src/commands/segment/DeleteTriggerSegmentCommand.cpp78
-rw-r--r--src/commands/segment/DeleteTriggerSegmentCommand.h66
-rw-r--r--src/commands/segment/EraseSegmentsStartingInRangeCommand.cpp99
-rw-r--r--src/commands/segment/EraseSegmentsStartingInRangeCommand.h67
-rw-r--r--src/commands/segment/InsertRangeCommand.cpp63
-rw-r--r--src/commands/segment/InsertRangeCommand.h47
-rw-r--r--src/commands/segment/ModifyDefaultTempoCommand.cpp48
-rw-r--r--src/commands/segment/ModifyDefaultTempoCommand.h66
-rw-r--r--src/commands/segment/MoveTracksCommand.cpp76
-rw-r--r--src/commands/segment/MoveTracksCommand.h66
-rw-r--r--src/commands/segment/OpenOrCloseRangeCommand.cpp181
-rw-r--r--src/commands/segment/OpenOrCloseRangeCommand.h84
-rw-r--r--src/commands/segment/PasteConductorDataCommand.cpp128
-rw-r--r--src/commands/segment/PasteConductorDataCommand.h67
-rw-r--r--src/commands/segment/PasteRangeCommand.cpp97
-rw-r--r--src/commands/segment/PasteRangeCommand.h52
-rw-r--r--src/commands/segment/PasteToTriggerSegmentCommand.cpp129
-rw-r--r--src/commands/segment/PasteToTriggerSegmentCommand.h73
-rw-r--r--src/commands/segment/RemoveTempoChangeCommand.cpp59
-rw-r--r--src/commands/segment/RemoveTempoChangeCommand.h75
-rw-r--r--src/commands/segment/RemoveTimeSignatureCommand.cpp60
-rw-r--r--src/commands/segment/RemoveTimeSignatureCommand.h74
-rw-r--r--src/commands/segment/RenameTrackCommand.cpp75
-rw-r--r--src/commands/segment/RenameTrackCommand.h67
-rw-r--r--src/commands/segment/SegmentAutoSplitCommand.cpp205
-rw-r--r--src/commands/segment/SegmentAutoSplitCommand.h66
-rw-r--r--src/commands/segment/SegmentChangePlayableRangeCommand.cpp77
-rw-r--r--src/commands/segment/SegmentChangePlayableRangeCommand.h67
-rw-r--r--src/commands/segment/SegmentChangeQuantizationCommand.cpp115
-rw-r--r--src/commands/segment/SegmentChangeQuantizationCommand.h73
-rw-r--r--src/commands/segment/SegmentChangeTransposeCommand.cpp72
-rw-r--r--src/commands/segment/SegmentChangeTransposeCommand.h65
-rw-r--r--src/commands/segment/SegmentColourCommand.cpp65
-rw-r--r--src/commands/segment/SegmentColourCommand.h66
-rw-r--r--src/commands/segment/SegmentColourMapCommand.cpp64
-rw-r--r--src/commands/segment/SegmentColourMapCommand.h71
-rw-r--r--src/commands/segment/SegmentCommand.cpp42
-rw-r--r--src/commands/segment/SegmentCommand.h59
-rw-r--r--src/commands/segment/SegmentCommandRepeat.cpp59
-rw-r--r--src/commands/segment/SegmentCommandRepeat.h81
-rw-r--r--src/commands/segment/SegmentEraseCommand.cpp108
-rw-r--r--src/commands/segment/SegmentEraseCommand.h70
-rw-r--r--src/commands/segment/SegmentInsertCommand.cpp124
-rw-r--r--src/commands/segment/SegmentInsertCommand.h76
-rw-r--r--src/commands/segment/SegmentJoinCommand.cpp175
-rw-r--r--src/commands/segment/SegmentJoinCommand.h65
-rw-r--r--src/commands/segment/SegmentLabelCommand.cpp73
-rw-r--r--src/commands/segment/SegmentLabelCommand.h67
-rw-r--r--src/commands/segment/SegmentQuickCopyCommand.cpp71
-rw-r--r--src/commands/segment/SegmentQuickCopyCommand.h68
-rw-r--r--src/commands/segment/SegmentReconfigureCommand.cpp114
-rw-r--r--src/commands/segment/SegmentReconfigureCommand.h81
-rw-r--r--src/commands/segment/SegmentRecordCommand.cpp67
-rw-r--r--src/commands/segment/SegmentRecordCommand.h67
-rw-r--r--src/commands/segment/SegmentRepeatToCopyCommand.cpp106
-rw-r--r--src/commands/segment/SegmentRepeatToCopyCommand.h62
-rw-r--r--src/commands/segment/SegmentRescaleCommand.cpp148
-rw-r--r--src/commands/segment/SegmentRescaleCommand.h76
-rw-r--r--src/commands/segment/SegmentResizeFromStartCommand.cpp85
-rw-r--r--src/commands/segment/SegmentResizeFromStartCommand.h69
-rw-r--r--src/commands/segment/SegmentSingleRepeatToCopyCommand.cpp73
-rw-r--r--src/commands/segment/SegmentSingleRepeatToCopyCommand.h65
-rw-r--r--src/commands/segment/SegmentSplitByPitchCommand.cpp280
-rw-r--r--src/commands/segment/SegmentSplitByPitchCommand.h83
-rw-r--r--src/commands/segment/SegmentSplitByRecordingSrcCommand.cpp153
-rw-r--r--src/commands/segment/SegmentSplitByRecordingSrcCommand.h70
-rw-r--r--src/commands/segment/SegmentSplitCommand.cpp185
-rw-r--r--src/commands/segment/SegmentSplitCommand.h65
-rw-r--r--src/commands/segment/SegmentSyncClefCommand.cpp67
-rw-r--r--src/commands/segment/SegmentSyncClefCommand.h55
-rw-r--r--src/commands/segment/SegmentSyncCommand.cpp103
-rw-r--r--src/commands/segment/SegmentSyncCommand.h66
-rw-r--r--src/commands/segment/SegmentTransposeCommand.cpp123
-rw-r--r--src/commands/segment/SegmentTransposeCommand.h64
-rw-r--r--src/commands/segment/SetTriggerSegmentBasePitchCommand.cpp74
-rw-r--r--src/commands/segment/SetTriggerSegmentBasePitchCommand.h63
-rw-r--r--src/commands/segment/SetTriggerSegmentBaseVelocityCommand.cpp74
-rw-r--r--src/commands/segment/SetTriggerSegmentBaseVelocityCommand.h63
-rw-r--r--src/commands/segment/SetTriggerSegmentDefaultRetuneCommand.cpp75
-rw-r--r--src/commands/segment/SetTriggerSegmentDefaultRetuneCommand.h64
-rw-r--r--src/commands/segment/SetTriggerSegmentDefaultTimeAdjustCommand.cpp74
-rw-r--r--src/commands/segment/SetTriggerSegmentDefaultTimeAdjustCommand.h64
114 files changed, 10007 insertions, 0 deletions
diff --git a/src/commands/segment/AddTempoChangeCommand.cpp b/src/commands/segment/AddTempoChangeCommand.cpp
new file mode 100644
index 0000000..6665215
--- /dev/null
+++ b/src/commands/segment/AddTempoChangeCommand.cpp
@@ -0,0 +1,66 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "AddTempoChangeCommand.h"
+
+#include "base/Composition.h"
+#include <qstring.h>
+
+
+namespace Rosegarden
+{
+
+AddTempoChangeCommand::~AddTempoChangeCommand()
+{
+ // nothing here either
+}
+
+void
+AddTempoChangeCommand::execute()
+{
+ int oldIndex = m_composition->getTempoChangeNumberAt(m_time);
+
+ if (oldIndex >= 0) {
+ std::pair<timeT, tempoT> data =
+ m_composition->getTempoChange(oldIndex);
+
+ if (data.first == m_time)
+ m_oldTempo = data.second;
+ }
+
+ m_tempoChangeIndex = m_composition->addTempoAtTime(m_time, m_tempo, m_target);
+}
+
+void
+AddTempoChangeCommand::unexecute()
+{
+ m_composition->removeTempoChange(m_tempoChangeIndex);
+
+ if (m_oldTempo != 0) {
+ m_composition->addTempoAtTime(m_time, m_oldTempo);
+ }
+}
+
+}
diff --git a/src/commands/segment/AddTempoChangeCommand.h b/src/commands/segment/AddTempoChangeCommand.h
new file mode 100644
index 0000000..07036dd
--- /dev/null
+++ b/src/commands/segment/AddTempoChangeCommand.h
@@ -0,0 +1,76 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_ADDTEMPOCHANGECOMMAND_H_
+#define _RG_ADDTEMPOCHANGECOMMAND_H_
+
+#include <kcommand.h>
+#include <qstring.h>
+#include "base/Event.h"
+#include "base/Composition.h" // for tempoT
+#include <klocale.h>
+
+
+
+
+namespace Rosegarden
+{
+
+class AddTempoChangeCommand : public KNamedCommand
+{
+public:
+ AddTempoChangeCommand(Composition *composition,
+ timeT time,
+ tempoT tempo,
+ tempoT target = -1):
+ KNamedCommand(getGlobalName()),
+ m_composition(composition),
+ m_time(time),
+ m_tempo(tempo),
+ m_target(target),
+ m_oldTempo(0),
+ m_tempoChangeIndex(0) {}
+
+ virtual ~AddTempoChangeCommand();
+
+ static QString getGlobalName() { return i18n("Add Te&mpo Change..."); }
+
+ virtual void execute();
+ virtual void unexecute();
+
+private:
+ Composition *m_composition;
+ timeT m_time;
+ tempoT m_tempo;
+ tempoT m_target;
+ tempoT m_oldTempo;
+ int m_tempoChangeIndex;
+};
+
+
+
+}
+
+#endif
diff --git a/src/commands/segment/AddTimeSignatureAndNormalizeCommand.cpp b/src/commands/segment/AddTimeSignatureAndNormalizeCommand.cpp
new file mode 100644
index 0000000..45b391b
--- /dev/null
+++ b/src/commands/segment/AddTimeSignatureAndNormalizeCommand.cpp
@@ -0,0 +1,78 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "AddTimeSignatureAndNormalizeCommand.h"
+
+#include "AddTimeSignatureCommand.h"
+#include "base/Composition.h"
+#include "base/NotationTypes.h"
+#include "commands/notation/MakeRegionViableCommand.h"
+
+
+namespace Rosegarden
+{
+
+AddTimeSignatureAndNormalizeCommand::AddTimeSignatureAndNormalizeCommand
+(Composition *composition, timeT time, TimeSignature timeSig) :
+ KMacroCommand(AddTimeSignatureCommand::getGlobalName())
+{
+ addCommand(new AddTimeSignatureCommand(composition, time, timeSig));
+
+ // only up to the next time signature
+ timeT nextTimeSigTime(composition->getDuration());
+
+ int index = composition->getTimeSignatureNumberAt(time);
+ if (composition->getTimeSignatureCount() > index + 1) {
+ nextTimeSigTime = composition->getTimeSignatureChange(index + 1).first;
+ }
+
+ for (Composition::iterator i = composition->begin();
+ i != composition->end(); ++i) {
+
+ if ((*i)->getType() != Segment::Internal) continue;
+
+ timeT startTime = (*i)->getStartTime();
+ timeT endTime = (*i)->getEndTime();
+
+ if (startTime >= nextTimeSigTime || endTime <= time)
+ continue;
+
+ // "Make Notes Viable" splits and ties notes at barlines, and
+ // also does a rest normalize. It's what we normally want
+ // when adding a time signature.
+
+ addCommand(new MakeRegionViableCommand
+ (**i,
+ std::max(startTime, time),
+ std::min(endTime, nextTimeSigTime)));
+ }
+}
+
+AddTimeSignatureAndNormalizeCommand::~AddTimeSignatureAndNormalizeCommand()
+{
+ // well, nothing really
+}
+
+}
diff --git a/src/commands/segment/AddTimeSignatureAndNormalizeCommand.h b/src/commands/segment/AddTimeSignatureAndNormalizeCommand.h
new file mode 100644
index 0000000..f22faa4
--- /dev/null
+++ b/src/commands/segment/AddTimeSignatureAndNormalizeCommand.h
@@ -0,0 +1,53 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_ADDTIMESIGNATUREANDNORMALIZECOMMAND_H_
+#define _RG_ADDTIMESIGNATUREANDNORMALIZECOMMAND_H_
+
+#include "base/NotationTypes.h"
+#include "base/Event.h"
+#include <kcommand.h>
+
+
+namespace Rosegarden
+{
+
+class Composition;
+
+
+class AddTimeSignatureAndNormalizeCommand : public KMacroCommand
+{
+public:
+ AddTimeSignatureAndNormalizeCommand(Composition *composition,
+ timeT time,
+ TimeSignature timeSig);
+ virtual ~AddTimeSignatureAndNormalizeCommand();
+};
+
+
+
+}
+
+#endif
diff --git a/src/commands/segment/AddTimeSignatureCommand.cpp b/src/commands/segment/AddTimeSignatureCommand.cpp
new file mode 100644
index 0000000..88f2d07
--- /dev/null
+++ b/src/commands/segment/AddTimeSignatureCommand.cpp
@@ -0,0 +1,78 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "AddTimeSignatureCommand.h"
+
+#include "base/Composition.h"
+#include "base/NotationTypes.h"
+#include <qstring.h>
+
+
+namespace Rosegarden
+{
+
+AddTimeSignatureCommand::AddTimeSignatureCommand(Composition *composition,
+ timeT time,
+ TimeSignature timeSig) :
+ KNamedCommand(getGlobalName()),
+ m_composition(composition),
+ m_time(time),
+ m_timeSignature(timeSig),
+ m_oldTimeSignature(0)
+{
+ // nothing else
+}
+
+AddTimeSignatureCommand::~AddTimeSignatureCommand()
+{
+ if (m_oldTimeSignature)
+ delete m_oldTimeSignature;
+}
+
+void
+AddTimeSignatureCommand::execute()
+{
+ int oldIndex = m_composition->getTimeSignatureNumberAt(m_time);
+ if (oldIndex >= 0) {
+ std::pair<timeT, TimeSignature> data =
+ m_composition->getTimeSignatureChange(oldIndex);
+ if (data.first == m_time) {
+ m_oldTimeSignature = new TimeSignature(data.second);
+ }
+ }
+
+ m_timeSigIndex = m_composition->addTimeSignature(m_time, m_timeSignature);
+}
+
+void
+AddTimeSignatureCommand::unexecute()
+{
+ m_composition->removeTimeSignature(m_timeSigIndex);
+ if (m_oldTimeSignature) {
+ m_composition->addTimeSignature(m_time, *m_oldTimeSignature);
+ }
+}
+
+}
diff --git a/src/commands/segment/AddTimeSignatureCommand.h b/src/commands/segment/AddTimeSignatureCommand.h
new file mode 100644
index 0000000..fbc875d
--- /dev/null
+++ b/src/commands/segment/AddTimeSignatureCommand.h
@@ -0,0 +1,71 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_ADDTIMESIGNATURECOMMAND_H_
+#define _RG_ADDTIMESIGNATURECOMMAND_H_
+
+#include "base/NotationTypes.h"
+#include <kcommand.h>
+#include <qstring.h>
+#include "base/Event.h"
+#include <klocale.h>
+
+
+
+
+namespace Rosegarden
+{
+
+class Composition;
+
+
+class AddTimeSignatureCommand : public KNamedCommand
+{
+public:
+ AddTimeSignatureCommand(Composition *composition,
+ timeT time,
+ TimeSignature timeSig);
+ virtual ~AddTimeSignatureCommand();
+
+ static QString getGlobalName() { return i18n("Add Time Si&gnature Change..."); }
+
+ virtual void execute();
+ virtual void unexecute();
+
+protected:
+ Composition *m_composition;
+ timeT m_time;
+ TimeSignature m_timeSignature;
+
+ TimeSignature *m_oldTimeSignature; // for undo
+ int m_timeSigIndex; // for undo
+};
+
+
+
+
+}
+
+#endif
diff --git a/src/commands/segment/AddTracksCommand.cpp b/src/commands/segment/AddTracksCommand.cpp
new file mode 100644
index 0000000..1f09227
--- /dev/null
+++ b/src/commands/segment/AddTracksCommand.cpp
@@ -0,0 +1,137 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "AddTracksCommand.h"
+
+#include "misc/Debug.h"
+#include "base/Composition.h"
+#include "base/MidiProgram.h"
+#include "base/Track.h"
+#include <qstring.h>
+
+
+namespace Rosegarden
+{
+
+AddTracksCommand::AddTracksCommand(Composition *composition,
+ unsigned int nbTracks,
+ InstrumentId id,
+ int position):
+ KNamedCommand(getGlobalName()),
+ m_composition(composition),
+ m_nbNewTracks(nbTracks),
+ m_instrumentId(id),
+ m_position(position),
+ m_detached(false)
+
+{
+}
+
+AddTracksCommand::~AddTracksCommand()
+{
+ if (m_detached) {
+ for (unsigned int i = 0; i < m_newTracks.size(); ++i)
+ delete m_newTracks[i];
+ }
+}
+
+void AddTracksCommand::execute()
+{
+ // Re-attach tracks
+ //
+ if (m_detached) {
+
+ for (unsigned int i = 0; i < m_newTracks.size(); i++) {
+ m_composition->addTrack(m_newTracks[i]);
+ }
+
+ for (TrackPositionMap::iterator i = m_oldPositions.begin();
+ i != m_oldPositions.end(); ++i) {
+
+ int newPosition = i->second + m_nbNewTracks;
+ Track *track = m_composition->getTrackById(i->first);
+ if (track) track->setPosition(newPosition);
+ }
+
+ return;
+ }
+
+ int highPosition = 0;
+
+ for (Composition::trackiterator it = m_composition->getTracks().begin();
+ it != m_composition->getTracks().end(); ++it) {
+
+ int pos = it->second->getPosition();
+
+ if (pos > highPosition) {
+ highPosition = pos;
+ }
+ }
+
+ if (m_position == -1) m_position = highPosition + 1;
+ if (m_position < 0) m_position = 0;
+ if (m_position > highPosition + 1) m_position = highPosition + 1;
+
+ for (Composition::trackiterator it = m_composition->getTracks().begin();
+ it != m_composition->getTracks().end(); ++it) {
+
+ int pos = it->second->getPosition();
+
+ if (pos >= m_position) {
+ m_oldPositions[it->first] = pos;
+ it->second->setPosition(pos + m_nbNewTracks);
+ }
+ }
+
+ for (unsigned int i = 0; i < m_nbNewTracks; ++i) {
+
+ TrackId trackId = m_composition->getNewTrackId();
+ Track *track = new Track(trackId);
+
+ track->setPosition(m_position + i);
+ track->setInstrument(m_instrumentId);
+
+ m_composition->addTrack(track);
+ m_newTracks.push_back(track);
+ }
+}
+
+void AddTracksCommand::unexecute()
+{
+ for (unsigned int i = 0; i < m_newTracks.size(); i++) {
+ m_composition->detachTrack(m_newTracks[i]);
+ }
+
+ for (TrackPositionMap::iterator i = m_oldPositions.begin();
+ i != m_oldPositions.end(); ++i) {
+
+ Track *track = m_composition->getTrackById(i->first);
+ if (track) track->setPosition(i->second);
+ }
+
+ m_detached = true;
+}
+
+}
diff --git a/src/commands/segment/AddTracksCommand.h b/src/commands/segment/AddTracksCommand.h
new file mode 100644
index 0000000..d3e09ca
--- /dev/null
+++ b/src/commands/segment/AddTracksCommand.h
@@ -0,0 +1,77 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_ADDTRACKSCOMMAND_H_
+#define _RG_ADDTRACKSCOMMAND_H_
+
+#include "base/MidiProgram.h"
+#include "base/Composition.h"
+#include <kcommand.h>
+#include <qstring.h>
+#include <vector>
+#include <map>
+#include <klocale.h>
+
+
+
+namespace Rosegarden
+{
+
+class Track;
+class Composition;
+
+
+class AddTracksCommand : public KNamedCommand
+{
+public:
+ AddTracksCommand(Composition *composition,
+ unsigned int nbTracks,
+ InstrumentId id,
+ int position); // -1 -> at end
+ virtual ~AddTracksCommand();
+
+ static QString getGlobalName() { return i18n("Add Tracks..."); }
+
+ virtual void execute();
+ virtual void unexecute();
+
+protected:
+ Composition *m_composition;
+ unsigned int m_nbNewTracks;
+ InstrumentId m_instrumentId;
+ int m_position;
+
+ typedef std::map<TrackId, int> TrackPositionMap;
+
+ std::vector<Track *> m_newTracks;
+ TrackPositionMap m_oldPositions;
+
+ bool m_detached;
+};
+
+
+}
+
+#endif
diff --git a/src/commands/segment/AddTriggerSegmentCommand.cpp b/src/commands/segment/AddTriggerSegmentCommand.cpp
new file mode 100644
index 0000000..12d406e
--- /dev/null
+++ b/src/commands/segment/AddTriggerSegmentCommand.cpp
@@ -0,0 +1,90 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "AddTriggerSegmentCommand.h"
+
+#include <klocale.h>
+#include "base/Composition.h"
+#include "base/Segment.h"
+#include "base/TriggerSegment.h"
+#include "document/RosegardenGUIDoc.h"
+
+
+namespace Rosegarden
+{
+
+AddTriggerSegmentCommand::AddTriggerSegmentCommand(RosegardenGUIDoc *doc,
+ timeT duration,
+ int basePitch,
+ int baseVelocity) :
+ KNamedCommand(i18n("Add Triggered Segment")),
+ m_composition(&doc->getComposition()),
+ m_duration(duration),
+ m_basePitch(basePitch),
+ m_baseVelocity(baseVelocity),
+ m_id(0),
+ m_segment(0),
+ m_detached(false)
+{
+ // nothing else
+}
+
+AddTriggerSegmentCommand::~AddTriggerSegmentCommand()
+{
+ if (m_detached)
+ delete m_segment;
+}
+
+TriggerSegmentId
+AddTriggerSegmentCommand::getId() const
+{
+ return m_id;
+}
+
+void
+AddTriggerSegmentCommand::execute()
+{
+ if (m_segment) {
+ m_composition->addTriggerSegment(m_segment, m_id, m_basePitch, m_baseVelocity);
+ } else {
+ m_segment = new Segment();
+ m_segment->setEndMarkerTime(m_duration);
+ TriggerSegmentRec *rec = m_composition->addTriggerSegment
+ (m_segment, m_basePitch, m_baseVelocity);
+ if (rec)
+ m_id = rec->getId();
+ }
+ m_detached = false;
+}
+
+void
+AddTriggerSegmentCommand::unexecute()
+{
+ if (m_segment)
+ m_composition->detachTriggerSegment(m_id);
+ m_detached = true;
+}
+
+}
diff --git a/src/commands/segment/AddTriggerSegmentCommand.h b/src/commands/segment/AddTriggerSegmentCommand.h
new file mode 100644
index 0000000..46d23cb
--- /dev/null
+++ b/src/commands/segment/AddTriggerSegmentCommand.h
@@ -0,0 +1,72 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_ADDTRIGGERSEGMENTCOMMAND_H_
+#define _RG_ADDTRIGGERSEGMENTCOMMAND_H_
+
+#include "base/TriggerSegment.h"
+#include <kcommand.h>
+#include "base/Event.h"
+
+
+
+
+namespace Rosegarden
+{
+
+class Segment;
+class RosegardenGUIDoc;
+class Composition;
+
+
+class AddTriggerSegmentCommand : public KNamedCommand
+{
+public:
+ AddTriggerSegmentCommand(RosegardenGUIDoc *doc,
+ timeT duration, // start time always 0
+ int basePitch = -1,
+ int baseVelocity = -1);
+ virtual ~AddTriggerSegmentCommand();
+
+ TriggerSegmentId getId() const; // after invocation
+
+ virtual void execute();
+ virtual void unexecute();
+
+private:
+ Composition *m_composition;
+ timeT m_duration;
+ int m_basePitch;
+ int m_baseVelocity;
+ TriggerSegmentId m_id;
+ Segment *m_segment;
+ bool m_detached;
+};
+
+
+
+}
+
+#endif
diff --git a/src/commands/segment/AudioSegmentAutoSplitCommand.cpp b/src/commands/segment/AudioSegmentAutoSplitCommand.cpp
new file mode 100644
index 0000000..d474b64
--- /dev/null
+++ b/src/commands/segment/AudioSegmentAutoSplitCommand.cpp
@@ -0,0 +1,191 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "AudioSegmentAutoSplitCommand.h"
+
+#include "base/Event.h"
+#include "misc/Debug.h"
+#include "misc/Strings.h"
+#include "base/Composition.h"
+#include "base/RealTime.h"
+#include "base/Segment.h"
+#include "document/RosegardenGUIDoc.h"
+#include "sound/AudioFileManager.h"
+#include "sound/PeakFileManager.h"
+#include <qstring.h>
+
+
+namespace Rosegarden
+{
+
+struct AutoSplitPoint
+{
+ timeT time;
+ timeT lastSoundTime;
+ Clef clef;
+ Rosegarden::Key key;
+ AutoSplitPoint(timeT t, timeT lst, Clef c, Rosegarden::Key k) :
+ time(t), lastSoundTime(lst), clef(c), key(k) { }
+};
+
+AudioSegmentAutoSplitCommand::AudioSegmentAutoSplitCommand(
+ RosegardenGUIDoc *doc,
+ Segment *segment,
+ int threshold) :
+ KNamedCommand(getGlobalName()),
+ m_segment(segment),
+ m_composition(segment->getComposition()),
+ m_audioFileManager(&(doc->getAudioFileManager())),
+ m_detached(false),
+ m_threshold(threshold)
+{}
+
+AudioSegmentAutoSplitCommand::~AudioSegmentAutoSplitCommand()
+{
+ if (m_detached) {
+ delete m_segment;
+ } else {
+ for (unsigned int i = 0; i < m_newSegments.size(); ++i) {
+ delete m_newSegments[i];
+ }
+ }
+}
+
+void
+AudioSegmentAutoSplitCommand::execute()
+{
+ if (m_newSegments.size() == 0) {
+
+ std::vector<AutoSplitPoint> splitPoints;
+
+ if (m_segment->getType() != Segment::Audio)
+ return ;
+
+ // Auto split the audio file - we ask for a minimum
+ // result file size of 0.2secs - that's probably fair
+ // enough.
+ //
+ std::vector<SplitPointPair> rtSplitPoints;
+
+ try {
+ rtSplitPoints =
+ m_audioFileManager->
+ getSplitPoints(m_segment->getAudioFileId(),
+ m_segment->getAudioStartTime(),
+ m_segment->getAudioEndTime(),
+ m_threshold,
+ RealTime(0, 200000000));
+ } catch (AudioFileManager::BadAudioPathException e) {
+ std::cerr << "ERROR: AudioSegmentAutoSplitCommand: Bad audio path: " << e.getMessage() << std::endl;
+ } catch (PeakFileManager::BadPeakFileException e) {
+ std::cerr << "ERROR: AudioSegmentAutoSplitCommand: Bad peak file: " << e.getMessage() << std::endl;
+ }
+
+ std::vector<SplitPointPair>::iterator it;
+ timeT absStartTime, absEndTime;
+
+ char splitNumber[10];
+ int splitCount = 0;
+
+ timeT origStartTime = m_segment->getStartTime();
+ RealTime audioStart = m_segment->getAudioStartTime();
+ RealTime origStartRT = m_composition->getElapsedRealTime(origStartTime);
+
+ for (it = rtSplitPoints.begin(); it != rtSplitPoints.end(); it++) {
+ // The start time for the segment is the original
+ // segment's start time, plus whatever it->first translates
+ // into as an offset from the original segment's start
+ // time
+
+ RG_DEBUG << "AudioSegmentAutoSplitCommand::execute: range " << it->first << " -> " << it->second << endl;
+
+ absStartTime = m_composition->getElapsedTimeForRealTime
+ (origStartRT - audioStart + it->first);
+
+ absEndTime = m_composition->getElapsedTimeForRealTime
+ (origStartRT - audioStart + it->second);
+
+ // absStartTime = m_segment->getStartTime() +
+ // m_composition->getElapsedTimeForRealTime(it->first - audioStart);
+
+ // absEndTime = m_segment->getStartTime() +
+ // m_composition->getElapsedTimeForRealTime(it->second - audioStart);
+
+ Segment *newSegment = new Segment(*m_segment);
+
+ newSegment->setStartTime(absStartTime);
+ newSegment->setAudioFileId(m_segment->getAudioFileId());
+ newSegment->setAudioStartTime(it->first);
+ newSegment->setAudioEndTime(it->second);
+ newSegment->setEndMarkerTime(absEndTime);
+
+ // label
+ sprintf(splitNumber, "%d", splitCount++);
+ newSegment->
+ setLabel(qstrtostr(i18n("%1 (autosplit %2)").arg
+ (strtoqstr(m_segment->getLabel())).arg
+ (splitNumber)));
+
+ newSegment->setColourIndex(m_segment->getColourIndex());
+
+ RG_DEBUG << "AudioSegmentAutoSplitCommand::execute "
+ << "abs start = " << absStartTime
+ << ", abs end = " << absEndTime
+ << ", seg start = " << newSegment->getStartTime()
+ << ", seg end = " << newSegment->getEndMarkerTime()
+ << ", audio start = " << newSegment->getAudioStartTime()
+ << ", audio end = " << newSegment->getAudioEndTime()
+ << endl;
+
+ m_newSegments.push_back(newSegment);
+ }
+ }
+
+ RG_DEBUG << "AudioSegmentAutoSplitCommand::execute: have " << m_newSegments.size() << " new segments" << endl;
+
+ for (unsigned int i = 0; i < m_newSegments.size(); ++i) {
+ m_composition->addSegment(m_newSegments[i]);
+ }
+
+ if (m_newSegments.size() > 0) {
+ m_composition->detachSegment(m_segment);
+ }
+
+ m_detached = true;
+}
+
+void
+AudioSegmentAutoSplitCommand::unexecute()
+{
+ for (unsigned int i = 0; i < m_newSegments.size(); ++i) {
+ m_composition->detachSegment(m_newSegments[i]);
+ }
+ if (m_newSegments.size() > 0) { // otherwise it was never detached
+ m_composition->addSegment(m_segment);
+ }
+ m_detached = false;
+}
+
+}
diff --git a/src/commands/segment/AudioSegmentAutoSplitCommand.h b/src/commands/segment/AudioSegmentAutoSplitCommand.h
new file mode 100644
index 0000000..a1c4b48
--- /dev/null
+++ b/src/commands/segment/AudioSegmentAutoSplitCommand.h
@@ -0,0 +1,71 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_AUDIOSEGMENTAUTOSPLITCOMMAND_H_
+#define _RG_AUDIOSEGMENTAUTOSPLITCOMMAND_H_
+
+#include <kcommand.h>
+#include <qstring.h>
+#include <vector>
+#include <klocale.h>
+
+
+
+
+namespace Rosegarden
+{
+
+class Segment;
+class RosegardenGUIDoc;
+class Composition;
+class AudioFileManager;
+
+
+class AudioSegmentAutoSplitCommand : public KNamedCommand
+{
+public:
+ AudioSegmentAutoSplitCommand(RosegardenGUIDoc *doc,
+ Segment *segment,
+ int threshold);
+ virtual ~AudioSegmentAutoSplitCommand();
+
+ virtual void execute();
+ virtual void unexecute();
+
+ static QString getGlobalName() { return i18n("&Split on Silence"); }
+
+private:
+ Segment *m_segment;
+ Composition *m_composition;
+ AudioFileManager *m_audioFileManager;
+ std::vector<Segment *> m_newSegments;
+ bool m_detached;
+ int m_threshold;
+};
+
+
+}
+
+#endif
diff --git a/src/commands/segment/AudioSegmentDistributeCommand.cpp b/src/commands/segment/AudioSegmentDistributeCommand.cpp
new file mode 100644
index 0000000..9bdfb97
--- /dev/null
+++ b/src/commands/segment/AudioSegmentDistributeCommand.cpp
@@ -0,0 +1,156 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "AudioSegmentDistributeCommand.h"
+
+#include "base/Event.h"
+#include "base/Composition.h"
+#include "base/NotationTypes.h"
+#include "base/RealTime.h"
+#include "base/Segment.h"
+#include "base/Selection.h"
+#include "sound/AudioFile.h"
+#include <qstring.h>
+
+
+namespace Rosegarden
+{
+
+AudioSegmentDistributeCommand::AudioSegmentDistributeCommand(
+ Composition *comp,
+ SegmentSelection &inputSelection,
+ Segment *audioSegment):
+ KNamedCommand(getGlobalName()),
+ m_composition(comp),
+ m_selection(inputSelection),
+ m_audioFile(0),
+ m_audioSegment(audioSegment),
+ m_executed(false)
+{}
+
+AudioSegmentDistributeCommand::AudioSegmentDistributeCommand(
+ Composition *comp,
+ SegmentSelection &inputSelection,
+ AudioFile *audioFile):
+ KNamedCommand(getGlobalName()),
+ m_composition(comp),
+ m_selection(inputSelection),
+ m_audioFile(audioFile),
+ m_audioSegment(0),
+ m_executed(false)
+{}
+
+AudioSegmentDistributeCommand::~AudioSegmentDistributeCommand()
+{
+ if (m_executed) {
+ for (SegmentSelection::iterator i = m_selection.begin();
+ i != m_selection.end(); ++i) {
+ delete *i;
+ }
+ } else {
+ for (unsigned int i = 0; i < m_newSegments.size(); ++i)
+ delete m_newSegments[i];
+ }
+}
+
+void
+AudioSegmentDistributeCommand::execute()
+{
+ // Store the insert times in a local vector
+ //
+ std::vector<timeT> insertTimes;
+
+ bool addNew = m_newSegments.size() == 0 ? true : false;
+
+ for (SegmentSelection::iterator i = m_selection.begin();
+ i != m_selection.end(); ++i) {
+ // For MIDI (Internal) Segments only of course
+ //
+ if ((*i)->getType() == Segment::Internal) {
+ if (addNew) {
+ for (Segment::iterator it = (*i)->begin();
+ it != (*i)->end(); ++it) {
+ if ((*it)->isa(Note::EventType)) {
+ Segment *segment =
+ new Segment(
+ Segment::Audio,
+ (*it)->getAbsoluteTime());
+ segment->setTrack((*i)->getTrack());
+
+ // If we've constructed against an AudioFile
+ //
+ if (m_audioFile) {
+ segment->setAudioFileId(m_audioFile->getId());
+ segment->setAudioStartTime(
+ RealTime::zeroTime);
+ segment->setAudioEndTime(
+ m_audioFile->getLength());
+ } else // or an audio Segment
+ {
+ segment->setAudioFileId(
+ m_audioSegment->getAudioFileId());
+ segment->setAudioStartTime(
+ m_audioSegment->getAudioStartTime());
+ segment->setAudioEndTime(
+ m_audioSegment->getAudioEndTime());
+ }
+
+ m_composition->addSegment(segment);
+ m_newSegments.push_back(segment);
+ }
+ }
+ }
+
+ // Detach original Segment
+ //
+ m_composition->detachSegment(*i);
+ }
+
+ }
+
+ if (!addNew && m_newSegments.size()) {
+ // Reattach new segments
+ //
+ for (unsigned int i = 0; i < m_newSegments.size(); ++i)
+ m_composition->addSegment(m_newSegments[i]);
+ }
+
+ m_executed = true;
+}
+
+void
+AudioSegmentDistributeCommand::unexecute()
+{
+ for (unsigned int i = 0; i < m_newSegments.size(); ++i)
+ m_composition->detachSegment(m_newSegments[i]);
+
+ for (SegmentSelection::iterator it = m_selection.begin();
+ it != m_selection.end(); ++it)
+ m_composition->addSegment(*it);
+
+ m_executed = false;
+}
+
+}
diff --git a/src/commands/segment/AudioSegmentDistributeCommand.h b/src/commands/segment/AudioSegmentDistributeCommand.h
new file mode 100644
index 0000000..d325daf
--- /dev/null
+++ b/src/commands/segment/AudioSegmentDistributeCommand.h
@@ -0,0 +1,86 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_AUDIOSEGMENTDISTRIBUTECOMMAND_H_
+#define _RG_AUDIOSEGMENTDISTRIBUTECOMMAND_H_
+
+#include "base/Selection.h"
+#include <kcommand.h>
+#include <qstring.h>
+#include <vector>
+#include <klocale.h>
+
+
+
+
+namespace Rosegarden
+{
+
+class Segment;
+class Composition;
+class AudioFile;
+
+
+/**
+ * AudioSegmentDistributeCommand - Distribute an Audio Segment triggered
+ * against the MIDI Note ons in a SegmentSelection.
+ *
+ * (I think this is actually unused --cc)
+ */
+class AudioSegmentDistributeCommand : public KNamedCommand
+{
+public:
+ AudioSegmentDistributeCommand(Composition *comp,
+ SegmentSelection &inputSelection,
+ Segment *audioSegment);
+
+ AudioSegmentDistributeCommand(Composition *comp,
+ SegmentSelection &inputSelection,
+ AudioFile *audioFile);
+
+ virtual ~AudioSegmentDistributeCommand();
+
+ static QString getGlobalName()
+ { return i18n("Distribute Audio Segments over MIDI"); }
+
+
+ virtual void execute();
+ virtual void unexecute();
+
+protected:
+ Composition *m_composition;
+ SegmentSelection m_selection;
+ AudioFile *m_audioFile;
+ Segment *m_audioSegment;
+ std::vector<Segment*> m_newSegments;
+ bool m_executed;
+
+};
+
+
+
+}
+
+#endif
diff --git a/src/commands/segment/AudioSegmentInsertCommand.cpp b/src/commands/segment/AudioSegmentInsertCommand.cpp
new file mode 100644
index 0000000..b5167f7
--- /dev/null
+++ b/src/commands/segment/AudioSegmentInsertCommand.cpp
@@ -0,0 +1,136 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "AudioSegmentInsertCommand.h"
+
+#include <klocale.h>
+#include "misc/Debug.h"
+#include "misc/Strings.h"
+#include "base/Composition.h"
+#include "base/RealTime.h"
+#include "base/Segment.h"
+#include "base/Studio.h"
+#include "base/Track.h"
+#include "document/RosegardenGUIDoc.h"
+#include "gui/general/GUIPalette.h"
+#include "sound/AudioFile.h"
+#include "sound/AudioFileManager.h"
+
+
+namespace Rosegarden
+{
+
+AudioSegmentInsertCommand::AudioSegmentInsertCommand(RosegardenGUIDoc *doc,
+ TrackId track,
+ timeT startTime,
+ AudioFileId audioFileId,
+ const RealTime &audioStartTime,
+ const RealTime &audioEndTime):
+ KNamedCommand(i18n("Create Segment")),
+ m_composition(&(doc->getComposition())),
+ m_audioFileManager(&(doc->getAudioFileManager())),
+ m_segment(0),
+ m_track(track),
+ m_startTime(startTime),
+ m_audioFileId(audioFileId),
+ m_audioStartTime(audioStartTime),
+ m_audioEndTime(audioEndTime),
+ m_detached(false)
+{}
+
+AudioSegmentInsertCommand::~AudioSegmentInsertCommand()
+{
+ if (m_detached) {
+ delete m_segment;
+ }
+}
+
+void
+AudioSegmentInsertCommand::execute()
+{
+ if (!m_segment) {
+ // Create and insert Segment
+ //
+ m_segment = new Segment(Segment::Audio);
+ m_segment->setTrack(m_track);
+ m_segment->setStartTime(m_startTime);
+ m_segment->setAudioStartTime(m_audioStartTime);
+ m_segment->setAudioEndTime(m_audioEndTime);
+ m_segment->setAudioFileId(m_audioFileId);
+
+ // Set color for audio segment (DMM)
+ //
+ m_segment->setColourIndex(GUIPalette::AudioDefaultIndex);
+
+ // Calculate end time
+ //
+ RealTime startTime =
+ m_composition->getElapsedRealTime(m_startTime);
+
+ RealTime endTime =
+ startTime + m_audioEndTime - m_audioStartTime;
+
+ timeT endTimeT = m_composition->getElapsedTimeForRealTime(endTime);
+
+ RG_DEBUG << "AudioSegmentInsertCommand::execute : start timeT "
+ << m_startTime << ", startTime " << startTime << ", audioStartTime " << m_audioStartTime << ", audioEndTime " << m_audioEndTime << ", endTime " << endTime << ", end timeT " << endTimeT << endl;
+
+ m_segment->setEndTime(endTimeT);
+
+ if (endTimeT > m_composition->getEndMarker()) {
+ m_composition->setEndMarker(m_composition->getBarEndForTime(endTimeT));
+ }
+
+ // Label by audio file name
+ //
+ std::string label = "";
+
+ AudioFile *aF =
+ m_audioFileManager->getAudioFile(m_audioFileId);
+
+ if (aF)
+ label = qstrtostr(i18n("%1 (inserted)").arg
+ (strtoqstr(aF->getName())));
+ else
+ label = qstrtostr(i18n("unknown audio file"));
+
+ m_segment->setLabel(label);
+
+ m_composition->addSegment(m_segment);
+ } else {
+ m_composition->addSegment(m_segment);
+ }
+
+ m_detached = false;
+}
+
+void
+AudioSegmentInsertCommand::unexecute()
+{
+ m_composition->detachSegment(m_segment);
+ m_detached = true;
+}
+
+}
diff --git a/src/commands/segment/AudioSegmentInsertCommand.h b/src/commands/segment/AudioSegmentInsertCommand.h
new file mode 100644
index 0000000..3510833
--- /dev/null
+++ b/src/commands/segment/AudioSegmentInsertCommand.h
@@ -0,0 +1,77 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_AUDIOSEGMENTINSERTCOMMAND_H_
+#define _RG_AUDIOSEGMENTINSERTCOMMAND_H_
+
+#include "base/RealTime.h"
+#include "base/Track.h"
+#include "sound/AudioFile.h"
+#include <kcommand.h>
+#include "base/Event.h"
+
+
+namespace Rosegarden
+{
+
+class Studio;
+class Segment;
+class RosegardenGUIDoc;
+class Composition;
+class AudioFileManager;
+
+
+class AudioSegmentInsertCommand : public KNamedCommand
+{
+public:
+ AudioSegmentInsertCommand(RosegardenGUIDoc *doc,
+ TrackId track,
+ timeT startTime,
+ AudioFileId audioFileId,
+ const RealTime &audioStartTime,
+ const RealTime &audioEndTime);
+ virtual ~AudioSegmentInsertCommand();
+
+ Segment *getNewSegment() { return m_segment; }
+
+ virtual void execute();
+ virtual void unexecute();
+
+private:
+ Composition *m_composition;
+ AudioFileManager *m_audioFileManager;
+ Segment *m_segment;
+ int m_track;
+ timeT m_startTime;
+ AudioFileId m_audioFileId;
+ RealTime m_audioStartTime;
+ RealTime m_audioEndTime;
+ bool m_detached;
+};
+
+
+}
+
+#endif
diff --git a/src/commands/segment/AudioSegmentRescaleCommand.cpp b/src/commands/segment/AudioSegmentRescaleCommand.cpp
new file mode 100644
index 0000000..1386783
--- /dev/null
+++ b/src/commands/segment/AudioSegmentRescaleCommand.cpp
@@ -0,0 +1,210 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "AudioSegmentRescaleCommand.h"
+
+#include "misc/Strings.h"
+#include "base/Event.h"
+#include "base/Composition.h"
+#include "base/NotationTypes.h"
+#include "base/Segment.h"
+#include "document/RosegardenGUIDoc.h"
+#include "sound/AudioFileTimeStretcher.h"
+#include "sound/AudioFileManager.h"
+#include "gui/widgets/ProgressDialog.h"
+#include <qstring.h>
+
+
+namespace Rosegarden
+{
+
+AudioSegmentRescaleCommand::AudioSegmentRescaleCommand(RosegardenGUIDoc *doc,
+ Segment *s,
+ float ratio) :
+ KNamedCommand(getGlobalName()),
+ m_afm(&doc->getAudioFileManager()),
+ m_stretcher(new AudioFileTimeStretcher(m_afm)),
+ m_segment(s),
+ m_newSegment(0),
+ m_fid(-1),
+ m_timesGiven(false),
+ m_startTime(0),
+ m_endMarkerTime(0),
+ m_ratio(ratio),
+ m_detached(false)
+{
+ // nothing
+}
+
+AudioSegmentRescaleCommand::AudioSegmentRescaleCommand(RosegardenGUIDoc *doc,
+ Segment *s,
+ float ratio,
+ timeT st,
+ timeT emt) :
+ KNamedCommand(getGlobalName()),
+ m_afm(&doc->getAudioFileManager()),
+ m_stretcher(new AudioFileTimeStretcher(m_afm)),
+ m_segment(s),
+ m_newSegment(0),
+ m_fid(-1),
+ m_timesGiven(true),
+ m_startTime(st),
+ m_endMarkerTime(emt),
+ m_ratio(ratio),
+ m_detached(false)
+{
+ // nothing
+}
+
+AudioSegmentRescaleCommand::~AudioSegmentRescaleCommand()
+{
+ delete m_stretcher;
+
+ if (m_detached) {
+ delete m_segment;
+ } else {
+ delete m_newSegment;
+ }
+}
+
+void
+AudioSegmentRescaleCommand::connectProgressDialog(ProgressDialog *dlg)
+{
+ QObject::connect(m_stretcher, SIGNAL(setProgress(int)),
+ dlg->progressBar(), SLOT(setValue(int)));
+ QObject::connect(dlg, SIGNAL(cancelClicked()),
+ m_stretcher, SLOT(slotStopTimestretch()));
+}
+
+void
+AudioSegmentRescaleCommand::disconnectProgressDialog(ProgressDialog *dlg)
+{
+ QObject::disconnect(m_stretcher, SIGNAL(setProgress(int)),
+ dlg->progressBar(), SLOT(setValue(int)));
+ QObject::disconnect(dlg, SIGNAL(cancelClicked()),
+ m_stretcher, SLOT(slotStopTimestretch()));
+}
+
+void
+AudioSegmentRescaleCommand::execute()
+{
+ timeT startTime = m_segment->getStartTime();
+
+ if (m_segment->getType() != Segment::Audio) {
+ return;
+ }
+
+ bool failed = false;
+
+ if (!m_newSegment) {
+
+ m_newSegment = new Segment(*m_segment);
+
+ QString oldLabel = strtoqstr(m_segment->getLabel());
+ if (!oldLabel.endsWith(i18n("(rescaled)"))) {
+ m_newSegment->setLabel(qstrtostr(i18n("%1 (rescaled)").arg
+ (oldLabel)));
+ }
+
+ AudioFileId sourceFileId = m_segment->getAudioFileId();
+ float absoluteRatio = m_ratio;
+
+ std::cerr << "AudioSegmentRescaleCommand: segment file id " << sourceFileId << ", given ratio " << m_ratio << std::endl;
+
+ if (m_segment->getStretchRatio() != 1.f &&
+ m_segment->getStretchRatio() != 0.f) {
+ sourceFileId = m_segment->getUnstretchedFileId();
+ absoluteRatio *= m_segment->getStretchRatio();
+ std::cerr << "AudioSegmentRescaleCommand: unstretched file id " << sourceFileId << ", prev ratio " << m_segment->getStretchRatio() << ", resulting ratio " << absoluteRatio << std::endl;
+ }
+
+ if (!m_timesGiven) {
+ m_endMarkerTime = m_segment->getStartTime() +
+ (m_segment->getEndMarkerTime() - m_segment->getStartTime()) * m_ratio;
+ }
+
+ try {
+ m_fid = m_stretcher->getStretchedAudioFile(sourceFileId,
+ absoluteRatio);
+ m_newSegment->setAudioFileId(m_fid);
+ m_newSegment->setUnstretchedFileId(sourceFileId);
+ m_newSegment->setStretchRatio(absoluteRatio);
+ m_newSegment->setAudioStartTime(m_segment->getAudioStartTime() *
+ m_ratio);
+ if (m_timesGiven) {
+ m_newSegment->setStartTime(m_startTime);
+ m_newSegment->setAudioEndTime(m_segment->getAudioEndTime() *
+ m_ratio);
+ m_newSegment->setEndMarkerTime(m_endMarkerTime);
+ } else {
+ m_newSegment->setEndMarkerTime(m_endMarkerTime);
+ m_newSegment->setAudioEndTime(m_segment->getAudioEndTime() *
+ m_ratio);
+ }
+ } catch (SoundFile::BadSoundFileException e) {
+ std::cerr << "AudioSegmentRescaleCommand: ERROR: BadSoundFileException: "
+ << e.getMessage() << std::endl;
+ delete m_newSegment;
+ m_newSegment = 0;
+ m_fid = -1;
+ failed = true;
+ } catch (AudioFileManager::BadAudioPathException e) {
+ std::cerr << "AudioSegmentRescaleCommand: ERROR: BadAudioPathException: "
+ << e.getMessage() << std::endl;
+ delete m_newSegment;
+ m_newSegment = 0;
+ m_fid = -1;
+ failed = true;
+ } catch (AudioFileTimeStretcher::CancelledException e) {
+ std::cerr << "AudioSegmentRescaleCommand: ERROR: Rescale cancelled" << std::endl;
+ delete m_newSegment;
+ m_newSegment = 0;
+ m_fid = -1;
+ failed = true;
+ }
+ }
+
+ if (failed) return;
+
+ m_segment->getComposition()->addSegment(m_newSegment);
+ m_segment->getComposition()->detachSegment(m_segment);
+
+// m_newSegment->setEndMarkerTime
+// (startTime + rescale(m_segment->getEndMarkerTime() - startTime));
+
+ m_detached = true;
+}
+
+void
+AudioSegmentRescaleCommand::unexecute()
+{
+ if (m_newSegment) {
+ m_newSegment->getComposition()->addSegment(m_segment);
+ m_newSegment->getComposition()->detachSegment(m_newSegment);
+ m_detached = false;
+ }
+}
+
+}
diff --git a/src/commands/segment/AudioSegmentRescaleCommand.h b/src/commands/segment/AudioSegmentRescaleCommand.h
new file mode 100644
index 0000000..a4edb13
--- /dev/null
+++ b/src/commands/segment/AudioSegmentRescaleCommand.h
@@ -0,0 +1,81 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_AUDIOSEGMENTRESCALECOMMAND_H_
+#define _RG_AUDIOSEGMENTRESCALECOMMAND_H_
+
+#include <kcommand.h>
+#include <qstring.h>
+#include "base/Event.h"
+#include <klocale.h>
+
+namespace Rosegarden
+{
+
+class Segment;
+class AudioFileManager;
+class AudioFileTimeStretcher;
+class RosegardenGUIDoc;
+class ProgressDialog;
+
+class AudioSegmentRescaleCommand : public KNamedCommand
+{
+public:
+ AudioSegmentRescaleCommand(RosegardenGUIDoc *doc,
+ Segment *segment, float ratio);
+ AudioSegmentRescaleCommand(RosegardenGUIDoc *doc,
+ Segment *segment, float ratio,
+ timeT newStartTime,
+ timeT newEndMarkerTime);
+ virtual ~AudioSegmentRescaleCommand();
+
+ virtual void execute();
+ virtual void unexecute();
+
+ AudioFileTimeStretcher *getStretcher() { return m_stretcher; }
+ int getNewAudioFileId() const { return m_fid; }
+
+ void connectProgressDialog(ProgressDialog *dlg);
+ void disconnectProgressDialog(ProgressDialog *dlg);
+
+ static QString getGlobalName() { return i18n("Stretch or S&quash..."); }
+
+private:
+ AudioFileManager *m_afm;
+ AudioFileTimeStretcher *m_stretcher;
+ Segment *m_segment;
+ Segment *m_newSegment;
+ bool m_timesGiven;
+ timeT m_startTime;
+ timeT m_endMarkerTime;
+ int m_fid;
+ float m_ratio;
+ bool m_detached;
+};
+
+
+
+}
+
+#endif
diff --git a/src/commands/segment/AudioSegmentResizeFromStartCommand.cpp b/src/commands/segment/AudioSegmentResizeFromStartCommand.cpp
new file mode 100644
index 0000000..5045500
--- /dev/null
+++ b/src/commands/segment/AudioSegmentResizeFromStartCommand.cpp
@@ -0,0 +1,87 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "AudioSegmentResizeFromStartCommand.h"
+
+#include <klocale.h>
+#include "base/Composition.h"
+#include "base/RealTime.h"
+#include "base/Segment.h"
+
+
+namespace Rosegarden
+{
+
+AudioSegmentResizeFromStartCommand::AudioSegmentResizeFromStartCommand(Segment *segment,
+ timeT newStartTime) :
+ KNamedCommand(i18n("Resize Segment")),
+ m_segment(segment),
+ m_newSegment(0),
+ m_detached(false),
+ m_oldStartTime(segment->getStartTime()),
+ m_newStartTime(newStartTime)
+{}
+
+AudioSegmentResizeFromStartCommand::~AudioSegmentResizeFromStartCommand()
+{
+ if (!m_detached)
+ delete m_segment;
+ else
+ delete m_newSegment;
+}
+
+void
+AudioSegmentResizeFromStartCommand::execute()
+{
+ Composition *c = m_segment->getComposition();
+
+ if (!m_newSegment) {
+ RealTime oldRT = c->getElapsedRealTime(m_oldStartTime);
+ RealTime newRT = c->getElapsedRealTime(m_newStartTime);
+
+ m_newSegment = new Segment(*m_segment);
+ m_newSegment->setStartTime(m_newStartTime);
+ m_newSegment->setAudioStartTime(m_segment->getAudioStartTime() -
+ (oldRT - newRT));
+ }
+
+ c->addSegment(m_newSegment);
+ m_newSegment->setEndMarkerTime(m_segment->getEndMarkerTime());
+ c->detachSegment(m_segment);
+
+ m_detached = false;
+}
+
+void
+AudioSegmentResizeFromStartCommand::unexecute()
+{
+ Composition *c = m_newSegment->getComposition();
+ c->addSegment(m_segment);
+ c->detachSegment(m_newSegment);
+
+ m_detached = true;
+}
+
+}
diff --git a/src/commands/segment/AudioSegmentResizeFromStartCommand.h b/src/commands/segment/AudioSegmentResizeFromStartCommand.h
new file mode 100644
index 0000000..734a6e0
--- /dev/null
+++ b/src/commands/segment/AudioSegmentResizeFromStartCommand.h
@@ -0,0 +1,66 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_AUDIOSEGMENTRESIZEFROMSTARTCOMMAND_H_
+#define _RG_AUDIOSEGMENTRESIZEFROMSTARTCOMMAND_H_
+
+#include <kcommand.h>
+#include "base/Event.h"
+
+
+
+
+namespace Rosegarden
+{
+
+class Segment;
+
+
+/**
+ * As above, but for audio segments.
+ */
+class AudioSegmentResizeFromStartCommand : public KNamedCommand
+{
+public:
+ AudioSegmentResizeFromStartCommand(Segment *segment,
+ timeT newStartTime);
+ virtual ~AudioSegmentResizeFromStartCommand();
+
+ virtual void execute();
+ virtual void unexecute();
+
+private:
+ Segment *m_segment;
+ Segment *m_newSegment;
+ bool m_detached;
+ timeT m_oldStartTime;
+ timeT m_newStartTime;
+};
+
+
+
+}
+
+#endif
diff --git a/src/commands/segment/AudioSegmentSplitCommand.cpp b/src/commands/segment/AudioSegmentSplitCommand.cpp
new file mode 100644
index 0000000..f0c462e
--- /dev/null
+++ b/src/commands/segment/AudioSegmentSplitCommand.cpp
@@ -0,0 +1,155 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "AudioSegmentSplitCommand.h"
+
+#include <klocale.h>
+#include "misc/Debug.h"
+#include "misc/Strings.h"
+#include "base/RealTime.h"
+#include "base/Composition.h"
+#include "base/Segment.h"
+#include <qstring.h>
+
+
+namespace Rosegarden
+{
+
+AudioSegmentSplitCommand::AudioSegmentSplitCommand(Segment *segment,
+ timeT splitTime) :
+ KNamedCommand(i18n("Split Audio Segment")),
+ m_segment(segment),
+ m_newSegment(0),
+ m_splitTime(splitTime),
+ m_previousEndMarkerTime(0),
+ m_detached(false)
+{}
+
+AudioSegmentSplitCommand::~AudioSegmentSplitCommand()
+{
+ if (m_detached) {
+ delete m_newSegment;
+ }
+ delete m_previousEndMarkerTime;
+}
+
+void
+AudioSegmentSplitCommand::execute()
+{
+ if (!m_newSegment) {
+
+ m_newSegment = new Segment(Segment::Audio);
+
+ // Basics
+ //
+ m_newSegment->setAudioFileId(m_segment->getAudioFileId());
+ m_newSegment->setTrack(m_segment->getTrack());
+
+ // Get the RealTime split time
+ //
+ RealTime splitDiff =
+ m_segment->getComposition()->getRealTimeDifference(
+ m_segment->getStartTime(), m_splitTime);
+
+ // Set audio start and end
+ //
+ m_newSegment->setAudioStartTime
+ (m_segment->getAudioStartTime() + splitDiff);
+ m_newSegment->setAudioEndTime(m_segment->getAudioEndTime());
+
+ // Insert into composition before setting end time
+ //
+ m_segment->getComposition()->addSegment(m_newSegment);
+
+ // Set start and end times
+ //
+ m_newSegment->setStartTime(m_splitTime);
+ m_newSegment->setEndTime(m_segment->getEndTime());
+
+ // Set original end time
+ //
+ // m_previousEndAudioTime = m_segment->getAudioEndTime();
+ // m_segment->setAudioEndTime(m_newSegment->getAudioStartTime());
+
+ RG_DEBUG << "AudioSegmentSplitCommand::execute: Set end audio of left segment to " << m_newSegment->getAudioStartTime() << endl;
+
+
+ // Set labels
+ //
+ m_segmentLabel = m_segment->getLabel();
+ QString newLabel = strtoqstr(m_segmentLabel);
+ if (!newLabel.endsWith(i18n(" (split)"))) {
+ newLabel = i18n("%1 (split)").arg(newLabel);
+ }
+ m_segment->setLabel(qstrtostr(newLabel));
+ m_newSegment->setLabel(m_segment->getLabel());
+
+ // Set color
+ //
+ m_newSegment->setColourIndex(m_segment->getColourIndex());
+ }
+
+ // Resize left hand Segment
+ //
+ const timeT *emt = m_segment->getRawEndMarkerTime();
+ if (emt) {
+ m_previousEndMarkerTime = new timeT(*emt);
+ } else {
+ m_previousEndMarkerTime = 0;
+ }
+
+ RG_DEBUG << "AudioSegmentSplitCommand::execute: Setting end marker of left segment to " << m_splitTime << endl;
+
+ m_segment->setEndMarkerTime(m_splitTime);
+
+ if (!m_newSegment->getComposition()) {
+ m_segment->getComposition()->addSegment(m_newSegment);
+ }
+
+ m_detached = false;
+
+}
+
+void
+AudioSegmentSplitCommand::unexecute()
+{
+ if (m_previousEndMarkerTime) {
+ RG_DEBUG << "AudioSegmentSplitCommand::unexecute: Restoring end marker of left segment to " << *m_previousEndMarkerTime << endl;
+
+ m_segment->setEndMarkerTime(*m_previousEndMarkerTime);
+ delete m_previousEndMarkerTime;
+ m_previousEndMarkerTime = 0;
+ } else {
+ m_segment->clearEndMarker();
+ }
+
+ m_segment->setLabel(m_segmentLabel);
+ // RG_DEBUG << "AudioSegmentSplitCommand::unexecute: Setting audio end time of left segment to " << m_previousEndAudioTime << endl;
+ // m_segment->setAudioEndTime(m_previousEndAudioTime);
+ m_segment->getComposition()->detachSegment(m_newSegment);
+ m_detached = true;
+}
+
+}
diff --git a/src/commands/segment/AudioSegmentSplitCommand.h b/src/commands/segment/AudioSegmentSplitCommand.h
new file mode 100644
index 0000000..ce7c59c
--- /dev/null
+++ b/src/commands/segment/AudioSegmentSplitCommand.h
@@ -0,0 +1,65 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_AUDIOSEGMENTSPLITCOMMAND_H_
+#define _RG_AUDIOSEGMENTSPLITCOMMAND_H_
+
+#include <string>
+#include <kcommand.h>
+#include "base/Event.h"
+
+
+
+
+namespace Rosegarden
+{
+
+class Segment;
+
+
+class AudioSegmentSplitCommand : public KNamedCommand
+{
+public:
+ AudioSegmentSplitCommand(Segment *segment,
+ timeT splitTime);
+ virtual ~AudioSegmentSplitCommand();
+
+ virtual void execute();
+ virtual void unexecute();
+
+private:
+ Segment *m_segment;
+ Segment *m_newSegment;
+ timeT m_splitTime;
+ timeT *m_previousEndMarkerTime;
+ bool m_detached;
+ std::string m_segmentLabel;
+// RealTime m_previousEndAudioTime;
+};
+
+
+}
+
+#endif
diff --git a/src/commands/segment/ChangeCompositionLengthCommand.cpp b/src/commands/segment/ChangeCompositionLengthCommand.cpp
new file mode 100644
index 0000000..bdeb7a5
--- /dev/null
+++ b/src/commands/segment/ChangeCompositionLengthCommand.cpp
@@ -0,0 +1,64 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "ChangeCompositionLengthCommand.h"
+
+#include "base/Composition.h"
+#include <qstring.h>
+
+
+namespace Rosegarden
+{
+
+ChangeCompositionLengthCommand::ChangeCompositionLengthCommand(
+ Composition *composition,
+ timeT startTime,
+ timeT endTime):
+ KNamedCommand(getGlobalName()),
+ m_composition(composition),
+ m_startTime(startTime),
+ m_endTime(endTime),
+ m_oldStartTime(m_composition->getStartMarker()),
+ m_oldEndTime(m_composition->getEndMarker())
+{}
+
+ChangeCompositionLengthCommand::~ChangeCompositionLengthCommand()
+{}
+
+void
+ChangeCompositionLengthCommand::execute()
+{
+ m_composition->setStartMarker(m_startTime);
+ m_composition->setEndMarker(m_endTime);
+}
+
+void
+ChangeCompositionLengthCommand::unexecute()
+{
+ m_composition->setStartMarker(m_oldStartTime);
+ m_composition->setEndMarker(m_oldEndTime);
+}
+
+}
diff --git a/src/commands/segment/ChangeCompositionLengthCommand.h b/src/commands/segment/ChangeCompositionLengthCommand.h
new file mode 100644
index 0000000..9e0db9b
--- /dev/null
+++ b/src/commands/segment/ChangeCompositionLengthCommand.h
@@ -0,0 +1,70 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_CHANGECOMPOSITIONLENGTHCOMMAND_H_
+#define _RG_CHANGECOMPOSITIONLENGTHCOMMAND_H_
+
+#include <kcommand.h>
+#include <qstring.h>
+#include "base/Event.h"
+#include <klocale.h>
+
+
+class Change;
+
+
+namespace Rosegarden
+{
+
+class Composition;
+
+
+class ChangeCompositionLengthCommand : public KNamedCommand
+{
+public:
+ ChangeCompositionLengthCommand(Composition *composition,
+ timeT startTime,
+ timeT endTime);
+ virtual ~ChangeCompositionLengthCommand();
+
+ static QString getGlobalName()
+ { return i18n("Change &Composition Start and End..."); }
+
+ virtual void execute();
+ virtual void unexecute();
+
+protected:
+ Composition *m_composition;
+ timeT m_startTime;
+ timeT m_endTime;
+ timeT m_oldStartTime;
+ timeT m_oldEndTime;
+
+};
+
+
+}
+
+#endif
diff --git a/src/commands/segment/CreateTempoMapFromSegmentCommand.cpp b/src/commands/segment/CreateTempoMapFromSegmentCommand.cpp
new file mode 100644
index 0000000..e548875
--- /dev/null
+++ b/src/commands/segment/CreateTempoMapFromSegmentCommand.cpp
@@ -0,0 +1,166 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "CreateTempoMapFromSegmentCommand.h"
+
+#include <klocale.h>
+#include "misc/Debug.h"
+#include "base/Composition.h"
+#include "base/NotationTypes.h"
+#include "base/RealTime.h"
+#include "base/Segment.h"
+
+
+namespace Rosegarden
+{
+
+CreateTempoMapFromSegmentCommand::CreateTempoMapFromSegmentCommand(Segment *groove) :
+ KNamedCommand(i18n("Set Tempos from Beat Segment")),
+ m_composition(groove->getComposition())
+{
+ initialise(groove);
+}
+
+CreateTempoMapFromSegmentCommand::~CreateTempoMapFromSegmentCommand()
+{
+ // nothing
+}
+
+void
+CreateTempoMapFromSegmentCommand::execute()
+{
+ for (TempoMap::iterator i = m_oldTempi.begin(); i != m_oldTempi.end(); ++i) {
+ int n = m_composition->getTempoChangeNumberAt(i->first);
+ if (n < m_composition->getTempoChangeCount()) {
+ m_composition->removeTempoChange(n);
+ }
+ }
+
+ for (TempoMap::iterator i = m_newTempi.begin(); i != m_newTempi.end(); ++i) {
+ m_composition->addTempoAtTime(i->first, i->second);
+ }
+}
+
+void
+CreateTempoMapFromSegmentCommand::unexecute()
+{
+ for (TempoMap::iterator i = m_newTempi.begin(); i != m_newTempi.end(); ++i) {
+ int n = m_composition->getTempoChangeNumberAt(i->first);
+ if (n < m_composition->getTempoChangeCount()) {
+ m_composition->removeTempoChange(n);
+ }
+ }
+
+ for (TempoMap::iterator i = m_oldTempi.begin(); i != m_oldTempi.end(); ++i) {
+ m_composition->addTempoAtTime(i->first, i->second);
+ }
+}
+
+void
+CreateTempoMapFromSegmentCommand::initialise(Segment *s)
+{
+ m_oldTempi.clear();
+ m_newTempi.clear();
+
+ //!!! need an additional option: per-chord, per-beat, per-bar.
+ // Let's work per-beat for the moment. Even for this, we should
+ // probably use TimeSignature.getDivisions()
+
+ std::vector<timeT> beatTimeTs;
+ std::vector<RealTime> beatRealTimes;
+
+ int startBar = m_composition->getBarNumber(s->getStartTime());
+ int barNo = startBar;
+ int beat = 0;
+
+ for (Segment::iterator i = s->begin(); s->isBeforeEndMarker(i); ++i) {
+ if ((*i)->isa(Note::EventType)) {
+
+ bool isNew;
+ TimeSignature sig =
+ m_composition->getTimeSignatureInBar(barNo, isNew);
+
+ beatTimeTs.push_back(m_composition->getBarStart(barNo) +
+ beat * sig.getBeatDuration());
+
+ if (++beat >= sig.getBeatsPerBar()) {
+ ++barNo;
+ beat = 0;
+ }
+
+ beatRealTimes.push_back(s->getComposition()->getElapsedRealTime
+ ((*i)->getAbsoluteTime()));
+ }
+ }
+
+ if (beatTimeTs.size() < 2)
+ return ;
+
+ tempoT prevTempo = 0;
+
+ // set up m_oldTempi and prevTempo
+
+ for (int i = m_composition->getTempoChangeNumberAt(*beatTimeTs.begin() - 1) + 1;
+ i <= m_composition->getTempoChangeNumberAt(*beatTimeTs.end() - 1); ++i) {
+
+ std::pair<timeT, tempoT> tempoChange =
+ m_composition->getTempoChange(i);
+ m_oldTempi[tempoChange.first] = tempoChange.second;
+ if (prevTempo == 0)
+ prevTempo = tempoChange.second;
+ }
+
+ RG_DEBUG << "starting tempo: " << prevTempo << endl;
+
+ timeT quarter = Note(Note::Crotchet).getDuration();
+
+ for (int beat = 1; beat < beatTimeTs.size(); ++beat) {
+
+ timeT beatTime = beatTimeTs[beat] - beatTimeTs[beat - 1];
+ RealTime beatRealTime = beatRealTimes[beat] - beatRealTimes[beat - 1];
+
+ // Calculate tempo to nearest qpm.
+ // This is 60 / {quarter note duration in seconds}
+ // = 60 / ( {beat in seconds} * {quarter in ticks} / { beat in ticks} )
+ // = ( 60 * {beat in ticks} ) / ( {beat in seconds} * {quarter in ticks} )
+ // Precision is deliberately limited to qpm to avoid silly values.
+
+ double beatSec = double(beatRealTime.sec) +
+ double(beatRealTime.usec() / 1000000.0);
+ double qpm = (60.0 * beatTime) / (beatSec * quarter);
+ tempoT tempo = Composition::getTempoForQpm(int(qpm + 0.001));
+
+ RG_DEBUG << "prev beat: " << beatTimeTs[beat] << ", prev beat real time " << beatRealTimes[beat] << endl;
+ RG_DEBUG << "time " << beatTime << ", rt " << beatRealTime << ", beatSec " << beatSec << ", tempo " << tempo << endl;
+
+ if (tempo != prevTempo) {
+ m_newTempi[beatTimeTs[beat - 1]] = tempo;
+ prevTempo = tempo;
+ }
+ }
+
+}
+
+}
diff --git a/src/commands/segment/CreateTempoMapFromSegmentCommand.h b/src/commands/segment/CreateTempoMapFromSegmentCommand.h
new file mode 100644
index 0000000..f6ea4d5
--- /dev/null
+++ b/src/commands/segment/CreateTempoMapFromSegmentCommand.h
@@ -0,0 +1,69 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_CREATETEMPOMAPFROMSEGMENTCOMMAND_H_
+#define _RG_CREATETEMPOMAPFROMSEGMENTCOMMAND_H_
+
+#include <map>
+#include <kcommand.h>
+#include "base/Event.h"
+#include "base/Composition.h" // for tempoT
+
+
+
+
+namespace Rosegarden
+{
+
+
+/**
+ * CreateTempoMapFromSegment applies timings found in a reference
+ * segment to the composition as a whole via the tempo map.
+ */
+
+class CreateTempoMapFromSegmentCommand : public KNamedCommand
+{
+public:
+ CreateTempoMapFromSegmentCommand(Segment *grooveSegment);
+ virtual ~CreateTempoMapFromSegmentCommand();
+
+ virtual void execute();
+ virtual void unexecute();
+
+private:
+ void initialise(Segment *s);
+
+ Composition *m_composition;
+
+ typedef std::map<timeT, tempoT> TempoMap;
+ TempoMap m_oldTempi;
+ TempoMap m_newTempi;
+};
+
+
+
+}
+
+#endif
diff --git a/src/commands/segment/CutRangeCommand.cpp b/src/commands/segment/CutRangeCommand.cpp
new file mode 100644
index 0000000..df91398
--- /dev/null
+++ b/src/commands/segment/CutRangeCommand.cpp
@@ -0,0 +1,47 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "CutRangeCommand.h"
+
+#include <klocale.h>
+#include "base/Clipboard.h"
+#include "base/Composition.h"
+#include "commands/edit/CopyCommand.h"
+#include "DeleteRangeCommand.h"
+
+
+namespace Rosegarden
+{
+
+CutRangeCommand::CutRangeCommand(Composition *composition,
+ timeT t0, timeT t1,
+ Clipboard *clipboard) :
+ KMacroCommand(i18n("Cut Range"))
+{
+ addCommand(new CopyCommand(composition, t0, t1, clipboard));
+ addCommand(new DeleteRangeCommand(composition, t0, t1));
+}
+
+}
diff --git a/src/commands/segment/CutRangeCommand.h b/src/commands/segment/CutRangeCommand.h
new file mode 100644
index 0000000..f2b3402
--- /dev/null
+++ b/src/commands/segment/CutRangeCommand.h
@@ -0,0 +1,53 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_CUTRANGECOMMAND_H_
+#define _RG_CUTRANGECOMMAND_H_
+
+#include "base/Event.h"
+#include <kcommand.h>
+
+
+namespace Rosegarden
+{
+
+class Composition;
+class Clipboard;
+
+
+class CutRangeCommand : public KMacroCommand
+{
+public:
+ CutRangeCommand(Composition *composition,
+ timeT begin,
+ timeT end,
+ Clipboard *clipboard);
+};
+
+
+
+}
+
+#endif
diff --git a/src/commands/segment/DeleteRangeCommand.cpp b/src/commands/segment/DeleteRangeCommand.cpp
new file mode 100644
index 0000000..05ec79f
--- /dev/null
+++ b/src/commands/segment/DeleteRangeCommand.cpp
@@ -0,0 +1,127 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "DeleteRangeCommand.h"
+
+#include "AudioSegmentSplitCommand.h"
+#include "base/Composition.h"
+#include "base/Segment.h"
+#include "base/Selection.h"
+#include "EraseSegmentsStartingInRangeCommand.h"
+#include "OpenOrCloseRangeCommand.h"
+#include "SegmentJoinCommand.h"
+#include "SegmentSplitCommand.h"
+
+
+namespace Rosegarden
+{
+
+DeleteRangeCommand::DeleteRangeCommand(Composition *composition,
+ timeT t0, timeT t1) :
+ KMacroCommand(i18n("Delete Range"))
+{
+ // First add commands to split the segments up. Make a note of
+ // segments that will need rejoining with their neighbours
+ // afterwards.
+
+ std::vector<Segment *> rejoins;
+
+ for (int e = 0; e < 2; ++e) {
+
+ // Split all segments at the range end first, then the range
+ // begin afterwards. This is because the split commands create
+ // new segments for the right part and leave the left parts in
+ // the original segments, so that we can use the same segment
+ // pointer to do the left split as we did for the right
+
+ timeT t = t1;
+ if (e == 1)
+ t = t0;
+
+ for (Composition::iterator i = composition->begin();
+ i != composition->end(); ++i) {
+
+ if ((*i)->getStartTime() >= t || (*i)->getEndMarkerTime() <= t) {
+ continue;
+ }
+
+ if ((*i)->getType() == Segment::Audio) {
+ addCommand(new AudioSegmentSplitCommand(*i, t));
+ } else {
+ addCommand(new SegmentSplitCommand(*i, t));
+
+ if (t == t0 && (*i)->getEndMarkerTime() > t1) {
+ rejoins.push_back(*i);
+ }
+ }
+ }
+ }
+
+ // Then commands to do the rest of the work
+
+ addCommand(new EraseSegmentsStartingInRangeCommand(composition, t0, t1));
+
+ addCommand(new OpenOrCloseRangeCommand(composition, t0, t1, false));
+
+ for (std::vector<Segment *>::iterator i = rejoins.begin();
+ i != rejoins.end(); ++i) {
+ addCommand(new RejoinCommand(composition, *i,
+ (*i)->getEndMarkerTime() + t0 - t1));
+ }
+}
+
+DeleteRangeCommand::~DeleteRangeCommand()
+{}
+
+void
+DeleteRangeCommand::RejoinCommand::execute()
+{
+ if (m_joinCommand) {
+ m_joinCommand->execute();
+ return ;
+ }
+
+ //!!! Need to remove the "(split)" names from the segment bits
+
+ for (Composition::iterator i = m_composition->begin();
+ i != m_composition->end(); ++i) {
+ if ((*i) == m_segment)
+ continue;
+ if ((*i)->getTrack() != m_segment->getTrack())
+ continue;
+ if ((*i)->getEndMarkerTime() != m_endMarkerTime)
+ continue;
+ if ((*i)->getStartTime() <= m_segment->getStartTime())
+ continue;
+ SegmentSelection selection;
+ selection.insert(m_segment);
+ selection.insert(*i);
+ m_joinCommand = new SegmentJoinCommand(selection);
+ m_joinCommand->execute();
+ break;
+ }
+}
+
+}
diff --git a/src/commands/segment/DeleteRangeCommand.h b/src/commands/segment/DeleteRangeCommand.h
new file mode 100644
index 0000000..6b198ea
--- /dev/null
+++ b/src/commands/segment/DeleteRangeCommand.h
@@ -0,0 +1,84 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_DELETERANGECOMMAND_H_
+#define _RG_DELETERANGECOMMAND_H_
+
+#include <kcommand.h>
+#include "base/Event.h"
+#include <klocale.h>
+
+#include "SegmentJoinCommand.h"
+
+
+namespace Rosegarden
+{
+
+class Segment;
+class Composition;
+
+
+class DeleteRangeCommand : public KMacroCommand
+{
+public:
+ DeleteRangeCommand(Composition *composition,
+ timeT begin,
+ timeT end);
+ virtual ~DeleteRangeCommand();
+
+private:
+ class RejoinCommand : public KNamedCommand
+ {
+ public:
+ // This command rejoins s on to a subsequent segment on the same
+ // track that ends at endMarkerTime (presumably the original end
+ // marker time of s, with the range duration subtracted).
+
+ RejoinCommand(Composition *c,
+ Segment *s,
+ timeT endMarkerTime) :
+ KNamedCommand(i18n("Rejoin Command")),
+ m_composition(c), m_segment(s), m_endMarkerTime(endMarkerTime),
+ m_joinCommand(0) { }
+
+ ~RejoinCommand() { delete m_joinCommand; }
+
+ void execute();
+ void unexecute() { if (m_joinCommand) m_joinCommand->unexecute(); }
+
+ private:
+ Composition *m_composition;
+ Segment *m_segment;
+ timeT m_endMarkerTime;
+
+ SegmentJoinCommand *m_joinCommand;
+ };
+};
+
+
+
+}
+
+#endif
diff --git a/src/commands/segment/DeleteTracksCommand.cpp b/src/commands/segment/DeleteTracksCommand.cpp
new file mode 100644
index 0000000..bad2be0
--- /dev/null
+++ b/src/commands/segment/DeleteTracksCommand.cpp
@@ -0,0 +1,161 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "DeleteTracksCommand.h"
+
+#include "misc/Debug.h"
+#include "base/Composition.h"
+#include "base/Segment.h"
+#include <qstring.h>
+
+
+namespace Rosegarden
+{
+
+DeleteTracksCommand::DeleteTracksCommand(Composition *composition,
+ std::vector<TrackId> tracks):
+ KNamedCommand(getGlobalName()),
+ m_composition(composition),
+ m_tracks(tracks),
+ m_detached(false)
+{}
+
+DeleteTracksCommand::~DeleteTracksCommand()
+{
+ if (m_detached) {
+ for (unsigned int i = 0; i < m_oldTracks.size(); ++i)
+ delete m_oldTracks[i];
+
+ for (unsigned int i = 0; i < m_oldSegments.size(); ++i)
+ delete m_oldSegments[i];
+
+ m_oldTracks.clear();
+ m_oldSegments.clear();
+ }
+}
+
+void DeleteTracksCommand::execute()
+{
+ Track *track = 0;
+ const Composition::segmentcontainer &segments =
+ m_composition->getSegments();
+
+ //cout << "DeleteTracksCommand::execute()" << endl;
+
+ m_oldSegments.clear();
+ m_oldTracks.clear();
+
+ // Remap positions and track numbers
+ //
+
+ Composition::trackiterator tit;
+ Composition::trackcontainer
+ &tracks = m_composition->getTracks();
+
+ for (unsigned int i = 0; i < m_tracks.size(); ++i) {
+ // detach segments and store tracks somewhere
+ track = m_composition->getTrackById(m_tracks[i]);
+
+ if (track) {
+ // detach all segments for that track
+ //
+ for (Composition::segmentcontainer::const_iterator
+ it = segments.begin();
+ it != segments.end(); ++it) {
+ if ((*it)->getTrack() == m_tracks[i]) {
+ m_oldSegments.push_back(*it);
+ m_composition->detachSegment(*it);
+ }
+ }
+
+ // store old tracks
+ m_oldTracks.push_back(track);
+ if (m_composition->detachTrack(track) == false) {
+ RG_DEBUG << "DeleteTracksCommand::execute - can't detach track" << endl;
+ }
+ }
+ }
+
+ std::vector<Track*>::iterator otIt;
+ for (otIt = m_oldTracks.begin(); otIt != m_oldTracks.end(); ++otIt) {
+ for (tit = tracks.begin(); tit != tracks.end(); ++tit) {
+ if ((*tit).second->getPosition() > (*otIt)->getPosition()) {
+ // If the track we've removed was after the current
+ // track then decrement the track position.
+ //
+ int newPosition = (*tit).second->getPosition() - 1;
+
+ (*tit).second->setPosition(newPosition);
+
+ }
+ }
+ }
+
+ m_detached = true;
+}
+
+void DeleteTracksCommand::unexecute()
+{
+ // Add the tracks and the segments back in
+ //
+
+ // Remap positions and track numbers
+ //
+ Composition::trackcontainer
+ &tracks = m_composition->getTracks();
+ Composition::trackiterator tit;
+
+ std::vector<Track*>::iterator otIt;
+ for (otIt = m_oldTracks.begin(); otIt != m_oldTracks.end(); ++otIt) {
+ // From the back we shuffle out the tracks to allow the new
+ // (old) track some space to come back in.
+ //
+ tit = tracks.end();
+ while (true) {
+ --tit;
+
+ if ((*tit).second->getPosition() >= (*otIt)->getPosition()) {
+ // If the track we're adding has position after the
+ // current track then increment position.
+ //
+ int newPosition = (*tit).second->getPosition() + 1;
+
+ (*tit).second->setPosition(newPosition);
+ }
+
+ if (tit == tracks.begin())
+ break;
+ }
+
+ m_composition->addTrack(*otIt);
+ }
+
+ for (unsigned int i = 0; i < m_oldSegments.size(); ++i)
+ m_composition->addSegment(m_oldSegments[i]);
+
+ m_detached = false;
+}
+
+}
diff --git a/src/commands/segment/DeleteTracksCommand.h b/src/commands/segment/DeleteTracksCommand.h
new file mode 100644
index 0000000..d1d2332
--- /dev/null
+++ b/src/commands/segment/DeleteTracksCommand.h
@@ -0,0 +1,68 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_DELETETRACKSCOMMAND_H_
+#define _RG_DELETETRACKSCOMMAND_H_
+
+#include <kcommand.h>
+#include <qstring.h>
+#include <vector>
+#include <klocale.h>
+#include "base/Track.h"
+
+
+namespace Rosegarden
+{
+
+class Track;
+class Segment;
+class Composition;
+
+
+class DeleteTracksCommand : public KNamedCommand
+{
+public:
+ DeleteTracksCommand(Composition *composition,
+ std::vector<TrackId> tracks);
+ virtual ~DeleteTracksCommand();
+
+ static QString getGlobalName() { return i18n("Delete Tracks..."); }
+
+ virtual void execute();
+ virtual void unexecute();
+
+protected:
+ Composition *m_composition;
+ std::vector<TrackId> m_tracks;
+
+ std::vector<Track*> m_oldTracks;
+ std::vector<Segment*> m_oldSegments;
+ bool m_detached;
+};
+
+
+}
+
+#endif
diff --git a/src/commands/segment/DeleteTriggerSegmentCommand.cpp b/src/commands/segment/DeleteTriggerSegmentCommand.cpp
new file mode 100644
index 0000000..3ddb4af
--- /dev/null
+++ b/src/commands/segment/DeleteTriggerSegmentCommand.cpp
@@ -0,0 +1,78 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "DeleteTriggerSegmentCommand.h"
+
+#include <klocale.h>
+#include "base/Composition.h"
+#include "base/Segment.h"
+#include "base/TriggerSegment.h"
+#include "document/RosegardenGUIDoc.h"
+
+
+namespace Rosegarden
+{
+
+DeleteTriggerSegmentCommand::DeleteTriggerSegmentCommand(RosegardenGUIDoc *doc,
+ TriggerSegmentId id) :
+ KNamedCommand(i18n("Delete Triggered Segment")),
+ m_composition(&doc->getComposition()),
+ m_id(id),
+ m_segment(0),
+ m_basePitch( -1),
+ m_baseVelocity( -1),
+ m_detached(true)
+{
+ // nothing else
+}
+
+DeleteTriggerSegmentCommand::~DeleteTriggerSegmentCommand()
+{
+ if (m_detached)
+ delete m_segment;
+}
+
+void
+DeleteTriggerSegmentCommand::execute()
+{
+ TriggerSegmentRec *rec = m_composition->getTriggerSegmentRec(m_id);
+ if (!rec)
+ return ;
+ m_segment = rec->getSegment();
+ m_basePitch = rec->getBasePitch();
+ m_baseVelocity = rec->getBaseVelocity();
+ m_composition->detachTriggerSegment(m_id);
+ m_detached = true;
+}
+
+void
+DeleteTriggerSegmentCommand::unexecute()
+{
+ if (m_segment)
+ m_composition->addTriggerSegment(m_segment, m_id, m_basePitch, m_baseVelocity);
+ m_detached = false;
+}
+
+}
diff --git a/src/commands/segment/DeleteTriggerSegmentCommand.h b/src/commands/segment/DeleteTriggerSegmentCommand.h
new file mode 100644
index 0000000..30986f7
--- /dev/null
+++ b/src/commands/segment/DeleteTriggerSegmentCommand.h
@@ -0,0 +1,66 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_DELETETRIGGERSEGMENTCOMMAND_H_
+#define _RG_DELETETRIGGERSEGMENTCOMMAND_H_
+
+#include "base/TriggerSegment.h"
+#include <kcommand.h>
+
+
+
+
+namespace Rosegarden
+{
+
+class Segment;
+class RosegardenGUIDoc;
+class Composition;
+
+
+class DeleteTriggerSegmentCommand : public KNamedCommand
+{
+public:
+ DeleteTriggerSegmentCommand(RosegardenGUIDoc *doc,
+ TriggerSegmentId);
+ virtual ~DeleteTriggerSegmentCommand();
+
+ virtual void execute();
+ virtual void unexecute();
+
+private:
+ Composition *m_composition;
+ TriggerSegmentId m_id;
+ Segment *m_segment;
+ int m_basePitch;
+ int m_baseVelocity;
+ bool m_detached;
+};
+
+
+
+}
+
+#endif
diff --git a/src/commands/segment/EraseSegmentsStartingInRangeCommand.cpp b/src/commands/segment/EraseSegmentsStartingInRangeCommand.cpp
new file mode 100644
index 0000000..35f7f10
--- /dev/null
+++ b/src/commands/segment/EraseSegmentsStartingInRangeCommand.cpp
@@ -0,0 +1,99 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "EraseSegmentsStartingInRangeCommand.h"
+
+#include <klocale.h>
+#include "base/Composition.h"
+#include "base/Segment.h"
+
+
+namespace Rosegarden
+{
+
+EraseSegmentsStartingInRangeCommand::EraseSegmentsStartingInRangeCommand(
+ Composition *composition,
+ timeT t0, timeT t1) :
+ KNamedCommand(i18n("Delete Range")),
+ m_composition(composition),
+ m_beginTime(t0),
+ m_endTime(t1),
+ m_detached(false)
+{}
+
+EraseSegmentsStartingInRangeCommand::~EraseSegmentsStartingInRangeCommand()
+{
+ if (m_detached) {
+ for (std::vector<Segment *>::iterator i = m_detaching.begin();
+ i != m_detaching.end(); ++i) {
+ delete *i;
+ }
+ }
+}
+
+void
+EraseSegmentsStartingInRangeCommand::execute()
+{
+ if (m_detaching.empty()) {
+
+ for (Composition::iterator i = m_composition->begin();
+ i != m_composition->end(); ++i) {
+
+ if ((*i)->getStartTime() >= m_beginTime &&
+ (*i)->getStartTime() < m_endTime) {
+ m_detaching.push_back(*i);
+ }
+ }
+ }
+
+ for (std::vector<Segment *>::iterator i = m_detaching.begin();
+ i != m_detaching.end(); ++i) {
+ m_composition->detachSegment(*i);
+ }
+
+ m_detached = true;
+}
+
+void
+EraseSegmentsStartingInRangeCommand::unexecute()
+{
+ for (std::vector<Segment *>::iterator i = m_detaching.begin();
+ i != m_detaching.end(); ++i) {
+
+ m_composition->addSegment(*i);
+
+ //!!! see horrible code in SegmentEraseCommand::unexecute()
+ // to restore the audio file ID association in audio file mgr
+ // when an audio segment is restored. Why is this necessary?
+ // What is the agency that removed the audio file association
+ // in the first place, and why? Need to investigate that
+ // before heedlessly duplicating the same horrors here.
+
+ }
+
+ m_detached = false;
+}
+
+}
diff --git a/src/commands/segment/EraseSegmentsStartingInRangeCommand.h b/src/commands/segment/EraseSegmentsStartingInRangeCommand.h
new file mode 100644
index 0000000..70b6978
--- /dev/null
+++ b/src/commands/segment/EraseSegmentsStartingInRangeCommand.h
@@ -0,0 +1,67 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_ERASESEGMENTSSTARTINGINRANGECOMMAND_H_
+#define _RG_ERASESEGMENTSSTARTINGINRANGECOMMAND_H_
+
+#include <kcommand.h>
+#include <vector>
+#include "base/Event.h"
+#include "gui/application/RosegardenDCOP.h"
+
+
+
+
+namespace Rosegarden
+{
+
+class Segment;
+class Composition;
+
+
+class EraseSegmentsStartingInRangeCommand : public KNamedCommand
+{
+public:
+ EraseSegmentsStartingInRangeCommand(Composition *composition,
+ timeT begin,
+ timeT end);
+ virtual ~EraseSegmentsStartingInRangeCommand();
+
+ virtual void execute();
+ virtual void unexecute();
+
+private:
+ Composition *m_composition;
+ timeT m_beginTime;
+ timeT m_endTime;
+
+ bool m_detached;
+ std::vector<Segment *> m_detaching;
+};
+
+
+}
+
+#endif
diff --git a/src/commands/segment/InsertRangeCommand.cpp b/src/commands/segment/InsertRangeCommand.cpp
new file mode 100644
index 0000000..73dc5fd
--- /dev/null
+++ b/src/commands/segment/InsertRangeCommand.cpp
@@ -0,0 +1,63 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "InsertRangeCommand.h"
+
+#include <klocale.h>
+#include "AudioSegmentSplitCommand.h"
+#include "base/Clipboard.h"
+#include "base/Composition.h"
+#include "base/Segment.h"
+#include "OpenOrCloseRangeCommand.h"
+#include "SegmentSplitCommand.h"
+
+
+namespace Rosegarden
+{
+
+InsertRangeCommand::InsertRangeCommand(Composition *composition,
+ timeT t0, timeT duration) :
+ KMacroCommand(i18n("Insert Range"))
+{
+ // Need to split segments before opening, at t0
+
+ for (Composition::iterator i = composition->begin();
+ i != composition->end(); ++i) {
+
+ if ((*i)->getStartTime() >= t0 || (*i)->getEndMarkerTime() <= t0) {
+ continue;
+ }
+
+ if ((*i)->getType() == Segment::Audio) {
+ addCommand(new AudioSegmentSplitCommand(*i, t0));
+ } else {
+ addCommand(new SegmentSplitCommand(*i, t0));
+ }
+ }
+
+ addCommand(new OpenOrCloseRangeCommand(composition, t0, t0 + duration, true));
+}
+
+}
diff --git a/src/commands/segment/InsertRangeCommand.h b/src/commands/segment/InsertRangeCommand.h
new file mode 100644
index 0000000..e3960c8
--- /dev/null
+++ b/src/commands/segment/InsertRangeCommand.h
@@ -0,0 +1,47 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_INSERTRANGECOMMAND_H_
+#define _RG_INSERTRANGECOMMAND_H_
+
+#include "base/Event.h"
+#include <kcommand.h>
+
+namespace Rosegarden
+{
+
+class Composition;
+
+class InsertRangeCommand : public KMacroCommand
+{
+public:
+ InsertRangeCommand(Composition *composition,
+ timeT startTime, timeT duration);
+};
+
+
+}
+
+#endif
diff --git a/src/commands/segment/ModifyDefaultTempoCommand.cpp b/src/commands/segment/ModifyDefaultTempoCommand.cpp
new file mode 100644
index 0000000..88360a4
--- /dev/null
+++ b/src/commands/segment/ModifyDefaultTempoCommand.cpp
@@ -0,0 +1,48 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "ModifyDefaultTempoCommand.h"
+
+#include "base/Composition.h"
+#include <qstring.h>
+
+
+namespace Rosegarden
+{
+
+void
+ModifyDefaultTempoCommand::execute()
+{
+ m_oldTempo = m_composition->getCompositionDefaultTempo();
+ m_composition->setCompositionDefaultTempo(m_tempo);
+}
+
+void
+ModifyDefaultTempoCommand::unexecute()
+{
+ m_composition->setCompositionDefaultTempo(m_oldTempo);
+}
+
+}
diff --git a/src/commands/segment/ModifyDefaultTempoCommand.h b/src/commands/segment/ModifyDefaultTempoCommand.h
new file mode 100644
index 0000000..50f736d
--- /dev/null
+++ b/src/commands/segment/ModifyDefaultTempoCommand.h
@@ -0,0 +1,66 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_MODIFYDEFAULTTEMPOCOMMAND_H_
+#define _RG_MODIFYDEFAULTTEMPOCOMMAND_H_
+
+#include <kcommand.h>
+#include <qstring.h>
+#include <klocale.h>
+#include "base/Composition.h" // for tempoT
+
+
+
+namespace Rosegarden
+{
+
+
+class ModifyDefaultTempoCommand : public KNamedCommand
+{
+public:
+ ModifyDefaultTempoCommand(Composition *composition,
+ tempoT tempo):
+ KNamedCommand(getGlobalName()),
+ m_composition(composition),
+ m_tempo(tempo) {}
+
+ virtual ~ModifyDefaultTempoCommand() {}
+
+ static QString getGlobalName() { return i18n("Modify &Default Tempo..."); }
+
+ virtual void execute();
+ virtual void unexecute();
+
+private:
+ Composition *m_composition;
+ tempoT m_tempo;
+ tempoT m_oldTempo;
+};
+
+
+
+}
+
+#endif
diff --git a/src/commands/segment/MoveTracksCommand.cpp b/src/commands/segment/MoveTracksCommand.cpp
new file mode 100644
index 0000000..49c089b
--- /dev/null
+++ b/src/commands/segment/MoveTracksCommand.cpp
@@ -0,0 +1,76 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "MoveTracksCommand.h"
+
+#include "base/Composition.h"
+#include "base/Track.h"
+#include <qstring.h>
+
+
+namespace Rosegarden
+{
+
+MoveTracksCommand::MoveTracksCommand(Composition *composition,
+ TrackId srcTrack,
+ TrackId destTrack):
+ KNamedCommand(getGlobalName()),
+ m_composition(composition),
+ m_srcTrack(srcTrack),
+ m_destTrack(destTrack)
+{}
+
+MoveTracksCommand::~MoveTracksCommand()
+{}
+
+void
+MoveTracksCommand::execute()
+{
+ Track *srcTrack = m_composition->getTrackById(m_srcTrack);
+ Track *destTrack = m_composition->getTrackById(m_destTrack);
+
+ int srcPosition = srcTrack->getPosition();
+
+ srcTrack->setPosition(destTrack->getPosition());
+ destTrack->setPosition(srcPosition);
+
+ m_composition->updateRefreshStatuses();
+}
+
+void
+MoveTracksCommand::unexecute()
+{
+ Track *srcTrack = m_composition->getTrackById(m_srcTrack);
+ Track *destTrack = m_composition->getTrackById(m_destTrack);
+
+ int srcPosition = srcTrack->getPosition();
+
+ srcTrack->setPosition(destTrack->getPosition());
+ destTrack->setPosition(srcPosition);
+
+ m_composition->updateRefreshStatuses();
+}
+
+}
diff --git a/src/commands/segment/MoveTracksCommand.h b/src/commands/segment/MoveTracksCommand.h
new file mode 100644
index 0000000..e35af5e
--- /dev/null
+++ b/src/commands/segment/MoveTracksCommand.h
@@ -0,0 +1,66 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_MOVETRACKSCOMMAND_H_
+#define _RG_MOVETRACKSCOMMAND_H_
+
+#include "base/Track.h"
+#include <kcommand.h>
+#include <qstring.h>
+#include <klocale.h>
+
+
+
+
+namespace Rosegarden
+{
+
+class Composition;
+
+
+class MoveTracksCommand : public KNamedCommand
+{
+public:
+ MoveTracksCommand(Composition *composition,
+ TrackId srcTrack,
+ TrackId destTrack);
+ virtual ~MoveTracksCommand();
+
+ static QString getGlobalName() { return i18n("Move Tracks..."); }
+
+ virtual void execute();
+ virtual void unexecute();
+
+protected:
+ Composition *m_composition;
+
+ TrackId m_srcTrack;
+ TrackId m_destTrack;
+};
+
+
+}
+
+#endif
diff --git a/src/commands/segment/OpenOrCloseRangeCommand.cpp b/src/commands/segment/OpenOrCloseRangeCommand.cpp
new file mode 100644
index 0000000..ad1db2c
--- /dev/null
+++ b/src/commands/segment/OpenOrCloseRangeCommand.cpp
@@ -0,0 +1,181 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "OpenOrCloseRangeCommand.h"
+
+#include <klocale.h>
+#include "misc/Debug.h"
+#include "base/Composition.h"
+#include "base/NotationTypes.h"
+#include "base/Segment.h"
+#include "base/Selection.h"
+
+
+namespace Rosegarden
+{
+
+OpenOrCloseRangeCommand::OpenOrCloseRangeCommand(Composition *composition,
+ timeT rangeBegin,
+ timeT rangeEnd,
+ bool open) :
+ KNamedCommand(i18n("Open or Close Range")),
+ m_composition(composition),
+ m_beginTime(rangeBegin),
+ m_endTime(rangeEnd),
+ m_prepared(false),
+ m_opening(open)
+{}
+
+OpenOrCloseRangeCommand::~OpenOrCloseRangeCommand()
+{}
+
+void
+OpenOrCloseRangeCommand::execute()
+{
+ timeT offset = m_endTime - m_beginTime;
+ if (!m_opening)
+ offset = -offset;
+
+ if (m_opening) {
+ if (offset + m_composition->getDuration() >
+ m_composition->getEndMarker()) {
+ m_composition->setEndMarker
+ (m_composition->getBarEndForTime
+ (m_composition->getDuration() + offset));
+ }
+ }
+
+ if (!m_prepared) {
+
+ timeT movingFrom = m_beginTime;
+ if (!m_opening)
+ movingFrom = m_endTime;
+
+ for (Composition::iterator i = m_composition->begin();
+ i != m_composition->end(); ++i) {
+
+ if ((*i)->getStartTime() >= movingFrom) {
+ m_moving.push_back(*i);
+ }
+ }
+
+ m_timesigsPre = TimeSignatureSelection
+ (*m_composition, movingFrom,
+ m_composition->getEndMarker(),
+ false);
+
+ m_temposPre = TempoSelection
+ (*m_composition, movingFrom,
+ m_composition->getEndMarker(),
+ false);
+
+ for (TimeSignatureSelection::timesigcontainer::const_iterator i =
+ m_timesigsPre.begin(); i != m_timesigsPre.end(); ++i) {
+
+ timeT t = i->first;
+ TimeSignature sig = i->second;
+ m_timesigsPost.addTimeSignature(t + offset, sig);
+ }
+
+ for (TempoSelection::tempocontainer::const_iterator i =
+ m_temposPre.begin(); i != m_temposPre.end(); ++i) {
+
+ timeT t = i->first;
+ TempoSelection::tempochange change = i->second;
+ m_temposPost.addTempo(t + offset, change.first, change.second);
+ }
+
+ m_prepared = true;
+ }
+
+ for (std::vector<Segment *>::iterator i = m_moving.begin();
+ i != m_moving.end(); ++i) {
+ // RG_DEBUG << "Moving segment on track " << (*i)->getTrack() << " from " << (*i)->getStartTime() << " to " << ((*i)->getStartTime() + offset) << " (current end time is " << (*i)->getEndTime() << ", end marker is " << (*i)->getEndMarkerTime() << ")" << endl;
+ (*i)->setStartTime((*i)->getStartTime() + offset);
+ }
+
+ for (TimeSignatureSelection::timesigcontainer::const_iterator i =
+ m_timesigsPre.begin(); i != m_timesigsPre.end(); ++i) {
+ int n = m_composition->getTimeSignatureNumberAt(i->first);
+ if (n >= 0)
+ m_composition->removeTimeSignature(n);
+ }
+
+ for (TimeSignatureSelection::timesigcontainer::const_iterator i =
+ m_timesigsPost.begin(); i != m_timesigsPost.end(); ++i) {
+ m_composition->addTimeSignature(i->first, i->second);
+ }
+
+ for (TempoSelection::tempocontainer::const_iterator i =
+ m_temposPre.begin(); i != m_temposPre.end(); ++i) {
+ int n = m_composition->getTempoChangeNumberAt(i->first);
+ if (n >= 0)
+ m_composition->removeTempoChange(n);
+ }
+
+ for (TempoSelection::tempocontainer::const_iterator i =
+ m_temposPost.begin(); i != m_temposPost.end(); ++i) {
+ m_composition->addTempoAtTime(i->first, i->second.first, i->second.second);
+ }
+}
+
+void
+OpenOrCloseRangeCommand::unexecute()
+{
+ timeT offset = m_beginTime - m_endTime;
+ if (!m_opening)
+ offset = -offset;
+
+ for (std::vector<Segment *>::iterator i = m_moving.begin();
+ i != m_moving.end(); ++i) {
+ (*i)->setStartTime((*i)->getStartTime() + offset);
+ }
+
+ for (TimeSignatureSelection::timesigcontainer::const_iterator i =
+ m_timesigsPost.begin(); i != m_timesigsPost.end(); ++i) {
+ int n = m_composition->getTimeSignatureNumberAt(i->first);
+ if (n >= 0)
+ m_composition->removeTimeSignature(n);
+ }
+
+ for (TimeSignatureSelection::timesigcontainer::const_iterator i =
+ m_timesigsPre.begin(); i != m_timesigsPre.end(); ++i) {
+ m_composition->addTimeSignature(i->first, i->second);
+ }
+
+ for (TempoSelection::tempocontainer::const_iterator i =
+ m_temposPost.begin(); i != m_temposPost.end(); ++i) {
+ int n = m_composition->getTempoChangeNumberAt(i->first);
+ if (n >= 0)
+ m_composition->removeTempoChange(n);
+ }
+
+ for (TempoSelection::tempocontainer::const_iterator i =
+ m_temposPre.begin(); i != m_temposPre.end(); ++i) {
+ m_composition->addTempoAtTime(i->first, i->second.first, i->second.second);
+ }
+}
+
+}
diff --git a/src/commands/segment/OpenOrCloseRangeCommand.h b/src/commands/segment/OpenOrCloseRangeCommand.h
new file mode 100644
index 0000000..6cb0f16
--- /dev/null
+++ b/src/commands/segment/OpenOrCloseRangeCommand.h
@@ -0,0 +1,84 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_OPENORCLOSERANGECOMMAND_H_
+#define _RG_OPENORCLOSERANGECOMMAND_H_
+
+#include "base/Selection.h"
+#include <kcommand.h>
+#include <vector>
+#include "base/Event.h"
+
+
+
+
+namespace Rosegarden
+{
+
+class Segment;
+class Composition;
+
+
+/**
+ * Pull all segments, time sigs, tempos etc starting after the end of
+ * a given range back by the duration of that range, so as to fill in
+ * the (presumably empty) range itself.
+ *
+ * This does not actually split any segments etc, it just moves them.
+ */
+class OpenOrCloseRangeCommand : public KNamedCommand
+{
+public:
+ OpenOrCloseRangeCommand(Composition *composition,
+ timeT rangeBegin,
+ timeT rangeEnd,
+ bool open);
+ virtual ~OpenOrCloseRangeCommand();
+
+ virtual void execute();
+ virtual void unexecute();
+
+private:
+ Composition *m_composition;
+ timeT m_beginTime;
+ timeT m_endTime;
+
+ bool m_prepared;
+ bool m_opening;
+
+ std::vector<Segment *> m_moving;
+
+ TimeSignatureSelection m_timesigsPre;
+ TimeSignatureSelection m_timesigsPost;
+
+ TempoSelection m_temposPre;
+ TempoSelection m_temposPost;
+};
+
+
+
+}
+
+#endif
diff --git a/src/commands/segment/PasteConductorDataCommand.cpp b/src/commands/segment/PasteConductorDataCommand.cpp
new file mode 100644
index 0000000..6db082f
--- /dev/null
+++ b/src/commands/segment/PasteConductorDataCommand.cpp
@@ -0,0 +1,128 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "PasteConductorDataCommand.h"
+
+#include <klocale.h>
+#include "base/Clipboard.h"
+#include "base/Composition.h"
+#include "base/NotationTypes.h"
+#include "base/Selection.h"
+
+
+namespace Rosegarden
+{
+
+PasteConductorDataCommand::PasteConductorDataCommand(Composition *composition,
+ Clipboard *clipboard,
+ timeT t) :
+ KNamedCommand(i18n("Paste Tempos and Time Signatures")),
+ m_composition(composition),
+ m_clipboard(new Clipboard(*clipboard)),
+ m_t0(t)
+{}
+
+PasteConductorDataCommand::~PasteConductorDataCommand()
+{
+ delete m_clipboard;
+}
+
+void
+PasteConductorDataCommand::execute()
+{
+ //!!! current implementation of execute and unexecute require
+ // that the target area of the composition be empty of tempo and
+ // timesig data before the command is executed
+
+ if (m_clipboard->hasTimeSignatureSelection()) {
+
+ for (TimeSignatureSelection::timesigcontainer::const_iterator i =
+ m_clipboard->getTimeSignatureSelection().begin();
+ i != m_clipboard->getTimeSignatureSelection().end(); ++i) {
+
+ timeT t = i->first;
+ t = t - m_clipboard->getBaseTime() + m_t0;
+ TimeSignature sig = i->second;
+
+ if (i == m_clipboard->getTimeSignatureSelection().begin() &&
+ m_composition->getTimeSignatureAt(t) == sig)
+ continue;
+
+ m_composition->addTimeSignature(t, sig);
+ }
+ }
+
+ if (m_clipboard->hasTempoSelection()) {
+
+ for (TempoSelection::tempocontainer::const_iterator i =
+ m_clipboard->getTempoSelection().begin();
+ i != m_clipboard->getTempoSelection().end(); ++i) {
+
+ timeT t = i->first;
+ t = t - m_clipboard->getBaseTime() + m_t0;
+ tempoT tempo = i->second.first;
+ tempoT targetTempo = i->second.second;
+
+ if (i == m_clipboard->getTempoSelection().begin() &&
+ targetTempo < 0 &&
+ m_composition->getTempoAtTime(t) == tempo)
+ continue;
+
+ m_composition->addTempoAtTime(t, tempo, targetTempo);
+ }
+ }
+}
+
+void
+PasteConductorDataCommand::unexecute()
+{
+ //!!! see note above
+
+ for (TimeSignatureSelection::timesigcontainer::const_iterator i =
+ m_clipboard->getTimeSignatureSelection().begin();
+ i != m_clipboard->getTimeSignatureSelection().end(); ++i) {
+
+ timeT t = i->first;
+ int n = m_composition->getTimeSignatureNumberAt(t);
+
+ if (n >= 0 && m_composition->getTimeSignatureChange(n).first == t) {
+ m_composition->removeTimeSignature(n);
+ }
+ }
+
+ for (TempoSelection::tempocontainer::const_iterator i =
+ m_clipboard->getTempoSelection().begin();
+ i != m_clipboard->getTempoSelection().end(); ++i) {
+
+ timeT t = i->first;
+ int n = m_composition->getTempoChangeNumberAt(t);
+
+ if (n >= 0 && m_composition->getTempoChange(n).first == t) {
+ m_composition->removeTempoChange(n);
+ }
+ }
+}
+
+}
diff --git a/src/commands/segment/PasteConductorDataCommand.h b/src/commands/segment/PasteConductorDataCommand.h
new file mode 100644
index 0000000..15b6e54
--- /dev/null
+++ b/src/commands/segment/PasteConductorDataCommand.h
@@ -0,0 +1,67 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_PASTECONDUCTORDATACOMMAND_H_
+#define _RG_PASTECONDUCTORDATACOMMAND_H_
+
+#include <kcommand.h>
+#include "base/Event.h"
+
+
+
+
+namespace Rosegarden
+{
+
+class Composition;
+class Clipboard;
+
+
+/**
+ * Paste time signature and tempo data from the given clipboard into
+ * the given composition starting at the given time.
+ */
+class PasteConductorDataCommand : public KNamedCommand
+{
+public:
+ PasteConductorDataCommand(Composition *composition,
+ Clipboard *clipboard,
+ timeT t);
+ virtual ~PasteConductorDataCommand();
+
+ virtual void execute();
+ virtual void unexecute();
+
+private:
+ Composition *m_composition;
+ Clipboard *m_clipboard;
+ timeT m_t0;
+};
+
+
+
+}
+
+#endif
diff --git a/src/commands/segment/PasteRangeCommand.cpp b/src/commands/segment/PasteRangeCommand.cpp
new file mode 100644
index 0000000..c2f9a0e
--- /dev/null
+++ b/src/commands/segment/PasteRangeCommand.cpp
@@ -0,0 +1,97 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "PasteRangeCommand.h"
+
+#include <klocale.h>
+#include "AudioSegmentSplitCommand.h"
+#include "base/Clipboard.h"
+#include "base/Composition.h"
+#include "base/Segment.h"
+#include "commands/edit/PasteSegmentsCommand.h"
+#include "OpenOrCloseRangeCommand.h"
+#include "PasteConductorDataCommand.h"
+#include "SegmentSplitCommand.h"
+
+
+namespace Rosegarden
+{
+
+PasteRangeCommand::PasteRangeCommand(Composition *composition,
+ Clipboard *clipboard,
+ timeT t0) :
+ KMacroCommand(i18n("Paste Range"))
+{
+ timeT clipBeginTime = clipboard->getBaseTime();
+
+ timeT t1 = t0;
+
+ if (clipboard->hasNominalRange()) {
+
+ clipboard->getNominalRange(clipBeginTime, t1);
+ t1 = t0 + (t1 - clipBeginTime);
+
+ } else {
+
+ timeT duration = 0;
+
+ for (Clipboard::iterator i = clipboard->begin();
+ i != clipboard->end(); ++i) {
+ timeT durationHere = (*i)->getEndMarkerTime() - clipBeginTime;
+ if (i == clipboard->begin() || durationHere > duration) {
+ duration = durationHere;
+ }
+ }
+
+ if (duration <= 0)
+ return ;
+ t1 = t0 + duration;
+ }
+
+ // Need to split segments before opening, at t0
+
+ for (Composition::iterator i = composition->begin();
+ i != composition->end(); ++i) {
+
+ if ((*i)->getStartTime() >= t0 || (*i)->getEndMarkerTime() <= t0) {
+ continue;
+ }
+
+ if ((*i)->getType() == Segment::Audio) {
+ addCommand(new AudioSegmentSplitCommand(*i, t0));
+ } else {
+ addCommand(new SegmentSplitCommand(*i, t0));
+ }
+ }
+
+ addCommand(new OpenOrCloseRangeCommand(composition, t0, t1, true));
+ addCommand(new PasteSegmentsCommand
+ (composition, clipboard, t0,
+ composition->getTrackByPosition(0)->getId(),
+ true));
+ addCommand(new PasteConductorDataCommand(composition, clipboard, t0));
+}
+
+}
diff --git a/src/commands/segment/PasteRangeCommand.h b/src/commands/segment/PasteRangeCommand.h
new file mode 100644
index 0000000..f64da24
--- /dev/null
+++ b/src/commands/segment/PasteRangeCommand.h
@@ -0,0 +1,52 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_PASTERANGECOMMAND_H_
+#define _RG_PASTERANGECOMMAND_H_
+
+#include "base/Event.h"
+#include <kcommand.h>
+
+
+namespace Rosegarden
+{
+
+class Composition;
+class Clipboard;
+
+
+class PasteRangeCommand : public KMacroCommand
+{
+public:
+ PasteRangeCommand(Composition *composition,
+ Clipboard *clipboard,
+ timeT pasteTime);
+};
+
+
+
+}
+
+#endif
diff --git a/src/commands/segment/PasteToTriggerSegmentCommand.cpp b/src/commands/segment/PasteToTriggerSegmentCommand.cpp
new file mode 100644
index 0000000..0447c40
--- /dev/null
+++ b/src/commands/segment/PasteToTriggerSegmentCommand.cpp
@@ -0,0 +1,129 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "PasteToTriggerSegmentCommand.h"
+
+#include "base/Event.h"
+#include <klocale.h>
+#include "misc/Strings.h"
+#include "base/Clipboard.h"
+#include "base/Composition.h"
+#include "base/NotationTypes.h"
+#include "base/Segment.h"
+#include "base/TriggerSegment.h"
+#include <qstring.h>
+
+
+namespace Rosegarden
+{
+
+PasteToTriggerSegmentCommand::PasteToTriggerSegmentCommand(Composition *composition,
+ Clipboard *clipboard,
+ QString label,
+ int basePitch,
+ int baseVelocity) :
+ KNamedCommand(i18n("Paste as New Triggered Segment")),
+ m_composition(composition),
+ m_clipboard(new Clipboard(*clipboard)),
+ m_label(label),
+ m_basePitch(basePitch),
+ m_baseVelocity(baseVelocity),
+ m_segment(0),
+ m_detached(false)
+{
+ // nothing else
+}
+
+PasteToTriggerSegmentCommand::~PasteToTriggerSegmentCommand()
+{
+ if (m_detached)
+ delete m_segment;
+ delete m_clipboard;
+}
+
+void
+PasteToTriggerSegmentCommand::execute()
+{
+ if (m_segment) {
+
+ m_composition->addTriggerSegment(m_segment, m_id, m_basePitch, m_baseVelocity);
+
+ } else {
+
+ if (m_clipboard->isEmpty())
+ return ;
+
+ m_segment = new Segment();
+
+ timeT earliestStartTime = 0;
+ timeT latestEndTime = 0;
+
+ for (Clipboard::iterator i = m_clipboard->begin();
+ i != m_clipboard->end(); ++i) {
+
+ if (i == m_clipboard->begin() ||
+ (*i)->getStartTime() < earliestStartTime) {
+ earliestStartTime = (*i)->getStartTime();
+ }
+
+ if ((*i)->getEndMarkerTime() > latestEndTime)
+ latestEndTime = (*i)->getEndMarkerTime();
+ }
+
+ for (Clipboard::iterator i = m_clipboard->begin();
+ i != m_clipboard->end(); ++i) {
+
+ for (Segment::iterator si = (*i)->begin();
+ (*i)->isBeforeEndMarker(si); ++si) {
+ if (!(*si)->isa(Note::EventRestType)) {
+ m_segment->insert
+ (new Event(**si,
+ (*si)->getAbsoluteTime() - earliestStartTime));
+ }
+ }
+ }
+
+ m_segment->setLabel(qstrtostr(m_label));
+
+ TriggerSegmentRec *rec =
+ m_composition->addTriggerSegment(m_segment, m_basePitch, m_baseVelocity);
+ if (rec)
+ m_id = rec->getId();
+ }
+
+ m_composition->getTriggerSegmentRec(m_id)->updateReferences();
+
+ m_detached = false;
+}
+
+void
+PasteToTriggerSegmentCommand::unexecute()
+{
+ if (m_segment)
+ m_composition->detachTriggerSegment(m_id);
+ m_detached = true;
+}
+
+}
diff --git a/src/commands/segment/PasteToTriggerSegmentCommand.h b/src/commands/segment/PasteToTriggerSegmentCommand.h
new file mode 100644
index 0000000..32f95e7
--- /dev/null
+++ b/src/commands/segment/PasteToTriggerSegmentCommand.h
@@ -0,0 +1,73 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_PASTETOTRIGGERSEGMENTCOMMAND_H_
+#define _RG_PASTETOTRIGGERSEGMENTCOMMAND_H_
+
+#include "base/TriggerSegment.h"
+#include <kcommand.h>
+#include <qstring.h>
+
+
+
+
+namespace Rosegarden
+{
+
+class Segment;
+class Composition;
+class Clipboard;
+
+
+class PasteToTriggerSegmentCommand : public KNamedCommand
+{
+public:
+ /// If basePitch is -1, the first pitch in the selection will be used
+ PasteToTriggerSegmentCommand(Composition *composition,
+ Clipboard *clipboard,
+ QString label,
+ int basePitch = -1,
+ int baseVelocity = -1);
+ virtual ~PasteToTriggerSegmentCommand();
+
+ virtual void execute();
+ virtual void unexecute();
+
+protected:
+ Composition *m_composition;
+ Clipboard *m_clipboard;
+ QString m_label;
+ int m_basePitch;
+ int m_baseVelocity;
+ Segment *m_segment;
+ TriggerSegmentId m_id;
+ bool m_detached;
+};
+
+
+
+}
+
+#endif
diff --git a/src/commands/segment/RemoveTempoChangeCommand.cpp b/src/commands/segment/RemoveTempoChangeCommand.cpp
new file mode 100644
index 0000000..11a89ad
--- /dev/null
+++ b/src/commands/segment/RemoveTempoChangeCommand.cpp
@@ -0,0 +1,59 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "RemoveTempoChangeCommand.h"
+
+#include "base/Composition.h"
+#include <qstring.h>
+
+
+namespace Rosegarden
+{
+
+void
+RemoveTempoChangeCommand::execute()
+{
+ if (m_tempoChangeIndex >= 0) {
+ std::pair<timeT, tempoT> data =
+ m_composition->getTempoChange(m_tempoChangeIndex);
+
+ // store
+ m_oldTime = data.first;
+ m_oldTempo = data.second;
+ }
+
+ // do we need to (re)store the index number?
+ //
+ m_composition->removeTempoChange(m_tempoChangeIndex);
+
+}
+
+void
+RemoveTempoChangeCommand::unexecute()
+{
+ m_composition->addTempoAtTime(m_oldTime, m_oldTempo);
+}
+
+}
diff --git a/src/commands/segment/RemoveTempoChangeCommand.h b/src/commands/segment/RemoveTempoChangeCommand.h
new file mode 100644
index 0000000..1900a8b
--- /dev/null
+++ b/src/commands/segment/RemoveTempoChangeCommand.h
@@ -0,0 +1,75 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_REMOVETEMPOCHANGECOMMAND_H_
+#define _RG_REMOVETEMPOCHANGECOMMAND_H_
+
+#include <kcommand.h>
+#include <qstring.h>
+#include "base/Event.h"
+#include "base/Composition.h" // for tempoT
+#include <klocale.h>
+
+
+class Remove;
+
+
+namespace Rosegarden
+{
+
+class Composition;
+
+
+class RemoveTempoChangeCommand : public KNamedCommand
+{
+public:
+ RemoveTempoChangeCommand(Composition *composition,
+ int index):
+ KNamedCommand(getGlobalName()),
+ m_composition(composition),
+ m_tempoChangeIndex(index),
+ m_oldTime(0),
+ m_oldTempo(0){}
+
+ virtual ~RemoveTempoChangeCommand() {}
+
+ static QString getGlobalName() { return i18n("Remove &Tempo Change..."); }
+
+ virtual void execute();
+ virtual void unexecute();
+
+private:
+ Composition *m_composition;
+ int m_tempoChangeIndex;
+ timeT m_oldTime;
+ tempoT m_oldTempo;
+};
+
+
+
+
+}
+
+#endif
diff --git a/src/commands/segment/RemoveTimeSignatureCommand.cpp b/src/commands/segment/RemoveTimeSignatureCommand.cpp
new file mode 100644
index 0000000..c6b59b1
--- /dev/null
+++ b/src/commands/segment/RemoveTimeSignatureCommand.cpp
@@ -0,0 +1,60 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "RemoveTimeSignatureCommand.h"
+
+#include "base/Composition.h"
+#include "base/NotationTypes.h"
+#include <qstring.h>
+
+
+namespace Rosegarden
+{
+
+void
+RemoveTimeSignatureCommand::execute()
+{
+ if (m_timeSigIndex >= 0) {
+ std::pair<timeT, TimeSignature> data =
+ m_composition->getTimeSignatureChange(m_timeSigIndex);
+
+ // store
+ m_oldTime = data.first;
+ m_oldTimeSignature = data.second;
+ }
+
+ // do we need to (re)store the index number?
+ //
+ m_composition->removeTimeSignature(m_timeSigIndex);
+
+}
+
+void
+RemoveTimeSignatureCommand::unexecute()
+{
+ m_composition->addTimeSignature(m_oldTime, m_oldTimeSignature);
+}
+
+}
diff --git a/src/commands/segment/RemoveTimeSignatureCommand.h b/src/commands/segment/RemoveTimeSignatureCommand.h
new file mode 100644
index 0000000..d29d666
--- /dev/null
+++ b/src/commands/segment/RemoveTimeSignatureCommand.h
@@ -0,0 +1,74 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_REMOVETIMESIGNATURECOMMAND_H_
+#define _RG_REMOVETIMESIGNATURECOMMAND_H_
+
+#include "base/NotationTypes.h"
+#include <kcommand.h>
+#include <qstring.h>
+#include "base/Event.h"
+#include <klocale.h>
+
+
+class Remove;
+
+
+namespace Rosegarden
+{
+
+class Composition;
+
+
+class RemoveTimeSignatureCommand : public KNamedCommand
+{
+public:
+ RemoveTimeSignatureCommand(Composition *composition,
+ int index):
+ KNamedCommand(getGlobalName()),
+ m_composition(composition),
+ m_timeSigIndex(index),
+ m_oldTime(0),
+ m_oldTimeSignature() { }
+
+ virtual ~RemoveTimeSignatureCommand() {}
+
+ static QString getGlobalName() { return i18n("Remove &Time Signature Change..."); }
+
+ virtual void execute();
+ virtual void unexecute();
+
+private:
+ Composition *m_composition;
+ int m_timeSigIndex;
+ timeT m_oldTime;
+ TimeSignature m_oldTimeSignature;
+};
+
+
+
+}
+
+#endif
diff --git a/src/commands/segment/RenameTrackCommand.cpp b/src/commands/segment/RenameTrackCommand.cpp
new file mode 100644
index 0000000..62d1d7e
--- /dev/null
+++ b/src/commands/segment/RenameTrackCommand.cpp
@@ -0,0 +1,75 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "RenameTrackCommand.h"
+
+#include "misc/Debug.h"
+#include "base/Composition.h"
+#include "base/Track.h"
+#include <qstring.h>
+
+
+namespace Rosegarden
+{
+
+RenameTrackCommand::RenameTrackCommand(Composition *composition,
+ TrackId trackId,
+ std::string name) :
+ KNamedCommand(getGlobalName()),
+ m_composition(composition),
+ m_track(trackId),
+ m_newName(name)
+{
+ Track *track = composition->getTrackById(m_track);
+ if (!track) {
+ RG_DEBUG << "Hey! No Track in RenameTrackCommand (track id " << track
+ << ")!" << endl;
+ return ;
+ }
+ m_oldName = track->getLabel();
+}
+
+RenameTrackCommand::~RenameTrackCommand()
+{}
+
+void
+RenameTrackCommand::execute()
+{
+ Track *track = m_composition->getTrackById(m_track);
+ if (!track)
+ return ;
+ track->setLabel(m_newName);
+}
+
+void
+RenameTrackCommand::unexecute()
+{
+ Track *track = m_composition->getTrackById(m_track);
+ if (!track)
+ return ;
+ track->setLabel(m_oldName);
+}
+
+}
diff --git a/src/commands/segment/RenameTrackCommand.h b/src/commands/segment/RenameTrackCommand.h
new file mode 100644
index 0000000..8e63a88
--- /dev/null
+++ b/src/commands/segment/RenameTrackCommand.h
@@ -0,0 +1,67 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_RENAMETRACKCOMMAND_H_
+#define _RG_RENAMETRACKCOMMAND_H_
+
+#include "base/Track.h"
+#include <string>
+#include <kcommand.h>
+#include <qstring.h>
+#include <klocale.h>
+
+
+
+
+namespace Rosegarden
+{
+
+class Composition;
+
+
+class RenameTrackCommand : public KNamedCommand
+{
+public:
+ RenameTrackCommand(Composition *composition,
+ TrackId track,
+ std::string name);
+ virtual ~RenameTrackCommand();
+
+ static QString getGlobalName() { return i18n("Rename Track"); }
+
+ virtual void execute();
+ virtual void unexecute();
+
+protected:
+ Composition *m_composition;
+ TrackId m_track;
+ std::string m_oldName;
+ std::string m_newName;
+};
+
+
+}
+
+#endif
diff --git a/src/commands/segment/SegmentAutoSplitCommand.cpp b/src/commands/segment/SegmentAutoSplitCommand.cpp
new file mode 100644
index 0000000..fbd6daa
--- /dev/null
+++ b/src/commands/segment/SegmentAutoSplitCommand.cpp
@@ -0,0 +1,205 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "SegmentAutoSplitCommand.h"
+
+#include "base/Event.h"
+#include "misc/Debug.h"
+#include "misc/Strings.h"
+#include "base/Composition.h"
+#include "base/NotationTypes.h"
+#include "base/Segment.h"
+#include <qstring.h>
+
+
+namespace Rosegarden
+{
+
+struct AutoSplitPoint
+{
+ timeT time;
+ timeT lastSoundTime;
+ Clef clef;
+ Rosegarden::Key key;
+ AutoSplitPoint(timeT t, timeT lst, Clef c, Rosegarden::Key k) :
+ time(t), lastSoundTime(lst), clef(c), key(k) { }
+};
+
+SegmentAutoSplitCommand::SegmentAutoSplitCommand(Segment *segment) :
+ KNamedCommand(getGlobalName()),
+ m_segment(segment),
+ m_composition(segment->getComposition()),
+ m_detached(false)
+{}
+
+SegmentAutoSplitCommand::~SegmentAutoSplitCommand()
+{
+ if (m_detached) {
+ delete m_segment;
+ } else {
+ for (unsigned int i = 0; i < m_newSegments.size(); ++i) {
+ delete m_newSegments[i];
+ }
+ }
+}
+
+void
+SegmentAutoSplitCommand::execute()
+{
+ if (m_newSegments.size() == 0) {
+
+ std::vector<AutoSplitPoint> splitPoints;
+
+ Clef clef;
+ Key key;
+ timeT segmentStart = m_segment->getStartTime();
+ timeT lastSoundTime = segmentStart;
+ timeT lastSplitTime = segmentStart - 1;
+
+ for (Segment::iterator i = m_segment->begin();
+ m_segment->isBeforeEndMarker(i); ++i) {
+
+ timeT myTime = (*i)->getAbsoluteTime();
+ int barNo = m_composition->getBarNumber(myTime);
+
+ if ((*i)->isa(Clef::EventType)) {
+ clef = Clef(**i);
+ } else if ((*i)->isa(Key::EventType)) {
+ key = Key(**i);
+ }
+
+ if (myTime <= lastSplitTime)
+ continue;
+
+ bool newTimeSig = false;
+ TimeSignature tsig =
+ m_composition->getTimeSignatureInBar(barNo, newTimeSig);
+
+ if (newTimeSig) {
+
+ // If there's a new time sig in this bar and we haven't
+ // already made a split in this bar, make one
+
+ if (splitPoints.size() == 0 ||
+ m_composition->getBarNumber
+ (splitPoints[splitPoints.size() - 1].time) < barNo) {
+
+ splitPoints.push_back(AutoSplitPoint(myTime, lastSoundTime,
+ clef, key));
+ lastSoundTime = lastSplitTime = myTime;
+ }
+
+ } else if ((*i)->isa(Note::EventRestType)) {
+
+ // Otherwise never start a subsegment on a rest
+
+ continue;
+
+ } else {
+
+ // When we meet a non-rest event, start a new split
+ // if an entire bar has passed since the last one
+
+ int lastSoundBarNo = m_composition->getBarNumber(lastSoundTime);
+
+ if (lastSoundBarNo < barNo - 1 ||
+ (lastSoundBarNo == barNo - 1 &&
+ m_composition->getBarStartForTime(lastSoundTime) ==
+ lastSoundTime &&
+ lastSoundTime > segmentStart)) {
+
+ splitPoints.push_back
+ (AutoSplitPoint
+ (m_composition->getBarStartForTime(myTime), lastSoundTime,
+ clef, key));
+ lastSplitTime = myTime;
+ }
+ }
+
+ lastSoundTime = std::max(lastSoundTime, myTime + (*i)->getDuration());
+ }
+
+ for (unsigned int split = 0; split <= splitPoints.size(); ++split) {
+
+ Segment *newSegment = new Segment();
+ newSegment->setTrack(m_segment->getTrack());
+ newSegment->setLabel(qstrtostr(i18n("%1 (part)").arg
+ (strtoqstr(m_segment->getLabel()))));
+ newSegment->setColourIndex(m_segment->getColourIndex());
+
+ timeT startTime = segmentStart;
+ if (split > 0) {
+
+ RG_DEBUG << "Auto-split point " << split - 1 << ": time "
+ << splitPoints[split - 1].time << ", lastSoundTime "
+ << splitPoints[split - 1].lastSoundTime << endl;
+
+ startTime = splitPoints[split - 1].time;
+ newSegment->insert(splitPoints[split - 1].clef.getAsEvent(startTime));
+ newSegment->insert(splitPoints[split - 1].key.getAsEvent(startTime));
+ }
+
+ Segment::iterator i = m_segment->findTime(startTime);
+
+ // A segment has to contain at least one note to be a worthy
+ // candidate for adding back into the composition
+ bool haveNotes = false;
+
+ while (m_segment->isBeforeEndMarker(i)) {
+ timeT t = (*i)->getAbsoluteTime();
+ if (split < splitPoints.size() &&
+ t >= splitPoints[split].lastSoundTime)
+ break;
+ if ((*i)->isa(Note::EventType))
+ haveNotes = true;
+ newSegment->insert(new Event(**i));
+ ++i;
+ }
+
+ if (haveNotes)
+ m_newSegments.push_back(newSegment);
+ else
+ delete newSegment;
+ }
+ }
+
+ m_composition->detachSegment(m_segment);
+ for (unsigned int i = 0; i < m_newSegments.size(); ++i) {
+ m_composition->addSegment(m_newSegments[i]);
+ }
+ m_detached = true;
+}
+
+void
+SegmentAutoSplitCommand::unexecute()
+{
+ for (unsigned int i = 0; i < m_newSegments.size(); ++i) {
+ m_composition->detachSegment(m_newSegments[i]);
+ }
+ m_composition->addSegment(m_segment);
+ m_detached = false;
+}
+
+}
diff --git a/src/commands/segment/SegmentAutoSplitCommand.h b/src/commands/segment/SegmentAutoSplitCommand.h
new file mode 100644
index 0000000..a7e54c7
--- /dev/null
+++ b/src/commands/segment/SegmentAutoSplitCommand.h
@@ -0,0 +1,66 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_SEGMENTAUTOSPLITCOMMAND_H_
+#define _RG_SEGMENTAUTOSPLITCOMMAND_H_
+
+#include <kcommand.h>
+#include <qstring.h>
+#include <vector>
+#include <klocale.h>
+
+
+
+
+namespace Rosegarden
+{
+
+class Segment;
+class Composition;
+
+
+class SegmentAutoSplitCommand : public KNamedCommand
+{
+public:
+ SegmentAutoSplitCommand(Segment *segment);
+ virtual ~SegmentAutoSplitCommand();
+
+ virtual void execute();
+ virtual void unexecute();
+
+ static QString getGlobalName() { return i18n("&Split on Silence"); }
+
+private:
+ Segment *m_segment;
+ Composition *m_composition;
+ std::vector<Segment *> m_newSegments;
+ bool m_detached;
+};
+
+
+
+}
+
+#endif
diff --git a/src/commands/segment/SegmentChangePlayableRangeCommand.cpp b/src/commands/segment/SegmentChangePlayableRangeCommand.cpp
new file mode 100644
index 0000000..b4d5d3a
--- /dev/null
+++ b/src/commands/segment/SegmentChangePlayableRangeCommand.cpp
@@ -0,0 +1,77 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2007
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "SegmentChangePlayableRangeCommand.h"
+
+#include "base/Segment.h"
+#include "gui/editors/notation/NotationStrings.h"
+#include <qstring.h>
+
+
+namespace Rosegarden
+{
+
+SegmentChangePlayableRangeCommand::SegmentChangePlayableRangeCommand(int low, int high, Segment *segment) :
+ KNamedCommand(getGlobalName(low, high)),
+ m_lowestPlayableNote(low),
+ m_highestPlayableNote(high),
+ m_segment(segment)
+{
+ // nothing
+}
+
+SegmentChangePlayableRangeCommand::~SegmentChangePlayableRangeCommand()
+{
+ // nothing
+}
+
+void
+SegmentChangePlayableRangeCommand::execute()
+{
+ m_oldLowestPlayableNote = m_segment->getLowestPlayable();
+ m_oldHighestPlayableNote = m_segment->getHighestPlayable();
+ m_segment->setLowestPlayable(m_lowestPlayableNote);
+ m_segment->setHighestPlayable(m_highestPlayableNote);
+}
+
+void
+SegmentChangePlayableRangeCommand::unexecute()
+{
+ m_segment->setLowestPlayable(m_oldLowestPlayableNote);
+ m_segment->setHighestPlayable(m_oldHighestPlayableNote);
+}
+
+QString
+SegmentChangePlayableRangeCommand::getGlobalName(int low, int high)
+{
+ bool unit = false; // fake code to allow trunk/ to compile!
+ if (!unit) {
+ return "Undo change playable range";
+ } else {
+ return QString("Change playable range to %1-%2").arg(low, high);
+ }
+}
+
+}
diff --git a/src/commands/segment/SegmentChangePlayableRangeCommand.h b/src/commands/segment/SegmentChangePlayableRangeCommand.h
new file mode 100644
index 0000000..d78aa5c
--- /dev/null
+++ b/src/commands/segment/SegmentChangePlayableRangeCommand.h
@@ -0,0 +1,67 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2007
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_SEGMENTCHANGEPLAYABLERANGECOMMAND_H_
+#define _RG_SEGMENTCHANGEPLAYABLERANGECOMMAND_H_
+
+#include <kcommand.h>
+#include <qstring.h>
+#include <vector>
+#include "base/Event.h"
+
+
+
+
+namespace Rosegarden
+{
+
+class Segment;
+
+
+class SegmentChangePlayableRangeCommand : public KNamedCommand
+{
+public:
+ /// Set transpose on segments.
+ SegmentChangePlayableRangeCommand(int /*low*/, int /*high*/, Segment *segment);
+ virtual ~SegmentChangePlayableRangeCommand();
+
+ virtual void execute();
+ virtual void unexecute();
+
+ static QString getGlobalName(int, int);
+
+private:
+ Segment *m_segment;
+ int m_oldLowestPlayableNote;
+ int m_oldHighestPlayableNote;
+ int m_lowestPlayableNote;
+ int m_highestPlayableNote;
+};
+
+
+
+}
+
+#endif
diff --git a/src/commands/segment/SegmentChangeQuantizationCommand.cpp b/src/commands/segment/SegmentChangeQuantizationCommand.cpp
new file mode 100644
index 0000000..22d09f4
--- /dev/null
+++ b/src/commands/segment/SegmentChangeQuantizationCommand.cpp
@@ -0,0 +1,115 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "SegmentChangeQuantizationCommand.h"
+
+#include "base/Segment.h"
+#include "base/BasicQuantizer.h"
+#include "gui/editors/notation/NotationStrings.h"
+#include <qstring.h>
+
+
+namespace Rosegarden
+{
+
+SegmentChangeQuantizationCommand::SegmentChangeQuantizationCommand(timeT unit) :
+ KNamedCommand(getGlobalName(unit)),
+ m_unit(unit)
+{
+ // nothing
+}
+
+SegmentChangeQuantizationCommand::~SegmentChangeQuantizationCommand()
+{
+ // nothing
+}
+
+void
+SegmentChangeQuantizationCommand::execute()
+{
+ for (unsigned int i = 0; i < m_records.size(); ++i) {
+
+ SegmentRec &rec = m_records[i];
+
+ if (m_unit) {
+
+ rec.oldUnit = rec.segment->getQuantizer()->getUnit();
+ rec.segment->setQuantizeLevel(m_unit);
+
+ rec.wasQuantized = rec.segment->hasQuantization();
+ rec.segment->setQuantization(true);
+
+ } else {
+
+ rec.wasQuantized = rec.segment->hasQuantization();
+ rec.segment->setQuantization(false);
+ }
+ }
+}
+
+void
+SegmentChangeQuantizationCommand::unexecute()
+{
+ for (unsigned int i = 0; i < m_records.size(); ++i) {
+
+ SegmentRec &rec = m_records[i];
+
+ if (m_unit) {
+
+ if (!rec.wasQuantized)
+ rec.segment->setQuantization(false);
+ rec.segment->setQuantizeLevel(rec.oldUnit);
+
+ } else {
+
+ if (rec.wasQuantized)
+ rec.segment->setQuantization(true);
+ }
+ }
+}
+
+void
+SegmentChangeQuantizationCommand::addSegment(Segment *s)
+{
+ SegmentRec rec;
+ rec.segment = s;
+ rec.oldUnit = 0; // shouldn't matter what we initialise this to
+ rec.wasQuantized = false; // shouldn't matter what we initialise this to
+ m_records.push_back(rec);
+}
+
+QString
+SegmentChangeQuantizationCommand::getGlobalName(timeT unit)
+{
+ if (!unit) {
+ return "Unquantize";
+ } else {
+ timeT error = 0;
+ QString label = NotationStrings::makeNoteMenuLabel(unit, true, error);
+ return QString("Quantize to %1").arg(label);
+ }
+}
+
+}
diff --git a/src/commands/segment/SegmentChangeQuantizationCommand.h b/src/commands/segment/SegmentChangeQuantizationCommand.h
new file mode 100644
index 0000000..e5d7a36
--- /dev/null
+++ b/src/commands/segment/SegmentChangeQuantizationCommand.h
@@ -0,0 +1,73 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_SEGMENTCHANGEQUANTIZATIONCOMMAND_H_
+#define _RG_SEGMENTCHANGEQUANTIZATIONCOMMAND_H_
+
+#include <kcommand.h>
+#include <qstring.h>
+#include <vector>
+#include "base/Event.h"
+
+
+
+
+namespace Rosegarden
+{
+
+class Segment;
+
+
+class SegmentChangeQuantizationCommand : public KNamedCommand
+{
+public:
+ /// Set quantization on segments. If unit is zero, switch quantization off
+ SegmentChangeQuantizationCommand(timeT);
+ virtual ~SegmentChangeQuantizationCommand();
+
+ void addSegment(Segment *s);
+
+ virtual void execute();
+ virtual void unexecute();
+
+ static QString getGlobalName(timeT);
+
+private:
+ struct SegmentRec {
+ Segment *segment;
+ timeT oldUnit;
+ bool wasQuantized;
+ };
+ typedef std::vector<SegmentRec> SegmentRecSet;
+ SegmentRecSet m_records;
+
+ timeT m_unit;
+};
+
+
+
+}
+
+#endif
diff --git a/src/commands/segment/SegmentChangeTransposeCommand.cpp b/src/commands/segment/SegmentChangeTransposeCommand.cpp
new file mode 100644
index 0000000..452c2d7
--- /dev/null
+++ b/src/commands/segment/SegmentChangeTransposeCommand.cpp
@@ -0,0 +1,72 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "SegmentChangeTransposeCommand.h"
+
+#include "base/Segment.h"
+#include "gui/editors/notation/NotationStrings.h"
+#include <qstring.h>
+
+
+namespace Rosegarden
+{
+
+SegmentChangeTransposeCommand::SegmentChangeTransposeCommand(int unit, Segment *segment) :
+ KNamedCommand(getGlobalName(unit)),
+ m_unit(unit),
+ m_segment(segment)
+{
+ // nothing
+}
+
+SegmentChangeTransposeCommand::~SegmentChangeTransposeCommand()
+{
+ // nothing
+}
+
+void
+SegmentChangeTransposeCommand::execute()
+{
+ m_oldUnit = m_segment->getTranspose();
+ m_segment->setTranspose(m_unit);
+}
+
+void
+SegmentChangeTransposeCommand::unexecute()
+{
+ m_segment->setTranspose(m_oldUnit);
+}
+
+QString
+SegmentChangeTransposeCommand::getGlobalName(int unit)
+{
+ if (!unit) {
+ return "Undo change transposition";
+ } else {
+ return QString("Change transposition to %1").arg(unit);
+ }
+}
+
+}
diff --git a/src/commands/segment/SegmentChangeTransposeCommand.h b/src/commands/segment/SegmentChangeTransposeCommand.h
new file mode 100644
index 0000000..64bd75a
--- /dev/null
+++ b/src/commands/segment/SegmentChangeTransposeCommand.h
@@ -0,0 +1,65 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_SEGMENTCHANGETRANSPOSECOMMAND_H_
+#define _RG_SEGMENTCHANGETRANSPOSECOMMAND_H_
+
+#include <kcommand.h>
+#include <qstring.h>
+#include <vector>
+#include "base/Event.h"
+
+
+
+
+namespace Rosegarden
+{
+
+class Segment;
+
+
+class SegmentChangeTransposeCommand : public KNamedCommand
+{
+public:
+ /// Set transpose on segments.
+ SegmentChangeTransposeCommand(int, Segment *segment);
+ virtual ~SegmentChangeTransposeCommand();
+
+ virtual void execute();
+ virtual void unexecute();
+
+ static QString getGlobalName(int);
+
+private:
+ Segment *m_segment;
+ int m_oldUnit;
+ int m_unit;
+};
+
+
+
+}
+
+#endif
diff --git a/src/commands/segment/SegmentColourCommand.cpp b/src/commands/segment/SegmentColourCommand.cpp
new file mode 100644
index 0000000..7dffc8f
--- /dev/null
+++ b/src/commands/segment/SegmentColourCommand.cpp
@@ -0,0 +1,65 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "SegmentColourCommand.h"
+
+#include "base/Segment.h"
+#include "base/Selection.h"
+#include <qstring.h>
+
+
+namespace Rosegarden
+{
+
+SegmentColourCommand::SegmentColourCommand(
+ SegmentSelection &segments,
+ const unsigned int index):
+ KNamedCommand(i18n("Change Segment Color")),
+ m_newColourIndex(index)
+{
+ for (SegmentSelection::iterator i = segments.begin(); i != segments.end(); ++i)
+ m_segments.push_back(*i);
+}
+
+SegmentColourCommand::~SegmentColourCommand()
+{}
+
+void
+SegmentColourCommand::execute()
+{
+ for (unsigned int i = 0; i < m_segments.size(); ++i) {
+ m_oldColourIndexes.push_back(m_segments[i]->getColourIndex());
+ m_segments[i]->setColourIndex(m_newColourIndex);
+ }
+}
+
+void
+SegmentColourCommand::unexecute()
+{
+ for (unsigned int i = 0; i < m_segments.size(); ++i)
+ m_segments[i]->setColourIndex(m_oldColourIndexes[i]);
+}
+
+}
diff --git a/src/commands/segment/SegmentColourCommand.h b/src/commands/segment/SegmentColourCommand.h
new file mode 100644
index 0000000..79b7d3d
--- /dev/null
+++ b/src/commands/segment/SegmentColourCommand.h
@@ -0,0 +1,66 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_SEGMENTCOLOURCOMMAND_H_
+#define _RG_SEGMENTCOLOURCOMMAND_H_
+
+#include "base/Segment.h"
+#include <kcommand.h>
+#include <qstring.h>
+#include <vector>
+#include <klocale.h>
+
+
+
+
+namespace Rosegarden
+{
+
+class SegmentSelection;
+
+
+class SegmentColourCommand : public KNamedCommand
+{
+public:
+ SegmentColourCommand(SegmentSelection &segments,
+ const unsigned int index);
+ virtual ~SegmentColourCommand();
+
+ static QString getGlobalName()
+ { return i18n("Change Segment Color..."); }
+
+ virtual void execute();
+ virtual void unexecute();
+protected:
+
+ std::vector<Segment*> m_segments;
+ std::vector<unsigned int> m_oldColourIndexes;
+ unsigned int m_newColourIndex;
+};
+
+
+}
+
+#endif
diff --git a/src/commands/segment/SegmentColourMapCommand.cpp b/src/commands/segment/SegmentColourMapCommand.cpp
new file mode 100644
index 0000000..0e09d4b
--- /dev/null
+++ b/src/commands/segment/SegmentColourMapCommand.cpp
@@ -0,0 +1,64 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "SegmentColourMapCommand.h"
+
+#include "base/ColourMap.h"
+#include "base/Segment.h"
+#include "document/RosegardenGUIDoc.h"
+#include <qstring.h>
+
+
+namespace Rosegarden
+{
+
+SegmentColourMapCommand::SegmentColourMapCommand(
+ RosegardenGUIDoc *doc,
+ const ColourMap &map):
+ KNamedCommand(i18n("Change Segment Color Map")),
+ m_doc(doc),
+ m_oldMap(m_doc->getComposition().getSegmentColourMap()),
+ m_newMap(map)
+{
+}
+
+SegmentColourMapCommand::~SegmentColourMapCommand()
+{}
+
+void
+SegmentColourMapCommand::execute()
+{
+ m_doc->getComposition().setSegmentColourMap(m_newMap);
+ m_doc->slotDocColoursChanged();
+}
+
+void
+SegmentColourMapCommand::unexecute()
+{
+ m_doc->getComposition().setSegmentColourMap(m_oldMap);
+ m_doc->slotDocColoursChanged();
+}
+
+}
diff --git a/src/commands/segment/SegmentColourMapCommand.h b/src/commands/segment/SegmentColourMapCommand.h
new file mode 100644
index 0000000..257cdce
--- /dev/null
+++ b/src/commands/segment/SegmentColourMapCommand.h
@@ -0,0 +1,71 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_SEGMENTCOLOURMAPCOMMAND_H_
+#define _RG_SEGMENTCOLOURMAPCOMMAND_H_
+
+#include "base/ColourMap.h"
+#include "base/Segment.h"
+#include <kcommand.h>
+#include <qstring.h>
+#include <klocale.h>
+
+
+
+
+namespace Rosegarden
+{
+
+class RosegardenGUIDoc;
+
+
+class SegmentColourMapCommand : public KNamedCommand
+{
+public:
+ SegmentColourMapCommand( RosegardenGUIDoc* doc,
+ const ColourMap& map);
+ virtual ~SegmentColourMapCommand();
+
+ static QString getGlobalName()
+ { return i18n("Change Segment Color Map..."); }
+
+ virtual void execute();
+ virtual void unexecute();
+protected:
+ RosegardenGUIDoc * m_doc;
+ ColourMap m_oldMap;
+ ColourMap m_newMap;
+};
+
+
+// Trigger Segment commands. These are the commands that create
+// and manage the triggered segments themselves. See editcommands.h
+// for SetTriggerCommand and ClearTriggersCommand which manipulate
+// the events that do the triggering.
+
+
+}
+
+#endif
diff --git a/src/commands/segment/SegmentCommand.cpp b/src/commands/segment/SegmentCommand.cpp
new file mode 100644
index 0000000..68ff846
--- /dev/null
+++ b/src/commands/segment/SegmentCommand.cpp
@@ -0,0 +1,42 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "SegmentCommand.h"
+
+#include "base/Segment.h"
+#include <qstring.h>
+
+
+namespace Rosegarden
+{
+
+SegmentCommand::SegmentCommand(QString name, const std::vector<Segment*>& segments)
+ : KNamedCommand(name)
+{
+ m_segments.resize(segments.size());
+ std::copy(segments.begin(), segments.end(), m_segments.begin());
+}
+
+}
diff --git a/src/commands/segment/SegmentCommand.h b/src/commands/segment/SegmentCommand.h
new file mode 100644
index 0000000..da28a04
--- /dev/null
+++ b/src/commands/segment/SegmentCommand.h
@@ -0,0 +1,59 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_SEGMENTCOMMAND_H_
+#define _RG_SEGMENTCOMMAND_H_
+
+#include <kcommand.h>
+#include <qstring.h>
+#include <vector>
+
+
+
+
+namespace Rosegarden
+{
+
+class Segment;
+
+
+/**
+ * Base class for commands from the SegmentParameterBox
+ */
+class SegmentCommand : public KNamedCommand
+{
+public:
+ SegmentCommand(QString name, const std::vector<Segment*>&);
+
+ typedef std::vector<Segment*> segmentlist;
+
+protected:
+ segmentlist m_segments;
+};
+
+
+}
+
+#endif
diff --git a/src/commands/segment/SegmentCommandRepeat.cpp b/src/commands/segment/SegmentCommandRepeat.cpp
new file mode 100644
index 0000000..4b707cb
--- /dev/null
+++ b/src/commands/segment/SegmentCommandRepeat.cpp
@@ -0,0 +1,59 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "SegmentCommandRepeat.h"
+
+#include <klocale.h>
+#include "base/Segment.h"
+#include "SegmentCommand.h"
+#include <qstring.h>
+
+
+namespace Rosegarden
+{
+
+SegmentCommandRepeat::SegmentCommandRepeat(const std::vector<Segment*>& segments,
+ bool repeat)
+ : SegmentCommand(i18n("Repeat Segments"), segments),
+ m_repeatState(repeat)
+{}
+
+void SegmentCommandRepeat::execute()
+{
+ segmentlist::iterator it;
+
+ for (it = m_segments.begin(); it != m_segments.end(); it++)
+ (*it)->setRepeating(m_repeatState);
+}
+
+void SegmentCommandRepeat::unexecute()
+{
+ segmentlist::iterator it;
+
+ for (it = m_segments.begin(); it != m_segments.end(); it++)
+ (*it)->setRepeating(!m_repeatState);
+}
+
+}
diff --git a/src/commands/segment/SegmentCommandRepeat.h b/src/commands/segment/SegmentCommandRepeat.h
new file mode 100644
index 0000000..0234070
--- /dev/null
+++ b/src/commands/segment/SegmentCommandRepeat.h
@@ -0,0 +1,81 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_SEGMENTCOMMANDREPEAT_H_
+#define _RG_SEGMENTCOMMANDREPEAT_H_
+
+#include "SegmentCommand.h"
+#include <vector>
+
+
+
+
+namespace Rosegarden
+{
+
+class Segment;
+
+
+/**
+ * Repeat segment command from the SegmentParameterBox
+ */
+class SegmentCommandRepeat : public SegmentCommand
+{
+public:
+ SegmentCommandRepeat(const std::vector<Segment*>&,
+ bool repeat);
+
+ virtual void execute();
+ virtual void unexecute();
+
+protected:
+ bool m_repeatState;
+};
+
+// Disabled until we find a better solution
+//
+// As it is, command creation happens on every change of the text
+// value of the combo box
+//
+//
+// class SegmentCommandChangeTransposeValue : public SegmentCommand
+// {
+// public:
+// SegmentCommandChangeTransposeValue(const std::vector<Segment*>&,
+// int transposeValue);
+
+// virtual void execute();
+// virtual void unexecute();
+
+// protected:
+// int m_transposeValue;
+// std::vector<int> m_savedValues;
+// };
+
+
+
+}
+
+#endif
diff --git a/src/commands/segment/SegmentEraseCommand.cpp b/src/commands/segment/SegmentEraseCommand.cpp
new file mode 100644
index 0000000..b15788f
--- /dev/null
+++ b/src/commands/segment/SegmentEraseCommand.cpp
@@ -0,0 +1,108 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "SegmentEraseCommand.h"
+
+#include <klocale.h>
+#include "misc/Debug.h"
+#include "base/Composition.h"
+#include "base/Segment.h"
+#include "sound/AudioFile.h"
+#include "sound/AudioFileManager.h"
+
+
+namespace Rosegarden
+{
+
+SegmentEraseCommand::SegmentEraseCommand(Segment *segment) :
+ KNamedCommand(i18n("Erase Segment")),
+ m_composition(segment->getComposition()),
+ m_segment(segment),
+ m_mgr(0),
+ m_audioFileName(""),
+ m_detached(false)
+{
+ // nothing else
+}
+
+SegmentEraseCommand::SegmentEraseCommand(Segment *segment,
+ AudioFileManager *mgr) :
+ KNamedCommand(i18n("Erase Segment")),
+ m_composition(segment->getComposition()),
+ m_segment(segment),
+ m_mgr(mgr),
+ m_detached(false)
+{
+ // If this is an audio segment, we want to make a note of
+ // its associated file name in case we need to undo and restore
+ // the file.
+ if (m_segment->getType() == Segment::Audio) {
+ unsigned int id = m_segment->getAudioFileId();
+ AudioFile *file = mgr->getAudioFile(id);
+ if (file)
+ m_audioFileName = file->getFilename();
+ }
+}
+
+SegmentEraseCommand::~SegmentEraseCommand()
+{
+ // This is the only place in this command that the Segment can
+ // safely be deleted, and then only if it is not in the
+ // Composition (i.e. if we executed more recently than we
+ // unexecuted). Can't safely call through the m_segment pointer
+ // here; someone else might have got to it first
+
+ if (m_detached) {
+ delete m_segment;
+ }
+}
+
+void
+SegmentEraseCommand::execute()
+{
+ m_composition->detachSegment(m_segment);
+ m_detached = true;
+}
+
+void
+SegmentEraseCommand::unexecute()
+{
+ m_composition->addSegment(m_segment);
+ m_detached = false;
+
+ if (m_segment->getType() == Segment::Audio &&
+ m_audioFileName != "" &&
+ m_mgr) {
+ int id = m_mgr->fileExists(m_audioFileName);
+
+ RG_DEBUG << "SegmentEraseCommand::unexecute: file is " << m_audioFileName << endl;
+
+ if (id == -1)
+ id = (int)m_mgr->addFile(m_audioFileName);
+ m_segment->setAudioFileId(id);
+ }
+}
+
+}
diff --git a/src/commands/segment/SegmentEraseCommand.h b/src/commands/segment/SegmentEraseCommand.h
new file mode 100644
index 0000000..493cd14
--- /dev/null
+++ b/src/commands/segment/SegmentEraseCommand.h
@@ -0,0 +1,70 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_SEGMENTERASECOMMAND_H_
+#define _RG_SEGMENTERASECOMMAND_H_
+
+#include <string>
+#include <kcommand.h>
+
+
+
+
+namespace Rosegarden
+{
+
+class Segment;
+class Composition;
+class AudioFileManager;
+
+
+////////////////////////////////////////////////////////////
+
+class SegmentEraseCommand : public KNamedCommand
+{
+public:
+ /// for removing segment normally
+ SegmentEraseCommand(Segment *segment);
+
+ /// for removing audio segment when removing an audio file
+ SegmentEraseCommand(Segment *segment,
+ AudioFileManager *mgr);
+ virtual ~SegmentEraseCommand();
+
+ virtual void execute();
+ virtual void unexecute();
+
+private:
+ Composition *m_composition;
+ Segment *m_segment;
+ AudioFileManager *m_mgr;
+ std::string m_audioFileName;
+ bool m_detached;
+};
+
+
+}
+
+#endif
diff --git a/src/commands/segment/SegmentInsertCommand.cpp b/src/commands/segment/SegmentInsertCommand.cpp
new file mode 100644
index 0000000..f10ef45
--- /dev/null
+++ b/src/commands/segment/SegmentInsertCommand.cpp
@@ -0,0 +1,124 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "SegmentInsertCommand.h"
+
+#include <klocale.h>
+#include "base/Composition.h"
+#include "base/Segment.h"
+#include "base/Studio.h"
+#include "base/Track.h"
+#include "document/RosegardenGUIDoc.h"
+
+
+namespace Rosegarden
+{
+
+SegmentInsertCommand::SegmentInsertCommand(RosegardenGUIDoc *doc,
+ TrackId track,
+ timeT startTime,
+ timeT endTime):
+ KNamedCommand(i18n("Create Segment")),
+ m_composition(&(doc->getComposition())),
+ m_studio(&(doc->getStudio())),
+ m_segment(0),
+ m_track(track),
+ m_startTime(startTime),
+ m_endTime(endTime),
+ m_detached(false)
+{}
+
+SegmentInsertCommand::SegmentInsertCommand(Composition *composition,
+ Segment *segment,
+ TrackId track):
+ KNamedCommand(i18n("Create Segment")),
+ m_composition(composition),
+ m_studio(0),
+ m_segment(segment),
+ m_track(track),
+ m_startTime(0),
+ m_endTime(0),
+ m_detached(false)
+{}
+
+SegmentInsertCommand::~SegmentInsertCommand()
+{
+ if (m_detached) {
+ delete m_segment;
+ }
+}
+
+Segment *
+SegmentInsertCommand::getSegment() const
+{
+ return m_segment;
+}
+
+void
+SegmentInsertCommand::execute()
+{
+ if (!m_segment) {
+ // Create and insert Segment
+ //
+ m_segment = new Segment();
+ m_segment->setTrack(m_track);
+ m_segment->setStartTime(m_startTime);
+ m_composition->addSegment(m_segment);
+ m_segment->setEndTime(m_endTime);
+
+ // Do our best to label the Segment with whatever is currently
+ // showing against it.
+ //
+ Track *track = m_composition->getTrackById(m_track);
+ std::string label;
+
+ if (track) {
+ // try to get a reasonable Segment name by Instrument
+ //
+ label = m_studio->getSegmentName(track->getInstrument());
+
+ // if not use the track label
+ //
+ if (label == "")
+ label = track->getLabel();
+
+ m_segment->setLabel(label);
+ }
+ } else {
+ m_segment->setTrack(m_track);
+ m_composition->addSegment(m_segment);
+ }
+
+ m_detached = false;
+}
+
+void
+SegmentInsertCommand::unexecute()
+{
+ m_composition->detachSegment(m_segment);
+ m_detached = true;
+}
+
+}
diff --git a/src/commands/segment/SegmentInsertCommand.h b/src/commands/segment/SegmentInsertCommand.h
new file mode 100644
index 0000000..932919a
--- /dev/null
+++ b/src/commands/segment/SegmentInsertCommand.h
@@ -0,0 +1,76 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_SEGMENTINSERTCOMMAND_H_
+#define _RG_SEGMENTINSERTCOMMAND_H_
+
+#include "base/Track.h"
+#include <kcommand.h>
+#include "base/Event.h"
+
+
+
+
+namespace Rosegarden
+{
+
+class Studio;
+class Segment;
+class RosegardenGUIDoc;
+class Composition;
+
+
+class SegmentInsertCommand : public KNamedCommand
+{
+public:
+ SegmentInsertCommand(RosegardenGUIDoc *doc,
+ TrackId track,
+ timeT startTime,
+ timeT endTime);
+ SegmentInsertCommand(Composition *composition,
+ Segment *segment,
+ TrackId track);
+ virtual ~SegmentInsertCommand();
+
+ Segment *getSegment() const; // after invocation
+
+ virtual void execute();
+ virtual void unexecute();
+
+private:
+ Composition *m_composition;
+ Studio *m_studio;
+ Segment *m_segment;
+ int m_track;
+ timeT m_startTime;
+ timeT m_endTime;
+ bool m_detached;
+};
+
+
+
+}
+
+#endif
diff --git a/src/commands/segment/SegmentJoinCommand.cpp b/src/commands/segment/SegmentJoinCommand.cpp
new file mode 100644
index 0000000..27b1bb8
--- /dev/null
+++ b/src/commands/segment/SegmentJoinCommand.cpp
@@ -0,0 +1,175 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "SegmentJoinCommand.h"
+
+#include "base/Composition.h"
+#include "base/Event.h"
+#include "base/NotationTypes.h"
+#include "base/Segment.h"
+#include "base/Selection.h"
+#include <qstring.h>
+
+
+namespace Rosegarden
+{
+
+SegmentJoinCommand::SegmentJoinCommand(SegmentSelection &
+ segments) :
+ KNamedCommand(getGlobalName()),
+ m_newSegment(0),
+ m_detached(false) // true if the old segments are detached, not the new
+{
+ for (SegmentSelection::iterator i = segments.begin();
+ i != segments.end(); ++i)
+ {
+ m_oldSegments.push_back(*i);
+ }
+ assert(m_oldSegments.size() > 0);
+}
+
+SegmentJoinCommand::~SegmentJoinCommand()
+{
+ if (m_detached) {
+ for (unsigned int i = 0; i < m_oldSegments.size(); ++i) {
+ delete m_oldSegments[i];
+ }
+ } else {
+ delete m_newSegment;
+ }
+}
+
+void
+SegmentJoinCommand::execute()
+{
+ Composition *composition = m_oldSegments[0]->getComposition();
+ if (!composition) {
+ std::cerr
+ << "SegmentJoinCommand::execute: ERROR: old segments are not in composition!"
+ << std::endl;
+ return ;
+ }
+
+ // we normalize rests in any overlapping areas
+ timeT overlapStart = 0, overlapEnd = 0;
+ bool haveOverlap = false;
+
+ if (!m_newSegment) {
+
+ m_newSegment = new Segment(*m_oldSegments[0]);
+
+ // that duplicated segment 0; now do the rest
+
+ for (unsigned int i = 1; i < m_oldSegments.size(); ++i) {
+
+ Segment *s = m_oldSegments[i];
+
+ timeT start = s->getStartTime(), end = s->getEndMarkerTime();
+
+ timeT os = 0, oe = 0;
+ bool haveOverlapHere = false;
+
+ if (start < m_newSegment->getEndMarkerTime() &&
+ end > m_newSegment->getStartTime()) {
+ haveOverlapHere = true;
+ os = std::max(start, m_newSegment->getStartTime());
+ oe = std::min(end, m_newSegment->getEndMarkerTime());
+ std::cerr << "overlap here, os = " << os << ", oe = " << oe << std::endl;
+ }
+
+ if (haveOverlapHere) {
+ if (haveOverlap) {
+ overlapStart = std::min(overlapStart, os);
+ overlapEnd = std::max(overlapEnd, oe);
+ } else {
+ overlapStart = os;
+ overlapEnd = oe;
+ haveOverlap = true;
+ }
+ }
+
+ if (start > m_newSegment->getEndMarkerTime()) {
+ m_newSegment->setEndMarkerTime(start);
+ }
+
+ for (Segment::iterator si = s->begin();
+ s->isBeforeEndMarker(si); ++si) {
+
+ // weed out duplicate clefs and keys
+
+ if ((*si)->isa(Clef::EventType)) {
+ try {
+ Clef newClef(**si);
+ if (m_newSegment->getClefAtTime
+ ((*si)->getAbsoluteTime() + 1) == newClef) {
+ continue;
+ }
+ } catch (...) { }
+ }
+
+ if ((*si)->isa(Key::EventType)) {
+ try {
+ Key newKey(**si);
+ if (m_newSegment->getKeyAtTime
+ ((*si)->getAbsoluteTime() + 1) == newKey) {
+ continue;
+ }
+ } catch (...) { }
+ }
+
+ m_newSegment->insert(new Event(**si));
+ }
+
+ if (end > m_newSegment->getEndMarkerTime()) {
+ m_newSegment->setEndMarkerTime(end);
+ }
+ }
+ }
+
+ composition->addSegment(m_newSegment);
+
+ if (haveOverlap) {
+ m_newSegment->normalizeRests(overlapStart, overlapEnd);
+ }
+
+ for (unsigned int i = 0; i < m_oldSegments.size(); ++i) {
+ composition->detachSegment(m_oldSegments[i]);
+ }
+
+ m_detached = true;
+}
+
+void
+SegmentJoinCommand::unexecute()
+{
+ for (unsigned int i = 0; i < m_oldSegments.size(); ++i) {
+ m_newSegment->getComposition()->addSegment(m_oldSegments[i]);
+ }
+
+ m_newSegment->getComposition()->detachSegment(m_newSegment);
+ m_detached = false;
+}
+
+}
diff --git a/src/commands/segment/SegmentJoinCommand.h b/src/commands/segment/SegmentJoinCommand.h
new file mode 100644
index 0000000..97c7924
--- /dev/null
+++ b/src/commands/segment/SegmentJoinCommand.h
@@ -0,0 +1,65 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_SEGMENTJOINCOMMAND_H_
+#define _RG_SEGMENTJOINCOMMAND_H_
+
+#include <kcommand.h>
+#include <qstring.h>
+#include <vector>
+#include <klocale.h>
+
+
+
+
+namespace Rosegarden
+{
+
+class SegmentSelection;
+class Segment;
+
+
+class SegmentJoinCommand : public KNamedCommand
+{
+public:
+ SegmentJoinCommand(SegmentSelection &segments);
+ virtual ~SegmentJoinCommand();
+
+ virtual void execute();
+ virtual void unexecute();
+
+ static QString getGlobalName() { return i18n("&Join"); }
+
+private:
+ std::vector<Segment *> m_oldSegments;
+ Segment *m_newSegment;
+ bool m_detached;
+};
+
+
+
+}
+
+#endif
diff --git a/src/commands/segment/SegmentLabelCommand.cpp b/src/commands/segment/SegmentLabelCommand.cpp
new file mode 100644
index 0000000..8bc0ff4
--- /dev/null
+++ b/src/commands/segment/SegmentLabelCommand.cpp
@@ -0,0 +1,73 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "SegmentLabelCommand.h"
+
+#include "misc/Strings.h"
+#include "base/Segment.h"
+#include "base/Selection.h"
+#include <qstring.h>
+
+
+namespace Rosegarden
+{
+
+SegmentLabelCommand::SegmentLabelCommand(
+ SegmentSelection &segments,
+ const QString &label):
+ KNamedCommand(i18n("Label Segments")),
+ m_newLabel(label)
+{
+ for (SegmentSelection::iterator i = segments.begin();
+ i != segments.end(); ++i)
+ m_segments.push_back(*i);
+}
+
+SegmentLabelCommand::~SegmentLabelCommand()
+{}
+
+void
+SegmentLabelCommand::execute()
+{
+ bool addLabels = false;
+ if (m_labels.size() == 0)
+ addLabels = true;
+
+ for (unsigned int i = 0; i < m_segments.size(); ++i) {
+ if (addLabels)
+ m_labels.push_back(strtoqstr(m_segments[i]->getLabel()));
+
+ m_segments[i]->setLabel(qstrtostr(m_newLabel));
+ }
+}
+
+void
+SegmentLabelCommand::unexecute()
+{
+ for (unsigned int i = 0; i < m_segments.size(); ++i)
+ m_segments[i]->setLabel(qstrtostr(m_labels[i]));
+}
+
+}
diff --git a/src/commands/segment/SegmentLabelCommand.h b/src/commands/segment/SegmentLabelCommand.h
new file mode 100644
index 0000000..1c55f3b
--- /dev/null
+++ b/src/commands/segment/SegmentLabelCommand.h
@@ -0,0 +1,67 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_SEGMENTLABELCOMMAND_H_
+#define _RG_SEGMENTLABELCOMMAND_H_
+
+#include <kcommand.h>
+#include <qstring.h>
+#include <vector>
+#include <klocale.h>
+
+
+
+
+namespace Rosegarden
+{
+
+class SegmentSelection;
+class Segment;
+
+
+class SegmentLabelCommand : public KNamedCommand
+{
+public:
+ SegmentLabelCommand(SegmentSelection &segments,
+ const QString &label);
+ virtual ~SegmentLabelCommand();
+
+ static QString getGlobalName()
+ { return i18n("Re&label..."); }
+
+ virtual void execute();
+ virtual void unexecute();
+protected:
+
+ std::vector<Segment*> m_segments;
+ std::vector<QString> m_labels;
+ QString m_newLabel;
+};
+
+
+
+}
+
+#endif
diff --git a/src/commands/segment/SegmentQuickCopyCommand.cpp b/src/commands/segment/SegmentQuickCopyCommand.cpp
new file mode 100644
index 0000000..1ce432c
--- /dev/null
+++ b/src/commands/segment/SegmentQuickCopyCommand.cpp
@@ -0,0 +1,71 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "SegmentQuickCopyCommand.h"
+
+#include "misc/Strings.h"
+#include "base/Composition.h"
+#include "base/Segment.h"
+#include <qstring.h>
+
+
+namespace Rosegarden
+{
+
+SegmentQuickCopyCommand::SegmentQuickCopyCommand(Segment *segment):
+ KNamedCommand(getGlobalName()),
+ m_composition(segment->getComposition()),
+ m_segmentToCopy(segment),
+ m_segment(0),
+ m_detached(false)
+{}
+
+SegmentQuickCopyCommand::~SegmentQuickCopyCommand()
+{
+ if (m_detached) {
+ delete m_segment;
+ }
+}
+
+void
+SegmentQuickCopyCommand::execute()
+{
+ if (!m_segment) {
+ m_segment = new Segment(*m_segmentToCopy);
+ m_segment->setLabel(qstrtostr(i18n("%1 (copied)").arg
+ (strtoqstr(m_segment->getLabel()))));
+ }
+ m_composition->addSegment(m_segment);
+ m_detached = false;
+}
+
+void
+SegmentQuickCopyCommand::unexecute()
+{
+ m_composition->detachSegment(m_segment);
+ m_detached = true;
+}
+
+}
diff --git a/src/commands/segment/SegmentQuickCopyCommand.h b/src/commands/segment/SegmentQuickCopyCommand.h
new file mode 100644
index 0000000..638b16a
--- /dev/null
+++ b/src/commands/segment/SegmentQuickCopyCommand.h
@@ -0,0 +1,68 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_SEGMENTQUICKCOPYCOMMAND_H_
+#define _RG_SEGMENTQUICKCOPYCOMMAND_H_
+
+#include <kcommand.h>
+#include <qstring.h>
+#include <klocale.h>
+
+
+
+
+namespace Rosegarden
+{
+
+class Segment;
+class Composition;
+
+
+class SegmentQuickCopyCommand : public KNamedCommand
+{
+public:
+ SegmentQuickCopyCommand(Segment *segment);
+ virtual ~SegmentQuickCopyCommand();
+
+ virtual void execute();
+ virtual void unexecute();
+
+ // return pointer to new copy
+ Segment* getCopy() { return m_segment; }
+
+ static QString getGlobalName() { return i18n("Quick-Copy Segment"); }
+
+private:
+ Composition *m_composition;
+ Segment *m_segmentToCopy;
+ Segment *m_segment;
+ bool m_detached;
+};
+
+
+
+}
+
+#endif
diff --git a/src/commands/segment/SegmentReconfigureCommand.cpp b/src/commands/segment/SegmentReconfigureCommand.cpp
new file mode 100644
index 0000000..ec9d1bd
--- /dev/null
+++ b/src/commands/segment/SegmentReconfigureCommand.cpp
@@ -0,0 +1,114 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "SegmentReconfigureCommand.h"
+
+#include "base/Segment.h"
+#include "base/Track.h"
+#include <qstring.h>
+
+
+namespace Rosegarden
+{
+
+SegmentReconfigureCommand::SegmentReconfigureCommand(QString name) :
+ KNamedCommand(name)
+{}
+
+SegmentReconfigureCommand::~SegmentReconfigureCommand()
+{}
+
+void
+SegmentReconfigureCommand::addSegment(Segment *segment,
+ timeT startTime,
+ timeT endMarkerTime,
+ TrackId track)
+{
+ SegmentRec record;
+ record.segment = segment;
+ record.startTime = startTime;
+ record.endMarkerTime = endMarkerTime;
+ record.track = track;
+ m_records.push_back(record);
+}
+
+void
+SegmentReconfigureCommand::addSegments(const SegmentRecSet &records)
+{
+ for (SegmentRecSet::const_iterator i = records.begin(); i != records.end(); ++i) {
+ m_records.push_back(*i);
+ }
+}
+
+void
+SegmentReconfigureCommand::execute()
+{
+ swap();
+}
+
+void
+SegmentReconfigureCommand::unexecute()
+{
+ swap();
+}
+
+void
+SegmentReconfigureCommand::swap()
+{
+ for (SegmentRecSet::iterator i = m_records.begin();
+ i != m_records.end(); ++i) {
+
+ // set the segment's values from the record, but set the
+ // previous values back in to the record for use in the
+ // next iteration of the execute/unexecute cycle.
+
+ // #1083496: look up both of the "old" values before we set
+ // anything, as setting the start time is likely to change the
+ // end marker time.
+
+ timeT prevStartTime = i->segment->getStartTime();
+ timeT prevEndMarkerTime = i->segment->getEndMarkerTime();
+
+ if (i->segment->getStartTime() != i->startTime) {
+ i->segment->setStartTime(i->startTime);
+ }
+
+ if (i->segment->getEndMarkerTime() != i->endMarkerTime) {
+ i->segment->setEndMarkerTime(i->endMarkerTime);
+ }
+
+ i->startTime = prevStartTime;
+ i->endMarkerTime = prevEndMarkerTime;
+
+ TrackId currentTrack = i->segment->getTrack();
+
+ if (currentTrack != i->track) {
+ i->segment->setTrack(i->track);
+ i->track = currentTrack;
+ }
+ }
+}
+
+}
diff --git a/src/commands/segment/SegmentReconfigureCommand.h b/src/commands/segment/SegmentReconfigureCommand.h
new file mode 100644
index 0000000..be82e47
--- /dev/null
+++ b/src/commands/segment/SegmentReconfigureCommand.h
@@ -0,0 +1,81 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_SEGMENTRECONFIGURECOMMAND_H_
+#define _RG_SEGMENTRECONFIGURECOMMAND_H_
+
+#include "base/Track.h"
+#include <kcommand.h>
+#include <qstring.h>
+#include <vector>
+#include "base/Event.h"
+
+
+
+
+namespace Rosegarden
+{
+
+class Segment;
+
+
+/**
+ * SegmentReconfigureCommand is a general-purpose command for
+ * moving, resizing or changing the track of one or more segments
+ */
+class SegmentReconfigureCommand : public KNamedCommand
+{
+public:
+ SegmentReconfigureCommand(QString name);
+ virtual ~SegmentReconfigureCommand();
+
+ struct SegmentRec {
+ Segment *segment;
+ timeT startTime;
+ timeT endMarkerTime;
+ TrackId track;
+ };
+ typedef std::vector<SegmentRec> SegmentRecSet;
+
+ void addSegment(Segment *segment,
+ timeT startTime,
+ timeT endMarkerTime,
+ TrackId track);
+
+ void addSegments(const SegmentRecSet &records);
+
+ void execute();
+ void unexecute();
+
+private:
+ SegmentRecSet m_records;
+ void swap();
+};
+
+
+
+}
+
+#endif
diff --git a/src/commands/segment/SegmentRecordCommand.cpp b/src/commands/segment/SegmentRecordCommand.cpp
new file mode 100644
index 0000000..f457f32
--- /dev/null
+++ b/src/commands/segment/SegmentRecordCommand.cpp
@@ -0,0 +1,67 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "SegmentRecordCommand.h"
+
+#include <klocale.h>
+#include "base/Composition.h"
+#include "base/Segment.h"
+
+
+namespace Rosegarden
+{
+
+SegmentRecordCommand::SegmentRecordCommand(Segment *s) :
+ KNamedCommand(i18n("Record")),
+ m_composition(s->getComposition()),
+ m_segment(s),
+ m_detached(false)
+{}
+
+SegmentRecordCommand::~SegmentRecordCommand()
+{
+ if (m_detached) {
+ delete m_segment;
+ }
+}
+
+void
+SegmentRecordCommand::execute()
+{
+ if (!m_segment->getComposition()) {
+ m_composition->addSegment(m_segment);
+ }
+
+ m_detached = false;
+}
+
+void
+SegmentRecordCommand::unexecute()
+{
+ m_composition->detachSegment(m_segment);
+ m_detached = true;
+}
+
+}
diff --git a/src/commands/segment/SegmentRecordCommand.h b/src/commands/segment/SegmentRecordCommand.h
new file mode 100644
index 0000000..c3f4ffe
--- /dev/null
+++ b/src/commands/segment/SegmentRecordCommand.h
@@ -0,0 +1,67 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_SEGMENTRECORDCOMMAND_H_
+#define _RG_SEGMENTRECORDCOMMAND_H_
+
+#include <kcommand.h>
+
+
+
+
+namespace Rosegarden
+{
+
+class Segment;
+class Composition;
+
+
+/**
+ * SegmentRecordCommand pretends to insert a Segment that is actually
+ * already in the Composition (the currently-being-recorded one). It's
+ * used at the end of recording, to ensure that GUI updates happen
+ * correctly, and it provides the ability to undo recording. (The
+ * unexecute does remove the segment, it doesn't just pretend to.)
+ */
+class SegmentRecordCommand : public KNamedCommand
+{
+public:
+ SegmentRecordCommand(Segment *segment);
+ virtual ~SegmentRecordCommand();
+
+ virtual void execute();
+ virtual void unexecute();
+
+private:
+ Composition *m_composition;
+ Segment *m_segment;
+ bool m_detached;
+};
+
+
+
+}
+
+#endif
diff --git a/src/commands/segment/SegmentRepeatToCopyCommand.cpp b/src/commands/segment/SegmentRepeatToCopyCommand.cpp
new file mode 100644
index 0000000..a0e0e43
--- /dev/null
+++ b/src/commands/segment/SegmentRepeatToCopyCommand.cpp
@@ -0,0 +1,106 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "SegmentRepeatToCopyCommand.h"
+
+#include "base/Event.h"
+#include <klocale.h>
+#include "base/Composition.h"
+#include "base/Segment.h"
+
+
+namespace Rosegarden
+{
+
+SegmentRepeatToCopyCommand::SegmentRepeatToCopyCommand(
+ Segment *segment):
+ KNamedCommand(i18n("Turn Repeats into Copies")),
+ m_composition(segment->getComposition()),
+ m_segment(segment),
+ m_detached(false)
+{}
+
+SegmentRepeatToCopyCommand::~SegmentRepeatToCopyCommand()
+{
+ if (m_detached) {
+ std::vector<Segment*>::iterator it =
+ m_newSegments.begin();
+
+ for (; it != m_newSegments.end(); it++)
+ delete (*it);
+ }
+}
+
+void
+SegmentRepeatToCopyCommand::execute()
+{
+ if (m_newSegments.size() == 0) {
+ timeT newStartTime = m_segment->getEndMarkerTime();
+ timeT newDuration =
+ m_segment->getEndMarkerTime() - m_segment->getStartTime();
+ Segment *newSegment;
+ timeT repeatEndTime = m_segment->getRepeatEndTime();
+
+ while (newStartTime + newDuration < repeatEndTime) {
+ // Create new segment, transpose and turn off repeat
+ //
+ newSegment = new Segment(*m_segment);
+ newSegment->setStartTime(newStartTime);
+ newSegment->setRepeating(false);
+
+ // Insert and store
+ m_composition->addSegment(newSegment);
+ m_newSegments.push_back(newSegment);
+
+ // Move onto next
+ newStartTime += newDuration;
+ }
+
+ // fill remaining partial segment
+ } else {
+ std::vector<Segment*>::iterator it =
+ m_newSegments.begin();
+
+ for (; it != m_newSegments.end(); it++)
+ m_composition->addSegment(*it);
+ }
+ m_segment->setRepeating(false);
+ m_detached = false;
+}
+
+void
+SegmentRepeatToCopyCommand::unexecute()
+{
+ std::vector<Segment*>::iterator it =
+ m_newSegments.begin();
+
+ for (; it != m_newSegments.end(); it++)
+ m_composition->detachSegment(*it);
+
+ m_detached = true;
+ m_segment->setRepeating(true);
+}
+
+}
diff --git a/src/commands/segment/SegmentRepeatToCopyCommand.h b/src/commands/segment/SegmentRepeatToCopyCommand.h
new file mode 100644
index 0000000..d0cc565
--- /dev/null
+++ b/src/commands/segment/SegmentRepeatToCopyCommand.h
@@ -0,0 +1,62 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_SEGMENTREPEATTOCOPYCOMMAND_H_
+#define _RG_SEGMENTREPEATTOCOPYCOMMAND_H_
+
+#include <kcommand.h>
+#include <vector>
+
+
+
+
+namespace Rosegarden
+{
+
+class Segment;
+class Composition;
+
+
+class SegmentRepeatToCopyCommand : public KNamedCommand
+{
+public:
+ SegmentRepeatToCopyCommand(Segment *segment);
+ virtual ~SegmentRepeatToCopyCommand();
+
+ virtual void execute();
+ virtual void unexecute();
+
+private:
+
+ Composition *m_composition;
+ Segment *m_segment;
+ std::vector<Segment*> m_newSegments;
+ bool m_detached;
+};
+
+
+}
+
+#endif
diff --git a/src/commands/segment/SegmentRescaleCommand.cpp b/src/commands/segment/SegmentRescaleCommand.cpp
new file mode 100644
index 0000000..d7a7c80
--- /dev/null
+++ b/src/commands/segment/SegmentRescaleCommand.cpp
@@ -0,0 +1,148 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "SegmentRescaleCommand.h"
+
+#include "misc/Strings.h"
+#include "base/Event.h"
+#include "base/Composition.h"
+#include "base/NotationTypes.h"
+#include "base/Segment.h"
+#include <qstring.h>
+
+
+namespace Rosegarden
+{
+
+SegmentRescaleCommand::SegmentRescaleCommand(Segment *s,
+ int multiplier,
+ int divisor) :
+ KNamedCommand(getGlobalName()),
+ m_segment(s),
+ m_newSegment(0),
+ m_startTimeGiven(false),
+ m_startTime(s->getStartTime()),
+ m_multiplier(multiplier),
+ m_divisor(divisor),
+ m_detached(false)
+{
+ // nothing
+}
+
+SegmentRescaleCommand::SegmentRescaleCommand(Segment *s,
+ int multiplier,
+ int divisor,
+ timeT st) :
+ KNamedCommand(getGlobalName()),
+ m_segment(s),
+ m_newSegment(0),
+ m_startTimeGiven(true),
+ m_startTime(st),
+ m_multiplier(multiplier),
+ m_divisor(divisor),
+ m_detached(false)
+{
+ // nothing
+}
+
+SegmentRescaleCommand::~SegmentRescaleCommand()
+{
+ if (m_detached) {
+ delete m_segment;
+ } else {
+ delete m_newSegment;
+ }
+}
+
+timeT
+SegmentRescaleCommand::rescale(timeT t)
+{
+ // avoid overflows by using doubles
+ double d = t;
+ d *= m_multiplier;
+ d /= m_divisor;
+ d += 0.5;
+ return (timeT)d;
+}
+
+void
+SegmentRescaleCommand::execute()
+{
+ timeT startTime = m_segment->getStartTime();
+
+ if (m_startTimeGiven) startTime = m_startTime;
+
+ if (!m_newSegment) {
+
+ m_newSegment = new Segment();
+ m_newSegment->setTrack(m_segment->getTrack());
+ QString oldLabel = strtoqstr(m_segment->getLabel());
+ if (oldLabel.endsWith(i18n("(rescaled)"))) {
+ m_newSegment->setLabel(m_segment->getLabel());
+ } else {
+ m_newSegment->setLabel(qstrtostr(i18n("%1 (rescaled)").arg
+ (oldLabel)));
+ }
+ m_newSegment->setColourIndex(m_segment->getColourIndex());
+
+ for (Segment::iterator i = m_segment->begin();
+ m_segment->isBeforeEndMarker(i); ++i) {
+
+ if ((*i)->isa(Note::EventRestType))
+ continue;
+
+ timeT dt = (*i)->getAbsoluteTime() - startTime;
+ timeT duration = (*i)->getDuration();
+
+ //!!! use doubles for this calculation where necessary
+
+ m_newSegment->insert
+ (new Event(**i,
+ startTime + rescale(dt),
+ rescale(duration)));
+ }
+ }
+
+ m_segment->getComposition()->addSegment(m_newSegment);
+ m_segment->getComposition()->detachSegment(m_segment);
+ m_newSegment->normalizeRests(m_newSegment->getStartTime(),
+ m_newSegment->getEndTime());
+
+ m_newSegment->setEndMarkerTime
+ (startTime + rescale(m_segment->getEndMarkerTime() -
+ m_segment->getStartTime()));
+
+ m_detached = true;
+}
+
+void
+SegmentRescaleCommand::unexecute()
+{
+ m_newSegment->getComposition()->addSegment(m_segment);
+ m_newSegment->getComposition()->detachSegment(m_newSegment);
+ m_detached = false;
+}
+
+}
diff --git a/src/commands/segment/SegmentRescaleCommand.h b/src/commands/segment/SegmentRescaleCommand.h
new file mode 100644
index 0000000..7a34727
--- /dev/null
+++ b/src/commands/segment/SegmentRescaleCommand.h
@@ -0,0 +1,76 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_SEGMENTRESCALECOMMAND_H_
+#define _RG_SEGMENTRESCALECOMMAND_H_
+
+#include <kcommand.h>
+#include <qstring.h>
+#include "base/Event.h"
+#include <klocale.h>
+
+
+
+
+namespace Rosegarden
+{
+
+class Segment;
+
+
+class SegmentRescaleCommand : public KNamedCommand
+{
+public:
+ SegmentRescaleCommand(Segment *segment,
+ int multiplier,
+ int divisor);
+ SegmentRescaleCommand(Segment *segment,
+ int multiplier,
+ int divisor,
+ timeT newStartTime);
+ virtual ~SegmentRescaleCommand();
+
+ virtual void execute();
+ virtual void unexecute();
+
+ static QString getGlobalName() { return i18n("Stretch or S&quash..."); }
+
+private:
+ Segment *m_segment;
+ Segment *m_newSegment;
+ bool m_startTimeGiven;
+ timeT m_startTime;
+ int m_multiplier;
+ int m_divisor;
+ bool m_detached;
+
+ timeT rescale(timeT);
+};
+
+
+
+}
+
+#endif
diff --git a/src/commands/segment/SegmentResizeFromStartCommand.cpp b/src/commands/segment/SegmentResizeFromStartCommand.cpp
new file mode 100644
index 0000000..a4157bb
--- /dev/null
+++ b/src/commands/segment/SegmentResizeFromStartCommand.cpp
@@ -0,0 +1,85 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "SegmentResizeFromStartCommand.h"
+
+#include <klocale.h>
+#include "base/Event.h"
+#include "base/Segment.h"
+#include "document/BasicCommand.h"
+
+
+namespace Rosegarden
+{
+
+SegmentResizeFromStartCommand::SegmentResizeFromStartCommand(Segment *s,
+ timeT time) :
+ BasicCommand(i18n("Resize Segment"), *s,
+ std::min(time, s->getStartTime()),
+ std::max(time, s->getStartTime())),
+ m_segment(s),
+ m_oldStartTime(s->getStartTime()),
+ m_newStartTime(time)
+{
+ // nothing else
+}
+
+SegmentResizeFromStartCommand::~SegmentResizeFromStartCommand()
+{
+ // nothing
+}
+
+void
+SegmentResizeFromStartCommand::modifySegment()
+{
+ if (m_newStartTime < m_oldStartTime) {
+ m_segment->fillWithRests(m_newStartTime, m_oldStartTime);
+ } else {
+
+ for (Segment::iterator i = m_segment->begin();
+ m_segment->isBeforeEndMarker(i); ) {
+
+ Segment::iterator j = i;
+ ++j;
+
+ if ((*i)->getAbsoluteTime() >= m_newStartTime)
+ break;
+
+ if ((*i)->getAbsoluteTime() + (*i)->getDuration() <= m_newStartTime) {
+ m_segment->erase(i);
+ } else {
+ Event *e = new Event
+ (**i, m_newStartTime,
+ (*i)->getAbsoluteTime() + (*i)->getDuration() - m_newStartTime);
+ m_segment->erase(i);
+ m_segment->insert(e);
+ }
+
+ i = j;
+ }
+ }
+}
+
+}
diff --git a/src/commands/segment/SegmentResizeFromStartCommand.h b/src/commands/segment/SegmentResizeFromStartCommand.h
new file mode 100644
index 0000000..8f0dc89
--- /dev/null
+++ b/src/commands/segment/SegmentResizeFromStartCommand.h
@@ -0,0 +1,69 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_SEGMENTRESIZEFROMSTARTCOMMAND_H_
+#define _RG_SEGMENTRESIZEFROMSTARTCOMMAND_H_
+
+#include "document/BasicCommand.h"
+#include "base/Event.h"
+
+
+
+
+namespace Rosegarden
+{
+
+class Segment;
+
+
+/**
+ * SegmentResizeFromStartCommand moves the start time of a segment
+ * leaving the events in it at the same absolute times as before, so
+ * padding with rests or deleting events as appropriate. (Distinct
+ * from Segment::setStartTime, as used by SegmentReconfigureCommand,
+ * which moves all the events in the segment.)
+ * Not for use on audio segments (see AudioSegmentResizeFromStartCommand).
+ */
+class SegmentResizeFromStartCommand : public BasicCommand
+{
+public:
+ SegmentResizeFromStartCommand(Segment *segment,
+ timeT newStartTime);
+ virtual ~SegmentResizeFromStartCommand();
+
+protected:
+ virtual void modifySegment();
+
+private:
+ Segment *m_segment;
+ timeT m_oldStartTime;
+ timeT m_newStartTime;
+};
+
+
+
+}
+
+#endif
diff --git a/src/commands/segment/SegmentSingleRepeatToCopyCommand.cpp b/src/commands/segment/SegmentSingleRepeatToCopyCommand.cpp
new file mode 100644
index 0000000..c9b92fb
--- /dev/null
+++ b/src/commands/segment/SegmentSingleRepeatToCopyCommand.cpp
@@ -0,0 +1,73 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "SegmentSingleRepeatToCopyCommand.h"
+
+#include <klocale.h>
+#include "base/Composition.h"
+#include "base/Segment.h"
+
+
+namespace Rosegarden
+{
+
+SegmentSingleRepeatToCopyCommand::SegmentSingleRepeatToCopyCommand(
+ Segment *segment,
+ timeT time):
+ KNamedCommand(i18n("Turn Single Repeat into Copy")),
+ m_composition(segment->getComposition()),
+ m_segment(segment),
+ m_newSegment(0),
+ m_time(time),
+ m_detached(false)
+{}
+
+SegmentSingleRepeatToCopyCommand::~SegmentSingleRepeatToCopyCommand()
+{
+ if (m_detached)
+ delete m_newSegment;
+}
+
+void
+SegmentSingleRepeatToCopyCommand::execute()
+{
+ if (!m_newSegment) {
+ m_newSegment = new Segment(*m_segment);
+ m_newSegment->setStartTime(m_time);
+ m_newSegment->setRepeating(true);
+ }
+
+ m_composition->addSegment(m_newSegment);
+ m_detached = false;
+}
+
+void
+SegmentSingleRepeatToCopyCommand::unexecute()
+{
+ m_composition->detachSegment(m_newSegment);
+ m_detached = true;
+}
+
+}
diff --git a/src/commands/segment/SegmentSingleRepeatToCopyCommand.h b/src/commands/segment/SegmentSingleRepeatToCopyCommand.h
new file mode 100644
index 0000000..0c4984e
--- /dev/null
+++ b/src/commands/segment/SegmentSingleRepeatToCopyCommand.h
@@ -0,0 +1,65 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_SEGMENTSINGLEREPEATTOCOPYCOMMAND_H_
+#define _RG_SEGMENTSINGLEREPEATTOCOPYCOMMAND_H_
+
+#include <kcommand.h>
+#include "base/Event.h"
+
+
+
+
+namespace Rosegarden
+{
+
+class Segment;
+class Composition;
+
+
+class SegmentSingleRepeatToCopyCommand : public KNamedCommand
+{
+public:
+ SegmentSingleRepeatToCopyCommand(Segment *segment,
+ timeT time);
+ virtual ~SegmentSingleRepeatToCopyCommand();
+
+ virtual void execute();
+ virtual void unexecute();
+
+ Segment *getNewSegment() const { return m_newSegment; }
+
+private:
+ Composition *m_composition;
+ Segment *m_segment;
+ Segment *m_newSegment;
+ timeT m_time;
+ bool m_detached;
+};
+
+
+}
+
+#endif
diff --git a/src/commands/segment/SegmentSplitByPitchCommand.cpp b/src/commands/segment/SegmentSplitByPitchCommand.cpp
new file mode 100644
index 0000000..2000a35
--- /dev/null
+++ b/src/commands/segment/SegmentSplitByPitchCommand.cpp
@@ -0,0 +1,280 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "SegmentSplitByPitchCommand.h"
+
+#include "base/BaseProperties.h"
+#include "base/Sets.h"
+#include "misc/Strings.h"
+#include "base/Composition.h"
+#include "base/Event.h"
+#include "base/NotationTypes.h"
+#include "base/NotationQuantizer.h"
+#include "base/Segment.h"
+#include "base/SegmentNotationHelper.h"
+#include <qstring.h>
+
+
+namespace Rosegarden
+{
+
+SegmentSplitByPitchCommand::SegmentSplitByPitchCommand(Segment *segment,
+ int p, bool r, bool d,
+ ClefHandling c) :
+ KNamedCommand(i18n("Split by Pitch")),
+ m_composition(segment->getComposition()),
+ m_segment(segment),
+ m_newSegmentA(0),
+ m_newSegmentB(0),
+ m_splitPitch(p),
+ m_ranging(r),
+ m_dupNonNoteEvents(d),
+ m_clefHandling(c),
+ m_executed(false)
+{}
+
+SegmentSplitByPitchCommand::~SegmentSplitByPitchCommand()
+{
+ if (m_executed) {
+ delete m_segment;
+ } else {
+ delete m_newSegmentA;
+ delete m_newSegmentB;
+ }
+}
+
+void
+SegmentSplitByPitchCommand::execute()
+{
+ if (!m_newSegmentA) {
+
+ m_newSegmentA = new Segment;
+ m_newSegmentB = new Segment;
+
+ m_newSegmentA->setTrack(m_segment->getTrack());
+ m_newSegmentA->setStartTime(m_segment->getStartTime());
+
+ m_newSegmentB->setTrack(m_segment->getTrack());
+ m_newSegmentB->setStartTime(m_segment->getStartTime());
+
+ int splitPitch(m_splitPitch);
+
+ for (Segment::iterator i = m_segment->begin();
+ m_segment->isBeforeEndMarker(i); ++i) {
+
+ if ((*i)->isa(Note::EventRestType))
+ continue;
+ if ((*i)->isa(Clef::EventType) &&
+ m_clefHandling != LeaveClefs)
+ continue;
+
+ if ((*i)->isa(Note::EventType)) {
+
+ if (m_ranging) {
+ splitPitch = getSplitPitchAt(i, splitPitch);
+ }
+
+ if ((*i)->has(BaseProperties::PITCH) &&
+ (*i)->get
+ <Int>(BaseProperties::PITCH) <
+ splitPitch) {
+ if (m_newSegmentB->empty()) {
+ m_newSegmentB->fillWithRests((*i)->getAbsoluteTime());
+ }
+ m_newSegmentB->insert(new Event(**i));
+ }
+ else {
+ if (m_newSegmentA->empty()) {
+ m_newSegmentA->fillWithRests((*i)->getAbsoluteTime());
+ }
+ m_newSegmentA->insert(new Event(**i));
+ }
+
+ } else {
+
+ m_newSegmentA->insert(new Event(**i));
+
+ if (m_dupNonNoteEvents) {
+ m_newSegmentB->insert(new Event(**i));
+ }
+ }
+ }
+
+ //!!! m_newSegmentA->fillWithRests(m_segment->getEndMarkerTime());
+ // m_newSegmentB->fillWithRests(m_segment->getEndMarkerTime());
+ m_newSegmentA->normalizeRests(m_segment->getStartTime(),
+ m_segment->getEndMarkerTime());
+ m_newSegmentB->normalizeRests(m_segment->getStartTime(),
+ m_segment->getEndMarkerTime());
+ }
+
+ m_composition->addSegment(m_newSegmentA);
+ m_composition->addSegment(m_newSegmentB);
+
+ SegmentNotationHelper helperA(*m_newSegmentA);
+ SegmentNotationHelper helperB(*m_newSegmentB);
+
+ if (m_clefHandling == RecalculateClefs) {
+
+ m_newSegmentA->insert
+ (helperA.guessClef(m_newSegmentA->begin(),
+ m_newSegmentA->end()).getAsEvent
+ (m_newSegmentA->getStartTime()));
+
+ m_newSegmentB->insert
+ (helperB.guessClef(m_newSegmentB->begin(),
+ m_newSegmentB->end()).getAsEvent
+ (m_newSegmentB->getStartTime()));
+
+ } else if (m_clefHandling == UseTrebleAndBassClefs) {
+
+ m_newSegmentA->insert
+ (Clef(Clef::Treble).getAsEvent
+ (m_newSegmentA->getStartTime()));
+
+ m_newSegmentB->insert
+ (Clef(Clef::Bass).getAsEvent
+ (m_newSegmentB->getStartTime()));
+ }
+
+ //!!! m_composition->getNotationQuantizer()->quantize(m_newSegmentA);
+ // m_composition->getNotationQuantizer()->quantize(m_newSegmentB);
+ helperA.autoBeam(m_newSegmentA->begin(), m_newSegmentA->end(),
+ BaseProperties::GROUP_TYPE_BEAMED);
+ helperB.autoBeam(m_newSegmentB->begin(), m_newSegmentB->end(),
+ BaseProperties::GROUP_TYPE_BEAMED);
+
+ std::string label = m_segment->getLabel();
+ m_newSegmentA->setLabel(qstrtostr(i18n("%1 (upper)").arg
+ (strtoqstr(label))));
+ m_newSegmentB->setLabel(qstrtostr(i18n("%1 (lower)").arg
+ (strtoqstr(label))));
+ m_newSegmentA->setColourIndex(m_segment->getColourIndex());
+ m_newSegmentB->setColourIndex(m_segment->getColourIndex());
+
+ m_composition->detachSegment(m_segment);
+ m_executed = true;
+}
+
+void
+SegmentSplitByPitchCommand::unexecute()
+{
+ m_composition->addSegment(m_segment);
+ m_composition->detachSegment(m_newSegmentA);
+ m_composition->detachSegment(m_newSegmentB);
+ m_executed = false;
+}
+
+int
+SegmentSplitByPitchCommand::getSplitPitchAt(Segment::iterator i,
+ int lastSplitPitch)
+{
+ typedef std::set<int>::iterator PitchItr;
+ std::set<int> pitches;
+
+ // when this algorithm appears to be working ok, we should be
+ // able to make it much quicker
+
+ const Quantizer *quantizer
+ (m_segment->getComposition()->getNotationQuantizer());
+
+ int myHighest, myLowest;
+ int prevHighest = 0, prevLowest = 0;
+ bool havePrev = false;
+
+ Chord c0(*m_segment, i, quantizer);
+ std::vector<int> c0p(c0.getPitches());
+ pitches.insert<std::vector<int>::iterator>(c0p.begin(), c0p.end());
+
+ myLowest = c0p[0];
+ myHighest = c0p[c0p.size() - 1];
+
+ Segment::iterator j(c0.getPreviousNote());
+ if (j != m_segment->end()) {
+
+ havePrev = true;
+
+ Chord c1(*m_segment, j, quantizer);
+ std::vector<int> c1p(c1.getPitches());
+ pitches.insert<std::vector<int>::iterator>(c1p.begin(), c1p.end());
+
+ prevLowest = c1p[0];
+ prevHighest = c1p[c1p.size() - 1];
+ }
+
+ if (pitches.size() < 2)
+ return lastSplitPitch;
+
+ PitchItr pi = pitches.begin();
+ int lowest(*pi);
+
+ pi = pitches.end();
+ --pi;
+ int highest(*pi);
+
+ if ((pitches.size() == 2 || highest - lowest <= 18) &&
+ myHighest > lastSplitPitch &&
+ myLowest < lastSplitPitch &&
+ prevHighest > lastSplitPitch &&
+ prevLowest < lastSplitPitch) {
+
+ if (havePrev) {
+ if ((myLowest > prevLowest && myHighest > prevHighest) ||
+ (myLowest < prevLowest && myHighest < prevHighest)) {
+ int avgDiff = ((myLowest - prevLowest) +
+ (myHighest - prevHighest)) / 2;
+ if (avgDiff < -5)
+ avgDiff = -5;
+ if (avgDiff > 5)
+ avgDiff = 5;
+ return lastSplitPitch + avgDiff;
+ }
+ }
+
+ return lastSplitPitch;
+ }
+
+ int middle = (highest - lowest) / 2 + lowest;
+
+ while (lastSplitPitch > middle && lastSplitPitch > m_splitPitch - 12) {
+ if (lastSplitPitch - lowest < 12)
+ return lastSplitPitch;
+ if (lastSplitPitch <= m_splitPitch - 12)
+ return lastSplitPitch;
+ --lastSplitPitch;
+ }
+
+ while (lastSplitPitch < middle && lastSplitPitch < m_splitPitch + 12) {
+ if (highest - lastSplitPitch < 12)
+ return lastSplitPitch;
+ if (lastSplitPitch >= m_splitPitch + 12)
+ return lastSplitPitch;
+ ++lastSplitPitch;
+ }
+
+ return lastSplitPitch;
+}
+
+}
diff --git a/src/commands/segment/SegmentSplitByPitchCommand.h b/src/commands/segment/SegmentSplitByPitchCommand.h
new file mode 100644
index 0000000..e536be6
--- /dev/null
+++ b/src/commands/segment/SegmentSplitByPitchCommand.h
@@ -0,0 +1,83 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_SEGMENTSPLITBYPITCHCOMMAND_H_
+#define _RG_SEGMENTSPLITBYPITCHCOMMAND_H_
+
+#include "base/Segment.h"
+#include <kcommand.h>
+#include <qstring.h>
+#include <klocale.h>
+#include "gui/general/ClefIndex.h"
+
+
+
+
+namespace Rosegarden
+{
+
+class Composition;
+
+
+class SegmentSplitByPitchCommand : public KNamedCommand
+{
+public:
+ enum ClefHandling {
+ LeaveClefs,
+ RecalculateClefs,
+ UseTrebleAndBassClefs
+ };
+
+ SegmentSplitByPitchCommand(Segment *segment,
+ int splitPitch,
+ bool ranging,
+ bool duplicateNonNoteEvents,
+ ClefHandling clefHandling);
+ virtual ~SegmentSplitByPitchCommand();
+
+ static QString getGlobalName()
+ { return i18n("Split by &Pitch..."); }
+
+ virtual void execute();
+ virtual void unexecute();
+
+private:
+ int getSplitPitchAt(Segment::iterator i, int lastSplitPitch);
+
+ Composition *m_composition;
+ Segment *m_segment;
+ Segment *m_newSegmentA;
+ Segment *m_newSegmentB;
+ int m_splitPitch;
+ bool m_ranging;
+ bool m_dupNonNoteEvents;
+ ClefHandling m_clefHandling;
+ bool m_executed;
+};
+
+
+}
+
+#endif
diff --git a/src/commands/segment/SegmentSplitByRecordingSrcCommand.cpp b/src/commands/segment/SegmentSplitByRecordingSrcCommand.cpp
new file mode 100644
index 0000000..fbb3c1b
--- /dev/null
+++ b/src/commands/segment/SegmentSplitByRecordingSrcCommand.cpp
@@ -0,0 +1,153 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "SegmentSplitByRecordingSrcCommand.h"
+
+#include "base/BaseProperties.h"
+#include "misc/Strings.h"
+#include "base/Composition.h"
+#include "base/Event.h"
+#include "base/NotationTypes.h"
+#include "base/Segment.h"
+#include <qstring.h>
+
+
+namespace Rosegarden
+{
+
+SegmentSplitByRecordingSrcCommand::SegmentSplitByRecordingSrcCommand (
+ Segment *segment, int channel, int device ) :
+ KNamedCommand(i18n("Split by Recording Source")),
+ m_composition(segment->getComposition()),
+ m_segment(segment),
+ m_newSegmentA(0),
+ m_channel(channel),
+ m_device(device),
+ m_executed(false)
+{}
+
+void
+SegmentSplitByRecordingSrcCommand::execute()
+{
+ if (!m_newSegmentA) {
+
+ m_newSegmentA = new Segment;
+ m_newSegmentB = new Segment;
+
+ m_newSegmentA->setTrack(m_segment->getTrack());
+ m_newSegmentA->setStartTime(m_segment->getStartTime());
+
+ m_newSegmentB->setTrack(m_segment->getTrack());
+ m_newSegmentB->setStartTime(m_segment->getStartTime());
+
+ bool selectedC = false;
+ bool selectedD = false;
+
+ for (Segment::iterator i = m_segment->begin();
+ m_segment->isBeforeEndMarker(i); ++i) {
+
+ if ((*i)->isa(Note::EventRestType))
+ continue;
+
+ if ( (*i)->isa(Clef::EventType) ||
+ (*i)->isa(Key::EventType) ) {
+
+ m_newSegmentA->insert(new Event(**i));
+ m_newSegmentB->insert(new Event(**i));
+ continue;
+ }
+
+ selectedC = false;
+ selectedD = false;
+
+ if ((*i)->has(BaseProperties::RECORDED_CHANNEL)) {
+ selectedC = true;
+ if (m_channel > -1)
+ selectedC = ( m_channel ==
+ (*i)->get
+ <Int>(BaseProperties::RECORDED_CHANNEL) );
+ }
+
+ if ((*i)->has(BaseProperties::RECORDED_PORT)) {
+ selectedD = true;
+ if (m_device > -1)
+ selectedD = ( m_device ==
+ (*i)->get
+ <Int>(BaseProperties::RECORDED_PORT) );
+ }
+
+ if (selectedC & selectedD) {
+ if (m_newSegmentB->empty()) {
+ m_newSegmentB->fillWithRests((*i)->getAbsoluteTime());
+ }
+ m_newSegmentB->insert(new Event(**i));
+ } else {
+ if (m_newSegmentA->empty()) {
+ m_newSegmentA->fillWithRests((*i)->getAbsoluteTime());
+ }
+ m_newSegmentA->insert(new Event(**i));
+ }
+ }
+
+ m_newSegmentA->normalizeRests(m_segment->getStartTime(),
+ m_segment->getEndMarkerTime());
+ m_newSegmentB->normalizeRests(m_segment->getStartTime(),
+ m_segment->getEndMarkerTime());
+
+ std::string label = m_segment->getLabel();
+ m_newSegmentA->setLabel(qstrtostr(i18n("%1 (split)").arg
+ (strtoqstr(label))));
+ m_newSegmentB->setLabel(qstrtostr(i18n("%1 (split)").arg
+ (strtoqstr(label))));
+ m_newSegmentA->setColourIndex(m_segment->getColourIndex());
+ m_newSegmentB->setColourIndex(m_segment->getColourIndex());
+ }
+
+ m_composition->addSegment(m_newSegmentA);
+ m_composition->addSegment(m_newSegmentB);
+ m_composition->detachSegment(m_segment);
+ m_executed = true;
+}
+
+void
+SegmentSplitByRecordingSrcCommand::unexecute()
+{
+ m_composition->addSegment(m_segment);
+ m_composition->detachSegment(m_newSegmentA);
+ m_composition->detachSegment(m_newSegmentB);
+ m_executed = false;
+}
+
+SegmentSplitByRecordingSrcCommand::~SegmentSplitByRecordingSrcCommand()
+{
+ if (m_executed) {
+ delete m_segment;
+ } else {
+ delete m_newSegmentA;
+ delete m_newSegmentB;
+ }
+}
+
+}
diff --git a/src/commands/segment/SegmentSplitByRecordingSrcCommand.h b/src/commands/segment/SegmentSplitByRecordingSrcCommand.h
new file mode 100644
index 0000000..3b087ab
--- /dev/null
+++ b/src/commands/segment/SegmentSplitByRecordingSrcCommand.h
@@ -0,0 +1,70 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_SEGMENTSPLITBYRECORDINGSRCCOMMAND_H_
+#define _RG_SEGMENTSPLITBYRECORDINGSRCCOMMAND_H_
+
+#include <kcommand.h>
+#include <qstring.h>
+#include <klocale.h>
+#include "gui/application/RosegardenDCOP.h"
+
+
+
+
+namespace Rosegarden
+{
+
+class Segment;
+class Composition;
+
+
+class SegmentSplitByRecordingSrcCommand : public KNamedCommand
+{
+public:
+ SegmentSplitByRecordingSrcCommand(Segment *segment,
+ int channel, int device);
+ virtual ~SegmentSplitByRecordingSrcCommand();
+
+ static QString getGlobalName()
+ { return i18n("Split by &Recording Source..."); }
+
+ virtual void execute();
+ virtual void unexecute();
+
+private:
+ Composition *m_composition;
+ Segment *m_segment;
+ Segment *m_newSegmentA;
+ Segment *m_newSegmentB;
+ int m_channel;
+ int m_device;
+ bool m_executed;
+};
+
+
+}
+
+#endif
diff --git a/src/commands/segment/SegmentSplitCommand.cpp b/src/commands/segment/SegmentSplitCommand.cpp
new file mode 100644
index 0000000..450ad3e
--- /dev/null
+++ b/src/commands/segment/SegmentSplitCommand.cpp
@@ -0,0 +1,185 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "SegmentSplitCommand.h"
+
+#include <klocale.h>
+#include "misc/Strings.h"
+#include "base/Event.h"
+#include "base/Composition.h"
+#include "base/NotationTypes.h"
+#include "base/Segment.h"
+#include <qstring.h>
+
+
+namespace Rosegarden
+{
+
+SegmentSplitCommand::SegmentSplitCommand(Segment *segment,
+ timeT splitTime) :
+ KNamedCommand(i18n("Split Segment")),
+ m_segment(segment),
+ m_newSegmentA(0),
+ m_newSegmentB(0),
+ m_splitTime(splitTime),
+ m_previousEndMarkerTime(0),
+ m_detached(true)
+{}
+
+SegmentSplitCommand::~SegmentSplitCommand()
+{
+ if (m_detached) {
+ delete m_newSegmentA;
+ delete m_newSegmentB;
+ }
+ delete m_previousEndMarkerTime;
+}
+
+void
+SegmentSplitCommand::execute()
+{
+ if (m_newSegmentA) {
+
+ m_segment->getComposition()->addSegment(m_newSegmentA);
+ m_segment->getComposition()->addSegment(m_newSegmentB);
+
+ m_segment->getComposition()->detachSegment(m_segment);
+
+ m_detached = false; // i.e. new segments are not detached
+ return;
+ }
+
+ m_newSegmentA = new Segment(*m_segment);
+ m_newSegmentB = new Segment();
+
+ m_newSegmentB->setTrack(m_segment->getTrack());
+ m_newSegmentB->setStartTime(m_splitTime);
+
+ m_segment->getComposition()->addSegment(m_newSegmentA);
+ m_segment->getComposition()->addSegment(m_newSegmentB);
+
+ Event *clefEvent = 0;
+ Event *keyEvent = 0;
+
+ // Copy the last occurrence of clef and key
+ // from the left hand side of the split (nb. timesig events
+ // don't appear in segments, only in composition)
+ //
+ Segment::iterator it = m_segment->findTime(m_splitTime);
+
+ while (it != m_segment->begin()) {
+
+ --it;
+
+ if (!clefEvent && (*it)->isa(Clef::EventType)) {
+ clefEvent = new Event(**it, m_splitTime);
+ }
+
+ if (!keyEvent && (*it)->isa(Key::EventType)) {
+ keyEvent = new Event(**it, m_splitTime);
+ }
+
+ if (clefEvent && keyEvent)
+ break;
+ }
+
+ // Insert relevant meta info if we've found some
+ //
+ if (clefEvent)
+ m_newSegmentB->insert(clefEvent);
+
+ if (keyEvent)
+ m_newSegmentB->insert(keyEvent);
+
+ // Copy through the Events
+ //
+ it = m_segment->findTime(m_splitTime);
+
+ if (it != m_segment->end() && (*it)->getAbsoluteTime() > m_splitTime) {
+ m_newSegmentB->fillWithRests((*it)->getAbsoluteTime());
+ }
+
+ while (it != m_segment->end()) {
+ m_newSegmentB->insert(new Event(**it));
+ ++it;
+ }
+ m_newSegmentB->setEndTime(m_segment->getEndTime());
+ m_newSegmentB->setEndMarkerTime(m_segment->getEndMarkerTime());
+
+ // Set labels
+ //
+ m_segmentLabel = m_segment->getLabel();
+ QString newLabel = strtoqstr(m_segmentLabel);
+ if (!newLabel.endsWith(i18n(" (split)"))) {
+ newLabel = i18n("%1 (split)").arg(newLabel);
+ }
+ m_newSegmentA->setLabel(newLabel);
+ m_newSegmentB->setLabel(newLabel);
+
+ m_newSegmentB->setColourIndex(m_segment->getColourIndex());
+ m_newSegmentB->setTranspose(m_segment->getTranspose());
+ m_newSegmentB->setDelay(m_segment->getDelay());
+
+ // Resize left hand Segment
+ //
+ std::vector<Event *> toErase, toInsert;
+ for (Segment::iterator i = m_newSegmentA->findTime(m_splitTime);
+ i != m_newSegmentA->end(); ++i) {
+ if ((*i)->getAbsoluteTime() >= m_splitTime) break;
+ if ((*i)->getAbsoluteTime() + (*i)->getDuration() > m_splitTime) {
+ Event *e = new Event(**i, (*i)->getAbsoluteTime(),
+ m_splitTime - (*i)->getAbsoluteTime());
+ toErase.push_back(*i);
+ toInsert.push_back(e);
+ }
+ }
+
+ for (int i = 0; i < toErase.size(); ++i) {
+ m_newSegmentA->eraseSingle(toErase[i]);
+ delete toErase[i];
+ }
+ for (int i = 0; i < toInsert.size(); ++i) {
+ m_newSegmentA->insert(toInsert[i]);
+ }
+
+ m_newSegmentA->setEndTime(m_splitTime);
+
+ m_segment->getComposition()->detachSegment(m_segment);
+
+ m_detached = false; // i.e. new segments are not detached
+}
+
+void
+SegmentSplitCommand::unexecute()
+{
+ m_newSegmentA->getComposition()->addSegment(m_segment);
+
+ m_segment->getComposition()->detachSegment(m_newSegmentA);
+ m_segment->getComposition()->detachSegment(m_newSegmentB);
+
+ m_detached = true; // i.e. new segments are not detached
+}
+
+}
diff --git a/src/commands/segment/SegmentSplitCommand.h b/src/commands/segment/SegmentSplitCommand.h
new file mode 100644
index 0000000..8b59b76
--- /dev/null
+++ b/src/commands/segment/SegmentSplitCommand.h
@@ -0,0 +1,65 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_SEGMENTSPLITCOMMAND_H_
+#define _RG_SEGMENTSPLITCOMMAND_H_
+
+#include <string>
+#include <kcommand.h>
+#include "base/Event.h"
+
+
+
+
+namespace Rosegarden
+{
+
+class Segment;
+
+
+class SegmentSplitCommand : public KNamedCommand
+{
+public:
+ SegmentSplitCommand(Segment *segment,
+ timeT splitTime);
+ virtual ~SegmentSplitCommand();
+
+ virtual void execute();
+ virtual void unexecute();
+
+private:
+ Segment *m_segment;
+ Segment *m_newSegmentA;
+ Segment *m_newSegmentB;
+ timeT m_splitTime;
+ timeT *m_previousEndMarkerTime;
+ bool m_detached;
+ std::string m_segmentLabel;
+};
+
+
+}
+
+#endif
diff --git a/src/commands/segment/SegmentSyncClefCommand.cpp b/src/commands/segment/SegmentSyncClefCommand.cpp
new file mode 100644
index 0000000..5e3560b
--- /dev/null
+++ b/src/commands/segment/SegmentSyncClefCommand.cpp
@@ -0,0 +1,67 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "SegmentSyncClefCommand.h"
+
+#include "base/Selection.h"
+#include "commands/notation/ClefInsertionCommand.h"
+
+namespace Rosegarden
+{
+SegmentSyncClefCommand::SegmentSyncClefCommand(Segment &segment, const Clef& clef) :
+ KMacroCommand(i18n("Sync segment clef"))
+{
+ processSegment(segment, clef);
+}
+
+void
+SegmentSyncClefCommand::processSegment(Segment &segment, const Clef& clef)
+{
+ KMacroCommand * macroCommand = this;
+
+ // TODO delete it somewhere.
+ EventSelection * wholeSegment = new EventSelection(segment, segment.getStartTime(), segment.getEndMarkerTime());
+
+ EventSelection::eventcontainer::iterator i;
+
+ for (i = wholeSegment->getSegmentEvents().begin();
+ i != wholeSegment->getSegmentEvents().end(); ++i) {
+ if ((*i)->isa(Rosegarden::Clef::EventType)) {
+ macroCommand->addCommand
+ (new ClefInsertionCommand
+ (segment,
+ (*i)->getAbsoluteTime(),
+ clef, false, false));
+ }
+ }
+
+}
+
+
+SegmentSyncClefCommand::~SegmentSyncClefCommand()
+{}
+
+
+}
diff --git a/src/commands/segment/SegmentSyncClefCommand.h b/src/commands/segment/SegmentSyncClefCommand.h
new file mode 100644
index 0000000..01b97fd
--- /dev/null
+++ b/src/commands/segment/SegmentSyncClefCommand.h
@@ -0,0 +1,55 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_SEGMENTSYNCCLEFCOMMAND_H_
+#define _RG_SEGMENTSYNCCLEFCOMMAND_H_
+
+#include <kcommand.h>
+#include "base/Event.h"
+#include "base/NotationTypes.h"
+#include "document/MultiViewCommandHistory.h"
+#include <klocale.h>
+
+namespace Rosegarden
+{
+
+class Segment;
+class SegmentSelection;
+
+
+class SegmentSyncClefCommand : public KMacroCommand
+{
+public:
+ SegmentSyncClefCommand(Segment &segment, const Clef& clef);
+
+ virtual ~SegmentSyncClefCommand();
+
+protected:
+ void processSegment(Segment &segment, const Clef& clef);
+};
+
+}
+
+#endif
diff --git a/src/commands/segment/SegmentSyncCommand.cpp b/src/commands/segment/SegmentSyncCommand.cpp
new file mode 100644
index 0000000..d5e9734
--- /dev/null
+++ b/src/commands/segment/SegmentSyncCommand.cpp
@@ -0,0 +1,103 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2007
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "SegmentSyncCommand.h"
+
+#include "base/Selection.h"
+#include "commands/notation/KeyInsertionCommand.h"
+#include "commands/edit/TransposeCommand.h"
+#include "commands/segment/SegmentChangeTransposeCommand.h"
+#include "commands/segment/SegmentTransposeCommand.h"
+#include "commands/segment/SegmentSyncClefCommand.h"
+
+namespace Rosegarden
+{
+SegmentSyncCommand::SegmentSyncCommand(Segment &segment, int newTranspose, int lowRange, int highRange, const Clef& clef) :
+ KMacroCommand(i18n("Sync segment parameters"))
+{
+ processSegment(segment, newTranspose, lowRange, highRange, clef);
+}
+
+SegmentSyncCommand::SegmentSyncCommand(SegmentSelection selection, int newTranspose, int lowRange, int highRange, const Clef& clef) :
+ KMacroCommand(i18n("Sync segment parameters"))
+{
+ for (SegmentSelection::iterator i = selection.begin();
+ i != selection.end(); ++i)
+ {
+ Segment &segment = **i;
+ processSegment(segment, newTranspose, lowRange, highRange, clef);
+ }
+}
+
+SegmentSyncCommand::SegmentSyncCommand(std::vector<Segment *> segments, int newTranspose, int lowRange, int highRange, const Clef& clef) :
+ KMacroCommand(i18n("Sync segment parameters"))
+{
+ for (int i = 0; i < segments.size(); i++) {
+ processSegment(*(segments[i]), newTranspose, lowRange, highRange, clef);
+ }
+}
+
+SegmentSyncCommand::SegmentSyncCommand(Composition::segmentcontainer& segments, TrackId selectedTrack, int newTranspose, int lowRange, int highRange, const Clef& clef) :
+ KMacroCommand(i18n("Sync segment parameters"))
+{
+ for (Composition::segmentcontainer::const_iterator si = segments.begin();
+ si != segments.end(); ++si) {
+ if ((*si)->getTrack() == selectedTrack) {
+ processSegment(**si, newTranspose, lowRange, highRange, clef);
+ }
+ }
+}
+
+void
+SegmentSyncCommand::processSegment(Segment &segment, int newTranspose, int lowRange, int highRange, const Clef& clef)
+{
+ KMacroCommand * macroCommand = this;
+
+ // if the new desired setting for 'transpose' is higher, we need to
+ // transpose the notes upwards to compensate:
+ int semitones = segment.getTranspose() - newTranspose;
+
+ // Say the old transpose was -2 and the new is 0, this corresponds to
+ // Bb and C. The height of the old transpose is 1 below the height of the new.
+ int oldHeight = Pitch(segment.getTranspose()).getHeightOnStaff(Clef::Treble, Key("C major"));
+ int newHeight = Pitch(newTranspose).getHeightOnStaff(Clef::Treble, Key("C major"));
+ int steps = oldHeight - newHeight;
+
+ SegmentTransposeCommand* command = new SegmentTransposeCommand(segment, true, steps, semitones, true);
+ macroCommand->addCommand(command);
+
+ // TODO do this in an undoable fashion:
+ segment.setLowestPlayable(lowRange);
+ segment.setHighestPlayable(highRange);
+
+ macroCommand->addCommand(new SegmentSyncClefCommand(segment, clef));
+}
+
+
+SegmentSyncCommand::~SegmentSyncCommand()
+{}
+
+
+}
diff --git a/src/commands/segment/SegmentSyncCommand.h b/src/commands/segment/SegmentSyncCommand.h
new file mode 100644
index 0000000..0d8e189
--- /dev/null
+++ b/src/commands/segment/SegmentSyncCommand.h
@@ -0,0 +1,66 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2007
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_SEGMENTSYNCCOMMAND_H_
+#define _RG_SEGMENTSYNCCOMMAND_H_
+
+#include <kcommand.h>
+#include "base/Composition.h"
+#include "base/Event.h"
+#include "base/NotationTypes.h"
+#include "document/MultiViewCommandHistory.h"
+#include <klocale.h>
+
+namespace Rosegarden
+{
+
+class Segment;
+class SegmentSelection;
+
+
+class SegmentSyncCommand : public KMacroCommand
+{
+public:
+ SegmentSyncCommand(Segment &segment,
+ int newTranspose, int lowRange, int highRange, const Clef& clef);
+
+ SegmentSyncCommand(SegmentSelection selection,
+ int newTranspose, int lowRange, int highRange, const Clef& clef);
+
+ SegmentSyncCommand(std::vector<Segment *> segments,
+ int newTranspose, int lowRange, int highRange, const Clef& clef);
+
+ SegmentSyncCommand(Composition::segmentcontainer& segments, TrackId track,
+ int newTranspose, int lowRange, int highRange, const Clef& clef);
+
+ virtual ~SegmentSyncCommand();
+
+protected:
+ void processSegment(Segment &segment, int newTranspose, int lowRange, int highRange, const Clef& clef);
+};
+
+}
+
+#endif
diff --git a/src/commands/segment/SegmentTransposeCommand.cpp b/src/commands/segment/SegmentTransposeCommand.cpp
new file mode 100644
index 0000000..d3e4221
--- /dev/null
+++ b/src/commands/segment/SegmentTransposeCommand.cpp
@@ -0,0 +1,123 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "SegmentTransposeCommand.h"
+
+#include "base/Selection.h"
+#include "commands/notation/KeyInsertionCommand.h"
+#include "commands/edit/TransposeCommand.h"
+#include "commands/segment/SegmentChangeTransposeCommand.h"
+
+namespace Rosegarden
+{
+SegmentTransposeCommand::SegmentTransposeCommand(Segment &segment, bool changeKey, int steps, int semitones, bool transposeSegmentBack) :
+ KMacroCommand(i18n("Change segment transposition"))
+{
+ processSegment(segment, changeKey, steps, semitones, transposeSegmentBack);
+}
+
+SegmentTransposeCommand::SegmentTransposeCommand(SegmentSelection selection, bool changeKey, int steps, int semitones, bool transposeSegmentBack) :
+ KMacroCommand(i18n("Change segment transposition"))
+{
+ //SegmentSelection selection(m_view->getSelection());
+ for (SegmentSelection::iterator i = selection.begin();
+ i != selection.end(); ++i)
+ {
+ Segment &segment = **i;
+ processSegment(segment, changeKey, steps, semitones, transposeSegmentBack);
+ }
+}
+
+void
+SegmentTransposeCommand::processSegment(Segment &segment, bool changeKey, int steps, int semitones, bool transposeSegmentBack)
+{
+ KMacroCommand * macroCommand = this;
+
+ // TODO delete it somewhere.
+ EventSelection * wholeSegment = new EventSelection(segment, segment.getStartTime(), segment.getEndMarkerTime());
+ macroCommand->addCommand(new TransposeCommand
+ (semitones, steps, *wholeSegment));
+
+ // Key insertion can do transposition, but a C4 to D becomes a D4, while
+ // a C4 to G becomes a G3. Because we let the user specify an explicit number
+ // of octaves to move the notes up/down, we add the keys without transposing
+ // and handle the transposition seperately:
+ if (changeKey)
+ {
+ Rosegarden::Key initialKey = segment.getKeyAtTime(segment.getStartTime());
+ Rosegarden::Key newInitialKey = initialKey.transpose(semitones, steps);
+
+ EventSelection::eventcontainer::iterator i;
+ //std::list<KeyInsertionCommand*> commands;
+
+ for (i = wholeSegment->getSegmentEvents().begin();
+ i != wholeSegment->getSegmentEvents().end(); ++i) {
+ // transpose key
+ if ((*i)->isa(Rosegarden::Key::EventType)) {
+ Rosegarden::Key trKey = (Rosegarden::Key (**i)).transpose(semitones, steps);
+ //commands.push_front
+ macroCommand->addCommand
+ (new KeyInsertionCommand
+ (segment,
+ (*i)->getAbsoluteTime(),
+ trKey,
+ false,
+ false,
+ false,
+ true));
+ }
+ }
+ std::list<KeyInsertionCommand*>::iterator ci;
+ //for (ci=commands.begin(); ci!=commands.end(); ci++)
+ //{
+ // commandHistory->addCommand(*ci);
+ //}
+
+ KeyInsertionCommand *firstKeyCommand = new KeyInsertionCommand
+ (segment,
+ segment.getStartTime(),
+ newInitialKey,
+ false,
+ false,
+ false,
+ true);
+ //commandHistory->addCommand(firstKeyCommand);
+ macroCommand->addCommand(firstKeyCommand);
+ }
+
+ if (transposeSegmentBack)
+ {
+ // Transpose segment in opposite direction
+ int newTranspose = segment.getTranspose() - semitones;
+ macroCommand->addCommand(new SegmentChangeTransposeCommand(newTranspose, &segment));
+ }
+}
+
+
+SegmentTransposeCommand::~SegmentTransposeCommand()
+{}
+
+
+}
diff --git a/src/commands/segment/SegmentTransposeCommand.h b/src/commands/segment/SegmentTransposeCommand.h
new file mode 100644
index 0000000..74af8d4
--- /dev/null
+++ b/src/commands/segment/SegmentTransposeCommand.h
@@ -0,0 +1,64 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_SEGMENTTRANSPOSECOMMAND_H_
+#define _RG_SEGMENTTRANSPOSECOMMAND_H_
+
+#include <kcommand.h>
+#include "base/Event.h"
+#include "document/MultiViewCommandHistory.h"
+#include <klocale.h>
+
+namespace Rosegarden
+{
+
+class Segment;
+class SegmentSelection;
+
+
+class SegmentTransposeCommand : public KMacroCommand
+{
+public:
+ SegmentTransposeCommand(Segment &segment,
+ bool changeKey, int steps, int semitones, bool transposeSegmentBack);
+
+ SegmentTransposeCommand(SegmentSelection selection,
+ bool changeKey, int steps, int semitones, bool transposeSegmentBack);
+
+ virtual ~SegmentTransposeCommand();
+
+ static QString getGlobalName(int semitones = 0, int step = 0) {
+ switch (semitones) {
+ default: return i18n("Transpose by &Interval...");
+ }
+ }
+
+protected:
+ void processSegment(Segment &segment, bool changeKey, int steps, int semitones, bool transposeSegmentBack);
+};
+
+}
+
+#endif
diff --git a/src/commands/segment/SetTriggerSegmentBasePitchCommand.cpp b/src/commands/segment/SetTriggerSegmentBasePitchCommand.cpp
new file mode 100644
index 0000000..9bb1bc3
--- /dev/null
+++ b/src/commands/segment/SetTriggerSegmentBasePitchCommand.cpp
@@ -0,0 +1,74 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "SetTriggerSegmentBasePitchCommand.h"
+
+#include <klocale.h>
+#include "base/Composition.h"
+#include "base/TriggerSegment.h"
+
+
+namespace Rosegarden
+{
+
+SetTriggerSegmentBasePitchCommand::SetTriggerSegmentBasePitchCommand(Composition *composition,
+ TriggerSegmentId id,
+ int newPitch) :
+ KNamedCommand(i18n("Set Base Pitch")),
+ m_composition(composition),
+ m_id(id),
+ m_newPitch(newPitch),
+ m_oldPitch( -1)
+{
+ // nothing
+}
+
+SetTriggerSegmentBasePitchCommand::~SetTriggerSegmentBasePitchCommand()
+{
+ // nothing
+}
+
+void
+SetTriggerSegmentBasePitchCommand::execute()
+{
+ TriggerSegmentRec *rec = m_composition->getTriggerSegmentRec(m_id);
+ if (!rec)
+ return ;
+ if (m_oldPitch == -1) {
+ m_oldPitch = rec->getBasePitch();
+ }
+ rec->setBasePitch(m_newPitch);
+}
+
+void
+SetTriggerSegmentBasePitchCommand::unexecute()
+{
+ TriggerSegmentRec *rec = m_composition->getTriggerSegmentRec(m_id);
+ if (!rec)
+ return ;
+ rec->setBasePitch(m_oldPitch);
+}
+
+}
diff --git a/src/commands/segment/SetTriggerSegmentBasePitchCommand.h b/src/commands/segment/SetTriggerSegmentBasePitchCommand.h
new file mode 100644
index 0000000..0d79c7c
--- /dev/null
+++ b/src/commands/segment/SetTriggerSegmentBasePitchCommand.h
@@ -0,0 +1,63 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_SETTRIGGERSEGMENTBASEPITCHCOMMAND_H_
+#define _RG_SETTRIGGERSEGMENTBASEPITCHCOMMAND_H_
+
+#include "base/TriggerSegment.h"
+#include <kcommand.h>
+
+
+
+
+namespace Rosegarden
+{
+
+class Composition;
+
+
+class SetTriggerSegmentBasePitchCommand : public KNamedCommand
+{
+public:
+ SetTriggerSegmentBasePitchCommand(Composition *composition,
+ TriggerSegmentId id,
+ int newPitch);
+ virtual ~SetTriggerSegmentBasePitchCommand();
+
+ virtual void execute();
+ virtual void unexecute();
+
+protected:
+ Composition *m_composition;
+ TriggerSegmentId m_id;
+ int m_newPitch;
+ int m_oldPitch;
+};
+
+
+
+}
+
+#endif
diff --git a/src/commands/segment/SetTriggerSegmentBaseVelocityCommand.cpp b/src/commands/segment/SetTriggerSegmentBaseVelocityCommand.cpp
new file mode 100644
index 0000000..f1bba10
--- /dev/null
+++ b/src/commands/segment/SetTriggerSegmentBaseVelocityCommand.cpp
@@ -0,0 +1,74 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "SetTriggerSegmentBaseVelocityCommand.h"
+
+#include <klocale.h>
+#include "base/Composition.h"
+#include "base/TriggerSegment.h"
+
+
+namespace Rosegarden
+{
+
+SetTriggerSegmentBaseVelocityCommand::SetTriggerSegmentBaseVelocityCommand(Composition *composition,
+ TriggerSegmentId id,
+ int newVelocity) :
+ KNamedCommand(i18n("Set Base Velocity")),
+ m_composition(composition),
+ m_id(id),
+ m_newVelocity(newVelocity),
+ m_oldVelocity( -1)
+{
+ // nothing
+}
+
+SetTriggerSegmentBaseVelocityCommand::~SetTriggerSegmentBaseVelocityCommand()
+{
+ // nothing
+}
+
+void
+SetTriggerSegmentBaseVelocityCommand::execute()
+{
+ TriggerSegmentRec *rec = m_composition->getTriggerSegmentRec(m_id);
+ if (!rec)
+ return ;
+ if (m_oldVelocity == -1) {
+ m_oldVelocity = rec->getBaseVelocity();
+ }
+ rec->setBaseVelocity(m_newVelocity);
+}
+
+void
+SetTriggerSegmentBaseVelocityCommand::unexecute()
+{
+ TriggerSegmentRec *rec = m_composition->getTriggerSegmentRec(m_id);
+ if (!rec)
+ return ;
+ rec->setBaseVelocity(m_oldVelocity);
+}
+
+}
diff --git a/src/commands/segment/SetTriggerSegmentBaseVelocityCommand.h b/src/commands/segment/SetTriggerSegmentBaseVelocityCommand.h
new file mode 100644
index 0000000..26875ec
--- /dev/null
+++ b/src/commands/segment/SetTriggerSegmentBaseVelocityCommand.h
@@ -0,0 +1,63 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_SETTRIGGERSEGMENTBASEVELOCITYCOMMAND_H_
+#define _RG_SETTRIGGERSEGMENTBASEVELOCITYCOMMAND_H_
+
+#include "base/TriggerSegment.h"
+#include <kcommand.h>
+
+
+
+
+namespace Rosegarden
+{
+
+class Composition;
+
+
+class SetTriggerSegmentBaseVelocityCommand : public KNamedCommand
+{
+public:
+ SetTriggerSegmentBaseVelocityCommand(Composition *composition,
+ TriggerSegmentId id,
+ int newVelocity);
+ virtual ~SetTriggerSegmentBaseVelocityCommand();
+
+ virtual void execute();
+ virtual void unexecute();
+
+protected:
+ Composition *m_composition;
+ TriggerSegmentId m_id;
+ int m_newVelocity;
+ int m_oldVelocity;
+};
+
+
+
+}
+
+#endif
diff --git a/src/commands/segment/SetTriggerSegmentDefaultRetuneCommand.cpp b/src/commands/segment/SetTriggerSegmentDefaultRetuneCommand.cpp
new file mode 100644
index 0000000..35ae878
--- /dev/null
+++ b/src/commands/segment/SetTriggerSegmentDefaultRetuneCommand.cpp
@@ -0,0 +1,75 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "SetTriggerSegmentDefaultRetuneCommand.h"
+
+#include <klocale.h>
+#include "base/Composition.h"
+#include "base/TriggerSegment.h"
+
+
+namespace Rosegarden
+{
+
+SetTriggerSegmentDefaultRetuneCommand::SetTriggerSegmentDefaultRetuneCommand(Composition *composition,
+ TriggerSegmentId id,
+ bool newDefaultRetune) :
+ KNamedCommand(i18n("Set Default Retune")),
+ m_composition(composition),
+ m_id(id),
+ m_newDefaultRetune(newDefaultRetune),
+ m_oldDefaultRetune(false),
+ m_haveOldDefaultRetune(false)
+{
+ // nothing
+}
+
+SetTriggerSegmentDefaultRetuneCommand::~SetTriggerSegmentDefaultRetuneCommand()
+{
+ // nothing
+}
+
+void
+SetTriggerSegmentDefaultRetuneCommand::execute()
+{
+ TriggerSegmentRec *rec = m_composition->getTriggerSegmentRec(m_id);
+ if (!rec)
+ return ;
+ if (!m_haveOldDefaultRetune) {
+ m_oldDefaultRetune = rec->getDefaultRetune();
+ }
+ rec->setDefaultRetune(m_newDefaultRetune);
+}
+
+void
+SetTriggerSegmentDefaultRetuneCommand::unexecute()
+{
+ TriggerSegmentRec *rec = m_composition->getTriggerSegmentRec(m_id);
+ if (!rec)
+ return ;
+ rec->setDefaultRetune(m_oldDefaultRetune);
+}
+
+}
diff --git a/src/commands/segment/SetTriggerSegmentDefaultRetuneCommand.h b/src/commands/segment/SetTriggerSegmentDefaultRetuneCommand.h
new file mode 100644
index 0000000..4563594
--- /dev/null
+++ b/src/commands/segment/SetTriggerSegmentDefaultRetuneCommand.h
@@ -0,0 +1,64 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_SETTRIGGERSEGMENTDEFAULTRETUNECOMMAND_H_
+#define _RG_SETTRIGGERSEGMENTDEFAULTRETUNECOMMAND_H_
+
+#include "base/TriggerSegment.h"
+#include <kcommand.h>
+
+
+
+
+namespace Rosegarden
+{
+
+class Composition;
+
+
+class SetTriggerSegmentDefaultRetuneCommand : public KNamedCommand
+{
+public:
+ SetTriggerSegmentDefaultRetuneCommand(Composition *composition,
+ TriggerSegmentId id,
+ bool newDefaultRetune);
+ virtual ~SetTriggerSegmentDefaultRetuneCommand();
+
+ virtual void execute();
+ virtual void unexecute();
+
+protected:
+ Composition *m_composition;
+ TriggerSegmentId m_id;
+ bool m_newDefaultRetune;
+ bool m_oldDefaultRetune;
+ bool m_haveOldDefaultRetune;
+};
+
+
+
+}
+
+#endif
diff --git a/src/commands/segment/SetTriggerSegmentDefaultTimeAdjustCommand.cpp b/src/commands/segment/SetTriggerSegmentDefaultTimeAdjustCommand.cpp
new file mode 100644
index 0000000..deb49a1
--- /dev/null
+++ b/src/commands/segment/SetTriggerSegmentDefaultTimeAdjustCommand.cpp
@@ -0,0 +1,74 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "SetTriggerSegmentDefaultTimeAdjustCommand.h"
+
+#include <klocale.h>
+#include "base/Composition.h"
+#include "base/TriggerSegment.h"
+
+
+namespace Rosegarden
+{
+
+SetTriggerSegmentDefaultTimeAdjustCommand::SetTriggerSegmentDefaultTimeAdjustCommand(Composition *composition,
+ TriggerSegmentId id,
+ std::string newDefaultTimeAdjust) :
+ KNamedCommand(i18n("Set Default Time Adjust")),
+ m_composition(composition),
+ m_id(id),
+ m_newDefaultTimeAdjust(newDefaultTimeAdjust),
+ m_oldDefaultTimeAdjust("")
+{
+ // nothing
+}
+
+SetTriggerSegmentDefaultTimeAdjustCommand::~SetTriggerSegmentDefaultTimeAdjustCommand()
+{
+ // nothing
+}
+
+void
+SetTriggerSegmentDefaultTimeAdjustCommand::execute()
+{
+ TriggerSegmentRec *rec = m_composition->getTriggerSegmentRec(m_id);
+ if (!rec)
+ return ;
+ if (m_oldDefaultTimeAdjust == "") {
+ m_oldDefaultTimeAdjust = rec->getDefaultTimeAdjust();
+ }
+ rec->setDefaultTimeAdjust(m_newDefaultTimeAdjust);
+}
+
+void
+SetTriggerSegmentDefaultTimeAdjustCommand::unexecute()
+{
+ TriggerSegmentRec *rec = m_composition->getTriggerSegmentRec(m_id);
+ if (!rec)
+ return ;
+ rec->setDefaultTimeAdjust(m_oldDefaultTimeAdjust);
+}
+
+}
diff --git a/src/commands/segment/SetTriggerSegmentDefaultTimeAdjustCommand.h b/src/commands/segment/SetTriggerSegmentDefaultTimeAdjustCommand.h
new file mode 100644
index 0000000..7d31b26
--- /dev/null
+++ b/src/commands/segment/SetTriggerSegmentDefaultTimeAdjustCommand.h
@@ -0,0 +1,64 @@
+
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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. See the file
+ COPYING included with this distribution for more information.
+*/
+
+#ifndef _RG_SETTRIGGERSEGMENTDEFAULTTIMEADJUSTCOMMAND_H_
+#define _RG_SETTRIGGERSEGMENTDEFAULTTIMEADJUSTCOMMAND_H_
+
+#include "base/TriggerSegment.h"
+#include <string>
+#include <kcommand.h>
+
+
+
+
+namespace Rosegarden
+{
+
+class Composition;
+
+
+class SetTriggerSegmentDefaultTimeAdjustCommand : public KNamedCommand
+{
+public:
+ SetTriggerSegmentDefaultTimeAdjustCommand(Composition *composition,
+ TriggerSegmentId id,
+ std::string newDefaultTimeAdjust);
+ virtual ~SetTriggerSegmentDefaultTimeAdjustCommand();
+
+ virtual void execute();
+ virtual void unexecute();
+
+protected:
+ Composition *m_composition;
+ TriggerSegmentId m_id;
+ std::string m_newDefaultTimeAdjust;
+ std::string m_oldDefaultTimeAdjust;
+};
+
+
+
+}
+
+#endif