]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/midi-item.cc
Run grand-replace (issue 3765)
[lilypond.git] / lily / midi-item.cc
index c17c369dcaf5d42df096f0691be196b4e5413e66..4909217c4319c108cca8aba6b22ea9533e5c9b37 100644 (file)
@@ -1,7 +1,7 @@
 /*
   This file is part of LilyPond, the GNU music typesetter.
 
-  Copyright (C) 1997--2012 Jan Nieuwenhuizen <janneke@gnu.org>
+  Copyright (C) 1997--2014 Jan Nieuwenhuizen <janneke@gnu.org>
 
   LilyPond is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -21,6 +21,7 @@
 
 #include "duration.hh"
 #include "international.hh"
+#include "libc-extension.hh"
 #include "main.hh"
 #include "midi-stream.hh"
 #include "misc.hh"
@@ -192,8 +193,10 @@ Midi_time_signature::to_string () const
 Midi_note::Midi_note (Audio_note *a)
   : Midi_channel_item (a),
     audio_ (a),
-    dynamic_byte_ (a->dynamic_ && a->dynamic_->volume_ >= 0
-                   ? Byte (a->dynamic_->volume_ * 0x7f) : Byte (0x5a))
+    dynamic_byte_ (min (max (Byte ((a->dynamic_ && a->dynamic_->volume_ >= 0
+                                    ? a->dynamic_->volume_ * 0x7f : 0x5a)
+                                   + a->extra_velocity_),
+                             Byte (0)), Byte (0x7f)))
 {
 }
 
@@ -399,8 +402,12 @@ Midi_control_function_value_change::to_string () const
   static const Real full_fine_scale = 0x3FFF;
   static const Real full_coarse_scale = 0x7F;
   bool fine_resolution = (control_function->lsb_control_number_ >= 0);
-  int value = lround (value_ * (fine_resolution ?
-                                full_fine_scale : full_coarse_scale));
+  // value_ is in range [0.0 .. 1.0].  For directional value ranges,
+  // #CENTER will correspond to 0.5 exactly, and my_round rounds
+  // upwards when in case of doubt.  That means that center position
+  // will round to 0x40 or 0x2000 by a hair's breadth.
+  int value = (int) my_round (value_ * (fine_resolution ?
+                                        full_fine_scale : full_coarse_scale));
   Byte status_byte = (char) (0xB0 + channel_);
   str += ::to_string ((char)status_byte);
   str += ::to_string ((char)(control_function->msb_control_number_));