/*
request.cc -- implement all musical requests.
- source file of the LilyPond music typesetter
+ source file of the GNU LilyPond music typesetter
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+ (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
*/
#include "musical-request.hh"
#include "misc.hh"
#include "debug.hh"
-#include "script-def.hh"
-#include "text-def.hh"
-#include "voice.hh"
-#include "voice-element.hh"
-
-void
-Stem_req::do_print() const
-{
- Rhythmic_req::do_print();
- mtor << "dir : " << dir_i_;
-}
-
-Stem_req::Stem_req(int s, int d)
- : Rhythmic_req(s,d)
-{
- dir_i_ = 0;
-}
-
-/* ************** */
-void Musical_req::do_print()const{}
-void Request::do_print() const{}
-
-/* *************** */
-
-void
-Request::print() const
-{
- mtor << name() << " {";
- do_print();
- mtor << "}\n";
-}
-
+#include "music-list.hh"
void
-Span_req::do_print() const
+Span_req::do_print () const
{
#ifndef NPRINT
- mtor << spantype ;
+ DOUT << span_dir_;
#endif
}
-Request::Request()
+Abbreviation_req::Abbreviation_req ()
{
- elt_l_ = 0;
- defined_ch_c_l_ = 0;
-}
-Request::Request(Request const&src)
-{
- elt_l_ = 0;
- defined_ch_c_l_ = src.defined_ch_c_l_;
-}
-/* *************** */
-Spacing_req::Spacing_req()
-{
- next = 0;
- distance = 0;
- strength = 0;
+ type_i_ = 0;
}
+
void
-Spacing_req::do_print()const
+Abbreviation_req::do_print () const
{
#ifndef NPRINT
- mtor << "next " << next << "dist " << distance << "strength\n";
+ DOUT << "type " << type_i_ << '\n';
#endif
}
-void
-Blank_req::do_print()const
-{
- Spacing_req::do_print();
-}
-/* *************** */
-Melodic_req::Melodic_req()
-{
- notename_i_ = 0;
- octave_i_ = 0;
- accidental_i_ = 0;
- forceacc_b_ = false;
-}
-
-void
-Melodic_req::do_print() const
-{
- mtor << "notename: " << notename_i_ << " acc: " <<accidental_i_<<" oct: "<< octave_i_;
-}
-int
-Melodic_req::height() const
-{
- return notename_i_ + octave_i_*7;
-}
-/*
- should be settable from input to allow "viola"-mode
- */
-static Byte pitch_byte_a[ 7 ] = { 0, 2, 4, 5, 7, 9, 11 };
-int
-Melodic_req::pitch() const
+void
+Melodic_req::transpose (Musical_pitch delta)
{
- return pitch_byte_a[ notename_i_ % 7 ] + accidental_i_ + octave_i_ * 12;
+ pitch_.transpose (delta);
+
+ if (abs (pitch_.accidental_i_) > 2)
+ {
+ warning (_f ("transposition by %s makes accidental larger than two",
+ delta.str ()));
+ }
}
-Plet_req::Plet_req()
-{
- type_c_ = ']';
- dur_i_ = 1;
- type_i_ = 1;
-}
-void
-Plet_req::do_print() const
-{
- mtor << "plet: " << type_c_ << ": " << dur_i_ << "/" << type_i_;
-}
-/* *************** */
-int
-Rhythmic_req::compare(const Rhythmic_req &r1, const Rhythmic_req &r2)
-{
- return sign(r1.duration() - r2.duration());
-}
-Rhythmic_req::Rhythmic_req(int b, int d)
+bool
+Melodic_req::do_equal_b (Request*r) const
{
- plet_factor = 1;
- balltype = b;
- dots = d;
+ Melodic_req* m= dynamic_cast <Melodic_req *> (r);
+ return m&& !compare (*m, *this);
}
-Rhythmic_req::Rhythmic_req()
+int
+Melodic_req::compare (Melodic_req const &m1 , Melodic_req const&m2)
{
- plet_factor = 1;
- balltype = 1;
- dots = 0;
+ return Musical_pitch::compare (m1.pitch_, m2.pitch_);
}
void
-Rhythmic_req::do_print() const
+Melodic_req::do_print () const
{
- mtor << "ball: " << balltype ;
- int d =dots;
- while (d--)
- mtor << '.';
-
- mtor<<", plet factor"<<plet_factor<<"\n";
+ pitch_.print ();
}
-Moment
-Rhythmic_req::duration() const {
- return wholes(balltype,dots)*plet_factor;
-}
-/* *************** */
-Lyric_req::Lyric_req(Text_def* def_p)
- :Text_req(0, def_p)
-{
- def_p->align_i_ = 0; // centre
- dir_i_ = -1; // lyrics below (invisible) staff
-}
-void
-Lyric_req::do_print() const
-{
- Rhythmic_req::do_print();
- Text_req::do_print();
-}
-/* *************** */
-void
-Note_req::do_print() const
-{
- Melodic_req::do_print();
- Rhythmic_req::do_print();
-}
-/* *************** */
-void
-Rest_req::do_print() const
+int
+Rhythmic_req::compare (Rhythmic_req const &r1, Rhythmic_req const &r2)
{
- Rhythmic_req::do_print();
+ return (r1.length_mom () - r2.length_mom ());
}
-/* *************** */
-Beam_req::Beam_req()
+bool
+Rhythmic_req::do_equal_b (Request*r) const
{
- nplet = 0;
-}
+ Rhythmic_req* rh = dynamic_cast <Rhythmic_req *> (r);
-void Beam_req::do_print()const{}
-/* *************** */
-void Slur_req::do_print()const{}
-/* *************** */
-int
-Span_req:: compare(const Span_req &r1, const Span_req &r2)
-{
- return r1.spantype - r2.spantype;
+ return rh && !compare (*this, *rh);
}
-Span_req::Span_req()
+void
+Rhythmic_req::do_print () const
{
- spantype = NOSPAN;
+#ifndef NPRINT
+ DOUT << "duration { " <<duration_.str () << "}";
+#endif
}
-/* *************** */
-Script_req::Script_req(int d , Script_def*def)
-{
- dir_i_ = d;
- scriptdef_p_ = def;
-}
-int
-Script_req::compare(const Script_req &d1, const Script_req &d2)
+Moment
+Rhythmic_req::length_mom () const
{
- return d1.dir_i_ == d2.dir_i_ &&
- d1.scriptdef_p_->compare(*d2.scriptdef_p_);
+ return duration_.length_mom ();
}
-Script_req::Script_req(Script_req const &s)
- : Request( s )
+void
+Rhythmic_req::compress (Moment m)
{
- dir_i_ = s.dir_i_;
- scriptdef_p_ = new Script_def(*s.scriptdef_p_);
+ duration_.compress (m);
}
void
-Script_req::do_print() const
+Lyric_req::do_print () const
{
- mtor << " dir " << dir_i_ ;
- scriptdef_p_->print();
+#ifndef NPRINT
+ Rhythmic_req::do_print ();
+ DOUT << "text = " << text_str_;
+#endif
}
-Script_req::~Script_req()
-{
- delete scriptdef_p_;
-}
-/* *************** */
-int
-Text_req:: compare(const Text_req &r1, const Text_req &r2)
-{
- bool b1 = (r1.dir_i_ == r2.dir_i_);
- bool b2 = (r1.tdef_p_ ->compare(*r2.tdef_p_));
- return b1 && b2;
-}
-Text_req::~Text_req()
+bool
+Note_req::do_equal_b (Request*r) const
{
- delete tdef_p_;
- tdef_p_ = 0;
+ Note_req *n = dynamic_cast<Note_req*> (r);
+ return n&& Rhythmic_req::do_equal_b (n) && Melodic_req::do_equal_b (n);
}
-Text_req::Text_req(Text_req const& src)
-{
- tdef_p_ = new Text_def(*src.tdef_p_);
- dir_i_ = src.dir_i_;
-}
-Text_req::Text_req(int dir_i, Text_def* tdef_p)
+Note_req::Note_req ()
{
- dir_i_ = dir_i;
- tdef_p_ = tdef_p;
+ cautionary_b_ = false;
+ forceacc_b_ = false;
}
-void
-Text_req::do_print() const
-{
- mtor << " dir " << dir_i_ ;
- tdef_p_->print();
-}
-
-/* *************** */
-Moment
-Skip_req::duration() const
-{
- return duration_;
-}
void
-Skip_req::do_print() const
+Note_req::do_print () const
{
- mtor << "duration: " << duration();
+#ifndef NPRINT
+ Melodic_req::do_print ();
+ if (cautionary_b_)
+ {
+ DOUT << " force cautionary accidental\n";
+ }
+ else if (forceacc_b_)
+ {
+ DOUT << " force accidental\n";
+ }
+ Rhythmic_req::do_print ();
+#endif
}
-Voice *
-Request::voice_l()
-{
- if (!elt_l_)
- return 0;
- else
- return (Voice*)elt_l_->voice_l_;
-}
-/* *************** */
-void
-Subtle_req::do_print() const
+bool
+Span_req::do_equal_b (Request*r) const
{
- mtor << " subtime " << subtime_;
+ Span_req * s = dynamic_cast <Span_req *> (r);
+ return s && span_dir_ == s->span_dir_;
}
-void
-Dynamic_req::do_print() const
+Span_req::Span_req ()
{
- Subtle_req::do_print();
+ span_dir_ = CENTER;
}
-void
-Absolute_dynamic_req::do_print() const
-{
- Dynamic_req::do_print();
- mtor << " loudness_" <<loudness_;
-}
-String
-Dynamic_req::loudness_str(Loudness l)
+void
+Text_script_req::do_print () const
{
- switch (l) {
- case FFF: return "fff";
- case FF: return "ff";
- case F: return "f";
- case MF: return "mf";
- case MP: return "mp";
- case P: return "p";
- case PP: return "pp";
- case PPP: return "ppp";
- }
- assert(false);
- return "";
+ DOUT << "text" << text_str_
+ << ", style = " << style_str_;
}
-Absolute_dynamic_req::Absolute_dynamic_req()
+bool
+Text_script_req::do_equal_b (Request *r) const
{
- loudness_ = MF;
+ Text_script_req * t = dynamic_cast<Text_script_req*>(r);
+ return t && t->text_str_ == text_str_ && t->style_str_ == style_str_;
}
-
-Span_dynamic_req::Span_dynamic_req()
+void
+Articulation_req::do_print () const
{
- dynamic_dir_i_ = 0;
+ DOUT << articulation_str_;
}
-void
-Span_dynamic_req::do_print()const
+bool
+Articulation_req::do_equal_b (Request*r) const
{
-#ifndef NPRINT
- Span_req::do_print();
- mtor << "louder/louder: " <<dynamic_dir_i_;
-#endif
+ Articulation_req * a = dynamic_cast<Articulation_req*>(r);
+
+ return a && articulation_str_ == a->articulation_str_;
}