]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/midi-item.cc
patch::: 1.3.96.jcn7
[lilypond.git] / lily / midi-item.cc
index 730a8658fb59cd8ae3434ade2e1d2818ee676002..bf1bef9b961651b64ab18e5ed5ee114d3a58c23b 100644 (file)
@@ -6,7 +6,6 @@
   (c)  1997--2000 Jan Nieuwenhuizen <janneke@gnu.org>
  */
 
-#include "proto.hh"
 #include "debug.hh"
 #include "misc.hh"
 #include "string.hh"
@@ -29,12 +28,15 @@ Midi_item::midi_p (Audio_item* a)
     return new Midi_note (i);
   else if (Audio_dynamic* i = dynamic_cast<Audio_dynamic*> (a))
     return new Midi_dynamic (i);
+  else if (Audio_piano_pedal* i = dynamic_cast<Audio_piano_pedal*> (a))
+    return new Midi_piano_pedal (i);
   else if (Audio_tempo* i = dynamic_cast<Audio_tempo*> (a))
     return new Midi_tempo (i);
   else if (Audio_time_signature* i = dynamic_cast<Audio_time_signature*> (a))
     return new Midi_time_signature (i);
   else if (Audio_text* i = dynamic_cast<Audio_text*> (a))
-    return i->text_str_.length_i () ? new Midi_text (i) : 0;
+    //return i->text_str_.length_i () ? new Midi_text (i) : 0;
+    return new Midi_text (i);
   else
     assert (0);
 
@@ -354,8 +356,9 @@ Midi_key::Midi_key (Audio_key*a)
 String
 Midi_key::str () const
 {
-  int sharps_i = audio_l_->key_.sharps_i ();
-  int flats_i = audio_l_->key_.flats_i ();
+  // fxime.
+  int sharps_i = 0; //audio_l_->key_.sharps_i ();
+  int flats_i = 0; //audio_l_->key_.flats_i ();
 
   // midi cannot handle non-conventional keys
   if (flats_i && sharps_i)
@@ -368,7 +371,9 @@ Midi_key::str () const
 
   String str = "ff5902";
   str += String_convert::i2hex_str (accidentals_i, 2, '0');
-  str += String_convert::i2hex_str ((int)audio_l_->key_.minor_b (), 2, '0');
+
+  // (int)audio_l_->key_.minor_b ()
+  str += String_convert::i2hex_str (0, 2, '0');
   return String_convert::hex2bin_str (str);
 }
 
@@ -477,13 +482,41 @@ Midi_dynamic::str () const
     27 LSB
    */
   static Real const full_scale = 127;
+  
+  int volume = (int)(audio_l_->volume_*full_scale);
+  if (volume <= 0)
+    volume = 1;
+  if (volume > full_scale)
+    volume = (int)full_scale;
 
   str += to_str ((char)0x07);
-  int volume = (int)(audio_l_->volume_*full_scale);
   str += to_str ((char)volume);
   return str;
 }
 
+Midi_piano_pedal::Midi_piano_pedal (Audio_piano_pedal* a)
+{
+  audio_l_ = a;
+}
+
+String
+Midi_piano_pedal::str () const
+{
+  Byte status_byte = (char) (0xB0 + channel_i_);
+  String str = to_str ((char)status_byte);
+
+  if (audio_l_->type_str_ == "Sostenuto")
+    str += to_str ((char)0x42);
+  else if (audio_l_->type_str_ == "Sustain")
+    str += to_str ((char)0x40);
+  else if (audio_l_->type_str_ == "UnaChorda")
+    str += to_str ((char)0x43);
+
+  int pedal = ((1 - audio_l_->dir_) / 2 ) * 0x7f;
+  str += to_str ((char)pedal);
+  return str;
+}
+
 Midi_tempo::Midi_tempo (Audio_tempo* a)
 {
   audio_l_ = a;
@@ -503,15 +536,6 @@ Midi_text::Midi_text (Audio_text* a)
   audio_l_ = a;
 }
 
-#if 0
-Midi_text::Midi_text (Midi_text::Type type, String text_str)
-  : Audio_text ()
-{
-  text_str_ = text_str;
-  type_ = type;
-}
-#endif
-
 String
 Midi_text::str () const
 {