From 9f160fcd0c8f1157b8a75f471961a0f24be37b66 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Thu, 27 Feb 1997 23:17:37 +0100 Subject: [PATCH] release: 0.0.37 --- Documentation/Makefile | 2 +- Documentation/faq.pod | 5 +- Documentation/language.pod | 413 +++++++++++++++++++++++++++++++++++++ NEWS | 24 +++ Sources.make | 24 ++- Variables.make | 2 +- configure | 2 +- deps/dummy.dep | 1 - flower/NEWS | 9 + flower/Sources.make | 4 +- flower/Variables.make | 2 +- flower/dstream.cc | 8 +- flower/fproto.hh | 1 + flower/path.cc | 25 ++- flower/scalar.cc | 18 +- flower/string.cc | 236 ++++++++++----------- flower/string.hh | 87 ++++---- flower/stringconversion.cc | 102 --------- flower/stringconversion.hh | 30 --- flower/stringdata.inl | 13 +- flower/stringtest.cc | 26 +-- flower/stringutil.cc | 7 +- hdr/midi-event.hh | 27 ++- hdr/midi-main.hh | 3 + hdr/midi-score.hh | 3 + hdr/midi-track.hh | 9 +- hdr/midiitem.hh | 2 +- hdr/my-midi-lexer.hh | 2 +- hdr/my-midi-parser.hh | 22 +- hdr/proto.hh | 8 + hdr/script.hh | 2 +- hdr/stem.hh | 2 +- hdr/textitem.hh | 2 +- input/Makefile | 3 +- input/fugue1.midi.ly | 100 +++++++++ input/pre1.midi.ly | 80 +++++++ input/standchen.ly | 2 +- src/beam.cc | 22 +- src/binary-source-file.cc | 8 +- src/dimen.cc | 4 +- src/inputfile.cc | 2 +- src/lexer.l | 22 +- src/lyricitem.cc | 2 +- src/main.cc | 14 +- src/midi-event.cc | 180 +++++++--------- src/midi-lexer.l | 20 +- src/midi-main.cc | 37 +++- src/midi-parser.y | 42 ++-- src/midi-score.cc | 39 ++++ src/midi-template.cc | 10 + src/midi-track.cc | 65 +++++- src/midiitem.cc | 29 +-- src/midistream.cc | 7 +- src/misc.cc | 1 + src/my-midi-lexer.cc | 4 +- src/my-midi-parser.cc | 78 ++++--- src/mylexer.cc | 2 +- src/note.cc | 2 +- src/parser.y | 7 + src/request.cc | 4 +- src/script.cc | 4 +- src/sourcefile.cc | 4 +- src/stem.cc | 2 +- src/tex.cc | 6 +- src/textitem.cc | 4 +- src/timedescription.cc | 15 +- src/walkregs.cc | 2 +- 67 files changed, 1310 insertions(+), 636 deletions(-) create mode 100644 Documentation/language.pod delete mode 100644 flower/stringconversion.cc delete mode 100644 flower/stringconversion.hh create mode 100644 input/fugue1.midi.ly create mode 100644 input/pre1.midi.ly diff --git a/Documentation/Makefile b/Documentation/Makefile index f8211b708c..0dc97f7dbe 100644 --- a/Documentation/Makefile +++ b/Documentation/Makefile @@ -1,5 +1,5 @@ PODS=README.pod CodingStyle.pod lilygut.pod lilyinput.pod error.pod\ - faq.pod index.pod + faq.pod index.pod language.pod TXTS=$(PODS:.pod=.txt) MANS=$(PODS:.pod=.1) HTMLS=$(PODS:.pod=.html) diff --git a/Documentation/faq.pod b/Documentation/faq.pod index d54266f053..79e511498e 100644 --- a/Documentation/faq.pod +++ b/Documentation/faq.pod @@ -56,11 +56,14 @@ A: By using g++ LilyPond is portable to all platforms which support g++ (there are quite a few). Not having to support other compilers saves us a *lot* of trouble. LilyPond & FlowerLib uses: -=over 5 +=over 6 =item * builtin bool +=item * +64 bit integral type long long + =item * typeof diff --git a/Documentation/language.pod b/Documentation/language.pod new file mode 100644 index 0000000000..e316fdc14e --- /dev/null +++ b/Documentation/language.pod @@ -0,0 +1,413 @@ +=head1 NAME + +language.pod -- state of the art mudela-vapourware. + +=head1 SYNOPSIS + +(damn pod) + +=head1 DESCRIPTION + +here are some thoughts on the language. Most of the examples are in +pseudo current mudela. Some stuff gratuitously taken from your mails. + +=head1 NOTE + +I dislike vapourware. That's why I oppose to concrete plans on how to +do input for features we don't know how to produce on paper + +=head1 AIM + +A musical notation that is relatively easy to comprehend to both +programmers and non programmers. The final aim is to be able to +express what can be expressed in sheet music. + +=over 5 + +=item * +play pieces + +=item * +typeset the pieces + +=back + +further requirements: + +=over 5 + +=item * +Possible to edit the layout without danger of changing the +original music. (fingerings, interpretation) + +=item * +Simple music manipulations, such as transposing, creating a +score for individual instruments as well as for the conductor, +extracting short pieces from a longer one, glueing several shorter +pieces into a single score. + +=back + +Pieces could be: + + +=over 5 + +=item * +Mahlerian orchestral score + +=item * +piano pieces + +=item * +pop songs (lyrics + chords) + +=item * +gregorian chant (?) + +=item * +bach multivoice organ music. + +=item * +short excerpts to be used in musicological publications. + +=back + +=head1 REQUIREMENTS + +=head2 Parser output + +When I say LilyPond input, I mean the final output of the parsing +step, which should be roughly the same as it is now: hierarchically, +using pseudo syntax + + Score { + Midi_def + Paper_def + Staff [multiple] { + Voices + Stafftype + (instrument) + } + } + + +Voice should stay the same: + + Voice { + Voice_elements + } + +and + + Voice_elements { + requests + } + + +=head2 Staffs + +We definitely need the concept of staff in the parser output, because +it is fundamental to LilyPond. I think the input language should +allow the user to do something like: + + melody = { c d e f g } + + %At this time I can't think of more than these stafftypes + staff { gregorian music { melody } } + staff { pianostaff music { melody } } + staff { melodic music { melody } } + staff { rhythmic music { melody } } + staff { lyric music { melody } } % silly, i admit. + +The staff could also define what the instrument would be (both in +print and in MIDI) + +Moreover, if music {} in score equals staff, then how do we do multiple +voices on one staff? + +We might be able to do without the staff{} construct, but I doubt if +it will make things easier. + +=head1 THOUGHTS + +=head2 Typing + +It is difficult to make mistakes with typing now because you have to +tell LilyPond what it is dealing with + + staff { identifier } + +versus + + staff { music { identifier } } + +I'm not sure on dropping this, I'm afraid it will make the language +less legible. Technically, dropping it is not very difficult (it will +introduce slight parser-source bloat) + +What if the staff is extended to have some more blocks, all of which +can be declared? Like the score now: + + score { + a_staff_id + a_midi_id + a_paper_id + a_command_id + } + +This will only be readable if the Mudela-user rigidly uses hungarian, +which he/she won't. + +=head2 Backslash + +I like it. Let's keep it in the language if we need it, it's a +universally accepted escape sequence. + +=head2 Braces + +I like the idea of <> vs. {}. Not because I think it is more clear, +but I dislike the word "music", I can't seem to find the proper word +for what "music" currently does, so I'd like to flush it. + +I would like to point that both <> and {} are indicating a +hierarchy. I think, we should continue to allow them to nest. I still +have no preference what to use for what. + +=head2 Command syntax + +Braces on commands are here now, because the {} are the only nesting +braces. We need to avoid that, since the brace is overused as it +is. We don't like lisp that much. (the key is the only commands which +really needs {} now) + +How about + + \bar "some args", "some more"; + +(note the ; ), which is a mix of perl and TeX. + +Of course \key should take a \notename. In fact, I think we should +program the note intervals (which are now hardcoded for midi purposes) +To allow adaptation to other scales. + +As simple fix, we might do key declarations: + + \keybes= \key { bes es } + + \key{\keybes} + + + +[LOOSE THOUGHT] + +We might drop this {} argument altogether, by merely enforcing +that each "statement" (music,score,staff,chord) takes a LIST as +argument, and use the {} to group lists. This is admittedly perl. This +is very sketchy. + + +=head2 Requests + +I want to give the user some access to the internals. Technically, +walkers/registers will happily typeset voices which mix lyrics and +notes, which combine stem requests and lyricreqs. I want to have a + + \request { melodic name = 5, acc = -10 + rhythmic ball=4 dots 2, lyric = "foobar" } + +type of syntax. This is the most flexible input format possible, since +any valid LilyPond input can be made. This strongly implies tying +mudela to LilyPond. That I don't mind, but it hampers +portability. Suppose some commercial systems want to read mudela +too. + +=head2 Lexer modes + +the $ and @ were quick hacks, which suck badly. Replacing it by a +mechanism that switches the lexer automatically would be better, but +it is still error prone, and it hurts uniformity. What I would like +best is unified syntax, but this seems impossible since lyrics could +clash with notenames. If possible it would simplify the parser, the +scanner, and the explanation of the language. + +What about: + + bes c d e f % notes + 'bes- sen sap % some lyric syllables + +We can make one of the ' ` " a lyric-indication, but then we would +have to change the octave indication, eg. + + _bes % lower + ^bes % higher + +or + + +bes % higher + -bes % lower + +And I am still not sure if it would be possible now, but I think this +is worthwile to investigate. Or we could replace @ by a +quote (take your pick) sign, which is a lot more intuitive. + +The big question remaining is: do we want to add any more modes than +lyric and note? + + +[LOOSE THOUGHT] + +Even looser ideas: we can take a look at the perl wagon. It has numerous +inputmodes. What about: + + lyric << ENDLYRIC + + bes- sen- sap + + ENDLYRIC + + music << ENDMUSIC + + c d e f g + + ENDMUSIC + + +[LOOSE THOUGHT] + +If we free up $ @ from their current meaning, $ and @ could be used to +signify other things. + +=head2 Concrete solution to lyric vs. note + +I think + + "lyric" + +is a valid lyric too. This implies that any bare string is checked if +it is a note. Now it prints an error if not, but I could change it to +assume it is a STRING (and can be reduced to lyric). Heck! I could +implement this tonight. We'd lose one mode! (after checking lexer +source) the only problem is preventing puctuation and the - and _ from +clashing with script symbols. + + +=head2 Command placement: + +Mats is an arduous fan of having the commands inside music. I am +not. I see the Mudela music as something which can be plugged into +different staffs, transposed, translated in time, copied, quoted, +etc. Encouraging "inline" commands would be bad since they hinder this +reuse of typed music. + +The way I figure it, the bad part is essentially counting +bars/wholes. Maybe we can get rid of it, by reinstalling the "mark" +commands. + +I definitely want to avoid complicated logic ("Hey there is another +bar request, should we merge this bar with another staff's", this kind +of "smartness" makes a lot M$ software inconsistent) inside LilyPond, +by making the input unambiguous in this respect. + +There is another complication: some symbols (bars) sometimes are +linked across staffs. I should first think of a way to do this in +LilyPond, before even considering a syntax. + + +=head2 Volta + +uhh? + +=head2 Numbers + +The syntax of /, * and : has to be settled, we have + + - notes (1, 2, 4, 8 etc) + - meter 2*4 + - plet 2/3 + - multiple notes: 3*4 + - abbreviations (not implemented) c4/4 or c4*4 + +=head2 Filtering + +This is a idea of mine: we could filter some request types from +voices, + +eg: + + \mel1 = \music { c-. d-. e-. f-. \meter {2*4} g-. a-. b.- c-. } + + \m1 = \filter { "script_req" \mel1 } + \m2 = \filter { "command_req" \mel1 } + \m3 = \filter { "melodic_req" \mel1 } + \m3 = \filter { ("rhythmic_req") && (!"lyric_req") && + ("stem_req" || "beam_req") \mel1 } + % syntax needs change. Clash with () slur? + + \mel2 = \music { c c g g a a g2 } + + \combined = \merge { \m1, \mel2 } + +This means m1 contains the scripts, of \mel, \m2 only the meter +command surrounded by (essentially) some skips, and \m3 the notes +without scripts or meters. This could be a solution to the "command in +music vs. command with skip". + +Combined with merging of requests, this would be a powerful tool. In +this example \combined is a combination of melody mel2 and the accents +of \mel1. + +This idea is for advanced users, but it would come in handy in urtext +editions: + + include "mozart-horn.ly" + + \m1 = \merge { \urmozart + \dennisbrain_interpretation } + \m2 = \merge { \urmozart + \barrytuckwell_interpretation } + + +=head2 Proposed operators: + +Just ideas: + + || && ! filter syntax + ++ concatenation of voices + + merging of voices + + +=head2 C++ OOP like input. + +I don't see the big win of this. + + score sc1= melody; + sc1.staff{\verse}; + sc1.staff{<\b1 \b2>} + sc1.paper=mypaperdef; + + +We're not doing a programming language. In this syntax the parser has +to lookup what sc1 means, decide if it should copied shallow/deep, +decide if has a staff block, switch the mode after it finds that staff +takes music. May be I'm just ranting, but it looks hairy to +me. Remember that at this stage we're just filling structs. + +In a distant future there might be a need for programming (are you +listening, Philip Glass?), but I think that would be something for +Mudela version 3. And I think using m4 (or something alike) would be +just as convenient. + +=head2 Transposition + +Has to be done. How about: + + \transpose { \from c \to g \music { ... }} + +=head2 Quoting + +Difficult. Hmm... + + \oboe = \music { ........................ } + + \oboefragment = \extract { \from 5*2 \to 6*2 \music { \oboe } } + + diff --git a/NEWS b/NEWS index 785c5bf38d..6592108aec 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,27 @@ +pl 37 + + +Documentation + - language.pod as starting point for mudela devel. + + - Jan's patches: +(jan's pl 36-3) + + - m2m produces .ly output +Internal + - simpler and better naming for Duration* + - the great String renaming / index to base=0 change + - Track_column, Lily_stream +Features + - m2m patchy --no-triplet option; + lilypond accepts m2m's real midi output (hand-add red tape) + - m2m output only valid durations, resync option wip +Bugfix + - m2m duration calc +Internal + - Duration, Plet, Duration_convert taking load off duration calc. + + pl 36 - Jan's patches: - do MIDI rests cleanly. diff --git a/Sources.make b/Sources.make index 0146217149..a4e776d8f4 100644 --- a/Sources.make +++ b/Sources.make @@ -1,7 +1,9 @@ # Sources.make # sourcefiles to be shipped. Also used for dependencies -hdr=bar.hh barreg.hh beam.hh boxes.hh break.hh clefreg.hh clefitem.hh\ +hdr=bar.hh barreg.hh beam.hh\ + binary-source-file.hh\ + boxes.hh break.hh clefreg.hh clefitem.hh\ colhpos.hh commandrequest.hh \ complexwalker.hh complexstaff.hh\ const.hh debug.hh dimen.hh directionalspanner.hh\ @@ -86,20 +88,30 @@ stablecc=request.cc bar.cc boxes.cc break.cc \ # m2m headers # mym2mhh=\ - binary-source-file.hh\ + duration.hh\ + lily-stream.hh\ midi-event.hh\ midi-main.hh\ midi-score.hh\ midi-track.hh\ my-midi-lexer.hh\ my-midi-parser.hh\ + track-column.hh\ + +# + +# m2m shared headers +# +mym2msharedhh=\ + binary-source-file.hh\ # - + # m2m source # mym2mcc=\ - binary-source-file.cc\ + duration.cc\ + lily-stream.cc\ midi-event.cc\ midi-main.cc\ midi-score.cc\ @@ -107,15 +119,17 @@ mym2mcc=\ midi-track.cc\ my-midi-lexer.cc\ my-midi-parser.cc\ + track-column.cc\ # # m2m shared source # mym2msharedcc=\ + binary-source-file.cc\ inputfile.cc\ sourcefile.cc\ source.cc\ - # + diff --git a/Variables.make b/Variables.make index 886b6eb256..6a9b2cf738 100644 --- a/Variables.make +++ b/Variables.make @@ -3,7 +3,7 @@ # version info MAJVER=0 MINVER=0 -PATCHLEVEL=36 +PATCHLEVEL=37 diff --git a/configure b/configure index 1c611713a5..fec8a5617d 100755 --- a/configure +++ b/configure @@ -12,7 +12,7 @@ function setversion() { MAKE=${MAKE:-make} PREFIX=${PREFIX:-.} -NEEDFLOWERVER=1.1.2 +NEEDFLOWERVER=1.1.4 echo using PREFIX=$PREFIX echo I need Flower version $NEEDFLOWERVER diff --git a/deps/dummy.dep b/deps/dummy.dep index 8b13789179..e69de29bb2 100644 --- a/deps/dummy.dep +++ b/deps/dummy.dep @@ -1 +0,0 @@ - diff --git a/flower/NEWS b/flower/NEWS index a01d6a140b..d6d6d86aed 100644 --- a/flower/NEWS +++ b/flower/NEWS @@ -1,3 +1,12 @@ +pl 1.1.3-1 + - great renaming of String and String_convert interfaces + - more conversions moved (copied actually) to String_convert + - String indexing now all base = 0, not found = -1 + - renamed by to byte + +pl 1.1.3 + - String::mid + - memmove test code pl 1.1.2 - StringConversio::bin2int_i diff --git a/flower/Sources.make b/flower/Sources.make index 3964ba9be5..82454e3e3c 100644 --- a/flower/Sources.make +++ b/flower/Sources.make @@ -1,6 +1,6 @@ cc=choleski.cc datafile.cc dstream.cc lgetopt.cc matdebug.cc matrix.cc\ -path.cc scalar.cc smat.cc string.cc stringconversion.cc stringutil.cc\ +path.cc scalar.cc smat.cc string.cc string-convert.cc stringutil.cc\ textdb.cc textstream.cc unionfind.cc vector.cc templatecc=cursor.tcc list.tcc plist.tcc interval.tcc\ @@ -11,7 +11,7 @@ inl=link.inl list.inl cursor.inl plist.inl stringdata.inl stringhandle.inl hh=assoc.hh associter.hh choleski.hh compare.hh cursor.hh dstream.hh\ fproto.hh handle.hh interval.hh iterate.hh lgetopt.hh link.hh list.hh\ matrix.hh path.hh pcursor.hh plist.hh rational.hh real.hh scalar.hh\ -smat.hh string.hh stringconversion.hh stringhandle.hh stringdata.hh\ +smat.hh string.hh string-convert.hh stringhandle.hh stringdata.hh\ textdb.hh textstream.hh unionfind.hh pqueue.hh\ varray.hh vector.hh vsmat.hh datafile.hh diff --git a/flower/Variables.make b/flower/Variables.make index 4e40f2453d..d8cca75c97 100644 --- a/flower/Variables.make +++ b/flower/Variables.make @@ -1,6 +1,6 @@ MAJVER=1 MINVER=1 -PATCHLEVEL=2 +PATCHLEVEL=3 PACKAGENAME=flower diff --git a/flower/dstream.cc b/flower/dstream.cc index 92790b5a08..8452b742eb 100644 --- a/flower/dstream.cc +++ b/flower/dstream.cc @@ -13,16 +13,16 @@ const INDTAB = 3; static String strip_pretty(String pret) { - String cl(pret.left(pret.pos('(')-1)); - int l = cl.lastPos(' '); - cl = cl.right(cl.len() -l); + String cl(pret.left_str(pret.index_i('('))); + int l = cl.index_last_i(' '); + cl = cl.right_str(cl.len() - l - 1); return cl; } static String strip_member(String pret) { - String cl(pret.left(pret.lastPos(':')-2)); + String cl(pret.left_str(pret.index_last_i(':')-1)); return cl; } diff --git a/flower/fproto.hh b/flower/fproto.hh index 1d643ed621..509d25d3fa 100644 --- a/flower/fproto.hh +++ b/flower/fproto.hh @@ -29,6 +29,7 @@ struct Getopt_long ; struct Matrix ; struct String_data ; struct String_handle ; +struct String_convert; struct String; struct virtual_smat ; struct Vector ; diff --git a/flower/path.cc b/flower/path.cc index 3dc38366f2..c79962f00f 100644 --- a/flower/path.cc +++ b/flower/path.cc @@ -17,30 +17,29 @@ split_path(String path, String &drive, String &dirs, String &filebase, String &extension) { // peel off components, one by one. - int di = path.pos(':'); - if (di) + int di = path.index_i(':'); + if (di >= 0) { - drive = path.left(di); - path = path.right(path.len() - di); + drive = path.left_str(di + 1); + path = path.right_str(path.len() - di -1); } else drive = ""; - di = path.lastPos(PATHSEP); - if (di) + di = path.index_last_i(PATHSEP); + if (di >=0) { - dirs = path.left(di); - path = path.right(path.len()-di); + dirs = path.left_str(di + 1); + path = path.right_str(path.len()-di -1); } else dirs = ""; - di = path.lastPos('.'); - if (di) + di = path.index_last_i('.'); + if (di >= 0) { - di --; // don't forget '.' - filebase = path.left(di); - extension =path.right(path.len()-di); + filebase = path.left_str(di); + extension =path.right_str(path.len()-di); } else { diff --git a/flower/scalar.cc b/flower/scalar.cc index 044b4d0b0f..5edd9e997f 100644 --- a/flower/scalar.cc +++ b/flower/scalar.cc @@ -10,15 +10,14 @@ Scalar::Scalar(Rational r) Scalar::operator Rational() { - int p = pos('/'); - if (!p) + int p = index_i('/'); + if (p == -1) return int(*this); - String s2 = right(len()-p); - p--; - String s1 = left(p); + String s2 = right_str(len()-p-1); + String s1 = left_str(p); - return Rational(s1.value(), s2.value()); + return Rational(s1.value_i(), s2.value_i()); } bool @@ -35,13 +34,13 @@ Scalar::isnum() Scalar::operator Real() { assert (isnum()); - return fvalue(); + return value_f(); } Scalar::operator int() { assert (isnum()); - return value(); + return value_i(); } @@ -52,8 +51,7 @@ Scalar::operator bool() const if (*this == "0") return false; String u (*this); - u.upper(); - if (u== "FALSE") + if ( u.upper_str() == "FALSE") return false; return true; } diff --git a/flower/string.cc b/flower/string.cc index 6e7378fdcc..a9368fe4e4 100644 --- a/flower/string.cc +++ b/flower/string.cc @@ -16,7 +16,7 @@ #include "string.hh" #ifdef STRING_DEBUG -void* mymemmove( void* dest, void* src, size_t n ); +void* mymemmove( void* dest, void const* src, size_t n ); #define memmove mymemmove #endif @@ -25,11 +25,10 @@ strlwr( char* s ) { char* p = s; - while( *p ) - { + while( *p ) { *p = tolower( *p ); /* a macro on some compilers */ p++; - } + } return s; } @@ -38,11 +37,10 @@ strupr( char* s ) { char* p = s; - while( *p ) - { + while( *p ) { *p = toupper( *p ); /* a macro on some compilers */ p++; - } + } return s; } @@ -71,7 +69,7 @@ String::copy_byte_p() const } void -String::printOn(ostream& os) const +String::print_on(ostream& os) const { if ( length_i() == strlen( ch_c_l() ) ) os << ch_c_l(); @@ -128,13 +126,13 @@ String::String(int i) String::String( const int i, const int n, char const c ) { - char fillChar = c; - if ( fillChar) - fillChar = '0'; + char fill_ch = c; + if ( fill_ch) + fill_ch = '0'; String v( i ); - String str = String( fillChar, n - v.length_i() ) + String( v ); + String str = String( fill_ch, n - v.length_i() ) + String( v ); strh_.set( str.byte_c_l(), str.length_i() ); } @@ -164,7 +162,7 @@ String::ch_l() // signed comparison, analogous to memcmp; int -String::compare(String const& s1, String const& s2 ) +String::compare_i(String const& s1, String const& s2 ) { Byte const* p1 = s1.byte_c_l(); Byte const* p2 = s2.byte_c_l(); @@ -181,96 +179,96 @@ String::compare(String const& s1, String const& s2 ) int -String::lastPos( char const c ) const +String::index_last_i( char const c ) const { - // not binary safe - assert( length_i() == strlen( ch_c_l() ) ); - char const* me = strh_.ch_c_l(); - int pos = 0; - if ( length_i() ) - { + // not binary safe + assert( length_i() == strlen( ch_c_l() ) ); + if ( !length_i() ) + return -1; + + char const* me = strh_.ch_c_l(); char const* p = strrchr(me, c ); - if ( p ) - pos = p - me + 1; - } - return pos; + if ( p ) + return p - me; + return -1; } int -String::lastPos( char const* string ) const +String::index_last_i( char const* string ) const { - // not binary safe - assert( length_i() == strlen( ch_c_l() ) ); - int pos = 0; - int length = strlen( string ); - if ( length_i() && length ) - { - int nextpos = this->pos( string ); - while( nextpos ) - { - pos += nextpos; - nextpos = right( length_i() - pos - length + 1 ).pos( string ); - } - } - return pos; + // not binary safe + assert( length_i() == strlen( ch_c_l() ) ); + + int length = strlen( string ); + if ( !length_i() || !length ) + return -1; + + int next_i = index_i( string ); + if ( next_i == -1 ) + return -1; + + int index_i = 0; + while( next_i >= 0 ) { + index_i += next_i; + next_i = right_str( length_i() - index_i - length ).index_i( string ); + } + return index_i; } // find c -// return 0 if not found. +// return -1 if not found. -// ? should return length_i()?, as in string.left(pos(delimiter)) +// ? should return length_i()?, as in string.left_str(index_i(delimiter)) int -String::pos(char c ) const +String::index_i(char c ) const { - // not binary safe - assert( length_i() == strlen( ch_c_l() ) ); - char const* me = strh_.ch_c_l(); - int pos = 0; - if ( length_i() ) - { + // not binary safe + assert( length_i() == strlen( ch_c_l() ) ); + if ( !length_i() ) + return -1; + + char const* me = strh_.ch_c_l(); char const* p = strchr( me, c ); - if ( p ) - pos = p - me + 1; - } - return pos; + if ( p ) + return p - me; + return -1; } // find searchfor. (what if this == "" && searchfor == "") ??? int -String::pos( char const* searchfor ) const -{ - // not binary safe - assert( length_i() == strlen( ch_c_l() ) ); - char const* me = strh_.ch_c_l(); - int pos = 0; - if ( length_i() && searchfor) - { +String::index_i( char const* searchfor ) const +{ + // not binary safe + assert( length_i() == strlen( ch_c_l() ) ); + if ( !length_i() || !searchfor ) + return -1; + + char const* me = strh_.ch_c_l(); char const* p = strstr(me, searchfor); - if ( p ) - pos = p - me + 1; - } - return pos; + if ( p ) + return p - me; + return -1; } // find chars of a set. int -String::posAny( char const* string ) const +String::index_any_i( char const* string ) const { - // not binary safe - assert( length_i() == strlen( ch_c_l() ) ); - int pos = 0; - char const* s = (char const* )strh_.ch_c_l(); - if ( length_i() && string ) - { + // not binary safe + assert( length_i() == strlen( ch_c_l() ) ); + + if ( !length_i() || !string ) + return -1; + + char const* s = (char const* )strh_.ch_c_l(); char const* p = strpbrk( s, string ); - if ( p ) - pos = p - s + 1; - } - return pos; + if ( p ) + return p - s; + return -1; } String -String::left( int n ) const +String::left_str( int n ) const { if (n >= length_i()) return *this; @@ -287,7 +285,7 @@ String::left( int n ) const // n rightmst chars String -String::right( int n ) const +String::right_str( int n ) const { if (n > length_i()) return *this; @@ -300,57 +298,53 @@ String::right( int n ) const String -String::nomid( const int pos, const int n ) const +String::nomid_str( int index_i, int n ) const { - String retval; - - if ( pos < 1 ) - return String(""); - if ( pos > length_i()) - return *this; + if ( index_i < 0 ) + return String(); + if ( index_i >= length_i() ) + return *this; - return String( String( left( pos - 1 ) ) + right( length_i() - pos - n + 1 )); + return String( String( left_str( index_i ) ) + right_str( length_i() - index_i - n )); } String -String::mid( int pos, int n ) const +String::mid_str( int index_i, int n ) const { - // HWN. This SUX: JCN: yep, please change me + all my invocations - // pos 1 == strh_->string[ 0 ]; - // pos 0 allowed for convenience - if ( !length_i() || ( pos < 0 ) || ( pos > length_i() ) && ( n < 1 ) ) - return String(); + if ( !length_i() || ( index_i < 0 ) || ( index_i >= length_i() ) || ( n < 1 ) ) + return String(); - // overflow... - if ( ( n > length_i() ) || ( pos + n - 1 > length_i() ) ) - n = length_i() - pos + 1; + if ( ( n > length_i() ) || ( index_i + n > length_i() ) ) + n = length_i() - index_i; - return String( byte_c_l() + pos -1, n ); + return String( byte_c_l() + index_i, n ); } -// to uppercase +// return uppercase String -String::upper() +String::upper_str() const { // not binary safe assert( length_i() == strlen( ch_c_l() ) ); - char *s = strh_.byte_l(); + String str = *this; + char *s = str.strh_.byte_l(); strupr( s ); - return *this; + return str; } -// to lowercase +// return lowercase String -String::lower() +String::lower_str() const { // not binary safe assert( length_i() == strlen( ch_c_l() ) ); - char* s = strh_.byte_l(); + String str = *this; + char* s = str.strh_.ch_l(); strlwr(s); - return *this; + return str; } String::String (double f, char const* fmt) @@ -369,53 +363,45 @@ String::String (double f, char const* fmt) *this = buf; } -long -String::value() const +int +String::value_i() const { - long l =0; - if (length_i()) { - int conv = sscanf(strh_.ch_c_l(), "%ld", &l); - assert(conv); - } - return l; + return String_convert::dec2_i( *this ); } double -String::fvalue() const +String::value_f() const { - double d =0; - if (length_i()) { - int conv = sscanf(strh_.ch_c_l(), "%lf", &d); - assert(conv); - } - return d; + return String_convert::dec2_f( *this ); } -String quoteString( String msg, String quote) +#if 0 +String +quoteString( String msg, String quote) { - return msg + " `" + quote + "' "; + return msg + " `" + quote + "' "; } - +#endif // 0 Byte* strrev( Byte* byte_l, int length_i ) { - Byte by; + Byte byte; Byte* left_byte_l = byte_l; Byte* right_byte_l = byte_l + length_i; while ( right_byte_l > left_byte_l ) { - by = *left_byte_l; + byte = *left_byte_l; *left_byte_l++ = *right_byte_l; - *right_byte_l-- = by; + *right_byte_l-- = byte; } return byte_l; } String -String::reversed() const +String::reversed_str() const { String str = *this; strrev( str.byte_l(), str.length_i() ); diff --git a/flower/string.hh b/flower/string.hh index a253b7ca61..7aa19047d1 100644 --- a/flower/string.hh +++ b/flower/string.hh @@ -25,20 +25,21 @@ ref counting through #String_handle# \item - conversion from bool, int, double, char *, char. + conversion from bool, int, double, char* , char. \item - conversion to int, upcase, downcase + to be moved to String_convert: + conversion to int, upcase, downcase \item printable. \item - indexing (pos, posAny, lastPos) + indexing (index_i, index_any_i, last_index_i) \item - cutting (left, right, mid) + cutting (left_str, right_str, mid_str) \item concat (+=, +) @@ -48,7 +49,7 @@ \item No operator[] is provided, since this would be enormously slow. If needed, - convert to const char *. + convert to char const* . \end{itemize} */ class String @@ -62,9 +63,9 @@ public: String() { } String(Rational); /// String s = "abc"; - String( const char* source ); + String( char const* source ); - String( Byte const* l_byte_c, int length_i ); + String( Byte const* byte_c_l, int length_i ); /// "ccccc" String( char c, int n = 1 ); @@ -76,7 +77,7 @@ public: String(bool ); /// String s( 3.14, 6, '#' ); - String ( double f , const char *fmt =0); + String ( double f , char const* fmt =0); String( int i, int n, char c = ' ' ); /// return a "new"-ed copy of contents @@ -88,7 +89,7 @@ public: Byte* byte_l(); /// deprecated; use ch_c_l() - operator const char *() const { return ch_c_l(); } + operator char const* () const { return ch_c_l(); } String operator =( const String & source ) { strh_ = source.strh_; return *this; } @@ -99,82 +100,82 @@ public: char operator []( int n ) const { return strh_[n]; } /// return n leftmost chars - String left( int n ) const; + String left_str( int n ) const; /// return n rightmost chars - String right( int n ) const; + String right_str( int n ) const; - /// convert this to upcase - String upper(); + /// return uppercase of *this + String upper_str() const; - /// convert this to downcase - String lower(); // & ?? + /// return lowercase of *this + String lower_str() const; /// return the "esrever" of *this - String reversed() const; + String reversed_str() const; - /// return a piece starting at pos (first char = pos 1), ength n - String mid(int pos, int n ) const; + /// return a piece starting at index_i (first char = index_i 0), length n + String mid_str(int index_i, int n ) const; /// cut out a middle piece, return remainder - String nomid(int pos, int n ) const; + String nomid_str(int index_i, int n ) const; /// signed comparison, analogous to memcmp; - static int compare(const String& s1,const String& s2); + static int compare_i(const String& s1,const String& s2); /// index of rightmost c - int lastPos( char c) const; + int index_last_i( char c) const; /// index of rightmost element of string - int lastPos( const char* string ) const; + int index_last_i( char const* string ) const; /** index of leftmost c. @return - 0 if not found, else index + 1 + -1 if not found, else index */ - int pos(char c ) const; - int pos(const char* string ) const; - int posAny(const char* string ) const; + int index_i(char c ) const; + int index_i(char const* string ) const; + int index_any_i(char const* string ) const; /// provide Stream output - void printOn(ostream& os) const; + void print_on(ostream& os) const; - /// convert to an integer - long value() const; - - /// convert to a double - double fvalue() const; - /// the length of the string int length_i() const; - // deprecated + // ***** depreciated int len() const { return length_i(); } + /// convert to an integer + int value_i() const; + + /// convert to a double + double value_f() const; + // ***** }; #include "compare.hh" -instantiate_compare(const String &, String::compare); +instantiate_compare(const String &, String::compare_i); -// because const char* also has an operator ==, this is for safety: -inline bool operator==(String s1, const char *s2){ +// because char const* also has an operator ==, this is for safety: +inline bool operator==(String s1, char const* s2){ return s1 == String(s2); } -inline bool operator==(const char *s1, String s2) +inline bool operator==(char const* s1, String s2) { return String(s1)==s2; } -inline bool operator!=(String s1, const char *s2 ) { +inline bool operator!=(String s1, char const* s2 ) { return s1!=String(s2); } -inline bool operator!=(const char *s1,String s2) { +inline bool operator!=(char const* s1,String s2) { return String(s2) !=s1; } @@ -189,13 +190,13 @@ operator + (String s1, String s2) inline ostream & operator << ( ostream& os, String d ) { - d.printOn(os); + d.print_on(os); return os; } -String quoteString(String message, String quote); +// String quoteString(String message, String quote); -#include "stringconversion.hh" +#include "string-convert.hh" #endif diff --git a/flower/stringconversion.cc b/flower/stringconversion.cc deleted file mode 100644 index 8b9144a9a7..0000000000 --- a/flower/stringconversion.cc +++ /dev/null @@ -1,102 +0,0 @@ -/* - PROJECT: FlowerSoft C++ library - FILE : stringconversion.cc - ---*/ - - -#include -#include "string.hh" - -String -StringConversion::bin2hex_str( String bin_str ) -{ - String str; - Byte const* byte_c_l = bin_str.byte_c_l(); - for ( int i = 0; i < bin_str.length_i(); i++ ) { - str += (char)nibble2hex_by( *byte_c_l >> 4 ); - str += (char)nibble2hex_by( *byte_c_l++ ); - } - return str; -} - -int -StringConversion::bin2int_i( String bin_str ) -{ - assert( bin_str.length_i() <= 4 ); - - int result_i = 0; - for ( int i = 0; i < bin_str.length_i(); i++ ) { - result_i <<= 8; - result_i |= bin_str[ i ]; - } - return result_i; -} - - -int -StringConversion::hex2bin_i( String hex_str, String& bin_str_r ) -{ - if ( hex_str.length_i() % 2 ) - hex_str = "0" + hex_str; - - bin_str_r = ""; - Byte const* byte_c_l= hex_str.byte_c_l(); - int i = 0; - while ( i < hex_str.length_i() ) { - int high_i = hex2nibble_i( *byte_c_l++ ); - int low_i = hex2nibble_i( *byte_c_l++ ); - if ( high_i < 0 || low_i < 0 ) - return 1; // illegal char - bin_str_r += String( (char)( high_i << 4 | low_i ), 1 ); - i += 2; - } - return 0; -} - -String -StringConversion::hex2bin_str( String hex_str ) -{ - String str; -// silly, asserts should alway be "on"! -// assert( !hex2bin_i( hex_str, str ) ); - int error_i = hex2bin_i( hex_str, str ); - assert( !error_i ); - return str; -} - -int -StringConversion::hex2nibble_i( Byte by ) -{ - if ( by >= '0' && by <= '9' ) - return by - '0'; - if ( by >= 'A' && by <= 'F' ) - return by - 'A' + 10; - if ( by >= 'a' && by <= 'f') - return by - 'a' + 10; - return -1; -} - -String -StringConversion::int2hex_str( int i, int length_i, char ch ) -{ - String str; - if ( !i ) - str = "0"; - while ( i ) { - str = ( i % 16 )["0123456789abcdef"] + str; - i /= 16; - } - if ( str.length_i() < length_i ) - str = String( ch, length_i - str.length_i() ) + str; - return str; -} - -Byte -StringConversion::nibble2hex_by( Byte by ) -{ - if ( ( by & 0x0f ) <= 9 ) - return ( by & 0x0f ) + '0'; - else - return ( by & 0x0f ) - 10 + 'a'; -} diff --git a/flower/stringconversion.hh b/flower/stringconversion.hh deleted file mode 100644 index 0bcd7f5c4c..0000000000 --- a/flower/stringconversion.hh +++ /dev/null @@ -1,30 +0,0 @@ -/* - PROJECT: FlowerSoft C++ library - FILE : stringconversion.hh - -*/ - -#ifndef STRING_CONVERSION_HH -#define STRING_CONVERSION_HH - -/** - all conversions from/to String go in here.( some time, anyway ) - The class is quite empty from data view. - */ -class StringConversion { - static int hex2bin_i( String hex_str, String& bin_str_r ); - static int hex2nibble_i( Byte by ); - static Byte nibble2hex_by( Byte by ); -public: - static String bin2dec_str( String dec_str ); - static String bin2hex_str( String bin_str ); - static String dec2bin_str( String str ); - static int bin2int_i( String str ); - static int dec2int_i( String str ); - static int hex2int_i( String str ); - static String hex2bin_str( String str ); - static String int2hex_str( int i, int length_i, char ch ); - static String int2dec_str( int i, int length_i, char ch ); -}; - -#endif // __STRING_CONVERSION_HH // diff --git a/flower/stringdata.inl b/flower/stringdata.inl index 927ca0998d..7b55481085 100644 --- a/flower/stringdata.inl +++ b/flower/stringdata.inl @@ -15,11 +15,14 @@ #include "stringdata.hh" const int INITIALMAX=8; -#ifdef STRING_DEBUG - -INLINE void* mymemmove( void* dest, void* src, size_t n ) -{ - return memcpy( dest, src, n ); // wohltempererit: 69006 +#include +void* +mymemmove( void* dest, void const* src, size_t n ); +#if 0 // redef STRING_DEBUG +INLINE void* +mymemmove( void* dest, void const* src, size_t n ) +{ + return memmove( dest, src, n ); // wohltempererit: 69006 } #define memmove mymemmove #endif diff --git a/flower/stringtest.cc b/flower/stringtest.cc index 71c1557912..c0c50da5c6 100644 --- a/flower/stringtest.cc +++ b/flower/stringtest.cc @@ -9,17 +9,17 @@ main() String str( "hai" ); cout << str << endl; cout << "left" << endl; - cout << " 0:" << str.left( 0 ) << endl; - cout << " 1:" << str.left( 1 ) << endl; - cout << " 2:" << str.left( 2 ) << endl; - cout << " 3:" << str.left( 3 ) << endl; - cout << " 4:" << str.left( 4 ) << endl; + cout << " 0:" << str.left_str( 0 ) << endl; + cout << " 1:" << str.left_str( 1 ) << endl; + cout << " 2:" << str.left_str( 2 ) << endl; + cout << " 3:" << str.left_str( 3 ) << endl; + cout << " 4:" << str.left_str( 4 ) << endl; cout << "right" << endl; - cout << " 0:" << str.right( 0 ) << endl; - cout << " 1:" << str.right( 1 ) << endl; - cout << " 2:" << str.right( 2 ) << endl; - cout << " 3:" << str.right( 3 ) << endl; - cout << " 4:" << str.right( 4 ) << endl; + cout << " 0:" << str.right_str( 0 ) << endl; + cout << " 1:" << str.right_str( 1 ) << endl; + cout << " 2:" << str.right_str( 2 ) << endl; + cout << " 3:" << str.right_str( 3 ) << endl; + cout << " 4:" << str.right_str( 4 ) << endl; str += " daar"; cout << str << endl; @@ -35,9 +35,9 @@ main() fn = ""; fn += ""; - delete fn.copy_by_p(); + delete fn.copy_byte_p(); - delete str.copy_by_p(); + delete str.copy_byte_p(); - cout << StringConversion::bin2hex_str( String( (char)0xff ) ) << endl; + cout << String_convert::bin2hex_str( String( (char)0xff ) ) << endl; } diff --git a/flower/stringutil.cc b/flower/stringutil.cc index 9adcd2ea1d..55e4fa1426 100644 --- a/flower/stringutil.cc +++ b/flower/stringutil.cc @@ -7,9 +7,12 @@ */ #ifdef STRING_DEBUG -void* mymemmove( void* dest, void* src, size_t n ) +#include +#include +void* +mymemmove( void* dest, void const* src, size_t n ) { - return memmove( dest, src, n ); // wohltempererit: 69006 + return memcpy( dest, src, n ); // wohltempererit: 69006 } #define memmove mymemmove #endif diff --git a/hdr/midi-event.hh b/hdr/midi-event.hh index a566dc50f7..06b17221aa 100644 --- a/hdr/midi-event.hh +++ b/hdr/midi-event.hh @@ -19,12 +19,12 @@ public: Midi_event(); virtual ~Midi_event(); - String mudela_str(); + virtual String mudela_str(); // = 0; + virtual void output_mudela( Lily_stream& lily_stream_r ); + virtual Moment mom(); protected: String mudela_str_; - -private: }; class Midi_key : public Midi_event { @@ -41,11 +41,16 @@ private: }; class Midi_note : public Midi_event { -public: -// Midi_note( Midi_key* midi_key_l, Midi_tempo* midi_tempo_l, Midi_time* midi_time_l, int pitch_i, Real duration_f ); - Midi_note( Midi_key* midi_key_l, Midi_time* midi_time_l, int clocks_per_whole_i, int pitch_i, Real duration_f ); + public: + int const c0_pitch_i_c_ = 60; + + Midi_note( Midi_key* midi_key_l, Midi_time* midi_time_l, int division_1_i, int pitch_i, int time_i ); virtual ~Midi_note(); + virtual Moment mom(); + +private: + Duration dur_; }; class Midi_tempo : public Midi_event { @@ -62,14 +67,16 @@ private: class Midi_time : public Midi_event { public: - Midi_time( int num_i, int den_i, int clocks_i, int count_32_i ); + Midi_time( int num_i, int den_i, int division_4_i, int count_32_i ); virtual ~Midi_time(); - String duration_str( int usecond24th_per_clock_i, Real delta_time_f ); - int whole_clocks_i(); + Duration i2_dur( int time_i, int division_1_i ); + int clocks_1_i(); private: - int whole_clocks_i_; + Real sync_f_; + Duration sync_dur_; + int clocks_1_i_; int num_i_; int den_i_; }; diff --git a/hdr/midi-main.hh b/hdr/midi-main.hh index 4eb86c27d2..b58e077d43 100644 --- a/hdr/midi-main.hh +++ b/hdr/midi-main.hh @@ -19,6 +19,9 @@ extern Verbose level_ver; #endif extern Source* source_l_g; +extern bool no_triplets_bo_g; void message( String message_str, char const* context_ch_c_l ); void warning( String message_str, char const* context_ch_c_l ); void error( String message_str, char const* context_ch_c_l ); + +String version_str(); diff --git a/hdr/midi-score.hh b/hdr/midi-score.hh index 2f88168a11..68707633ef 100644 --- a/hdr/midi-score.hh +++ b/hdr/midi-score.hh @@ -14,7 +14,10 @@ public: void add_track( Midi_track* midi_track_p ); + int output_mudela( String filename_str ); + private: + IPointerList midi_track_p_list_; int format_i_; int tracks_i_; int tempo_i_; diff --git a/hdr/midi-track.hh b/hdr/midi-track.hh index ce258c6eae..d1458ed0ca 100644 --- a/hdr/midi-track.hh +++ b/hdr/midi-track.hh @@ -9,12 +9,17 @@ /// (midi_track) class Midi_track { public: - Midi_track(); + Midi_track( int track_i ); ~Midi_track(); - void add_event( Midi_event* midi_event_p ); + void add_event( Moment mom, Midi_event* midi_event_p ); + String name_str(); + void output_mudela( Lily_stream& lily_stream_r ); + Track_column* tcol_l( Moment mom ); private: + IPointerList tcol_p_list_; + String name_str_; }; #endif // MIDI_TRACK_HH diff --git a/hdr/midiitem.hh b/hdr/midiitem.hh index 486637c367..f4b14aa5ef 100644 --- a/hdr/midiitem.hh +++ b/hdr/midiitem.hh @@ -10,7 +10,7 @@ struct Midi_item { /* *************** */ - static String int2varlength_str( int i ); + static String i2varint_str( int i ); virtual void output_midi( Midi_stream& midi_stream_r ); virtual String str() = 0; }; diff --git a/hdr/my-midi-lexer.hh b/hdr/my-midi-lexer.hh index 5245d1be84..032bf6752b 100644 --- a/hdr/my-midi-lexer.hh +++ b/hdr/my-midi-lexer.hh @@ -27,7 +27,7 @@ public: int close_i(); void error( char const* sz_l ); char const* here_ch_c_l(); - static int varint2int_i( String str ); + static int varint2_i( String str ); int yylex(); private: diff --git a/hdr/my-midi-parser.hh b/hdr/my-midi-parser.hh index fd7e088654..d199bc1c4e 100644 --- a/hdr/my-midi-parser.hh +++ b/hdr/my-midi-parser.hh @@ -6,9 +6,8 @@ #ifndef MY_MIDI_PARSER_HH #define MY_MIDI_PARSER_HH -#include "proto.hh" -#include "varray.hh" -#include "string.hh" +// #include "proto.hh" +// #include "string.hh" int yyparse(); @@ -20,25 +19,26 @@ public: void add_score( Midi_score* midi_score_p ); void error( char const* sz_l ); int parse(); - void forward( Real f ); + void forward( int i ); + Moment mom(); void note_begin( int channel_i, int pitch_i, int dyn_i ); Midi_event* note_end_midi_event_p( int channel_i, int pitch_i, int dyn_i ); - int output( String filename_str ); - void set_division( int clocks_per_4_i ); + int output_mudela( String filename_str ); + void reset(); + void set_division_4( int division_4_i ); void set_key( int accidentals_i, int minor_i ); void set_tempo( int useconds_i ); void set_time( int num_i, int den_i, int clocks_i, int count_32_i ); private: - Real now_f_; - Real step_f_; + Int64 now_i64_; // 31 bits yields tipically about 1000 bars static int const CHANNELS_i = 16; static int const PITCHES_i = 128; - Real running_f_f_a_[ CHANNELS_i ][ PITCHES_i ]; + Int64 running_i64_i64_a_[ CHANNELS_i ][ PITCHES_i ]; - Array midi_score_p_array_; - int clocks_per_whole_i_; + Midi_score* midi_score_p_; + int division_1_i_; Midi_key* midi_key_p_; Midi_tempo* midi_tempo_p_; Midi_time* midi_time_p_; diff --git a/hdr/proto.hh b/hdr/proto.hh index 0f2a007c79..0ca6d726dd 100644 --- a/hdr/proto.hh +++ b/hdr/proto.hh @@ -10,6 +10,9 @@ #include "fproto.hh" #include "real.hh" +/// (i64) +typedef long long Int64; + struct Absdynamic_req; struct Accidental; struct Atom; @@ -33,6 +36,8 @@ struct Complex_staff; struct Complex_walker; struct Cresc_req; struct Decresc_req; +struct Duration; +struct Duration_iterator; struct Durational_req; struct Dynamic; struct Group_change_req; @@ -50,6 +55,7 @@ struct Key_change_req; struct Key_item; struct Keyword; struct Keyword_table; +struct Lily_stream; struct Line_of_score; struct Line_of_staff; struct Linestaff; @@ -98,6 +104,7 @@ struct Offset; struct Output; struct PCol; struct Plet_req; +struct Plet; struct PScore; struct PStaff; struct Paperdef; @@ -151,6 +158,7 @@ struct Text_register; struct Text_req; struct Timing_req; struct Time_description; +struct Track_column; struct Voice; struct Voice_element; struct Voice_group_registers; diff --git a/hdr/script.hh b/hdr/script.hh index 9c48c75e24..7c089e3a54 100644 --- a/hdr/script.hh +++ b/hdr/script.hh @@ -32,7 +32,7 @@ struct Script : Item { private: void set_symdir(); void set_default_dir(); - void set_default_pos(); + void set_default_index(); Symbol symbol()const; }; diff --git a/hdr/stem.hh b/hdr/stem.hh index ccc02a6b59..2aafd66074 100644 --- a/hdr/stem.hh +++ b/hdr/stem.hh @@ -63,7 +63,7 @@ struct Stem : Item { void add(Notehead*n); const char * name() const; - Real hpos()const; + Real hindex()const; void do_print() const; void set_stemend(Real); int get_default_dir(); diff --git a/hdr/textitem.hh b/hdr/textitem.hh index c7df9069d9..4e0e454941 100644 --- a/hdr/textitem.hh +++ b/hdr/textitem.hh @@ -18,7 +18,7 @@ struct Text_item : Item { /* ***************/ const char * name() const; - virtual void set_default_pos(); + virtual void set_default_index(); Molecule* brew_molecule_p() const; void do_pre_processing(); diff --git a/input/Makefile b/input/Makefile index 92dfaf11c5..47e58f972d 100644 --- a/input/Makefile +++ b/input/Makefile @@ -7,7 +7,8 @@ DISTFILES=Makefile kortjakje.ly maartje.ly\ martien.ly mlalt.ly mlvio1.ly mlvio2.ly mlcello.ly\ coriolan-alto.ly rhythm.ly \ standchen.tex scsii-menuetto.tex scsii-menuetto.ly\ - martien.tex + martien.tex\ + pre1.midi.ly fugue1.midi.ly dist: diff --git a/input/fugue1.midi.ly b/input/fugue1.midi.ly new file mode 100644 index 0000000000..b2c091fc8b --- /dev/null +++ b/input/fugue1.midi.ly @@ -0,0 +1,100 @@ +% Creator: This is m2m 0.0.36-2/FlowerLib 1.1.3-1 of Feb 27 1997 02:41:23 +% Automatically generated, at Thu Feb 27 08:38:27 1997 +% from input file: + +track0 = music { $ + % \Time: 4/8, 96: 8 % \Tempo: 967742: 61 4 per minute + % \Tempo: 1000000: 60 4 per minute + % \Tempo: 1052632: 56 4 per minute + % \Tempo: 1132075: 53 4 per minute + % \Tempo: 1200000: 50 4 per minute + % \Tempo: 1463415: 40 4 per minute + % \Tempo: 1578947: 38 4 per minute + +$} % track0 + +track1 = music { $ + g8 a8 b8 c8. d32 c32 b8 e8 a8 d8. e16 d16 c16 + b16 g16 a16 b16 c16 b16 c16 d16 e16 d16 e16 + fis16 g8 b8 c8 a8 d16 c16 b16 a16 g8. g16 f16 + e16 f16 g16 a16 g16 a16 b16 c2 b4 c8 d8 e8 f8. + g32 f32 e8 a8 d8 g8. a16 g16 f16 e8 a8. b16 a16 + g16 f2 e8. fis16 g2 fis4 g16 f16 e16 d16 c16 + d16 c16 b16 a16 c16 b16 a16 c16 a16 gis8 e8 + d8 c16 b16 a16 gis16 a16 b16 c16 fis16 gis16 + a16 b8 a16 b16 c8 f8 e8 d4 c16 b16 c64 b64 c64 + b64 c64 b64 c64 b64 c64 b32. a32. a4 g8 a8 b8 + c8. d32 c32 b8 c8 d8 e8 f8. g32 f32 e8 a8 d8 g8. + a16 g16 f16 e8 a8 d8 ais8 a8 g16 f16 g16 f16 + g16 e16 f16 g16 g64 a64 g32 f32 g32 a16 cis16 + d16 g16 f64 e64 f64 e64 f64 e16. d32. d8. g8 + a8 b8 c8. d32 c32 b8 e8 a8 d8. e16 d16 c16 b16 + c16 d16 e16 f16 g16 a16 g16 f16 e16 d16 c16 + c64 b64 c64 b8. c8 d8 g8 c4 b8 c4 b8 ais8 a8 d4 + c8 d8 e8 f8.. a32. g32. f32. e32. f32. e32. + d32. c2 g32 a32 b16 c16 d16 e16 f8. c32 d32 + e32 f16 g16 a8. b16 c2 +$} % track1 + +track2 = music { $ + c8 d8 e8 f8. g32 f32 e8 a8 d8 g8. a16 g16 f16 + e16 f16 e16 d16 c16 d16 c16 b16 a8 fis8 g4. + f16 e16 f8 d8 g8 f8 e8 d8 g4 f16 e16 f8.. f16 + e8 d4 c8 f8 g16 f16 e16 f8 d8 g4.. g8 a8 b8 c8. + d32 c32 b8 e8 a8 d8. e16 d16 c16 b16.. d8 e8 + fis8 g8. a32 g32 f8 b8 e8 a8. b16 a16 gis16 + fis8 f8 e8 d8. e16 fis16 gis16 a16 gis16 a16 + b16 gis16 fis16 gis16 a16 b8 c8 d8 e8 f8. g32 + f32 e8 a8 d8 g8. a16 g16 f16 e16. e16. fis16. + g4 fis8 gis8 a4 g8 a8 b8 c8. d32 c32 b16. e8 + a8 d8. e16 d16 c16 b8 g8 cis8 d8 e8 cis8 d8 e8 + a8 e8 fis8 g8 a8. b32 a32 g8 c8 fis8 b8. c16 + b16 a16 g16 fis16 e16 d16 e4 d4. a16 g16 f16 + e16 g16 f16 g4. a16 a16 ais8 c4 d8 g8 g4. f4 + e8 d4 e16. a4 g4 f8 g8 a8 ais8. c32 ais32 a8 + d8 g8 c8. d16 c16 ais16 a16 ais16 a16 g16 f16 + g16 f16 e16 g16 a4 f16 d8 e2 +$} % track2 + +track3 = music { $ + g8 a8 b8 c8. d32 c32 b8 e8 a8 d8. e16 d16 c16 + b8 c4 ais8 a8 d8 g8 c8 a16 b16 c16 d4 g4 g8 a8 + b8 c8. d32 c32 b8 e8 a8 d8. e16 d16 c16 b8 e4. + d4 b16 c16 a16 e16 d16 c16 b16 c16 a16 b16 c16 + d16 c16 b16 a16 g4 e8 fis8 gis8 a8. b32 a32 + g8 c8 fis8 b8. c16 b16 a16 gis16.. a4 gis8 + a4 g8 a8 b8 c8. d32 c32 b8 e8 a8 d4 g8 d4 c8 a8 + e4 d8 a8 b8 cis8 d8. e32 d32 c8 f8 b8 e8. f16 + e16 d16 cis8 a8 b8 cis8 d8. e32 d32 c8 fis8 + b8 e8. fis16 e16 d16 c4.. d16 c16 b16 a16 g16 + a16 fis16 g16.. b16.. c16.. d8 e8. f32 e32 + d8 g8 c8 f8. g16 f16 e16 d4 e8 d4 g8 g4. c8 d8 + e8 f8. g32 f32 e8 a8 d8 g8. a16 g16 f16 e16 d16 + e16 f16 g16 a16 ais16 g16 a16 e16 f16 g16 a16 + b16 c16 a16 c1 +$} % track3 + +track4 = music { $ + c8 d8 e8 f8. g32 f32 e8 a8 d8 g8. a16 g16 f16 + e16 f16 e16 d16 c16 d16 c16 b16 a8 d8 a8 fis8 + g16 a16 ais16 g16 cis8 d8 a4 e4 a16 b16 c16 + d16 c16 b16 a16 g16 c8 g8 a8 b8 c8. d32 c32 b8 + e8 a8 d8. e16 d16 c16 b8 e4 d8 c8 f4 e4 d4 e8 f8 + e16 d16 e4 a4 g8 a8 b8 c8. d32 c32 b8 e8 a8 d8. + e16 d16 c16 b8 ais8 a8 g8 a8 fis8 g8 e8 d4 e8 + f8 g8. a32 g32 f8 ais8 e8 a8. b16. a16 g16 f16 + e16 f16 d16 g8 a8 d4.. e16 d16 c16 b16 a16 g16 + fis16 e8 e8 fis8 g4 a16 g16 fis8 d8 g1 a4 b8 + c8 f16 a16 g16 f16 e16 d16 c16 b16 c16 d16 e16 + f16 g8 g8 b2 c8 +$} % track4 + +score { + staff { melodic music { track0 } } + staff { melodic music { track1 } } + staff { melodic music { track2 } } + staff { melodic music { track3 } } + staff { melodic music { track4 } } + commands { meter { 4*4 } } + midi { tempo 4:60 } +} diff --git a/input/pre1.midi.ly b/input/pre1.midi.ly new file mode 100644 index 0000000000..ca6beafb22 --- /dev/null +++ b/input/pre1.midi.ly @@ -0,0 +1,80 @@ +% Creator: This is m2m 0.0.36-2/FlowerLib 1.1.3-1 of Feb 27 1997 02:41:23 +% Automatically generated, at Thu Feb 27 02:54:33 1997 +% from input file: + +track0 = music { $ + % \Time: 4/8, 96: 8 % \Tempo: 857143: 69 4 per minute + % \Tempo: 882353: 67 4 per minute + % \Tempo: 909091: 65 4 per minute + % \Tempo: 937500: 64 4 per minute + % \Tempo: 967742: 61 4 per minute + % \Tempo: 1000000: 60 4 per minute + % \Tempo: 1200000: 50 4 per minute + % \Tempo: 1224490: 48 4 per minute + % \Tempo: 833333: 72 4 per minute + +$} % track0 + +track1 = music { $ + g16 c16 e16 g16 c16 e16 g16 c16 e16 g16 c16 + e16 a16 d16 f16 a16 d16 f16 a16 d16 f16 a16 + d16 f16 g16 d16 f16 g16 d16 f16 g16 d16 f16 + g16 d16 f16 g16 c16 e16 g16 c16 e16 g16 c16 + e16 g16 c16 e16 a16 e16 a16 a16 e16 a16 a16 + e16 a16 a16 e16 a16 fis16 a16 d16 fis16 a16 + d16 fis16 a16 d16 fis16 a16 d16 g16 d16 g16 + g16 d16 g16 g16 d16 g16 g16 d16 g16 e16 g16 + c16 e16 g16 c16 e16 g16 c16 e16 g16 c16 e16 + g16 c16 e16 g16 c16 e16 g16 c16 e16 g16 c16 + d16 fis16 c16 d16 fis16 c16 d16 fis16 c16 + d16 fis16 c16 d16 g16 b16 d16 g16 b16 d16 g16 + b16 d16 g16 b16 e16 g16 cis16 e16 g16 cis16 + e16 g16 cis16 e16 g16 cis16 d16 a16 d16 d16 + a16 d16 d16 a16 d16 d16 a16 d16 d16 f16 b16 + d16 f16 b16 d16 f16 b16 d16 f16 b16 c16 g16 + c16 c16 g16 c16 c16 g16 c16 c16 g16 c16 a16 + c16 f16 a16 c16 f16 a16 c16 f16 a16 c16 f16 + a16 c16 f16 a16 c16 f16 a16 c16 f16 a16 c16 + f16 g16 b16 f16 g16 b16 f16 g16 b16 f16 g16 + b16 f16 g16 c16 e16 g16 c16 e16 g16 c16 e16 + g16 c16 e16 ais16 c16 e16 ais16 c16 e16 ais16 + c16 e16 ais16 c16 e16 a16 c16 e16 a16 c16 e16 + a16 c16 e16 a16 c16 e16 a16 c16 dis16 a16 c16 + dis16 a16 c16 dis16 a16 c16 dis16 b16 c16 + d16 b16 c16 d16 b16 c16 d16 b16 c16 d16 g16 + b16 d16 g16 b16 d16 g16 b16 d16 g16 b16 d16 + g16 c16 e16 g16 c16 e16 g16 c16 e16 g16 c16 + e16 g16 c16 f16 g16 c16 f16 g16 c16 f16 g16 + c16 f16 g16 b16 f16 g16 b16 f16 g16 b16 f16 + g16 b16 f16 a16 c16 fis16 a16 c16 fis16 a16 + c16 fis16 a16 c16 fis16 g16 c16 g16 g16 c16 + g16 g16 c16 g16 g16 c16 g16 g16 c16 f16 g16 + c16 f16 g16 c16 f16 g16 c16 f16 g16 b16 f16 + g16 b16 f16 g16 b16 f16 g16 b16 f16 g16 ais16 + e16 g16 ais16 e16 g16 ais16 e16 g16 ais16 + e16 f16 a16 c16 f16 c16 a16 c16 a16 f16 a16 + f16 d16 f16 d16 g16 b16 d16 f16 d16 b16 d16 + b16 g16 b16 d16 f16 e64 f64 e32 d16 c1 +$} % track1 + +track2 = music { $ + c2 e4. c2 e4. c2 d4. c2 d4. b2 d4. b2 d4. c2 e4. + c2 e4. c2 e4. c2 e4. c2 d4. c2 d4. b2 d4. b2 d4. + b2 c4. b2 c4. a2 c4. a2 c4. d2 a4. d2 a4. g2 b4. + g2 b4. g2 ais4. g2 ais4. f2 a4. f2 a4. f2 gis4. + f2 gis4. e2 g4. e2 g4. e2 f4. e2 f4. d2 f4. d2 + f4. g2 d4. g2 d4. c2 e4. c2 e4. c2 g4. c2 g4. + f2 f4. f2 f4. fis2 c2 fis2 c4. gis2 f4. gis2 + f4. g2 f4. g2 f4. g2 e2 g2 e4. g2 d4. g2 d2 g2 + d4. g2 d4. g2 dis4. g2 dis4. g2 e4. g2 e4. g2 + d4. g2 d4. g2 d4. g2 d4. c2 c4. c2 c4. c1 c1 b1 + c1 c1 +$} % track2 + +score { + staff { melodic music { track0 } } + staff { melodic music { track1 } } + staff { melodic music { track2 } } + commands { meter { 4*4 } } + midi { tempo 4:60 } +} diff --git a/input/standchen.ly b/input/standchen.ly index 41abb47413..650cf456a3 100644 --- a/input/standchen.ly +++ b/input/standchen.ly @@ -487,6 +487,6 @@ score { output "standchen.out" } midi { - tempo 4:80 + tempo 4:60 } } diff --git a/src/beam.cc b/src/beam.cc index 1b0fa2baa3..f554d424bc 100644 --- a/src/beam.cc +++ b/src/beam.cc @@ -28,7 +28,7 @@ struct Stem_info { Stem_info::Stem_info(const Stem*s) { - x = s->hpos(); + x = s->hindex(); int dir = s->dir; idealy = max(dir*s->top, dir*s->bot); miny = max(dir*s->minnote, dir*s-> maxnote); @@ -119,9 +119,9 @@ void Beam::set_stemlens() { iter_top(stems,s); - Real x0 = s->hpos(); + Real x0 = s->hindex(); for (; s.ok() ; s++) { - Real x = s->hpos()-x0; + Real x = s->hindex()-x0; s->set_stemend(left_pos + slope * x); } } @@ -192,8 +192,8 @@ Interval Beam::width() const { Beam * me = (Beam*) this; // ugh - return Interval( (*me->stems.top()) ->hpos(), - (*me->stems.bottom()) ->hpos() ); + return Interval( (*me->stems.top()) ->hindex(), + (*me->stems.bottom()) ->hindex() ); } /* @@ -202,8 +202,8 @@ Beam::width() const Molecule Beam::stem_beams(Stem *here, Stem *next, Stem *prev)const { - assert( !next || next->hpos() > here->hpos() ); - assert( !prev || prev->hpos() < here->hpos() ); + assert( !next || next->hindex() > here->hindex() ); + assert( !prev || prev->hindex() < here->hindex() ); Real dy=paper()->internote()*2; Real stemdx = paper()->rule_thickness(); Real sl = slope*paper()->internote(); @@ -216,7 +216,7 @@ Beam::stem_beams(Stem *here, Stem *next, Stem *prev)const if (prev) { int lhalfs= lhalfs = here->beams_left - prev->beams_right ; int lwholebeams= here->beams_left beams_right ; - Real w = (here->hpos() - prev->hpos())/4; + Real w = (here->hindex() - prev->hindex())/4; Symbol dummy; Atom a(dummy); if (lhalfs) // generates warnings if not @@ -233,7 +233,7 @@ Beam::stem_beams(Stem *here, Stem *next, Stem *prev)const int rhalfs = here->beams_right - next->beams_left; int rwholebeams = here->beams_right beams_left; - Real w = next->hpos() - here->hpos(); + Real w = next->hindex() - here->hindex(); Atom a = paper()->lookup_p_->beam(sl, w + stemdx); int j = 0; @@ -264,7 +264,7 @@ Beam::brew_molecule_p() const return out; { Real inter=paper()->internote(); out = new Molecule; - Real x0 = stems.top()->hpos(); + Real x0 = stems.top()->hindex(); for (iter_top(stems,i); i.ok(); i++) { PCursor p(i-1); @@ -273,7 +273,7 @@ Beam::brew_molecule_p() const return out; Stem * next = n.ok() ? n.ptr() : 0; Molecule sb = stem_beams(i, next, prev); - Real x = i->hpos()-x0; + Real x = i->hindex()-x0; sb.translate(Offset(x, (x * slope + left_pos)* inter)); out->add(sb); } diff --git a/src/binary-source-file.cc b/src/binary-source-file.cc index 8335a13a5e..8545f221e9 100644 --- a/src/binary-source-file.cc +++ b/src/binary-source-file.cc @@ -32,13 +32,13 @@ Binary_source_file::error_str( char const* pos_ch_c_l ) char const* end_ch_c_l = pos_ch_c_l + 7 0 && (isspace(s[i]) || isalpha(s[i])) ){ i--; } String unit(s + i+1); - return convert_dimen(dim.fvalue(), unit); + return convert_dimen(dim.value_f(), unit); } diff --git a/src/inputfile.cc b/src/inputfile.cc index 2245c8dbe0..9e1a496834 100644 --- a/src/inputfile.cc +++ b/src/inputfile.cc @@ -29,7 +29,7 @@ Input_file::Input_file(String s) else { Source_file* sourcefile_p = 0; // ugh, very dirty, need to go away - if ( ( pf.right( 3 ).lower() == "mid" ) || ( pf.right( 4 ).lower() == "midi" ) ) + if ( ( pf.right_str( 3 ).lower_str() == "mid" ) || ( pf.right_str( 4 ).lower_str() == "midi" ) ) sourcefile_p = new Binary_source_file( pf ); else sourcefile_p = new Source_file( pf ); diff --git a/src/lexer.l b/src/lexer.l index 1e4e8488a5..6f72f7f2cc 100644 --- a/src/lexer.l +++ b/src/lexer.l @@ -106,7 +106,7 @@ COMMENT [%#].*\n return DOTS; } {INT} { - yylval.i = String(YYText()).value(); + yylval.i = String_convert::dec2_i( String( YYText() ) ); return INT; } {COMMENT} { @@ -119,7 +119,7 @@ COMMENT [%#].*\n } \"[^"]*\" { String s (YYText()+1); - s = s.left(s.len()-1); + s = s.left_str(s.length_i()-1); yylval.string = new String(s); return STRING; } @@ -144,7 +144,7 @@ COMMENT [%#].*\n return DOTS; } {INT} { - yylval.i = String(YYText()).value(); + yylval.i = String_convert::dec2_i( String( YYText() ) ); return INT; } {NOTECOMMAND} { @@ -172,19 +172,19 @@ COMMENT [%#].*\n } \"[^"]*\" { String s (YYText()+1); - s = s.left(s.len()-1); + s = s.left_str(s.length_i()-1); yylval.string = new String(s); return STRING; } {LYRICS} { String s (YYText()); int i = 0; - while ((i=s.pos("_")) != 0) // change word binding "_" to " " - *(s.ch_l() + i - 1) = ' '; - if ((i=s.pos("\\,")) !=0) // change "\," to TeX's "\c " + while ((i=s.index_i("_")) != -1) // change word binding "_" to " " + *(s.ch_l() + i) = ' '; + if ((i=s.index_i("\\,")) != -1) // change "\," to TeX's "\c " { - *(s.ch_l() + i) = 'c'; - s = s.left(i+1) + " " + s.right(s.len()-i-1); + *(s.ch_l() + i + 1) = 'c'; + s = s.left_str(i+2) + " " + s.right_str(s.length_i()-i-2); } yylval.string = new String(s); return STRING; @@ -221,8 +221,8 @@ include { [ \t]* { /* eat the whitespace */ } \"[^"]*\"+ { /* got the include file name */ String s (YYText()+1); - s = s.left(s.len()-1); - defined_ch_c_l = here_ch_c_l() - String( YYText() ).len() - 1; + s = s.left_str(s.length_i()-1); + defined_ch_c_l = here_ch_c_l() - String( YYText() ).length_i() - 1; new_input(s); yy_pop_state(); } diff --git a/src/lyricitem.cc b/src/lyricitem.cc index 30f49e5bf4..b35c866761 100644 --- a/src/lyricitem.cc +++ b/src/lyricitem.cc @@ -23,6 +23,6 @@ Lyric_item::do_pre_processing() // override Text_item // test context-error - if ( tdef_l_->text_str_.pos( "Gates" ) )// :-) + if ( tdef_l_->text_str_.index_i( "Gates" ) )// :-) warning( "foul word", tdef_l_->defined_ch_c_l_ ); } diff --git a/src/main.cc b/src/main.cc index 55a5129055..450545ab25 100644 --- a/src/main.cc +++ b/src/main.cc @@ -18,7 +18,7 @@ extern void parse_file(String,String); void -destill_inname( String &inName); +destill_inname( String &name_str_r); long_option_init theopts[] = { 1, "output", 'o', 0, "warranty", 'w', @@ -147,20 +147,20 @@ find_file(String f) /// make input file name: add default extension. "" is stdin. void -destill_inname( String &inName) +destill_inname( String &name_str_r) { - if ( inName.len() ) + if ( name_str_r.length_i() ) { - if( inName[ 0 ] != '-' ) + if( name_str_r[ 0 ] != '-' ) { String a,b,c,d; - split_path(inName,a,b,c,d); + split_path(name_str_r,a,b,c,d); // add extension if not present. if (d == "") d = ".ly"; - inName = a+b+c+d; + name_str_r = a+b+c+d; } - } else inName = ""; + } else name_str_r = ""; } diff --git a/src/midi-event.cc b/src/midi-event.cc index 850379271c..e62a888a83 100644 --- a/src/midi-event.cc +++ b/src/midi-event.cc @@ -4,16 +4,17 @@ // copyright 1997 Jan Nieuwenhuizen #include -#include "proto.hh" +#include "proto.hh" #include "plist.hh" // all for midi-main.hh #include "string.hh" #include "source.hh" #include "sourcefile.hh" #include "midi-main.hh" // *tors - #include "moment.hh" +#include "duration.hh" #include "midi-event.hh" +#include "lily-stream.hh" Midi_event::Midi_event() { @@ -23,12 +24,24 @@ Midi_event::~Midi_event() { } +Moment +Midi_event::mom() +{ + return Moment( 0 ); +} + String Midi_event::mudela_str() { return mudela_str_; } +void +Midi_event::output_mudela( Lily_stream& lily_stream_r ) +{ + lily_stream_r << mudela_str_ << String( " " ); +} + Midi_key::Midi_key( int accidentals_i, int minor_i ) { accidentals_i_ = accidentals_i; @@ -37,7 +50,7 @@ Midi_key::Midi_key( int accidentals_i, int minor_i ) key_i_ = ( ( accidentals_i % 7 )[ "cgdaebf" ] - 'a' + 2 ) % 7; else key_i_ = ( ( -accidentals_i % 7 )[ "fbeadg" ] - 'a' + 2 ) % 7; - mudela_str_ = String( "\\key\\" ); + mudela_str_ = String( "% \\key\\" ); if ( !minor_i_ ) mudela_str_ += String( (char)( key_i_ - 2 + 'A' ) ); else @@ -72,28 +85,53 @@ Midi_key::notename_str( int pitch_i ) else notename_str += "es"; accidental_i--; - return notename_str; + String octave_str; + + octave_str += String( '\'', ( pitch_i - Midi_note::c0_pitch_i_c_ ) / 12 ); + octave_str += String( '`', ( Midi_note::c0_pitch_i_c_ - pitch_i ) / 12 ); + return octave_str + notename_str; } Midi_key::~Midi_key() { } -Midi_note::Midi_note( Midi_key* midi_key_l, Midi_time* midi_time_l, int clocks_per_whole_i, int pitch_i, Real delta_time_f ) +Midi_note::Midi_note( Midi_key* midi_key_l, Midi_time* midi_time_l, int division_1_i, int pitch_i, int time_i ) { - mudela_str_ = midi_key_l->notename_str( pitch_i ); - mudela_str_ += midi_time_l->duration_str( clocks_per_whole_i, delta_time_f ); + dur_ = midi_time_l->i2_dur( time_i, division_1_i ); + + if ( dur_.plet_p_ ) + mudela_str_ += String( "\\plet{ " ) + + String_convert::i2dec_str( dur_.plet_p_->iso_i_, 0, 0 ) + + "/" + + String_convert::i2dec_str( dur_.plet_p_->type_i_, 0, 0 ) + + " } "; + + mudela_str_ += midi_key_l->notename_str( pitch_i ); + + Duration dur = dur_; + dur.set_plet( 0 ); + mudela_str_ += Duration_convert::dur2_str( dur ); + + if ( dur_.plet_p_ ) + mudela_str_ += String( " \\plet{ 1/1 }" ); } Midi_note::~Midi_note() { } +Moment +Midi_note::mom() +{ + return Duration_convert::dur2_mom( dur_ ); +} + Midi_tempo::Midi_tempo( int useconds_per_4_i ) { useconds_per_4_i_ = useconds_per_4_i; seconds_per_1_f_ = (Real)useconds_per_4_i_ * 4 / 1e6; - mudela_str_ = "\\Tempo: "; + mudela_str_ = "% \\Tempo: "; mudela_str_ += String( useconds_per_4_i_ ); mudela_str_ += String( ": " ) + String( get_tempo_i( Moment( 1, 4 ) ) ) @@ -110,21 +148,18 @@ Midi_tempo::get_tempo_i( Moment moment ) return Moment( 60 ) / moment / Moment( seconds_per_1_f_ ); } -Midi_time::Midi_time( int num_i, int den_i, int clocks_i, int count_32_i ) +Midi_time::Midi_time( int num_i, int den_i, int clocks_4_i, int count_32_i ) + : sync_dur_( 8 ) { -// we should warn, at least! -// assert( count_32_i == 8 ); + sync_f_ = 1.0; if ( count_32_i != 8 ) warning( String( "#32 in quarter: " ) + String( count_32_i ), 0 ); num_i_ = num_i; den_i_ = 2 << den_i; - // huh?, see midiitem.cc; reasonably for fugue1.midi -// whole_clocks_i_ = clocks_i * 4 * 10; - whole_clocks_i_ = clocks_i * 4; -// whole_clocks_i_ = clocks_i; - mudela_str_ = "\\Time: "; + clocks_1_i_ = clocks_4_i * 4; + mudela_str_ = "% \\Time: "; mudela_str_ += String( num_i_ ) + "/" + String( den_i_ ) - + ", " + String( whole_clocks_i_ ) + + ", " + String( clocks_1_i_ ) + ": " + String( count_32_i ); } @@ -132,101 +167,32 @@ Midi_time::~Midi_time() { } -String -Midi_time::duration_str( int clocks_per_whole_i, Real delta_time_f ) -{ - dtor << "(" << delta_time_f; - String str; - - Moment delta_time_moment = 1.0; - if ( delta_time_f ) { - // 288/96*.25 = .75 - // 96/96*.25 = .25 - // 24/96*.25 = 0.0625 -// delta_time_moment = Moment( delta_time_f ) / Moment( whole_clocks_i() ); - if ( clocks_per_whole_i > 0 ) - delta_time_moment = Moment( delta_time_f ) / Moment( clocks_per_whole_i ); - else - delta_time_moment = Moment( -clocks_per_whole_i ) / Moment( delta_time_f ); - } - - dtor << ", " << (Real)delta_time_moment << "): "; - - static Real sync_f = 1; - delta_time_moment = delta_time_moment / sync_f; - - double dummy_f; - if ( ( sync_f == 1 ) - && ( abs( modf( (Real)delta_time_moment / ( (Real)1 / 64 / 3 ), &dummy_f ) ) ) > 1e-6 ) { - sync_f = (Real)delta_time_moment / 0.125; - delta_time_moment = (Real)delta_time_moment / sync_f; - mtor << "\nsyncing: " << sync_f << ", " -// << (Real)sync_f / usecond24th_per_clock_i << endl; - << (Real)whole_clocks_i() << endl; - } - - static bool must_resync_bo = false; - if ( ( (Real)delta_time_moment / 0.125 > 16 ) - || ( (Real)delta_time_moment / 0.125 < ( (Real)1 / 16 ) ) ) - must_resync_bo = true; - - if ( must_resync_bo ) { - must_resync_bo = false; - delta_time_moment = delta_time_moment * sync_f; - sync_f = (Real)delta_time_moment / 0.125; - delta_time_moment = (Real)delta_time_moment / sync_f; - mtor << "\nresyncing: " << sync_f << ", " -// << (Real)sync_f / usecond24th_per_clock_i << endl; - << (Real)whole_clocks_i() << endl; - } - - if ( !delta_time_moment ) - return "0"; - - // output of modf: double - double duration_f = 0; - Real rest_f = modf( ( Moment( 1 ) / delta_time_moment ), &duration_f ); - int dots_i = 0; - int plet_type_i = 0; - if ( rest_f ) { - // output of modf: double - double dots_f = 0; - Real dots_rest_f = modf( rest_f * 3, &dots_f ); - if ( !dots_rest_f ) - dots_i = (int)rint( dots_f ); - else if ( abs( dots_rest_f - rint( dots_rest_f ) ) < 1e-8 ) - dots_i = (int)rint( dots_rest_f ); - // try 3plet - else if ( !modf( (Real)3 * delta_time_moment / 2, &duration_f ) ) - plet_type_i = 3; - // try 6plet - else if ( !modf( (Real)6 * delta_time_moment / 2, &duration_f ) ) - plet_type_i = 6; - else { -// str += String( "\n*" ) + String( (int)( 1 / rest_f ) ); - str += String( "\n*" ) + String( rest_f ); - must_resync_bo = true; - } - } - - if ( dots_i ) { - for ( int i = dots_i; i ; i-- ) - delta_time_moment *= (Real)2 / 3; - modf( ( Moment( 1 ) / delta_time_moment ), &duration_f ); +Duration +Midi_time::i2_dur( int time_i, int division_1_i ) +{ + Moment mom = Duration_convert::i2_mom( time_i, division_1_i ); + mom /= sync_f_; + + dtor << "\n% (" << time_i << ", " << mom << "): " + << sync_f_ << endl; + + Duration dur = Duration_convert::mom2_dur( mom ); + if ( !dur.type_i_ ) { + vtor << "\n% resyncing(" << time_i << ", " << mom << "): " + << sync_f_ << " -> "; + mom *= sync_f_; + sync_f_ = Duration_convert::sync_f( sync_dur_, mom ); + vtor << sync_f_ << endl; + mom /= sync_f_; + dur = Duration_convert::mom2_dur( mom ); } - str += String( (int)( duration_f ) ); - if ( dots_i ) - str += String( '.', dots_i ); - if ( plet_type_i ) - str += String( "/" ) + String( plet_type_i ); - - return str; + return dur; } int -Midi_time::whole_clocks_i() +Midi_time::clocks_1_i() { - return whole_clocks_i_; + return clocks_1_i_; } diff --git a/src/midi-lexer.l b/src/midi-lexer.l index dfbafd5fbf..49f74ead0e 100644 --- a/src/midi-lexer.l +++ b/src/midi-lexer.l @@ -89,14 +89,14 @@ SSME [\0x7f][\x03] } {INT8} { error( String( "top level: illegal byte: " ) - + StringConversion::bin2hex_str( String( *YYText() ) ) ); + + String_convert::bin2hex_str( String( *YYText() ) ) ); exit( 1 ); } {INT32} { dtor << "lex: int32" << endl; assert( YYLeng() == 4 ); String str( (Byte const*)YYText(), YYLeng() ); - yylval.i = StringConversion::bin2int_i( str ); + yylval.i = String_convert::bin2_i( str ); yy_pop_state(); return INT32; } @@ -104,7 +104,7 @@ SSME [\0x7f][\x03] dtor << "lex: int16" << endl; assert( YYLeng() == 2 ); String str( (Byte const*)YYText(), YYLeng() ); - yylval.i = StringConversion::bin2int_i( str ); + yylval.i = String_convert::bin2_i( str ); yy_pop_state(); return INT16; } @@ -119,16 +119,16 @@ SSME [\0x7f][\x03] {VARINT} { String str( (Byte const*)YYText(), YYLeng() ); - yylval.i = My_midi_lexer::varint2int_i( str ); + yylval.i = My_midi_lexer::varint2_i( str ); dtor << String( "lex: track: varint(" ) + String( yylval.i ) + "): " - + StringConversion::bin2hex_str( str ) << endl; + + String_convert::bin2hex_str( str ) << endl; yy_push_state( event ); return VARINT; } {INT8} { error( String( "track: illegal byte: " ) - + StringConversion::bin2hex_str( String( *YYText() ) ) ); + + String_convert::bin2hex_str( String( *YYText() ) ) ); exit( 1 ); } {RUNNING_STATUS} { @@ -240,7 +240,7 @@ SSME [\0x7f][\x03] } {INT8} { error( String( "event: illegal byte: " ) - + StringConversion::bin2hex_str( String( *YYText() ) ) ); + + String_convert::bin2hex_str( String( *YYText() ) ) ); exit( 1 ); } {SEQUENCE} { // ssss sequence number @@ -353,7 +353,7 @@ SSME [\0x7f][\x03] } {INT8} { warning( String( "meta_event: unimplemented event: " ) - + StringConversion::bin2hex_str( String( *YYText() ) ), + + String_convert::bin2hex_str( String( *YYText() ) ), *this->here_ch_c_l() ); yy_pop_state(); yy_pop_state(); @@ -365,7 +365,7 @@ SSME [\0x7f][\x03] {VARINT} { dtor << "lex: data" << endl; String str( (Byte const*)YYText(), YYLeng() ); - int i = My_midi_lexer::varint2int_i( str ); + int i = My_midi_lexer::varint2_i( str ); String* str_p = new String; while ( i-- ) *str_p += (char)yyinput(); @@ -375,7 +375,7 @@ SSME [\0x7f][\x03] } {INT8} { error( String( "data: illegal byte: " ) - + StringConversion::bin2hex_str( String( *YYText() ) ) ); + + String_convert::bin2hex_str( String( *YYText() ) ) ); exit( 1 ); } diff --git a/src/midi-main.cc b/src/midi-main.cc index 5b6ecb3e2d..5dfdf64662 100644 --- a/src/midi-main.cc +++ b/src/midi-main.cc @@ -5,6 +5,7 @@ // copyright 1997 Jan Nieuwenhuizen #include +#include #include "proto.hh" #include "plist.hh" #include "version.hh" @@ -15,6 +16,7 @@ #include "sourcefile.hh" #include "midi-main.hh" #include "moment.hh" +#include "duration.hh" #include "midi-event.hh" #include "midi-track.hh" #include "my-midi-lexer.hh" @@ -25,6 +27,9 @@ Source* source_l_g = &source; Verbose level_ver = NORMAL_ver; +// ugh +bool no_triplets_bo_g = false; + //ugh char const* defined_ch_c_l = 0; @@ -76,9 +81,10 @@ help() { btor << "--debug, -d be really verbose\n" - "--help, -h This help\n" - "--include, -I add to file search path.\n" - "--output, -o set default output\n" + "--help, -h this help\n" + "--include=DIR, -I DIR add DIR to search path\n" + "--no-triplets, -n assume no triplets\n" + "--output=FILE, -o FILE set FILE as default output\n" "--quiet, -q be quiet\n" "--verbose, -v be verbose\n" "--warranty, -w show warranty & copyright\n" @@ -88,8 +94,7 @@ help() void identify() { - mtor << "This is m2m " << VERSIONSTR << "/FlowerLib " << FVERSIONSTR - << " of " << __DATE__ << " " << __TIME__ << endl; + mtor << version_str() << endl; } void @@ -119,6 +124,15 @@ notice() "USA.\n"; } +// should simply have Root class... +String +version_str() +{ + return String ( "This is m2m " ) + VERSIONSTR + + "/FlowerLib " + FVERSIONSTR + + " of " + __DATE__ + " " + __TIME__; +} + int main( int argc_i, char* argv_sz_a[] ) { @@ -126,6 +140,7 @@ main( int argc_i, char* argv_sz_a[] ) 0, "debug", 'd', 0, "help", 'h', // 1, "include", 'I', + 0, "no-triplets", 'n', 1, "output", 'o', 0, "quiet", 'q', 0, "verbose", 'v', @@ -148,6 +163,9 @@ main( int argc_i, char* argv_sz_a[] ) // case 'I': // path->push( getopt_long.optarg ); // break; + case 'n': + no_triplets_bo_g = true; + break; case 'o': output_str = getopt_long.optarg; break; @@ -172,7 +190,14 @@ main( int argc_i, char* argv_sz_a[] ) int error_i = midi_parser.parse(); if ( error_i ) return error_i; - error_i = midi_parser.output( output_str ); + if ( !output_str.length_i() ) { + output_str = String( arg_sz ) + ".ly"; + // i-m sure there-s already some routine for this + int name_i; // too bad we can-t declare local to if + if ( ( name_i = output_str.index_last_i( '/' ) ) != -1 ) + output_str = output_str.mid_str( name_i + 1, INT_MAX ); + } + error_i = midi_parser.output_mudela( output_str ); if ( error_i ) return error_i; } diff --git a/src/midi-parser.y b/src/midi-parser.y index 56680f4b77..466b5c58d5 100644 --- a/src/midi-parser.y +++ b/src/midi-parser.y @@ -12,6 +12,7 @@ #include "my-midi-lexer.hh" #include "my-midi-parser.hh" #include "moment.hh" +#include "duration.hh" #include "midi-event.hh" #include "midi-track.hh" #include "midi-score.hh" @@ -20,6 +21,9 @@ #define YYDEBUG 1 #endif +//ugh +static track_i = 0; + %} %union { @@ -61,6 +65,7 @@ midi: /* empty */ | midi midi_score { midi_parser_l_g->add_score( $2 ); + track_i = 0; } ; @@ -69,34 +74,31 @@ midi_score: } | midi_score track { $$->add_track( $2 ); + midi_parser_l_g->reset(); } ; header: HEADER INT32 INT16 INT16 INT16 { $$ = new Midi_score( $3, $4, $5 ); - midi_parser_l_g->set_division( $5 ); + midi_parser_l_g->set_division_4( $5 ); } ; track: TRACK INT32 { - $$ = new Midi_track; + $$ = new Midi_track( track_i++ ); } | track event { - $$->add_event( $2 ); + $$->add_event( midi_parser_l_g->mom(), $2 ); } ; event: varint the_event { - if ( $2 && $2->mudela_str().length_i() ) { - if ( ( $2->mudela_str()[ 0 ] >= 'a' ) - && $2->mudela_str()[ 0 ] <= 'g' ) - qtor << $2->mudela_str() << " "; - else - vtor << $2->mudela_str() << " "; - } + $$ = $2; + if ( $2 && $2->mudela_str().length_i() ) + dtor << $2->mudela_str() << " " << flush; } ; @@ -130,7 +132,7 @@ the_meta_event: } | text_event DATA { $$ = 0; - vtor << *$2 << endl; + dtor << *$2 << endl; delete $2; } | END_OF_TRACK { @@ -138,7 +140,7 @@ the_meta_event: } | TEMPO INT8 INT8 INT8 { $$ = new Midi_tempo( ( $2 << 16 ) + ( $3 << 8 ) + $4 ); - vtor << $$->mudela_str() << endl; // ?? waai not at event: + dtor << $$->mudela_str() << endl; // ?? waai not at event: midi_parser_l_g->set_tempo( ( $2 << 16 ) + ( $3 << 8 ) + $4 ); } | SMPTE_OFFSET INT8 INT8 INT8 INT8 INT8 { @@ -146,7 +148,7 @@ the_meta_event: } | TIME INT8 INT8 INT8 INT8 { $$ = new Midi_time( $2, $3, $4, $5 ); - vtor << $$->mudela_str() << endl; // ?? waai not at event: + dtor << $$->mudela_str() << endl; // ?? waai not at event: midi_parser_l_g->set_time( $2, $3, $4, $5 ); } | KEY INT8 INT8 { @@ -161,25 +163,25 @@ the_meta_event: text_event: TEXT { - vtor << endl << "Text: "; + dtor << "\n% Text: "; } | COPYRIGHT { - vtor << endl << "Copyright: "; + dtor << "\n% Copyright: "; } | TRACK_NAME { - vtor << endl << "Track name: "; + dtor << "\n% Track name: "; } | INSTRUMENT_NAME { - vtor << endl << "Instrument name: "; + dtor << "\n% Instrument name: "; } | LYRIC { - vtor << endl << "Lyric: "; + dtor << "\n% Lyric: "; } | MARKER { - vtor << endl << "Marker: "; + dtor << "\n% Marker: "; } | CUE_POINT { - vtor << endl << "Cue point: "; + dtor << "\n% Cue point: "; } ; diff --git a/src/midi-score.cc b/src/midi-score.cc index 02a79a542d..f24f9093d1 100644 --- a/src/midi-score.cc +++ b/src/midi-score.cc @@ -4,6 +4,16 @@ // copyright 1997 Jan Nieuwenhuizen #include "proto.hh" +#include "plist.hh" +#include "string.hh" +#include "moment.hh" +#include "duration.hh" +#include "sourcefile.hh" +#include "source.hh" +#include "midi-main.hh" // *tors +#include "midi-event.hh" +#include "lily-stream.hh" +#include "track-column.hh" #include "midi-track.hh" #include "midi-score.hh" @@ -21,4 +31,33 @@ Midi_score::~Midi_score() void Midi_score::add_track( Midi_track* midi_track_p ) { + midi_track_p_list_.bottom().add( midi_track_p ); } + +int +Midi_score::output_mudela( String filename_str ) +{ + mtor << "Lily output to " << filename_str << " ..." << endl; + + Lily_stream lily_stream( filename_str ); + for ( PCursor midi_track_l_pcur( midi_track_p_list_.top() ); midi_track_l_pcur.ok(); midi_track_l_pcur++ ) { + midi_track_l_pcur->output_mudela( lily_stream ); + lily_stream << "\n"; + } + + lily_stream << "score {\n"; + + for ( PCursor midi_track_l_pcur( midi_track_p_list_.top() ); midi_track_l_pcur.ok(); midi_track_l_pcur++ ) { + lily_stream << "\tstaff { melodic music { "; + lily_stream << midi_track_l_pcur->name_str(); + lily_stream << " } }\n"; + } + + lily_stream << "\tcommands { meter { 4*4 } }\n"; + lily_stream << "\tmidi { tempo 4:60 }\n"; + + lily_stream << "}\n"; + + return 0; +} + diff --git a/src/midi-template.cc b/src/midi-template.cc index 02315c320b..c4caa838b4 100644 --- a/src/midi-template.cc +++ b/src/midi-template.cc @@ -16,4 +16,14 @@ class ostream; #include "string.hh" #include "sourcefile.hh" +#include "moment.hh" +#include "duration.hh" +#include "midi-event.hh" +#include "lily-stream.hh" +#include "track-column.hh" +#include "midi-track.hh" + +IPL_instantiate(Midi_event); +IPL_instantiate(Midi_track); IPL_instantiate(Source_file); +IPL_instantiate(Track_column); diff --git a/src/midi-track.cc b/src/midi-track.cc index 77abf04e1c..99bd9dee8c 100644 --- a/src/midi-track.cc +++ b/src/midi-track.cc @@ -4,13 +4,23 @@ // copyright 1997 Jan Nieuwenhuizen #include "proto.hh" +#include "plist.hh" #include "string.hh" +#include "sourcefile.hh" +#include "source.hh" +#include "midi-main.hh" // *tors + #include "moment.hh" +#include "duration.hh" #include "midi-event.hh" +#include "lily-stream.hh" +#include "track-column.hh" #include "midi-track.hh" -Midi_track::Midi_track() +Midi_track::Midi_track( int track_i ) { + name_str_ = String( "track" ) + String( track_i ); + tcol_p_list_.bottom().add( new Track_column( Moment( 0 ) ) ); } Midi_track::~Midi_track() @@ -18,6 +28,57 @@ Midi_track::~Midi_track() } void -Midi_track::add_event( Midi_event* midi_event_p ) +Midi_track::add_event( Moment mom, Midi_event* midi_event_p ) +{ + if ( ! midi_event_p ) + return; + tcol_l( mom - midi_event_p->mom() )->add_event( midi_event_p ); +} + +// too much red tape ? +String +Midi_track::name_str() +{ + return name_str_; +} + +void +Midi_track::output_mudela( Lily_stream& lily_stream_r ) { + lily_stream_r << name_str_ << " = music { $\n"; + lily_stream_r << "\t"; + int column_i = 8; + + for ( PCursor tcol_l_pcur( tcol_p_list_.top() ); tcol_l_pcur.ok(); tcol_l_pcur++ ) { + if ( tcol_l_pcur->midi_event_p_list_.size() > 1 ) + warning( "oeps, chord: can-t do that yet", 0 ); + if ( !tcol_l_pcur->midi_event_p_list_.size() ) + continue; + lily_stream_r << **tcol_l_pcur->midi_event_p_list_.top(); + column_i += tcol_l_pcur->midi_event_p_list_.top()->mudela_str().length_i(); + if ( column_i > 40 ) { + lily_stream_r << "\n\t"; + column_i = 8; + } + } + lily_stream_r << "\n$} % " << name_str_ << "\n"; } + +Track_column* +Midi_track::tcol_l( Moment mom ) +{ + for ( PCursor tcol_l_pcur( tcol_p_list_.top() ); tcol_l_pcur.ok(); tcol_l_pcur++ ) { + if ( tcol_l_pcur->mom() == mom ) + return *tcol_l_pcur; + if ( tcol_l_pcur->mom() > mom ) { + Track_column* tcol_p = new Track_column( mom ); + tcol_l_pcur.insert( tcol_p ); + return tcol_p; + } + } + + Track_column* tcol_p = new Track_column( mom ); + tcol_p_list_.bottom().add( tcol_p ); + return tcol_p; +} + diff --git a/src/midiitem.cc b/src/midiitem.cc index 0ce9ead5e0..c57f9ff5de 100644 --- a/src/midiitem.cc +++ b/src/midiitem.cc @@ -38,8 +38,8 @@ String Midi_chunk::str() { String str = header_str_; - String length_str = StringConversion::int2hex_str( data_str_.length_i() + footer_str_.length_i(), 8, '0' ); - length_str = StringConversion::hex2bin_str( length_str ); + String length_str = String_convert::i2hex_str( data_str_.length_i() + footer_str_.length_i(), 8, '0' ); + length_str = String_convert::hex2bin_str( length_str ); str += length_str; str += data_str_; str += footer_str_; @@ -61,20 +61,20 @@ Midi_header::Midi_header( int format_i, int tracks_i, int clocks_per_4_i ) { String str; - String format_str = StringConversion::int2hex_str( format_i, 4, '0' ); - str += StringConversion::hex2bin_str( format_str ); + String format_str = String_convert::i2hex_str( format_i, 4, '0' ); + str += String_convert::hex2bin_str( format_str ); - String tracks_str = StringConversion::int2hex_str( tracks_i, 4, '0' ); - str += StringConversion::hex2bin_str( tracks_str ); + String tracks_str = String_convert::i2hex_str( tracks_i, 4, '0' ); + str += String_convert::hex2bin_str( tracks_str ); - String tempo_str = StringConversion::int2hex_str( clocks_per_4_i, 4, '0' ); - str += StringConversion::hex2bin_str( tempo_str ); + String tempo_str = String_convert::i2hex_str( clocks_per_4_i, 4, '0' ); + str += String_convert::hex2bin_str( tempo_str ); set( "MThd", str, "" ); } String -Midi_item::int2varlength_str( int i ) +Midi_item::i2varint_str( int i ) { int buffer_i = i & 0x7f; while ( (i >>= 7) > 0 ) { @@ -136,8 +136,8 @@ Midi_tempo::str() { int useconds_per_4_i = 60 * (int)1e6 / tempo_i_; String str = "ff5103"; - str += StringConversion::int2hex_str( useconds_per_4_i, 6, '0' ); - return StringConversion::hex2bin_str( str ); + str += String_convert::i2hex_str( useconds_per_4_i, 6, '0' ); + return String_convert::hex2bin_str( str ); } Midi_track::Midi_track( int number_i ) @@ -169,10 +169,10 @@ Midi_track::Midi_track( int number_i ) String data_str; // only for format 0 (currently using format 1)? - data_str += StringConversion::hex2bin_str( data_ch_c_l ); + data_str += String_convert::hex2bin_str( data_ch_c_l ); char const* footer_ch_c_l = "00" "ff2f" "00"; - String footer_str = StringConversion::hex2bin_str( footer_ch_c_l ); + String footer_str = String_convert::hex2bin_str( footer_ch_c_l ); set( "MTrk", data_str, footer_str ); } @@ -181,13 +181,14 @@ void Midi_track::add( int delta_time_i, String event_str ) { assert(delta_time_i >= 0); - Midi_chunk::add( int2varlength_str( delta_time_i ) + event_str ); + Midi_chunk::add( i2varint_str( delta_time_i ) + event_str ); } void Midi_track::add( Moment delta_time_moment, Midi_item* mitem_l ) { // use convention of 384 clocks per 4 + // use Duration_convert int delta_time_i = delta_time_moment * Moment( 384 ) / Moment( 1, 4 ); add( delta_time_i, mitem_l->str() ); } diff --git a/src/midistream.cc b/src/midistream.cc index 84b105d27d..f561e0b946 100644 --- a/src/midistream.cc +++ b/src/midistream.cc @@ -18,6 +18,7 @@ Midi_stream::Midi_stream( String filename_str, int tracks_i, int clocks_per_4_i filename_str_ = filename_str; tracks_i_ = tracks_i; clocks_per_4_i_ = clocks_per_4_i; + os_p_ = 0; open(); header(); } @@ -32,7 +33,7 @@ Midi_stream::operator <<( String str ) { // still debugging... if ( check_debug ) - str = StringConversion::bin2hex_str( str ); + str = String_convert::bin2hex_str( str ); // string now 1.0.26-2 handles binary streaming *os_p_ << str; return *this; @@ -51,7 +52,7 @@ Midi_stream& Midi_stream::operator <<( int i ) { // output binary string ourselves - *this << Midi_item::int2varlength_str( i ); + *this << Midi_item::i2varint_str( i ); return *this; } @@ -71,7 +72,7 @@ Midi_stream::header() // 00 60 96 per quarter-note // char const ch_c_l = "0000" "0006" "0001" "0001" "0060"; -// str += StringConversion::hex2bin_str( ch_c_l ); +// str += String_convert::hex2bin_str( ch_c_l ); // *os_p_ << str; // *this << Midi_header( 1, 1, tempo_i_ ); diff --git a/src/misc.cc b/src/misc.cc index f89cdec9f1..093af7f0d4 100644 --- a/src/misc.cc +++ b/src/misc.cc @@ -6,6 +6,7 @@ #include "moment.hh" +// depreciated, see struct Duration* Moment wholes(int dur, int dots) { diff --git a/src/my-midi-lexer.cc b/src/my-midi-lexer.cc index a070992f53..c261e5c503 100644 --- a/src/my-midi-lexer.cc +++ b/src/my-midi-lexer.cc @@ -57,7 +57,7 @@ My_midi_lexer::here_ch_c_l() } int -My_midi_lexer::varint2int_i( String str ) +My_midi_lexer::varint2_i( String str ) { int var_i = 0; @@ -68,7 +68,7 @@ My_midi_lexer::varint2int_i( String str ) if ( ! ( byte & 0x80 ) ) return var_i; } - cout << "\nvarint2int:" << StringConversion::bin2hex_str( str ) << endl; + cout << "\nvarint2_i:" << String_convert::bin2hex_str( str ) << endl; assert( 0 ); // illegal varint return 0; } diff --git a/src/my-midi-parser.cc b/src/my-midi-parser.cc index cd12082239..62f4d499c8 100644 --- a/src/my-midi-parser.cc +++ b/src/my-midi-parser.cc @@ -13,7 +13,12 @@ #include "my-midi-lexer.hh" #include "my-midi-parser.hh" +#include "duration.hh" #include "midi-event.hh" +#include "lily-stream.hh" +#include "track-column.hh" +#include "midi-track.hh" +#include "midi-score.hh" #include "my-midi-lexer.hh" #include "my-midi-parser.hh" @@ -30,21 +35,32 @@ My_midi_parser::My_midi_parser( String filename_str ) { midi_lexer_p_ = new My_midi_lexer( filename_str ); midi_parser_l_g = this; + defined_ch_c_l_ = 0; + fatal_error_i_ = 0; + midi_key_p_ = 0; + midi_score_p_ = 0; + midi_tempo_p_ = 0; + midi_time_p_ = 0; + reset(); +} +void +My_midi_parser::reset() +{ + delete midi_key_p_; midi_key_p_ = new Midi_key( 0, 0 ); -// midi_tempo_p_ = new Midi_tempo( 384 ); // wiellie dunno! - // 07A120 == 500000 - midi_tempo_p_ = new Midi_tempo( 0x07a120 ); // wiellie dunno! - midi_time_p_ = new Midi_time( 4, 4, 0x24, 8 ); + // useconds per 4: 250000 === 60 4 per minute + delete midi_tempo_p_; + midi_tempo_p_ = new Midi_tempo( 250000 ); + delete midi_time_p_; + midi_time_p_ = new Midi_time( 4, 4, 384, 8 ); - defined_ch_c_l_ = 0; - fatal_error_i_ = 0; - now_f_ = 0; - step_f_ = 0; + now_i64_ = 0; for ( int i = 0; i < CHANNELS_i; i++ ) for ( int j = 0; j < PITCHES_i; j++ ) - running_f_f_a_[ i ][ j ] = 0; +// running_i64_i64_a_[ i ][ j ] = -1; + running_i64_i64_a_[ i ][ j ] = 0; } My_midi_parser::~My_midi_parser() @@ -54,13 +70,14 @@ My_midi_parser::~My_midi_parser() delete midi_key_p_; delete midi_tempo_p_; delete midi_time_p_; + delete midi_score_p_; } void My_midi_parser::add_score( Midi_score* midi_score_p ) { - midi_score_p_array_.push( midi_score_p ); - cout << endl; + assert( !midi_score_p_ ); + midi_score_p_ = midi_score_p; } void @@ -73,36 +90,41 @@ My_midi_parser::error( char const* sz_l ) } void -My_midi_parser::forward( Real f ) +My_midi_parser::forward( int i ) +{ + now_i64_ += i; +} + +Moment +My_midi_parser::mom() { - // ugh - if ( f ) - step_f_ = f; - now_f_ += step_f_; + return Duration_convert::i2_mom( now_i64_, division_1_i_ ); } void My_midi_parser::note_begin( int channel_i, int pitch_i, int dyn_i ) { // one pitch a channel at time! - // heu, what if start at t = 0? -// assert( !running_f_f_a_[ channel_i ][ pitch_i ] ); - running_f_f_a_[ channel_i ][ pitch_i ] = now_f_; + // heu, what about { < c2 > < c4 d4 > } +// assert( running_i64_i64_a_[ channel_i ][ pitch_i ] == -1 ); + running_i64_i64_a_[ channel_i ][ pitch_i ] = now_i64_; } Midi_event* My_midi_parser::note_end_midi_event_p( int channel_i, int pitch_i, int dyn_i ) { - Real start_f = running_f_f_a_[ channel_i ] [ pitch_i ]; - // did we start? -> heu, don-t know: what if start at t = 0? -// assert( start_f ); - return new Midi_note( midi_key_p_, midi_time_p_, clocks_per_whole_i_, pitch_i, now_f_ - start_f ); + Int64 start_i64 = running_i64_i64_a_[ channel_i ][ pitch_i ]; +// running_i64_i64_a_[ channel_i ][ pitch_i ] = -1; + // did we start? +// assert( start_i64 != -1 ); + return new Midi_note( midi_key_p_, midi_time_p_, division_1_i_, pitch_i, now_i64_ - start_i64 ); } int -My_midi_parser::output( String filename_str ) +My_midi_parser::output_mudela( String filename_str ) { - return 0; + assert( midi_score_p_ ); + return midi_score_p_->output_mudela( filename_str ); } int @@ -112,10 +134,10 @@ My_midi_parser::parse() } void -My_midi_parser::set_division( int clocks_per_4_i ) +My_midi_parser::set_division_4( int division_4_i ) { - clocks_per_whole_i_ = clocks_per_4_i * 4; - if ( clocks_per_4_i < 0 ) + division_1_i_ = division_4_i * 4; + if ( division_4_i < 0 ) warning( "seconds iso metrical time" , 0 ); } diff --git a/src/mylexer.cc b/src/mylexer.cc index a02c323ea3..10c395759c 100644 --- a/src/mylexer.cc +++ b/src/mylexer.cc @@ -60,7 +60,7 @@ static Keyword_ent the_key_tab[]={ int My_flex_lexer::ret_notename(int *p, String text, int octave_mod) { - text.lower(); + text = text.lower_str(); char const* ch_c_l = here_ch_c_l(); if ( ch_c_l ) { ch_c_l--; diff --git a/src/note.cc b/src/note.cc index 95a7d8313d..0f7eb8e85f 100644 --- a/src/note.cc +++ b/src/note.cc @@ -25,7 +25,7 @@ bool last_duration_mode = false; void set_duration_mode(String s) { - s.upper(); + s = s.upper_str(); last_duration_mode = (s== "LAST"); } diff --git a/src/parser.y b/src/parser.y index d065f19cae..b8b175ef1a 100644 --- a/src/parser.y +++ b/src/parser.y @@ -622,6 +622,13 @@ explicit_duration: get_default_duration($$); $$[1] = $1; } + | INT '*' INT '/' INT { + // ugh, must use Duration + set_plet( $3, $5 ); + $$[ 0 ] = $1; + $$[ 1 ] = 0; + set_plet( 1, 1 ); + } ; default_duration: diff --git a/src/request.cc b/src/request.cc index bce34a8575..991be88550 100644 --- a/src/request.cc +++ b/src/request.cc @@ -101,12 +101,12 @@ Melodic_req::height() const /* should be settable from input to allow "viola"-mode */ -static Byte pitch_by_a[ 7 ] = { 0, 2, 4, 5, 7, 9, 11 }; +static Byte pitch_byte_a[ 7 ] = { 0, 2, 4, 5, 7, 9, 11 }; int Melodic_req::pitch() const { - return pitch_by_a[ notename_i_ % 7 ] + accidental_i_ + octave_i_ * 12; + return pitch_byte_a[ notename_i_ % 7 ] + accidental_i_ + octave_i_ * 12; } Plet_req::Plet_req() diff --git a/src/script.cc b/src/script.cc index db87b6baf1..a98a8a9926 100644 --- a/src/script.cc +++ b/src/script.cc @@ -57,7 +57,7 @@ Script::support_height() const return r; } void -Script::set_default_pos() +Script::set_default_index() { Real inter_f= paper()->internote(); Interval dy = symbol().dim.y; @@ -115,7 +115,7 @@ Script::do_pre_processing() void Script::do_post_processing() { - set_default_pos(); + set_default_index(); } Molecule* diff --git a/src/sourcefile.cc b/src/sourcefile.cc index eac2b1f84a..5caa8545fa 100644 --- a/src/sourcefile.cc +++ b/src/sourcefile.cc @@ -104,10 +104,10 @@ Source_file::error_str( char const* pos_ch_c_l ) else error_col_i++; - String str = line_str.left( pos_ch_c_l - begin_ch_c_l ) + String str = line_str.left_str( pos_ch_c_l - begin_ch_c_l ) + String( '\n' ) + String( ' ', error_col_i ) - + line_str.mid( pos_ch_c_l - begin_ch_c_l + 1, INT_MAX ); // String::mid should take 0 arg.. + + line_str.mid_str( pos_ch_c_l - begin_ch_c_l + 1, INT_MAX ); // String::mid should take 0 arg.. return str; } diff --git a/src/stem.cc b/src/stem.cc index 22123356c6..e9a4f943bf 100644 --- a/src/stem.cc +++ b/src/stem.cc @@ -186,7 +186,7 @@ Stem::brew_molecule_p()const return out; } Real -Stem::hpos()const +Stem::hindex()const { return pcol_l_->hpos + stem_xoffset; // hmm. + offset_.x; } diff --git a/src/tex.cc b/src/tex.cc index 1a5c4a08c5..d7f1162d29 100644 --- a/src/tex.cc +++ b/src/tex.cc @@ -14,10 +14,10 @@ vstrut(Real h) static void substitute_arg(String& r, String arg) { - int p = r.pos('%'); + int p = r.index_i('%'); if (!p ) return ; else p--; - r = r.left(p) + arg + r.right(r.len() - p -1); + r = r.left_str(p) + arg + r.right_str(r.length_i() - p -1); } @@ -27,7 +27,7 @@ substitute_args(String source, Array args) String retval (source); for (int i = 0 ; i < args.size(); i++) substitute_arg(retval, args[i]); - while (retval.pos('%')) + while (retval.index_i('%')) substitute_arg(retval, ""); return retval; } diff --git a/src/textitem.cc b/src/textitem.cc index 110e95e3bf..56fb8e054b 100644 --- a/src/textitem.cc +++ b/src/textitem.cc @@ -17,7 +17,7 @@ Text_item::Text_item(Text_req* treq_l, int staffsize_i) } void -Text_item::set_default_pos() +Text_item::set_default_index() { pos_i_ = (dir_i_ > 0) ? staffsize_i_ + 2: -4; } @@ -25,7 +25,7 @@ Text_item::set_default_pos() void Text_item::do_pre_processing() { - set_default_pos(); + set_default_index(); } diff --git a/src/timedescription.cc b/src/timedescription.cc index c9c3d52860..59d1189b11 100644 --- a/src/timedescription.cc +++ b/src/timedescription.cc @@ -1,3 +1,11 @@ +/* + timedescription.cc -- implement Time_description + + source file of the LilyPond music typesetter + + (c) 1997 Han-Wen Nienhuys +*/ + #include "timedescription.hh" #include "debug.hh" @@ -17,13 +25,15 @@ Time_description::str()const void Time_description::print() const -{ +{ +#ifndef NPRINT mtor << str(); +#endif } void Time_description::OK() const { -#ifdef NDEBUG +#ifndef NDEBUG if (!cadenza_b_) assert(whole_in_measure_ < whole_per_measure_); assert(0 <= whole_in_measure_); @@ -52,6 +62,7 @@ Time_description::Time_description() bars_i_ = 0; cadenza_b_ = false; } + void Time_description::add(Moment dt) { diff --git a/src/walkregs.cc b/src/walkregs.cc index 4381688398..dc24ecd96a 100644 --- a/src/walkregs.cc +++ b/src/walkregs.cc @@ -16,8 +16,8 @@ Walker_registers::Walker_registers(Complex_walker *w) { add( new Bar_register(w)); - add( new Meter_register(w)); add( new Clef_register(w)); add( new Key_register(w)); + add( new Meter_register(w)); add( new Local_key_register(w)); } -- 2.39.5