From efcb546f723e1d5c08f9658670d6fe606da66243 Mon Sep 17 00:00:00 2001 From: fred Date: Sun, 1 Dec 1996 17:45:47 +0000 Subject: [PATCH] lilypond-0.0.13 --- hdr/identifier.hh | 10 ++-- hdr/inputmusic.hh | 80 +++++++++++++++++++++++++ src/identifier.cc | 6 +- src/inputmusic.cc | 147 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 236 insertions(+), 7 deletions(-) create mode 100644 hdr/inputmusic.hh create mode 100644 src/inputmusic.cc diff --git a/hdr/identifier.hh b/hdr/identifier.hh index 9cb80386c0..f1d99678d9 100644 --- a/hdr/identifier.hh +++ b/hdr/identifier.hh @@ -18,7 +18,7 @@ struct Identifier Identifier(String n) ; virtual ~Identifier(); virtual Staff * staff() { assert(false); } - virtual Voice * voice() { assert(false); } + virtual Voice_list * voices() { assert(false); } }; struct Staff_id : Identifier { @@ -27,10 +27,10 @@ struct Staff_id : Identifier { ~Staff_id(); }; -struct Voice_id : Identifier { - Voice_id(String s, Voice*st):Identifier(s) { data = st; } - virtual Voice * voice() { return (Voice*)data; } - ~Voice_id(); +struct Voices_id : Identifier { + Voices_id(String s, Voice_list*st):Identifier(s) { data = st; } + virtual Voice_list * voices() { return (Voice_list*)data; } + ~Voices_id(); }; #endif // IDENTIFIER_HH diff --git a/hdr/inputmusic.hh b/hdr/inputmusic.hh new file mode 100644 index 0000000000..d5bf580fc6 --- /dev/null +++ b/hdr/inputmusic.hh @@ -0,0 +1,80 @@ +/* + inputmusic.hh -- part of LilyPond + + (c) 1996 Han-Wen Nienhuys +*/ + +#ifndef INPUTMUSIC_HH +#define INPUTMUSIC_HH + +#include "plist.hh" +#include "proto.hh" + +struct Voice_list : public PointerList { + void translate_time(Real dt); + /// delete stuff; not in destructor! + void junk(); +}; + +struct Vertical_music { + virtual Vertical_simple *simple() { return 0;} + virtual Voice_list convert()=0; + virtual Real length()=0; + virtual void translate_time(Real dt)=0; +}; + +struct Horizontal_music { + virtual Voice_list convert()=0; + virtual Real length()=0; + virtual void translate_time(Real dt)=0; +}; + +struct Horizontal_simple : Horizontal_music { + Voice * voice_; + + /****************/ + + Horizontal_simple(); + void set(Voice*); + virtual Real length(); + virtual Voice_list convert(); + virtual void translate_time(Real dt); + +}; + +struct Vertical_simple : Vertical_music { + Voice * voice_; + + /****************/ + Vertical_simple(); + void add(Voice_element*); + virtual Vertical_simple*simple() { return this; } + virtual Real length(); + virtual Voice_list convert(); + virtual void translate_time(Real dt); +}; + +struct Music_voice : Horizontal_music { + PointerList voice_ ; + + /****************/ + + Real length(); + void add(Vertical_music*); + void add(Voice_element*); + virtual Voice_list convert(); + virtual void translate_time(Real dt); +}; + +struct Music_general_chord : Vertical_music { + PointerList chord_; + + /****************/ + void add(Horizontal_music*); + virtual Real length(); + virtual Voice_list convert(); + virtual void translate_time(Real dt); +}; + + +#endif // INPUTMUSIC_HH diff --git a/src/identifier.cc b/src/identifier.cc index 024fe06486..40281ce718 100644 --- a/src/identifier.cc +++ b/src/identifier.cc @@ -2,6 +2,7 @@ #include "identifier.hh" #include "staff.hh" #include "lexer.hh" +#include "inputmusic.hh" Identifier::Identifier(String n) @@ -20,7 +21,8 @@ Staff_id::~Staff_id() delete staff(); } -Voice_id::~Voice_id() +Voices_id::~Voices_id() { - delete voice(); + voices()->junk(); + delete voices(); } diff --git a/src/inputmusic.cc b/src/inputmusic.cc new file mode 100644 index 0000000000..b00835b95d --- /dev/null +++ b/src/inputmusic.cc @@ -0,0 +1,147 @@ +#include "inputmusic.hh" +#include "voice.hh" + +Vertical_simple::Vertical_simple() +{ + voice_ = new Voice; +} + +void +Vertical_simple::add(Voice_element*v) +{ + voice_->add(v); +} + +Real +Vertical_simple::length() +{ + return voice_->last(); +} +void +Vertical_simple::translate_time(Real t) +{ + voice_->start += t; +} +Voice_list +Vertical_simple::convert() +{ + Voice_list l; + l.bottom().add(voice_); + return l; +} + + +/****************/ + +void +Music_voice::add(Voice_element*v) +{ + PCursor c(voice_.bottom()); + if (!c.ok() || !c->simple()) { + Vertical_simple*vs = new Vertical_simple; + + c.add(vs); + } + + c = voice_.bottom(); + Vertical_simple *s = c->simple(); + s->add(v); +} + +void +Music_voice::add(Vertical_music*v) +{ + // v->translate_time(length()); + voice_.bottom().add(v); +} + +Real +Music_voice::length() +{ + Real l = 0.0; + + for (PCursor i(voice_); i.ok(); i++) + l += i->length(); + return l; +} + + +Voice_list +Music_voice::convert() +{ + Voice_list l; + Real here = 0.0; + + for (PCursor i(voice_); i.ok(); i++) { + Real len = i->length(); // has to be stored, since translate_time doesn't work on copies of the contents of i. + Voice_list k(i->convert()); + k.translate_time(here); + l.concatenate(k); + here +=len; + + } + return l; +} + +void +Music_voice::translate_time(Real t) +{ + for (PCursor i(voice_); i.ok(); i++) + i->translate_time(t); +} + + + +/****************/ + +void +Music_general_chord::translate_time(Real t) +{ + for (PCursor i(chord_); i.ok(); i++) + i->translate_time(t); +} + + + +Real +Music_general_chord::length() +{ + Real l =0.0; + + for (PCursor i(chord_); i.ok(); i++) + l = MAX(l, i->length()); + return l; +} + +void +Music_general_chord::add(Horizontal_music*h) +{ + chord_.bottom().add(h); +} + +Voice_list +Music_general_chord::convert() +{ + Voice_list l; + for (PCursor i(chord_); i.ok(); i++) { + Voice_list k(i->convert()); + l.concatenate(k); + } + return l; +} + +/****************/ + +void +Voice_list::translate_time(Real x) +{ + for (PCursor i(*this); i.ok(); i++) + i->start += x; +} + +void +Voice_list::junk() +{ + for (PCursor i(*this); i.ok(); i++) + delete i.ptr(); +} -- 2.39.5