summaryrefslogtreecommitdiff
path: root/libs/ardour/midi_model.cc
diff options
context:
space:
mode:
authorCarl Hetherington <carl@carlh.net>2011-04-06 02:04:37 +0000
committerCarl Hetherington <carl@carlh.net>2011-04-06 02:04:37 +0000
commite8c8befb87ee0891d6a3bbda5871abb506fb45b9 (patch)
treed86c2c91a788f1f8b376c6d19714b1542500beeb /libs/ardour/midi_model.cc
parentebb31e504b56ec71452e2eda4f9314fd255e77c1 (diff)
Differentiate between pitch-shift (for audio) and transpose (for MIDI). Fixes #3940.
git-svn-id: svn://localhost/ardour2/branches/3.0@9299 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/midi_model.cc')
-rw-r--r--libs/ardour/midi_model.cc40
1 files changed, 40 insertions, 0 deletions
diff --git a/libs/ardour/midi_model.cc b/libs/ardour/midi_model.cc
index 1691380c93..e1a955d43c 100644
--- a/libs/ardour/midi_model.cc
+++ b/libs/ardour/midi_model.cc
@@ -1899,3 +1899,43 @@ MidiModel::insert_silence_at_start (TimeType t)
apply_command_as_subcommand (s->session(), c);
}
}
+
+/** Transpose notes in a time range by a given number of semitones. Notes
+ * will be clamped at 0 and 127 if the transposition would make them exceed
+ * that range.
+ *
+ * @param from Start time.
+ * @param end End time.
+ * @param semitones Number of semitones to transpose by (+ve is higher, -ve is lower).
+ */
+void
+MidiModel::transpose (TimeType from, TimeType to, int semitones)
+{
+ boost::shared_ptr<const MidiSource> s = midi_source ();
+
+ NoteDiffCommand* c = new_note_diff_command (_("transpose"));
+
+ for (Notes::iterator i = notes().begin(); i != notes().end(); ++i) {
+
+ if ((*i)->time() >= to) {
+
+ /* finished */
+ break;
+
+ } else if ((*i)->time() >= from) {
+
+ int new_note = (*i)->note() + semitones;
+
+ if (new_note < 0) {
+ new_note = 0;
+ } else if (new_note > 127) {
+ new_note = 127;
+ }
+
+ c->change (*i, NoteDiffCommand::NoteNumber, (uint8_t) new_note);
+
+ }
+ }
+
+ apply_command (s->session (), c);
+}