]> git.donarmstrong.com Git - lilypond.git/commitdiff
lilypond-0.0.13
authorfred <fred>
Sun, 1 Dec 1996 17:45:47 +0000 (17:45 +0000)
committerfred <fred>
Sun, 1 Dec 1996 17:45:47 +0000 (17:45 +0000)
hdr/identifier.hh
hdr/inputmusic.hh [new file with mode: 0644]
src/identifier.cc
src/inputmusic.cc [new file with mode: 0644]

index 9cb80386c0a51ae15bff1b52a8177012419499ee..f1d99678d9ab7499614bfe04b0af2ccbb89c4de3 100644 (file)
@@ -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 (file)
index 0000000..d5bf580
--- /dev/null
@@ -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<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
index 024fe06486b30501bbd7cc9182d73e078a29ee28..40281ce718b345d82681e4406767323e3789f645 100644 (file)
@@ -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 (file)
index 0000000..b00835b
--- /dev/null
@@ -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<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();
+}