]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/midi-item.cc
(get_indexed_char): scale metrics by
[lilypond.git] / lily / midi-item.cc
index 2452a46951e62daa384fe839d940e8f10b624d31..064fdd2292deb1ff2986e00fc069e7a543410171 100644 (file)
@@ -3,22 +3,25 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1997--2003 Jan Nieuwenhuizen <janneke@gnu.org>
+  (c) 1997--2004 Jan Nieuwenhuizen <janneke@gnu.org>
  */
 
+#include "midi-item.hh"
+
 #include "warn.hh"
 #include "main.hh"
 #include "misc.hh"
-#include "string.hh"
 #include "string-convert.hh"
-#include "midi-item.hh"
 #include "midi-stream.hh"
-#include "audio-item.hh"
 #include "duration.hh"
 #include "scm-option.hh"
-
 #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)
 {
@@ -139,11 +142,11 @@ Midi_instrument::to_string () const
   /*
     UGH. don't use eval.
    */
-  SCM proc = scm_primitive_eval (ly_symbol2scm ("midi-program")); 
-  SCM program = gh_call1 (proc, ly_symbol2scm (audio_->str_.to_str0 ()));
+  SCM proc = ly_scheme_function ("midi-program");
+  SCM program = scm_call_1 (proc, ly_symbol2scm (audio_->str_.to_str0 ()));
   found = (program != SCM_BOOL_F);
   if (found)
-    program_byte = gh_scm2int(program);
+    program_byte = scm_to_int (program);
   else
       warning (_f ("no such MIDI instrument: `%s'", audio_->str_.to_str0 ()));
 
@@ -234,6 +237,15 @@ Midi_note::get_length () const
   return m;
 }
 
+int
+Midi_note::get_fine_tuning () const
+{
+  int ft = audio_->pitch_.quartertone_pitch ();
+  ft -= 2 * audio_->pitch_.semitone_pitch ();
+  ft *= 50; // 1 quarter tone = 50 cents
+  return ft;
+}
+
 int
 Midi_note::get_pitch () const
 {
@@ -250,11 +262,30 @@ String
 Midi_note::to_string () const
 {
   Byte status_byte = (char) (0x90 + channel_);
+  String str = "";
+  int finetune;
 
-  String str = ::to_string ((char)status_byte);
-  str += ::to_string ((char) (get_pitch () + c0_pitch_i_));
+  // print warning if fine tuning was needed, HJJ
+  if (get_fine_tuning () != 0)
+    {
+      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));
+    }
 
+  str += ::to_string ((char)status_byte);
+  str += ::to_string ((char) (get_pitch () + c0_pitch_i_));
   str += ::to_string ((char)dynamic_byte_);
+
   return str;
 }
 
@@ -279,6 +310,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;
 }
 
@@ -417,7 +458,7 @@ Midi_track::data_string () const
   String str = Midi_chunk::data_string ();
   if (midi_debug_global_b)
     str += "\n";
-  for (Cons<Midi_event> *i=event_p_list_.head_; i; i = i->next_) 
+  for (Cons<Midi_event> *i = event_p_list_.head_; i; i = i->next_) 
     {
       str += i->car_->to_string ();
       if (midi_debug_global_b)