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 {
~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
--- /dev/null
+/*
+ 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<Voice*> {
+ 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<Vertical_music*> 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<Horizontal_music*> chord_;
+
+ /****************/
+ void add(Horizontal_music*);
+ virtual Real length();
+ virtual Voice_list convert();
+ virtual void translate_time(Real dt);
+};
+
+
+#endif // INPUTMUSIC_HH
#include "identifier.hh"
#include "staff.hh"
#include "lexer.hh"
+#include "inputmusic.hh"
Identifier::Identifier(String n)
delete staff();
}
-Voice_id::~Voice_id()
+Voices_id::~Voices_id()
{
- delete voice();
+ voices()->junk();
+ delete voices();
}
--- /dev/null
+#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<Vertical_music*> 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<Vertical_music*> i(voice_); i.ok(); i++)
+ l += i->length();
+ return l;
+}
+
+
+Voice_list
+Music_voice::convert()
+{
+ Voice_list l;
+ Real here = 0.0;
+
+ for (PCursor<Vertical_music*> 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<Vertical_music*> i(voice_); i.ok(); i++)
+ i->translate_time(t);
+}
+
+
+
+/****************/
+
+void
+Music_general_chord::translate_time(Real t)
+{
+ for (PCursor<Horizontal_music*> i(chord_); i.ok(); i++)
+ i->translate_time(t);
+}
+
+
+
+Real
+Music_general_chord::length()
+{
+ Real l =0.0;
+
+ for (PCursor<Horizontal_music*> 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<Horizontal_music*> i(chord_); i.ok(); i++) {
+ Voice_list k(i->convert());
+ l.concatenate(k);
+ }
+ return l;
+}
+
+/****************/
+
+void
+Voice_list::translate_time(Real x)
+{
+ for (PCursor<Voice*> i(*this); i.ok(); i++)
+ i->start += x;
+}
+
+void
+Voice_list::junk()
+{
+ for (PCursor<Voice*> i(*this); i.ok(); i++)
+ delete i.ptr();
+}