source file of the GNU LilyPond music typesetter
- (c) 1998 Han-Wen Nienhuys <hanwen@cs.ruu.nl>
+ (c) 1998--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
*/
#include "musical-pitch.hh"
#include "debug.hh"
+#include "main.hh"
-Musical_pitch::Musical_pitch ()
+int
+compare (Array<Musical_pitch>* left, Array<Musical_pitch>* right)
{
- init ();
+ assert (left);
+ assert (right);
+
+ if (left->size () == right->size ())
+ {
+ for (int i = 0; i < left->size (); i++)
+ {
+ int r = Musical_pitch::compare ((*left)[i], (*right)[i]);
+ if (r)
+ return r;
+ }
+ }
+ else
+ return 1;
+
+ return 0;
}
-void
-Musical_pitch::init ()
+SCM
+Musical_pitch::to_scm ()const
{
- notename_i_ = 0;
- octave_i_ = 0;
- accidental_i_ = 0;
+ return gh_list (gh_int2scm (octave_i_),
+ gh_int2scm (notename_i_),
+ gh_int2scm (accidental_i_),
+ SCM_UNDEFINED);
}
-void
-Musical_pitch::print () const
+
+Musical_pitch::Musical_pitch (SCM s)
{
-#ifndef NPRINT
- DOUT << str();
-#endif
+ octave_i_ = gh_scm2int (gh_car (s));
+ notename_i_ = gh_scm2int (gh_cadr (s));
+ accidental_i_ = gh_scm2int (gh_caddr (s));
}
+Musical_pitch::Musical_pitch (int n, int a, int o)
+{
+ notename_i_ = n;
+ accidental_i_ = a;
+ octave_i_ = o;
+}
+
+
int
Musical_pitch::compare (Musical_pitch const &m1, Musical_pitch const &m2)
{
}
+#if 0
+// nice test for internationalisation strings
char const *accname[] = {"double flat", "flat", "natural",
"sharp" , "double sharp"};
+#else
+char const *accname[] = {"eses", "es", "", "is" , "isis"};
+#endif
String
Musical_pitch::str () const
{
int n = (notename_i_ + 2) % 7;
- String s (char(n + 'a'));
+ String s = to_str (char(n + 'a'));
if (accidental_i_)
- s += " " + String (accname[accidental_i_ + 2]);
+ s += String (accname[accidental_i_ + 2]);
+
+ if (octave_i_ > 0)
+ {
+ int o = octave_i_ + 1;
+ while (o--)
+ s += "'";
+ }
+ else if (octave_i_ <0)
+ {
+ int o = (-octave_i_) - 1;
+ while (o--)
+ s += to_str (',');
+ }
- if (octave_i_)
- s += String ((octave_i_> 0)? "^": "_") + String(octave_i_);
-
return s;
}
+/*
+ change me to relative, counting from last pitch p
+ return copy of resulting pitch
+ */
Musical_pitch
Musical_pitch::to_relative_octave (Musical_pitch p)
{
up_pitch.accidental_i_ = accidental_i_;
down_pitch.accidental_i_ = accidental_i_;
+ Musical_pitch n = *this;
up_pitch.up_to (notename_i_);
down_pitch.down_to (notename_i_);
+
int h = p.steps ();
if (abs (up_pitch.steps () - h) < abs (down_pitch.steps () - h))
- {
- *this = up_pitch;
- /* this sux imnsho
- if (oct_mod > 0) // ugh
- oct_mod --;*/
- }
+ n = up_pitch;
else
- {
- *this = down_pitch;
- /* if (oct_mod < 0)
- oct_mod ++;*/
- }
+ n = down_pitch;
- octave_i_ += oct_mod;
+ n.octave_i_ += oct_mod;
+
+ *this = n;
return *this;
}
notename_i_ = notename;
}
-#if 0
-
-Musical_pitch
-My_lily_parser::get_melodic_req (Musical_pitch p, int quotes)
-{
- if (relative_octave_mode_b_)
- {
- set_nearest (melodic);
- int d = melodic->pitch () - last_melodic_->pitch ();
- int shift = 0;
- if (quotes && (sign (d) == sign (quotes)))
- shift -= sign (quotes);
- if (!quotes && (abs (d) == 6))
- {
- String str = _("Octave ambiguity; assuming ");
- /*
- [TODO]
- figure this out.
-
- If the distance is exactly*) half an octave, there is
- no nearest pitch. In that case, we'll try to guess what
- composer/ typist meant.
- Firstly, we'll do this by comparing the 'notename distance':
-
- f b' % name-distance: f g a b: 3
-
- is surely a shorter notename distance than
-
- f 'b % name-distance: b c d e f: 4
-
- (should we give a warning at all, or can we safely assume
- this is a positive interval up?)
-
- *) It is conceivable that, musically speaking, the interval
- with the greater pitch-distance is thought to be smaller?
-
- */
-
- int name_delta = melodic->notename_i_ - last_melodic_->notename_i_;
- int name_near = abs (name_delta) % 7;
- int name_wrap = (7 - abs (name_delta)) % 7;
- if (name_near != name_wrap)
- shift = name_near < name_wrap ? sign (name_delta) : -sign (name_delta);
- else if (sign (last_melodic_->accidental_i_)
- != sign (melodic->accidental_i_))
- shift = last_melodic_->accidental_i_ - melodic->accidental_i_;
- else
- shift = -1;
- String name_str = notename_str (melodic);
- str += shift > 0 ? name_str + "'" : "'" + name_str;
- if (sign (d) == sign (shift))
- shift = 0;
- melodic->warning (str);
- }
- melodic->octave_i_ += quotes + shift;
- }
- else
- {
- Melodic_req nearest (*melodic);
- set_nearest (&nearest);
- melodic->octave_i_ += quotes;
-
- if (find_quarts_global_b)
- {
- int e = melodic->pitch () - nearest.pitch ();
- if (e)
- {
- int d = melodic->pitch () - last_melodic_->pitch ();
- String str = _("Interval greater than quart");
- int n = 1 + (abs (d) - 1) / 12;
- String quote_str ('\'', n);
- str += _(", relative: ");
- String name_str = notename_str (melodic);
- str += d < 0 ? quote_str + name_str : name_str + quote_str;
- melodic->warning (str);
- }
- }
- }
- delete last_melodic_;
- last_melodic_ = melodic->clone ()->musical ()->melodic ();
- return melodic;
-}
-#endif