summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWerner Schweer <ws.seh.de>2006-09-01 21:05:40 +0000
committerWerner Schweer <ws.seh.de>2006-09-01 21:05:40 +0000
commitd7e887c06328cb708bd28d598b92fcc5d2806bd8 (patch)
tree1317556f59b14680bfe8e039a9bd29c01199d982
parent98f6d7feddcde52442ee1af5e2254f4d324ebf9b (diff)
add new files
-rw-r--r--muse/muse/midiedit/midicmd.cpp118
-rw-r--r--muse/muse/midiedit/midicmd.h52
2 files changed, 170 insertions, 0 deletions
diff --git a/muse/muse/midiedit/midicmd.cpp b/muse/muse/midiedit/midicmd.cpp
new file mode 100644
index 00000000..fd3f29ed
--- /dev/null
+++ b/muse/muse/midiedit/midicmd.cpp
@@ -0,0 +1,118 @@
+//=============================================================================
+// MusE
+// Linux Music Editor
+// $Id:$
+//
+// Copyright (C) 2002-2006 by Werner Schweer and others
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+//=============================================================================
+
+#include "midicmd.h"
+#include "song.h"
+#include "widgets/gatetime.h"
+#include "audio.h"
+
+//---------------------------------------------------------
+// processEvents
+//---------------------------------------------------------
+
+void MidiCmd::processEvents(CItemList* items)
+ {
+ modified = 0;
+ song->startUndo();
+ range = 0; //editor->applyTo();
+ process(items, &range);
+// editor->setApplyTo(range);
+ song->endUndo(modified);
+ }
+
+//---------------------------------------------------------
+// eventInRange
+//---------------------------------------------------------
+
+bool MidiCmd::itemInRange(CItem* item)
+ {
+ unsigned tick = item->event.tick();
+ bool selected = item->isSelected();
+ bool inLoop = (tick >= song->lpos()) && (tick < song->rpos());
+ return (
+ (range == 0)
+ || (range == 1 && selected)
+ || (range == 2 && inLoop)
+ || (range == 3 && selected && inLoop)
+ );
+ }
+
+//---------------------------------------------------------
+// changeEvent
+//---------------------------------------------------------
+
+void MidiCmd::changeEvent(Event oldEvent, Event newEvent, Part* part)
+ {
+ audio->msgChangeEvent(oldEvent, newEvent, part, false);
+ modified = SC_EVENT_MODIFIED;
+ }
+
+//==================================================================
+
+//---------------------------------------------------------
+// ModifyGateTimeCmd
+//---------------------------------------------------------
+
+class ModifyGateTimeCmd : public MidiCmd
+ {
+ protected:
+ virtual void process(CItemList* items, int* range);
+
+ public:
+ ModifyGateTimeCmd() {}
+ };
+
+//---------------------------------------------------------
+// process
+// return true if events are modified
+//---------------------------------------------------------
+
+void ModifyGateTimeCmd::process(CItemList* items, int* range)
+ {
+ GateTime w(0);
+ w.setRange(*range);
+ if (!w.exec())
+ return;
+ *range = w.range(); // all, selected, looped, sel+loop
+ int rate = w.rateVal();
+ int offset = w.offsetVal();
+
+ for (iCItem k = items->begin(); k != items->end(); ++k) {
+ CItem* item = k->second;
+ Event event = item->event;
+ if (event.type() != Note)
+ continue;
+
+ if (itemInRange(item)) {
+ unsigned len = event.lenTick();
+ len = rate ? (len * 100) / rate : 1;
+ len += offset;
+ if (len <= 1)
+ len = 1;
+
+ if (event.lenTick() != len) {
+ Event newEvent = event.clone();
+ newEvent.setLenTick(len);
+ changeEvent(event, newEvent, item->part);
+ }
+ }
+ }
+ }
+
diff --git a/muse/muse/midiedit/midicmd.h b/muse/muse/midiedit/midicmd.h
new file mode 100644
index 00000000..2cfabb26
--- /dev/null
+++ b/muse/muse/midiedit/midicmd.h
@@ -0,0 +1,52 @@
+//=============================================================================
+// MusE
+// Linux Music Editor
+// $Id:$
+//
+// Copyright (C) 2002-2006 by Werner Schweer and others
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+//=============================================================================
+
+#ifndef __MIDICMD_H__
+#define __MIDICMD_H__
+
+#include "citem.h"
+
+//---------------------------------------------------------
+// MidiCmd
+// abstract base class for midi commands
+//---------------------------------------------------------
+
+class MidiCmd {
+ int modified;
+
+ protected:
+ int range;
+
+ // convenience classes for derived classes
+ bool itemInRange(CItem* item);
+ void changeEvent(Event oldEvent, Event newEvent, Part* part);
+
+ // virtual functions provided by derived classes
+ virtual void process(CItemList*, int*) = 0;
+
+ public:
+ MidiCmd() {}
+ virtual ~MidiCmd() {}
+ void processEvents(CItemList*);
+ };
+
+
+#endif
+