summaryrefslogtreecommitdiffstats
path: root/src/commands/matrix
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands/matrix')
-rw-r--r--src/commands/matrix/MatrixEraseCommand.cpp70
-rw-r--r--src/commands/matrix/MatrixEraseCommand.h62
-rw-r--r--src/commands/matrix/MatrixInsertionCommand.cpp74
-rw-r--r--src/commands/matrix/MatrixInsertionCommand.h64
-rw-r--r--src/commands/matrix/MatrixModifyCommand.cpp81
-rw-r--r--src/commands/matrix/MatrixModifyCommand.h63
-rw-r--r--src/commands/matrix/MatrixPercussionInsertionCommand.cpp192
-rw-r--r--src/commands/matrix/MatrixPercussionInsertionCommand.h73
8 files changed, 679 insertions, 0 deletions
diff --git a/src/commands/matrix/MatrixEraseCommand.cpp b/src/commands/matrix/MatrixEraseCommand.cpp
new file mode 100644
index 0000000..c35259e
--- /dev/null
+++ b/src/commands/matrix/MatrixEraseCommand.cpp
@@ -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 <[email protected]>,
+ Chris Cannam <[email protected]>,
+ Richard Bown <[email protected]>
+
+ 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 "MatrixEraseCommand.h"
+
+#include <klocale.h>
+#include "base/Event.h"
+#include "base/NotationTypes.h"
+#include "base/Segment.h"
+#include "base/SegmentMatrixHelper.h"
+#include "document/BasicCommand.h"
+
+
+namespace Rosegarden
+{
+
+MatrixEraseCommand::MatrixEraseCommand(Segment &segment,
+ Event *event) :
+ BasicCommand(i18n("Erase Note"),
+ segment,
+ event->getAbsoluteTime(),
+ event->getAbsoluteTime() + event->getDuration(),
+ true),
+ m_event(event),
+ m_relayoutEndTime(getEndTime())
+{
+ // nothing
+}
+
+timeT MatrixEraseCommand::getRelayoutEndTime()
+{
+ return m_relayoutEndTime;
+}
+
+void MatrixEraseCommand::modifySegment()
+{
+ SegmentMatrixHelper helper(getSegment());
+
+ std::string eventType = m_event->getType();
+
+ if (eventType == Note::EventType) {
+
+ helper.deleteNote(m_event, false);
+
+ }
+}
+
+}
diff --git a/src/commands/matrix/MatrixEraseCommand.h b/src/commands/matrix/MatrixEraseCommand.h
new file mode 100644
index 0000000..244c0f9
--- /dev/null
+++ b/src/commands/matrix/MatrixEraseCommand.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 <[email protected]>,
+ Chris Cannam <[email protected]>,
+ Richard Bown <[email protected]>
+
+ 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_MATRIXERASECOMMAND_H_
+#define _RG_MATRIXERASECOMMAND_H_
+
+#include "document/BasicCommand.h"
+#include "base/Event.h"
+
+
+
+
+namespace Rosegarden
+{
+
+class Segment;
+class Event;
+
+
+class MatrixEraseCommand : public BasicCommand
+{
+public:
+ MatrixEraseCommand(Segment &segment,
+ Event *event);
+
+ virtual timeT getRelayoutEndTime();
+
+protected:
+ virtual void modifySegment();
+
+ Event *m_event; // only used on 1st execute (cf bruteForceRedo)
+ timeT m_relayoutEndTime;
+};
+
+//------------------------------
+
+
+}
+
+#endif
diff --git a/src/commands/matrix/MatrixInsertionCommand.cpp b/src/commands/matrix/MatrixInsertionCommand.cpp
new file mode 100644
index 0000000..5b03d1a
--- /dev/null
+++ b/src/commands/matrix/MatrixInsertionCommand.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 <[email protected]>,
+ Chris Cannam <[email protected]>,
+ Richard Bown <[email protected]>
+
+ 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 "MatrixInsertionCommand.h"
+
+#include <klocale.h>
+#include "base/Event.h"
+#include "base/Segment.h"
+#include "base/SegmentMatrixHelper.h"
+#include "document/BasicCommand.h"
+#include "base/BaseProperties.h"
+#include "misc/Debug.h"
+
+
+namespace Rosegarden
+{
+
+using namespace BaseProperties;
+
+MatrixInsertionCommand::MatrixInsertionCommand(Segment &segment,
+ timeT time,
+ timeT endTime,
+ Event *event) :
+ BasicCommand(i18n("Insert Note"), segment, time, endTime),
+ m_event(new Event(*event,
+ std::min(time, endTime),
+ (time < endTime) ? endTime - time : time - endTime))
+{
+ // nothing
+}
+
+MatrixInsertionCommand::~MatrixInsertionCommand()
+{
+ delete m_event;
+ // don't want to delete m_lastInsertedEvent, it's just an alias
+}
+
+void MatrixInsertionCommand::modifySegment()
+{
+ MATRIX_DEBUG << "MatrixInsertionCommand::modifySegment()\n";
+
+ if (!m_event->has(VELOCITY)) {
+ m_event->set
+ <Int>(VELOCITY, 100);
+ }
+
+ SegmentMatrixHelper helper(getSegment());
+ m_lastInsertedEvent = new Event(*m_event);
+ helper.insertNote(m_lastInsertedEvent);
+}
+
+}
diff --git a/src/commands/matrix/MatrixInsertionCommand.h b/src/commands/matrix/MatrixInsertionCommand.h
new file mode 100644
index 0000000..bca8e0a
--- /dev/null
+++ b/src/commands/matrix/MatrixInsertionCommand.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 <[email protected]>,
+ Chris Cannam <[email protected]>,
+ Richard Bown <[email protected]>
+
+ 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_MATRIXINSERTIONCOMMAND_H_
+#define _RG_MATRIXINSERTIONCOMMAND_H_
+
+#include "document/BasicCommand.h"
+#include "base/Event.h"
+
+
+
+
+namespace Rosegarden
+{
+
+class Segment;
+class Event;
+
+
+class MatrixInsertionCommand : public BasicCommand
+{
+public:
+ MatrixInsertionCommand(Segment &segment,
+ timeT time,
+ timeT endTime,
+ Event *event);
+
+ virtual ~MatrixInsertionCommand();
+
+ Event *getLastInsertedEvent() { return m_lastInsertedEvent; }
+
+protected:
+ virtual void modifySegment();
+
+ Event *m_event;
+ Event *m_lastInsertedEvent; // an alias for another event
+};
+
+
+}
+
+#endif
diff --git a/src/commands/matrix/MatrixModifyCommand.cpp b/src/commands/matrix/MatrixModifyCommand.cpp
new file mode 100644
index 0000000..b78d6f3
--- /dev/null
+++ b/src/commands/matrix/MatrixModifyCommand.cpp
@@ -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 <[email protected]>,
+ Chris Cannam <[email protected]>,
+ Richard Bown <[email protected]>
+
+ 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 "MatrixModifyCommand.h"
+
+#include "base/Event.h"
+#include <klocale.h>
+#include "base/NotationTypes.h"
+#include "base/Segment.h"
+#include "document/BasicCommand.h"
+
+
+namespace Rosegarden
+{
+
+MatrixModifyCommand::MatrixModifyCommand(Segment &segment,
+ Event *oldEvent,
+ Event *newEvent,
+ bool isMove,
+ bool normalize):
+ BasicCommand((isMove ? i18n("Move Note") : i18n("Modify Note")),
+ segment,
+ std::min(newEvent->getAbsoluteTime(),
+ oldEvent->getAbsoluteTime()),
+ std::max(oldEvent->getAbsoluteTime() +
+ oldEvent->getDuration(),
+ newEvent->getAbsoluteTime() +
+ newEvent->getDuration()),
+ true),
+ m_normalize(normalize),
+ m_oldEvent(oldEvent),
+ m_newEvent(newEvent)
+{}
+
+void MatrixModifyCommand::modifySegment()
+{
+ std::string eventType = m_oldEvent->getType();
+
+ if (eventType == Note::EventType) {
+
+ timeT normalizeStart = std::min(m_newEvent->getAbsoluteTime(),
+ m_oldEvent->getAbsoluteTime());
+
+ timeT normalizeEnd = std::max(m_newEvent->getAbsoluteTime() +
+ m_newEvent->getDuration(),
+ m_oldEvent->getAbsoluteTime() +
+ m_oldEvent->getDuration());
+
+ Segment &segment(getSegment());
+ segment.insert(m_newEvent);
+ segment.eraseSingle(m_oldEvent);
+
+ if (m_normalize) {
+ segment.normalizeRests(normalizeStart, normalizeEnd);
+ }
+ }
+}
+
+}
diff --git a/src/commands/matrix/MatrixModifyCommand.h b/src/commands/matrix/MatrixModifyCommand.h
new file mode 100644
index 0000000..df9bdc0
--- /dev/null
+++ b/src/commands/matrix/MatrixModifyCommand.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 <[email protected]>,
+ Chris Cannam <[email protected]>,
+ Richard Bown <[email protected]>
+
+ 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_MATRIXMODIFYCOMMAND_H_
+#define _RG_MATRIXMODIFYCOMMAND_H_
+
+#include "document/BasicCommand.h"
+
+
+
+
+namespace Rosegarden
+{
+
+class Segment;
+class Event;
+
+
+class MatrixModifyCommand : public BasicCommand
+{
+public:
+ MatrixModifyCommand(Segment &segment,
+ Event *oldEvent,
+ Event *newEvent,
+ bool isMove,
+ bool normalize);
+
+protected:
+ virtual void modifySegment();
+
+ bool m_normalize;
+
+ Event *m_oldEvent;
+ Event *m_newEvent;
+};
+
+
+
+}
+
+#endif
diff --git a/src/commands/matrix/MatrixPercussionInsertionCommand.cpp b/src/commands/matrix/MatrixPercussionInsertionCommand.cpp
new file mode 100644
index 0000000..513663d
--- /dev/null
+++ b/src/commands/matrix/MatrixPercussionInsertionCommand.cpp
@@ -0,0 +1,192 @@
+/* -*- 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 <[email protected]>,
+ Chris Cannam <[email protected]>,
+ Richard Bown <[email protected]>
+
+ 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 "MatrixPercussionInsertionCommand.h"
+
+#include <klocale.h>
+#include "base/Composition.h"
+#include "base/Event.h"
+#include "base/NotationTypes.h"
+#include "base/Segment.h"
+#include "base/SegmentMatrixHelper.h"
+#include "document/BasicCommand.h"
+#include "base/BaseProperties.h"
+#include "misc/Debug.h"
+
+
+namespace Rosegarden
+{
+using namespace BaseProperties;
+
+
+MatrixPercussionInsertionCommand::MatrixPercussionInsertionCommand(Segment &segment,
+ timeT time,
+ Event *event) :
+ BasicCommand(i18n("Insert Percussion Note"), segment,
+ getEffectiveStartTime(segment, time, *event),
+ getEndTime(segment, time, *event)),
+ m_event(0),
+ m_time(time)
+{
+ timeT endTime = getEndTime(segment, time, *event);
+ m_event = new Event(*event, time, endTime - time);
+}
+
+MatrixPercussionInsertionCommand::~MatrixPercussionInsertionCommand()
+{
+ delete m_event;
+ // don't want to delete m_lastInsertedEvent, it's just an alias
+}
+
+void MatrixPercussionInsertionCommand::modifySegment()
+{
+ MATRIX_DEBUG << "MatrixPercussionInsertionCommand::modifySegment()\n";
+
+ if (!m_event->has(VELOCITY)) {
+ m_event->set
+ <Int>(VELOCITY, 100);
+ }
+
+ Segment &s = getSegment();
+
+ Segment::iterator i = s.findTime(m_time);
+
+ int pitch = 0;
+ if (m_event->has(PITCH)) {
+ pitch = m_event->get
+ <Int>(PITCH);
+ }
+
+ while (i != s.begin()) {
+
+ --i;
+
+ if ((*i)->getAbsoluteTime() < m_time &&
+ (*i)->isa(Note::EventType)) {
+
+ if ((*i)->has(PITCH) &&
+ (*i)->get
+ <Int>(PITCH) == pitch) {
+
+ if ((*i)->getAbsoluteTime() + (*i)->getDuration() > m_time) {
+ Event *newPrevious = new Event
+ (**i, (*i)->getAbsoluteTime(), m_time - (*i)->getAbsoluteTime());
+ s.erase(i);
+ i = s.insert(newPrevious);
+ } else {
+ break;
+ }
+ }
+ }
+ }
+
+ SegmentMatrixHelper helper(s);
+ m_lastInsertedEvent = new Event(*m_event);
+ helper.insertNote(m_lastInsertedEvent);
+}
+
+timeT
+MatrixPercussionInsertionCommand::getEffectiveStartTime(Segment &segment,
+ timeT time,
+ Event &event)
+{
+ timeT startTime = time;
+
+ int pitch = 0;
+ if (event.has(PITCH)) {
+ pitch = event.get<Int>(PITCH);
+ }
+
+ Segment::iterator i = segment.findTime(time);
+ while (i != segment.begin()) {
+ --i;
+
+ if ((*i)->has(PITCH) &&
+ (*i)->get
+ <Int>(PITCH) == pitch) {
+
+ if ((*i)->getAbsoluteTime() < time &&
+ (*i)->isa(Note::EventType)) {
+ if ((*i)->getAbsoluteTime() + (*i)->getDuration() > time) {
+ startTime = (*i)->getAbsoluteTime();
+ } else {
+ break;
+ }
+ }
+ }
+ }
+
+ return startTime;
+}
+
+timeT
+MatrixPercussionInsertionCommand::getEndTime(Segment &segment,
+ timeT time,
+ Event &event)
+{
+ timeT endTime =
+ time + Note(Note::Semibreve,
+ 0).getDuration();
+ timeT barEndTime = segment.getBarEndForTime(time);
+ timeT segmentEndTime = segment.getEndMarkerTime();
+
+ if (barEndTime > endTime)
+ endTime = barEndTime;
+ if (endTime > segmentEndTime)
+ endTime = segmentEndTime;
+
+ int pitch = 0;
+ if (event.has(PITCH)) {
+ pitch = event.get<Int>(PITCH);
+ }
+
+ for (Segment::iterator i = segment.findTime(time);
+ segment.isBeforeEndMarker(i); ++i) {
+
+ if ((*i)->has(PITCH) &&
+ (*i)->get
+ <Int>(PITCH) == pitch) {
+
+ if ((*i)->getAbsoluteTime() > time &&
+ (*i)->isa(Note::EventType)) {
+ endTime = (*i)->getAbsoluteTime();
+ }
+ }
+ }
+
+ Composition *comp = segment.getComposition();
+ std::pair<timeT, timeT> barRange =
+ comp->getBarRangeForTime(time);
+ timeT barDuration = barRange.second - barRange.first;
+
+
+ if (endTime > time + barDuration) {
+ endTime = time + barDuration;
+ }
+
+ return endTime;
+}
+
+}
diff --git a/src/commands/matrix/MatrixPercussionInsertionCommand.h b/src/commands/matrix/MatrixPercussionInsertionCommand.h
new file mode 100644
index 0000000..513754d
--- /dev/null
+++ b/src/commands/matrix/MatrixPercussionInsertionCommand.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 <[email protected]>,
+ Chris Cannam <[email protected]>,
+ Richard Bown <[email protected]>
+
+ 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_MATRIXPERCUSSIONINSERTIONCOMMAND_H_
+#define _RG_MATRIXPERCUSSIONINSERTIONCOMMAND_H_
+
+#include "document/BasicCommand.h"
+#include "base/Event.h"
+
+
+
+
+namespace Rosegarden
+{
+
+class Segment;
+class Event;
+
+
+class MatrixPercussionInsertionCommand : public BasicCommand
+{
+public:
+ MatrixPercussionInsertionCommand(Segment &segment,
+ timeT time,
+ Event *event);
+
+ virtual ~MatrixPercussionInsertionCommand();
+
+ Event *getLastInsertedEvent() { return m_lastInsertedEvent; }
+
+protected:
+ virtual void modifySegment();
+
+ timeT getEffectiveStartTime(Segment &segment,
+ timeT startTime,
+ Event &event);
+ timeT getEndTime(Segment &segment,
+ timeT endTime,
+ Event &event);
+
+ Event *m_event;
+ timeT m_time;
+ Event *m_lastInsertedEvent; // an alias for another event
+};
+
+//------------------------------
+
+
+}
+
+#endif