lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Small pitch bends correct and tested. (issue4654063)


From: lemniskata . bernoullego
Subject: Small pitch bends correct and tested. (issue4654063)
Date: Sat, 25 Jun 2011 20:13:04 +0000

Reviewers: gbreed,

Message:
Graham Breed wrote:

I've found and patched two problems with the pitch bend
tuning code:

1) The pitch isn't always rounded to the nearest equally
tempered value, so the result looks strange in a sequencer,
and artifacts caused by the pitch bends are more severe.

2) The tuning is rounded to cents before the pitch bends
are calculated.  It may not be a big deal, but there's no
need for it, and the code's simpler calculating the bends
directly.

I don't think either of these are registered issues.  As
I'm new with Git, the two issues are mixed in the two
patches.  Problem (1) is fixed in get_semitone_pitch().
It's just a question of rounding off the result.
Everything else is for problem (2).


Description:
Small pitch bends correct and tested.

Pitch bends are not rounded to cents.

Pitch bends of full precision centered on zero.

Please review this at http://codereview.appspot.com/4654063/

Affected files:
  M lily/midi-item.cc


Index: lily/midi-item.cc
diff --git a/lily/midi-item.cc b/lily/midi-item.cc
index 1fcb259ae13c2c0b6b0ee94967476cd8099f3928..02bdd7ac84b1e09cd44afb71873da4984d494a03 100644
--- a/lily/midi-item.cc
+++ b/lily/midi-item.cc
@@ -28,10 +28,8 @@
 #include "string-convert.hh"
 #include "warn.hh"

-#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)
+#define PITCH_WHEEL_SEMITONE 0X1000

 Midi_item *
 Midi_item::get_midi (Audio_item *a)
@@ -193,15 +191,16 @@ Midi_note::get_fine_tuning () const
                   + audio_->transposing_.tone_pitch ()) * Rational (2);
   tune -= Rational (get_semitone_pitch ());

-  tune *= 100;
+  tune *= PITCH_WHEEL_SEMITONE;
   return (int) double (tune);
 }

 int
 Midi_note::get_semitone_pitch () const
 {
-  return int (double ((audio_->pitch_.tone_pitch ()
-                      + audio_->transposing_.tone_pitch ()) * Rational (2)));
+  double tune = double ((audio_->pitch_.tone_pitch ()
+                      + audio_->transposing_.tone_pitch ()) * Rational (2));
+  return (tune > 0)? int (tune + 0.5): int(tune - 0.5);
 }

 string
@@ -214,10 +213,7 @@ Midi_note::to_string () const
   // print warning if fine tuning was needed, HJJ
   if (get_fine_tuning () != 0)
     {
-      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);
+      finetune = PITCH_WHEEL_CENTER + get_fine_tuning();

       str += ::to_string ((char) (0xE0 + channel_));
       str += ::to_string ((char) (finetune & 0x7F));





reply via email to

[Prev in Thread] Current Thread [Next in Thread]