From: Heikki Junes <heikki.junes@hut.fi>
Date: Tue, 4 Nov 2003 15:28:52 +0000 (+0000)
Subject:        * lily/midi-item.cc: fine tune quarter tones.
X-Git-Tag: release/2.1.23~310
X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=b8cf15cdddad1d02e557da5c68a386d082e10597;p=lilypond.git

   * lily/midi-item.cc: fine tune quarter tones.
---

diff --git a/ChangeLog b/ChangeLog
index a95026109b..6bc3f58190 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2003-11-04  Heikki Junes  <hjunes@cc.hut.fi>
+
+	* lily/midi-item.cc: fine tune quarter tones.
+
 2003-11-03  Heikki Junes  <hjunes@cc.hut.fi>
 
 	* lily/midi-item.cc lily/include/midi-item.hh (get_fine_tuning):
diff --git a/VERSION b/VERSION
index 133206e0f6..3b89cf9686 100644
--- a/VERSION
+++ b/VERSION
@@ -2,5 +2,5 @@ PACKAGE_NAME=LilyPond
 MAJOR_VERSION=2
 MINOR_VERSION=1
 PATCH_LEVEL=0
-MY_PATCH_LEVEL=hjj1
+MY_PATCH_LEVEL=hjj2
 
diff --git a/lily/midi-item.cc b/lily/midi-item.cc
index 2ac68b6b55..c61e8307fd 100644
--- a/lily/midi-item.cc
+++ b/lily/midi-item.cc
@@ -19,6 +19,11 @@
 
 #include "killing-cons.tcc"
 
+#define PITCH_WHEEL_TOP    0x3FFF
+#define PITCH_WHEEL_CENTER 0x2000
+#define PITCH_WHEEL_BOTTOM 0x0000
+#define PITCH_WHEEL_RANGE  (PITCH_WHEEL_TOP - PITCH_WHEEL_BOTTOM)
+
 Midi_item*
 Midi_item::get_midi (Audio_item* a)
 {
@@ -259,18 +264,30 @@ String
 Midi_note::to_string () const
 {
   Byte status_byte = (char) (0x90 + channel_);
+  String str = "";
+  int finetune;
 
   // print warning if fine tuning was needed, HJJ
   if (get_fine_tuning () != 0)
     {
-      warning (_f ("Omitting fine tuning (of %d cents) a note.", 
+      warning (_f ("Experimental: temporarily fine tuning (of %d cents) a channel.", 
 	    get_fine_tuning ()));
+
+      finetune = PITCH_WHEEL_CENTER;
+      // Move pitch wheel to a shifted position.
+      // The pitch wheel range (of 4 semitones) is multiplied by the cents.
+      finetune += (PITCH_WHEEL_RANGE * get_fine_tuning ()) / (4 * 100);
+
+      str += ::to_string ((char) (0xE0 + channel_));
+      str += ::to_string ((char) (finetune & 0x7F));
+      str += ::to_string ((char) (finetune >> 7));
+      str += ::to_string ((char) (0x00));
     }
 
-  String str = ::to_string ((char)status_byte);
+  str += ::to_string ((char)status_byte);
   str += ::to_string ((char) (get_pitch () + c0_pitch_i_));
-
   str += ::to_string ((char)dynamic_byte_);
+
   return str;
 }
 
@@ -295,6 +312,16 @@ Midi_note_off::to_string () const
   String str = ::to_string ((char)status_byte);
   str += ::to_string ((char) (get_pitch () + Midi_note::c0_pitch_i_));
   str += ::to_string ((char)aftertouch_byte_);
+
+  if (get_fine_tuning () != 0)
+    {
+      // Move pitch wheel back to the central position.
+      str += ::to_string ((char) 0x00);
+      str += ::to_string ((char) (0xE0 + channel_));
+      str += ::to_string ((char) (PITCH_WHEEL_CENTER & 0x7F));
+      str += ::to_string ((char) (PITCH_WHEEL_CENTER >> 7));
+    }
+
   return str;
 }