+++ /dev/null
-# class name silence?
-
-My_flex_lexer 1
-yyFlexLexer 1
-PCol 1
-Score_column 1
-Ineq_constrained_qp 1
-Spacing_problem 1
-Colinfo 1
-Mixed_qp 1
-PScore 1
-Idealspacing 1
-
-# yydebug
-InitParser 1
-Parser 1
-InitDeclarations 1
-
-# FlexLexer debug
-InitLexer 1
-Lexer 1
-
-parse_duration 1
-parse_pitchmod 1
-Col_configuration 1
-Request 0
-Note_req 1
-Rhythmic_req 0
-Rest_req 1
-delete_identifiers 1
-Command 1
-Staff_commands 1
-Stem 1
-Staff 0
-Score 1
-Voice 0
-Voice_element 0
-Input_cursor 1
-Commands_at 1
-Input_command 1
-Time_description 1
-Melodic_req 0
-Midi_walker 0
-Stem_req 1
-Group_change_req 0
-Script_req 1
-Colinfo 1
-Word_wrap 1
-Text_req 1
-Script_def 1
-Text_def 1
-Paperdef 1
-Symtable 1
-Symtables 1
\ No newline at end of file
--- /dev/null
+TOPLEVEL_MAJOR_VERSION = 0
+TOPLEVEL_MINOR_VERSION = 0
+TOPLEVEL_PATCH_LEVEL = 39
+# use to send patches, always empty for released version:
+TOPLEVEL_MY_PATCH_LEVEL = -1# include separator: "-1" or ".a"
+#
(add-hook 'c-mode-hook
'(lambda ()(setq c-basic-offset 4)))
+
+
(add-hook 'c++-mode-hook
'(lambda() (c-set-style "Stroustrup")
)
)
-=head2 FILES
-The class C<This_is_a_class> is declared in F<this-is-a-class.hh> and
-implemented in F<this-is-a-class.cc>.
=head2 CLASSES and TYPES:
Class::member()
Type Class::member_type_
-the C<type> is a Hungarian notation postfix for C<Type>. See below
+the C<type> is a Hungarian notation postfix for $C<Type>$. See below
=head2 COMMENTS
NB: in PCursor (which is part of the library) P stands for PointerCursor
-=head2 MEMBERS (2)
+=head2 MEMBERS(2)
Standard methods:
=head2 Hungarian
The Hungarian Notation was conceived by or at least got its name from,
-the hungarian programmer x. It is a naming convention with the aim to
-make code more readable (for fellow programmers) and more accessible
-for programmers that are new to a project.
+the hungarian programmer Charles Simonyi. It is a naming convention
+with the aim to make code more readable (for fellow programmers), and
+more accessible for programmers that are new to a project.
The essence of the Hungarian Notation is that every identifier has a
part which identifies its type (for functions this is the result
=over 5
=item C<byte>
-unsigned cher. (The postfix _by is ambiguous)
+unsigned char. (The postfix _by is ambiguous)
-=item C<b>
+=item C<bo>
bool
=item C<bi>
=item C<a>
array
-=item C<arr>
+=item C<array>
user built array.
=item C<c>
Temporary variable: an unsigned integer
=item C<test_ch>
-Variable Test: a character
+Variable test: a character
=item C<first_name_str>
Variable first_name: a String class object
-=item C<first_name_ch_a>
-Variable first_name: a C<char> array
+=item C<last_name_ch_a>
+Variable last_name: a C<char> array
-=item C<loop_i_p>
-Variable Loop: an C<Int*> that you must delete
+=item C<foo_i_p>
+Variable foo: an C<Int*> that you must delete
-=item C<loop_i_l>
-Variable Loop: an C<Int*> that you must not delete
+=item C<bar_i_l>
+Variable bar: an C<Int*> that you must not delete
=back
-PODS=README.pod CodingStyle.pod lilygut.pod lilyinput.pod error.pod\
- faq.pod index.pod language.pod
-TXTS=$(PODS:.pod=.txt)
-MANS=$(PODS:.pod=.1)
-HTMLS=$(PODS:.pod=.html)
-DISTFILES=$(PODS) Makefile lelie_logo.png make_website
-
-
-default:
- $(MAKE) -C .. doc
-
-doc: $(TXTS)
-
-dist:
- ln $(DISTFILES) $(DDIR)/$(SUBDIR)
-clean:
- rm -f $(TXTS) $(MANS)
-
-%.txt: %.1
- groff -man -Tascii $< > $@
-
-%.1: %.pod
- pod2man --center="LilyPond documentation" --section="0"\
- --release="LilyPond $(MAJVER).$(MINVER).$(PATCHLEVEL)" $< > $@
+# Documentation/Makefile
+
+# subdir level:
+#
+depth = ..
+#
+
+# identify module:
+#
+NAME = Documentation
+MAJOR_VERSION = $(TOPLEVEL_MAJOR_VERSION)
+MINOR_VERSION = $(TOPLEVEL_MINOR_VERSION)
+PATCH_LEVEL = $(TOPLEVEL_PATCH_LEVEL)
+# use to send patches, always empty for released version:
+MY_PATCH_LEVEL = $(TOPLEVEL_MY_PATCH_LEVEL)
+build = ./$(depth)/lily/.build
+#
+
+# generic variables:
+#
+include ./$(depth)/make/Variables.make
+#
+
+# list of source files:
+#
+PODFILES = $(shell ls *.pod)
+OUTPODFILES = $(patsubst %,$(outdir)/%,$(PODFILES))
+TEXTFILES = $(OUTPODFILES:.pod=.text)
+MANFILES = $(OUTPODFILES:.pod=.1)
+HTMLFILES = $(OUTPODFILES:.pod=.html)
+#
+
+# list of distribution files:
+#
+DISTFILES = $(PODFILES) Makefile lelie_logo.png
+#
+
+default: do-doc
+
+do-doc: $(TEXTFILES)
html: $(pod)
pod2html
htmldist: html
- make_website
+ ./$(bindir)/make_website
+
+# generic targets and rules:
+#
+include ./$(depth)/make/Targets.make
+include ./$(depth)/make/Rules.make
+#
+
=item B<-M,--midi>
-Do midi output only.
+do midi output only
=item B<-d,--debug>,
=over 5
=item *
-A fast computer (a full page of music typically takes 1 minute
+a fast computer (a full page of music typically takes 1 minute
on my 486/66, using the DEBUG compile. It's lot slower than most
MusiXTeX preprocessors)
You probably want to edit Variables.make to tailor the compilation
flags. If you're not into debugging C++, then you should go for no
-debugging and C<-O2>.
+debugging and C<-O2>
=head1 AUTHORS
Han-Wen Nienhuys <hanwen@stack.nl>, Main author
=item *
-Jan C. Nieuwenhuizen <jan@digicash.com>, Context errors, Lyrics, Midi
-output, m2m, bits of FlowerLib, general comments.
+Jan Nieuwenhuizen <jan@digicash.com>, Context errors, Lyrics,
+bits of FlowerLib, general comments.
=item *
-Mats Bengtsson <matsb@s3.kth.se>, bugfixes, testing, criticism, general comments.
+Mats Bengtsson <matsb@s3.kth.se>, bugfixes, testing, general comments.
=back
=head1 SEE ALSO
-There are some documentation files in the subdirectory
-F<Documentation/>, among others: lilygut, lilyinput, error, faq. There
-is a rudimentary webpage at the following URL:
-http://www.stack.nl/~hanwen/lilypond/index.html
+There are some documentation files in the subdirectory F<Documentation/>,
+among others: lilygut, lilyinput, error, faq,
=head1 REMARKS
Some questions that have been answered before.
-Q: Gee, I really like MPP, why would I want to switch to LilyPond?
-
-A: The design of MPP is broken beyond repair: it is very difficult to
-enhance MPP, and any working version is (probably) bug-ridden.
-
-Every once in a while, I have a major attack of hybris, and I go in to
-enhance MPP. I usually end up thoroughly frustated within an hour or
-so. I concur, it does work but extending MPP is a major pain.
-
-We will not sacrifice development time on something else than the most
-trivial bugfixes. If you insist on using MusiXTeX, then LilyPond is
-not for you, and you might try PMX which does also nice output.
-
-
Q: Why are [] around the notes, and () inbetween?
A: [] designate beams, a note can only be in one beam at the same
A0: Reconsider. Try Linux. It's fun!
A1: Currently (patchlevel 27), LilyPond (and flowerLib) compiles, links
-and runs on Windhoos-NT, using the CYGNUS GNU port (release b17.1).
+and runs on windhoos-nt, using the cygnus gnu port (release b17.1).
I (JCN) only had to make a minor workaround for missing library calls.
Have a look at http://www.cygnus.com/gnu-win32. To make LilyPond type
-C<make $OS>. (I am not promising to maintain this platform, it is just that
+make $OS. (I am not promising to maintain this platform, it is just that
when having to use doze, i-m sometimes too lazy to reboot.)
-A2: I haven't had time to find a GCC crosscompiler (I<with> g++, mind you) to
+A2: I haven't had time to find a GCC crosscompiler (*with* g++, mind you) to
DOS/win (in rpm, please :).
A: Yes.
-
Q: Why shouldn't I put all commands (\clef, \meter) inside the music?
A: You should do what you like, but at some time we will enable
Q: Why do I need g++ >= 2.7?
A: By using g++ LilyPond is portable to all platforms which support
-g++ (there are quite a few, more than platforms which have AT&T CC or
-Micro$oft C++). Not having to support other compilers saves us a I<lot>
-of trouble. You need a version better than 2.7 because LilyPond &
-FlowerLib uses:
+g++ (there are quite a few). Not having to support other compilers
+saves us a *lot* of trouble. LilyPond & FlowerLib uses:
=over 6
=back
-Q: Why do I have to tell LilyPond explictly that the lowest-line-note
-is "es" if I am using the key of "bes"?
-
-A: The goal of lilypond (and MPP) was to design a language which
-conveys the I<musical> message of a piece. That is the reason that it
-does not ask you to enter the line on which the note is is. (Or the
-"natural" note-name without any "es" or "is" postfix)
-
-We do realise it is a bit shortsighted of us to assume that any user could
-readily read the music he/she is entering. We might extend LilyPond to
-allow "programmable" intervals, keys and clefs (and thus give him a
-means to build his own scales, custom etc.).
-
-For now, you can program LilyPond to use custom notenames and do
-
- notenames { ces_key_notenames }
- music { $ % music in the key of ces
- ...
- $}
- notenames { dutch_notenames } % restore default
-
-as an ad-hoc solution.
-
programmers and non programmers. The final aim is to be able to
express what can be expressed in sheet music.
-This document is intended to summarise the plans for mudela 2 (mudela
-0 being mpp-input, and mudela-1 LilyPond input upto version 0.0.38).
-Ideas for any further extensions (mudela 3, read total vapourware)
-should be marked as such.
-
-
=over 5
=item *
We might be able to do without the staff{} construct, but I doubt if
it will make things easier.
-=head1 DECISIONS
-
-[none, yet]
-
-
=head1 THOUGHTS
=head2 Typing
\key{\keybes}
-[LOOSE]
-We could be even more rabid, and use '\rab' as \bar terminator.
-
-Just kidding of course...
[LOOSE THOUGHT]
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 mudela-isated music.
+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"
linked across staffs. I should first think of a way to do this in
LilyPond, before even considering a syntax.
-[see also: filtering]
=head2 Volta
The syntax of /, * and : has to be settled, we have
- - notes (1, 2, 4, 8 etc), which also can take 1*2/3 to do plets.
+ - notes (1, 2, 4, 8 etc)
- meter 2*4
- plet 2/3
- multiple notes: 3*4
- abbreviations (not implemented) c4/4 or c4*4
- - measure grouping, {2*4 3*4}
- - skip
-
=head2 Filtering
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
Mudela version 3. And I think using m4 (or something alike) would be
just as convenient.
-It might clear things up, if JCN told us what is so special about this
-syntax (without the C++ looks).
-
=head2 Transposition
Has to be done. How about:
+++ /dev/null
-#!/usr/bin/perl -w
-sub
- set_hrefs
-{
- while (<HTMLIN>) {
- s#href=([A-Za-z.]+)#href=$base/$1#g;
- print HTMLOUT $_;
- }
-}
-
-local $base="lilypond/";
-local @examples=("wohltemperirt");
-
-system 'pod2html';
-
-print "resetting refs.\n";
-
-foreach $a (<*.html>)
-{
- rename $a, "$a~";
- open HTMLIN, "$a~";
- open HTMLOUT, ">$a";
- set_hrefs;
-}
-
-foreach $a (@examples) {
- $texfile="test";
- system "ln ../input/$a.ly ./$a.ly.txt";
- system "cd ..; lilypond input/$a; tex $texfile;".
- "dvips -o $texfile.ps $texfile;";
-
- # generate the pixmap at twice the size, then rescale (for antialiasing)
- if ( ! -f "$a.gif" ) {
- system "mv ../$texfile.ps $a.ps; ".
- "mv ../lelie.midi $a.midi; ".
- "gs -q -sDEVICE=ppmraw -sOutputFile=- -r200 -dNOPAUSE $a.ps -c quit |pnmscale 0.5| ppmtogif > $a.gif";
- }
-}
-
-system "tar hcf website.tar *.html *.gif lelie_logo.png *.ps *.ly.txt *.midi docxx/;" .
- "gzip -f9 website.tar;"
+++ /dev/null
-# Generate.make ?
-
-parsheadorig=$(CCDIR)/parser.tab.h
-parsheadnew=$(HEADERDIR)/parser.hh
-
-#
-# take some trouble to avoid overwriting the old y.tab.h,
-# because otherwise all dependants would be remade.
-$(CCDIR)/parser.cc: $(CCDIR)/parser.y
- $(BISON) -d $<
- mv $(CCDIR)/parser.tab.c $@
- (if diff $(parsheadorig) $(parsheadnew)>/dev/null; then \
- echo Ignoring $(parsheadorig); \
- else \
- mv $(parsheadorig) $(parsheadnew); \
- fi )
-
-$(parsheadnew): $(CCDIR)/parser.cc
-
-$(HEADERDIR)/version.hh: Variables.make make_version
- make_version $(MAJVER) $(MINVER) $(PATCHLEVEL) "$(CXX) $(CXXVER)" > $@
-
-$(CCDIR)/%.cc: $(CCDIR)/%.y
- $(BISON) -d $<
- mv $(CCDIR)/$(shell basename $@ .cc ).tab.h $(HEADERDIR)/$(shell basename $@ .cc).hh
- mv $(CCDIR)/$(shell basename $@ .cc ).tab.c $@
-
-$(CCDIR)/%.cc: $(CCDIR)/%.l
- $(FLEX) -t $< > $@
-
--- /dev/null
+IMPORTANT:
+
+ if you have downloaded a
+
+ *.pre*
+
+ version, then this is version is *not* meant for producing nice output
+ (but to keep your patchsets up to date). It might not even compile.
+
+
+INSTALL:
+
+ to make LilyPond, simply type:
+
+ sh configure
+ make
+
+ assuming you have the gnu development tools, and your make is gnu make,
+ else try something like:
+
+ MAKE=gmake configure
+ MAKE=gmake gmake
+
+ \begin{masochist}
+ Windows NT:
+
+ you need the cygnus win32 gnu port development stuff; have a look
+ at http://www.cygnus.com/gnu-win32.
+
+ to make LilyPond under, brr, aargh, well, simply type:
+
+ bash bin/configure
+ make win32
+ \end{masochist}
+
+
+SUPPORT
+
+ LilyPond (pl 0.0.39) is known to compile on the following platforms:
+
+ * linux 2.0.28, g++ 2.7.2[.1]
+ * aix 4.1, g++ 2.7.2
+ * windows-nt 4.0, cygnus gnu-win32 beta17.1 (~=g++ 2.7.2)
+ * linux 2.0.28 X to doze, gcc-go32 (~=g++ 2.7.2)
+
+Have fun!
+
+ hanwen@stack.nl
+ jan@digicash.com
+
+++ /dev/null
-include Variables.make
-
-initdefault: $(CCDIR)/parser.cc $(CCDIR)/lexer.cc hdr/version.hh alldeps
-
-include Generate.make
-
-alldeps: #$(ALLDEPS)
- touch $(DEPDIR)/dummy.dep
-
-#$(DEPDIR)/%.dep: $(CCDIR)/%.cc
-# $(DODEP) $(CXX) -E $(CXXFLAGS) $^ > /dev/null
-
-# Makefile
-# top level makefile of LilyPond
+#
+# project LilyPond -- the musical typesetter
+# title top level makefile for LilyPond
+# file Makefile
+#
+# Copyright (c) 1997 by
+# Jan Nieuwenhuizen <jan@digicash.com>
+# Han-Wen Nienhuys <hanwen@stack.nl>
+# ...your sort order here, or how to comment-out a comment
+
+# subdir level:
+#
+depth = .
+#
+
+# identify module:
+#
+NAME = lilypond
+
+# edit in .version only!
+MAJOR_VERSION = $(TOPLEVEL_MAJOR_VERSION)
+MINOR_VERSION = $(TOPLEVEL_MINOR_VERSION)
+PATCH_LEVEL = $(TOPLEVEL_PATCH_LEVEL)
+# use to send patches, always empty for released version:
+MY_PATCH_LEVEL = $(TOPLEVEL_MY_PATCH_LEVEL)
+build = ./$(depth)/lily/.build
+#
+
+# generic variables:
+#
+include ./$(depth)/make/Variables.make
+#
+
+# descent order into subdirectories:
+#
+SUBDIRS = flower lib lily m2m \
+ Documentation bin init input make tex
+#
+
+# list of distribution files:
+#
+SYMLINKS = configure
+README_FILES = ANNOUNCE COPYING INSTALL NEWS README TODO
+DISTFILES= Makefile .version $(README_FILES) $(SYMLINKS)
+#
+
+# generic targets and rules:
+#
+include ./$(depth)/make/Targets.make
+include ./$(depth)/make/Rules.make
+#
-include Variables.make
-
-.SUFFIXES:
-.SUFFIXES: .cc .o .hh .y .l .pod .txt .1 .dep
-
-
-$(exe): $(obs)
- $(STRIPDEBUG) $(STABLEOBS)
- $(LINKER) -o $@ $^ $(LOADLIBES)
-
-$(m2m): $(m2mobs)
- $(LINKER) -o $@ $^ $(LOADLIBES)
-
-.PHONY: clean docxx
-
-clean:
- rm -f $(allexe) $(DOCDIR)/* core $(allobs)
- for SUBDIR in $(SUBDIRS); \
- do \
- $(MAKE) SUBDIR=$$SUBDIR -C $$SUBDIR clean;\
- done
-
-distclean: clean
- rm -f version.hh $(gencc) .GENERATE *~ $(ALLDEPS)
-
-all: $(exe) $(m2m) doc
-
-# value of $(OSTYPE) on windhoos; "make $OSTYPE" if you use bash :-)
-win32:
- $(MAKE) -C . CXX=g++
-
-doc:
- $(MAKE) -C Documentation doc
-
-# doc++ documentation of classes
-docxx: $(progdocs)
- doc++ -kp -d $(DOCDIR) $^
-
-
-include $(DEPDIR)/*.dep
-
-$(OBJECTDIR)/%.o: $(CCDIR)/%.cc
- $(DODEP)\
- $(CXX) -c $(CXXFLAGS) $(OUTPUT_OPTION)
-
-$(OBJECTDIR)/version.o: $(obs) $(HEADERDIR)/version.hh
-
-include Generate.make
-
-dist:
- -mkdir $(DDIR)
- ln $(DFILES) $(DDIR)/
- for SUBDIR in $(SUBDIRS); \
- do mkdir $(DDIR)/$$SUBDIR; \
- $(MAKE) SUBDIR=$$SUBDIR -C $$SUBDIR dist;\
- done
- tar cfz $(DNAME).tar.gz $(DNAME)/
- rm -rf $(DDIR)/
-
-TAGS:
- $(MAKE) -C $(HEADERDIR) TAGS
- $(MAKE) -C $(CCDIR) TAGS
+pl 39-1
+ - doze target (for 16 bit dos xcompiler: gcc-go32)
+Internal
+ - make/User.make; C..FLAGS sorted out
+Bugfix
+ - make clean...
+
+pl 39
+ - new make structure, featuring:
+ * top-level/sub-level build
+ * auto custom-library dependencies/build
+ * top-level/sub-level dist
+ * minimal(? can even smaller) specific Makefiles
+ * which makes for simple lib/exe module split (make/Template.make)
+ * integrated flowerlib
+ * all stuff into subbirs (make/Stuff.make)
+ * all headers into <module>/include dirs (make/Include.make)
+ * all output into <module>/out (executables into bin/)
+ * more make features, like make config, make help
+ * small lily lib
+ * lilypond-x.x.x/.version for toplevel lily version
+ * lilypond-x.x.x/<module>/.version for <module> version (eg: flower)
+ * versioning using additional optional MY_PATCH_LEVEL
+ for easy make_patch
+
+ - bin/cptogen
+
+Internal
+ - generic m2m header: m2m.hh
+
+Bugfix
+ - small fixes, make, dist, configure
+
+pl 38-5
+ - all of the below, e.g. new filenames and new makefile
+ structure patches merged
+
pl 38
Internal
intrinsically hierarchical. All walker communication is done via a
"top level" register.
+pl 37-3
+ - m2m handles voices
+ - instrument, track_name, copyright/left stuff for m2m/ly
+
+Internal
+ - Midi_voice
+
+pl 37-1
+ - text, key, tempo event in midi output/ly input
+
+Internal
+ - simple makefile structure, allows for multiple projects
+
******
pl 37
make doc
-in the top-level dir
-
-
======================
NOTE:
+++ /dev/null
-# Sources.make
-# sourcefiles to be shipped. Also used for dependencies
-
-hdr=bar.hh bar-reg.hh beam.hh\
- binary-source-file.hh\
- boxes.hh break.hh class-name.hh clef-reg.hh clef-item.hh\
- colhpos.hh commandrequest.hh \
- complex-walker.hh complex-staff.hh\
- const.hh debug.hh dimen.hh directional-spanner.hh\
- glob.hh grouping.hh headreg.hh idealspacing.hh\
- identifier.hh identparent.hh \
- input-music.hh input-score.hh input-staff.hh\
- input-file.hh\
- item.hh key.hh key-item.hh\
- key-reg.hh\
- keyword.hh leastsquares.hh lexer.hh linespace.hh \
- local-key-item.hh local-key-reg.hh lookup.hh \
- lyric-item.hh lyricstaff.hh lyricwalker.hh\
- main.hh meter.hh meter-reg.hh\
- midi-def.hh midi-item.hh midi-output.hh midi-stream.hh\
- midi-walker.hh\
- misc.hh\
- molecule.hh moment.hh musicalrequest.hh\
- notehead.hh notename.hh offset.hh paper-def.hh\
- parseconstruct.hh pcol.hh proto.hh\
- pscore.hh pstaff.hh qlp.hh\
- qlpsolve.hh register.hh registergroup.hh reqtodo.hh \
- request.hh rest.hh score-column.hh score.hh\
- scoreline.hh score-walker.hh script.hh script-def.hh script-reg.hh \
- slur.hh slur-reg.hh source.hh source-file.hh\
- spanner.hh staff.hh\
- staff-elem.hh staff-elem-info.hh staffline.hh staffsym.hh stem-beam-reg.hh\
- staff-column.hh stem.hh staff-walker.hh symbol.hh symtable.hh\
- tex.hh text-def.hh \
- textitem.hh text-reg.hh textspanner.hh time-description.hh \
- tex-stream.hh voice.hh\
- voice-element.hh voice-regs.hh voice-group-regs.hh walkregs.hh
-
-mycc=bar.cc bar-reg.cc beam.cc \
- binary-source-file.cc\
- boxes.cc break.cc calcideal.cc clef-reg.cc\
- clef-item.cc colhpos.cc commandrequest.cc\
- complex-staff.cc complex-walker.cc \
- debug.cc dimen.cc\
- directional-spanner.cc\
- grouping.cc groupregs.cc headreg.cc\
- idealspacing.cc identifier.cc\
- input-music.cc input-score.cc\
- input-staff.cc\
- input-file.cc\
- item.cc key.cc key-item.cc \
- key-reg.cc keyword.cc\
- leastsquares.cc lexerinit.cc linespace.cc \
- local-key-item.cc local-key-reg.cc lookup.cc\
- lyric-item.cc lyricstaff.cc lyricwalker.cc\
- main.cc meter.cc meter-reg.cc\
- midi-def.cc midi-item.cc midi-output.cc midi-stream.cc\
- midi-walker.cc misc.cc molecule.cc mylexer.cc note.cc\
- notehead.cc notename.cc\
- paper-def.cc pcol.cc pscore.cc pstaff.cc qlp.cc qlpsolve.cc\
- register.cc registergroup.cc request.cc rest.cc\
- score-column.cc score.cc\
- scoreline.cc scores.cc score-walker.cc script.cc\
- script-def.cc script-reg.cc slur.cc\
- slur-reg.cc source.cc source-file.cc\
- spanner.cc staff.cc\
- staff-elem.cc staffline.cc staffsym.cc\
- stem-beam-reg.cc staff-column.cc stem.cc\
- staff-elem-info.cc staff-walker.cc symbol.cc\
- symtable.cc tex.cc texbeam.cc\
- texslur.cc text-def.cc textitem.cc text-reg.cc textspanner.cc\
- time-description.cc tex-stream.cc voice.cc voiceelt.cc \
- voice-regs.cc voice-group-regs.cc\
- walkregs.cc warn.cc windhoos-suck-suck-suck-thank-you-cygnus.cc wordwrap.cc\
- template1.cc template2.cc template3.cc template4.cc\
- template5.cc template6.cc version.cc
-
-# a bit of a hack to keep exec size under control.
-stablecc=request.cc bar.cc boxes.cc break.cc \
- item.cc keyword.cc leastsquares.cc \
- molecule.cc meter.cc\
- paper-def.cc parser.cc lexer.cc pstaff.cc qlp.cc qlpsolve.cc\
- template1.cc template2.cc template3.cc template4.cc\
- template5.cc template6.cc version.cc tex-stream.cc tex.cc\
- voice.cc wordwrap.cc spanner.cc
-
-
-# m2m headers
-#
-mym2mhh=\
- 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=\
- duration.cc\
- lily-stream.cc\
- midi-event.cc\
- midi-main.cc\
- midi-score.cc\
- midi-template.cc\
- midi-track.cc\
- my-midi-lexer.cc\
- my-midi-parser.cc\
- track-column.cc\
-
-#
-
-# m2m shared source
-#
-mym2msharedcc=\
- binary-source-file.cc\
- input-file.cc\
- source-file.cc\
- source.cc\
-
-#
-
This is an assorted collection of stuff that will be done, might be
done, or is an idea that I want to think about
+STUFF
+ * generate all (.hh) files into out dirs
+
+ * sort out headers, see m2m
+
+ * do platform stuff: configure, header(s), targets, build (out?)
+
BUGS
* plet bugs: scales.ly
* caching breakpoints
- * use exceptions iso assert?
\ No newline at end of file
+ * use exceptions iso assert?
+++ /dev/null
-# -*-Makefile-*-
-
-# version info
-MAJVER=0
-MINVER=0
-PATCHLEVEL=38
-
-
-
-####
-#### USER CONFIGURABLE
-####
-
-#PROFILEFLAG=-pg
-OPTIFLAG=-DNDEBUG -DNPRINT -O2
-DEBUGFLAG=-g
-
-# uncomment for windhoos
-# CXX=g++
-
-# turn off -pipe if linker doesn't support it
-EXTRACXXFLAGS=-pipe -Wall -W -Wmissing-prototypes -DSTRING_UTILS_INLINED
-
-#
-# -lefence = ElectricFence.
-#
-# ElectricFence is a memory debugger which uses the
-# VM hardware to trap malloc/free errors.
-#
-
-EXTRALIB+= #-lefence
-
-####
-#### END USER CONFIGURABLE part.
-####
-
-ifdef PROFILEFLAG
- DEFINES+=$(OPTIFLAG) $(PROFILEFLAG)
- EXTRALIB+=-pg
-endif
-
-ifndef DEBUGFLAG
- DEFINES+=$(OPTIFLAG)
-else
- DEFINES+=$(DEBUGFLAG)
-endif
-
-
-
-VERSION=$(MAJVER).$(MINVER).$(PATCHLEVEL)
-CXXVER=`$(CXX) --version`
-
-# directories
-TOPDIR := $(shell if [ "$$PWD" != "" ]; then echo $$PWD; else pwd; fi)
-
-OBJECTDIR=objects
-HEADERDIR=hdr
-CCDIR=src
-INITDIR=init
-DEPDIR=deps
-INPUTDIR=input
-
-#
-#
-include Sources.make
-
-# UGH, this sux!
-gencc=parser.cc lexer.cc
-cc=$(mycc) $(gencc)
-mym2mgencc=midi-parser.cc midi-lexer.cc
-m2mcc=$(mym2mcc) $(mym2mgencc) $(mym2msharedcc)
-
-MY_CCSOURCE=$(addprefix $(CCDIR)/, $(mycc))
-CCSOURCE=$(addprefix $(CCDIR)/, $(cc))
-
-obs=$(addprefix $(OBJECTDIR)/,$(cc:.cc=.o))
-m2mobs=$(addprefix $(OBJECTDIR)/,$(m2mcc:.cc=.o))
-
-allcc=$(mycc) $(mym2mcc)
-allobs=$(obs) $(m2mobs)
-allexe=$(exe) $(m2m)
-M2MCCSOURCE=$(addprefix $(CCDIR)/, $(m2mcc))
-ALLDEPS=$(addprefix $(DEPDIR)/,$(cc:.cc=.dep))
-STABLEOBS=$(addprefix $(OBJECTDIR)/,$(stablecc:.cc=.o))
-allhdr=$(hdr) $(mym2mhh)
-HEADERS=$(addprefix $(HEADERDIR)/,$(allhdr))
-progdocs=$(HEADERS) $(MY_CCSOURCE)
-
-#dist
-.EXPORT_ALL_VARIABLES:
-
-DOCDIR=docxx
-
-PACKAGENAME=lilypond
-DNAME=$(PACKAGENAME)-$(VERSION)
-M2MNAME=m2m
-
-# distribution files.
-othersrc=lexer.l parser.y midi-lexer.l midi-parser.y
-SCRIPTS=make_version make_patch genheader clearlily
-MAKFILES=Makefile Variables.make Sources.make Initial.make Generate.make \
- configure
-OFILES=COPYING README NEWS TODO ANNOUNCE
-IFILES= titledefs.tex lilyponddefs.tex \
- ltest.tex test.tex .dstreamrc dimen.tex
-DFILES=$(MAKFILES) $(OFILES) $(IFILES) $(SCRIPTS)
-
-#compiling
-LOADLIBES=-L$(FLOWERDIR) -lflower $(EXTRALIB) -lg++
-FLOWERDIR=../flower
-
-CXXFLAGS=$(DEFINES) -I$(HEADERDIR) -I$(FLOWERDIR) $(EXTRACXXFLAGS)
-FLEX=flex
-BISON=bison
-exe=$(PACKAGENAME)
-m2m=$(M2MNAME)
-OUTPUT_OPTION=$< -o $@
-DDIR=$(TOPDIR)/$(DNAME)
-SUBDIRS=Documentation $(OBJECTDIR) $(CCDIR) $(HEADERDIR) $(INITDIR) $(DEPDIR) \
- $(INPUTDIR)
-
-depfile=deps/$(subst .o,.dep,$(notdir $@))
-DODEP=rm -f $(depfile); DEPENDENCIES_OUTPUT="$(depfile) $(OBJECTDIR)/$(notdir $@)"
-
-STRIPDEBUG=true #replace to do stripping of certain objects
-LINKER=$(CXX)
-include Site.make
-
-TAGSACTION=etags -l c++ --no-defines
-
--- /dev/null
+# bin/Makefile
+
+# subdir level:
+#
+depth = ..
+#
+
+build = ./$(depth)/lily/.build
+
+# generic stuff/Makefile
+#
+include ./$(depth)/make/Stuff.make
+#
+
+# list of distribution files:
+#
+SCRIPTS = clearlily configure cpgento genheader make_patch make_fversion make_version make_website
+DISTFILES = Makefile $(SCRIPTS)
+#
+
--- /dev/null
+#!/bin/sh
+
+# unclobber current dir.
+rm -vf *.aux *.log `grep -li "^% Creator: LilyPond" *.out` *.orig *~
+
+# docxx mess
+rm -vf *.class HIER*.html dxxgifs.tex gifs.db icon?.gif logo.gif down.gif \
+ aindex.html index.html
--- /dev/null
+#!/bin/sh
+#
+# project LilyPond -- the musical typesetter
+# title (bash/sh/ksh) script to setup library and auto generated files
+# file bin/configure
+#
+# Copyright (c) 1997 by
+# Han-Wen Nienhuys <hanwen@stack.nl>
+# Jan Nieuwenhuizen <jan@digicash.com>
+#
+
+MAKE=${MAKE:-make}
+NEEDFLOWERVER=1.1.6
+PREFIX=${PREFIX:-.}
+
+
+#############
+#############
+
+# without "function" ok for ksh, bash
+setversion() {
+ eval `sed -n 's/^\([A-Z_]*\)[ ]*=[ ]*\([^ \#]*\).*$/\1=\2/p' $1`
+# NEWVER=$TOPLEVEL_MAJOR_VERSION.$TOPLEVEL_MINOR_VERSION.$TOPLEVEL_PATCH_LEVEL$TOPLEVEL_MY_PATCH_LEVEL
+ NEWVER=$MAJOR_VERSION.$MINOR_VERSION.$PATCH_LEVEL$MY_PATCH_LEVEL
+ echo
+ echo "Current version ("`pwd`") is:"
+ echo " $NEWVER"
+ echo
+}
+
+do_outdir() {
+ if [ \! -d $1/out ]
+ then
+ mkdir $1/out
+ echo 0 > $1/.build
+ fi
+}
+
+echo using PREFIX=$PREFIX
+echo I need Flower version $NEEDFLOWERVER
+
+flowertar=flower-$NEEDFLOWERVER
+
+#ugh
+do_outdir flower/lib
+do_outdir Documentation
+do_outdir lib
+do_outdir lily
+do_outdir m2m
+
+# mmm
+if [ -x flower ]
+then
+ echo Found flowerdir
+else
+ if [ -d $flowertar ]
+ then
+ ln -fs $flowertar flower
+ elif [ -d ../$flowertar ]
+ then
+ ln -fs ../$flowertar flower
+ else
+ echo "can't find $flowertar"
+ exit 1;
+ fi
+fi
+
+echo Configuring Flower Library
+setversion ./flower/.version
+if [ $NEWVER != $NEEDFLOWERVER ]; then
+ echo "You seem to be having an incorrect version of the Flower library"
+else
+ echo "You got the correct Flower version."
+fi
+
+#ugh
+echo '#define LIBDIR "'$PREFIX'/"'> lib/out/config.hh
+touch flower/lib/out/flower-config.hh
+touch make/Site.make
+$MAKE -C make -f Initial.make
+
+echo "The sources are ready for compiling. "
+echo "To make sure that you don't have any stale dependencies: do"
+echo " make clean"
+
--- /dev/null
+#!/bin/sh
+# cpgento
+#
+
+if test $# -ne 1
+then
+ echo "Usage: "
+ echo " cpgento LOCATION, e.g.:";
+ echo
+ echo " cpgento /mnt/aix/usr/src/lily"
+ echo " CP=rcp cpgento fred@pcnov095.win.tue.nl:music/lily"
+ exit 1
+fi
+
+MAKE=${MAKE:-make}
+CP=${CP:-cp}
+
+genlily="out/parser.hh out/parser.cc out/lexer.cc"
+echo generating $genlily ...
+$MAKE -C lily $genlily
+
+genm2m="out/midi-parser.hh out/midi-parser.cc out/midi-lexer.cc"
+echo generating $genm2m ...
+$MAKE -C m2m $genm2m
+
+lilydir=`pwd | sed "s/.*\///"`
+todir=$1/$lilydir
+echo "copying $lilydir -> $todir"
+
+cpto() {
+ name=$1
+ tostuff=$todir/$name/out
+ genstuff="$2"
+ if [ "$CP" = "cp" -a \! -d $tostuff ]
+ then
+ echo mkdir -p $tostuff
+ mkdir -p $tostuff
+ fi
+ echo $CP $genstuff $tostuff
+ (cd $name; $CP $genstuff $tostuff)
+}
+
+cpto lily "$genlily"
+cpto m2m "$genm2m"
+
+# if you cannot gen the above, you-ll probably want:
+flexlexerh=/usr/include/FlexLexer.h
+cpto lib $flexlexerh
+
--- /dev/null
+#!/usr/bin/perl -w
+
+die "arg needed\n" if (!($#ARGV+1));
+my $fn = $ARGV[0];
+my $hh_q = ($fn =~ /hh$/ );
+my $MAILADRESS=$ENV{MAILADRESS};
+my @pw=(getpwuid($<));
+my $username=$pw[6];
+my $what="implement ";
+$what = "declare " if ($hh_q);
+my $headstr ="/*
+ $fn -- $what
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 $username <$MAILADRESS>
+*/\n";
+
+my $startdef= $fn;
+$startdef =~ s/[\.-]/_/g;
+$startdef =~ tr/a-z/A-Z/;
+my $terminatestr="\n";
+if ($hh_q) {
+ $headstr .= "\n\n#ifndef $startdef\n#define $startdef\n";
+ $terminatestr .= "#endif // $startdef\n"
+}
+
+print $headstr, $terminatestr;
+
+
+
--- /dev/null
+#!/bin/sh
+echo '#ifndef FVERSION_HH'
+echo '#define FVERSION_HH'
+echo '#define FMAJOR_VERSION ' "$1"
+echo '#define FMINOR_VERSION ' "$2"
+echo '#define FPATCH_LEVEL ' "$3"
+echo '#define FMY_PATCH_LEVEL ' "$4"
+echo '#define FBUILD ' "$5"
+echo '#define FVERSIONSTR "'$1.$2.$3$4 \#$5'"'
+echo '#define FCOMPILER "'$6'"'
+echo '#endif'
--- /dev/null
+#!/bin/sh
+
+case $# in
+0) echo make_patch old new name
+ exit 1;;
+esac
+
+old=$1
+new=$2
+nm=$3-
+
+newarc=../releases/$nm$new.tar.gz
+oldarc=../releases/$nm$old.tar.gz
+
+
+if [ ! -x $nm$new ]
+then
+ echo untarring ..
+ if [ ! -f $newarc ]
+ then
+ echo cant find $newarc
+ exit
+ fi
+ tar zfxv $newarc
+fi
+if [ ! -x $nm$old ]
+then
+ echo untarring
+
+ if [ ! -f $oldarc ]
+ then
+ echo cant find oldarc
+ exit
+ fi
+ tar zfxv $oldarc
+fi
+
+#(cd $nm$old; touch depend; make clean)
+#(cd $nm$new; touch depend; make clean)
+(cd $nm$new; diff -urP ../$nm$old . > ../patch-$new)
+rm -rf $nm$old $nm$new
--- /dev/null
+#!/bin/sh
+echo '#ifndef VERSION_HH'
+echo '#define VERSION_HH'
+echo '#define MAJOR_VERSION ' "$1"
+echo '#define MINOR_VERSION ' "$2"
+echo '#define PATCH_LEVEL ' "$3"
+echo '#define MY_PATCH_LEVEL ' "$4"
+echo '#define BUILD ' "$5"
+echo '#define VERSIONSTR "'$1.$2.$3$4 \#$5'"'
+echo '#define COMPILER "'$6'"'
+echo '#endif'
--- /dev/null
+#!/usr/bin/perl -w
+sub
+ set_hrefs
+{
+ while (<HTMLIN>) {
+ s#href=([A-Za-z.]+)#href=$base/$1#g;
+ print HTMLOUT $_;
+ }
+}
+
+local $base="lilypond/";
+local @examples=("wohltemperirt");
+
+system 'pod2html';
+
+print "resetting refs.\n";
+
+foreach $a (<*.html>)
+{
+ rename $a, "$a~";
+ open HTMLIN, "$a~";
+ open HTMLOUT, ">$a";
+ set_hrefs;
+}
+
+foreach $a (@examples) {
+ $texfile="test";
+ system "ln ../input/$a.ly ./$a.ly.txt";
+ system "cd ..; lilypond input/$a; tex $texfile;".
+ "dvips -o $texfile.ps $texfile;";
+
+ # generate the pixmap at twice the size, then rescale (for antialiasing)
+ if ( ! -f "$a.gif" ) {
+ system "mv ../$texfile.ps $a.ps; ".
+ "mv ../lelie.midi $a.midi; ".
+ "gs -q -sDEVICE=ppmraw -sOutputFile=- -r200 -dNOPAUSE $a.ps -c quit |pnmscale 0.5| ppmtogif > $a.gif";
+ }
+}
+
+system "cd out; tar hcf ../website.tar *.html *.gif lelie_logo.png *.ps *.ly.txt *.midi docxx/;" .
+ "gzip -f9 website.tar;"
+++ /dev/null
-#!/bin/sh
-
-# unclobber current dir.
-rm -vf *.aux *.log `grep -li "^% Creator: LilyPond" *.out` *.orig *~
-
-# docxx mess
-rm -vf *.class HIER*.html dxxgifs.tex gifs.db icon?.gif logo.gif down.gif \
- aindex.html index.html
+++ /dev/null
-#!/bin/sh
-
-# script to setup library and auto generated files.
-
-function setversion() {
- eval `sed -n 's/^\([A-Z]*\)=\([p0-9].*\)$/\1=\2/p' Variables.make`
- NEWVER=$MAJVER.$MINVER.$PATCHLEVEL
- echo
- echo "Current version ("`pwd`") is $NEWVER"
- echo
-}
-
-MAKE=${MAKE:-make}
-PREFIX=${PREFIX:-.}
-NEEDFLOWERVER=1.1.4
-
-echo using PREFIX=$PREFIX
-echo I need Flower version $NEEDFLOWERVER
-
-flowertar=flower-$NEEDFLOWERVER
-here=`pwd`
-cd ..
-
-if [ -x flower ]
-then
- echo Found flowerdir
-else
-
- if [ ! -d $flowertar ]
- then
- echo "can't find $flowertar"
- exit 1;
- fi
- rm flower
- ln -s $flowertar flower
-fi
-
-echo Compiling Library
-{
- cd flower;
- setversion
- if [ $NEWVER != $NEEDFLOWERVER ]; then
- echo "You seem to be having an incorrect version of the Flower library"
- else
- echo "You got the correct Flower version."
- fi
- $MAKE
-}
-
-cd $here
-
-echo '#define LIBDIR "'$PREFIX'/"'> hdr/config.hh
-touch Site.make
-$MAKE -f Initial.make
-
-echo "The sources are ready for compiling. "
-echo "To make sure that you don't have any stale dependencies: do"
-echo " make clean"
--- /dev/null
+bin/configure
\ No newline at end of file
+++ /dev/null
-DISTFILES=Makefile dummy.dep
-
-
-
-dummy.dep:
- touch dummy.dep
-
-
-dist: $(DISTFILES)
- ln $(DISTFILES) $(DDIR)/$(SUBDIR)
-
-clean:
- true
+++ /dev/null
-\font\musicfont=musixsps
-\font\slurfont=xslu16
-\def\thefont{\musicfont}
-
-\def\mb#1{{\thefont\char#1}}
-
-\newdimen\wid
-\newdimen\inc
-\newdimen\here
-\def\hruler#1{%
- \wid=#1pt
- \inc=\wid
- \divide\inc by #1
- \divide\wid by 2
- \here=-\wid
- \loop\ifdim\here<\wid\advance\here by\inc
- \hbox to0pt{\kern\here\vrule width0.05pt height 2pt\hss}%
- \repeat%
-}
-
-\def\vruler#1{%
- \wid=#1pt
- \inc=\wid
- \divide\inc by #1
- \divide\wid by 2
- \here=-\wid
- \loop\ifdim\here<\wid\advance\here by\inc
- \vbox to0pt{\vskip\here\vrule width2pt height 0.05pt\vss}%
- \repeat%
-}
-\def\twhrul{\hbox to 0pt{\hbox{\hruler{20}\vrule
- width0.1pt height 3ptdepth 1pt}}}
-\def\twvrul{\hbox{\vbox to 20pt{\vruler{20}\vrule
- width3pt height 0.1pt}}}
-
-\def\doitem#1{
- #1 %
- %\twvrul%doesn't work
- \hbox to 50pt{\qquad\twhrul\mb{#1}\hss}\setbox0=\hbox{\mb{#1}} width \the\wd0\ depth \the\dp0 \ height \the\ht0}
-
-\newcount\n
-\def\charn{\n=-1
- \loop\ifnum\n<255\advance\n by1
- \doitem{\number\n}\endgraf\repeat}
-
-
- \charn
-
-\bye
\ No newline at end of file
--- /dev/null
+MAJOR_VERSION = 1
+MINOR_VERSION = 1
+PATCH_LEVEL = 6
+# use to send patches, always empty for released version:
+MY_PATCH_LEVEL = -1# include separator: "-1" or ".a"
+#
$(staticlib): $(obs) fversion.hh
$(AR) cr libflower.a $(obs)
-include depend
+include deps/*.dep
+
+deps/*.dep:
+ touch deps/dummy.dep
depend: Sources.make
$(CXX) $(CXXFLAGS) -MM $(cc) > depend
+
+$(OBJECTDIR)/%.o: $(CCDIR)/%.cc
+ $(DODEP)\
+ $(CXX) -c $(CXXFLAGS) $(OUTPUT_OPTION)
+
+
clean:
rm -f $(obs) $(staticlib) fversion.hh
dist:
-mkdir $(DDIR)
ln $(DFILES) $(DDIR)/
- tar cfz $(DNAME).tar.gz $(DDIR)/*
+ -for SUBDIR in $(SUBDIRS); \
+ do mkdir $(DDIR)/$$SUBDIR; \
+ $(MAKE) SUBDIR=$$SUBDIR -C $$SUBDIR dist;\
+ done
+ tar cfz $(DNAME).tar.gz $(DNAME)/
rm -rf $(DDIR)/
TAGS: $(ALLSOURCES)
etags -CT $(inl) $(cc) $(hh)
+
+
+test: stringtest
+
+stringtest: $(OBJECTDIR)/stringtest.o
+ g++ -o $@ $< -L. -lflower
\ No newline at end of file
-pl 1.1.3-1
+
+pl 1.1.4
+ - great file-renaming.
+ - String cleanup (binary <-> null terminate), several bugfixes
- 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
-cc=choleski.cc datafile.cc dstream.cc lgetopt.cc matdebug.cc matrix.cc\
-path.cc scalar.cc smat.cc string.cc string-convert.cc stringutil.cc\
-textdb.cc textstream.cc unionfind.cc vector.cc
+cc=choleski.cc data-file.cc dstream.cc lgetopt.cc libc-extension.cc matdebug.cc\
+ matrix.cc\
+ path.cc scalar.cc smat.cc string.cc string-convert.cc stringutil.cc\
+ text-db.cc text-stream.cc unionfind.cc vector.cc
templatecc=cursor.tcc list.tcc plist.tcc interval.tcc\
pcursor.tcc
-inl=link.inl list.inl cursor.inl plist.inl stringdata.inl stringhandle.inl
+inl=link.inl list.inl cursor.inl plist.inl string-data.inl string-handle.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 string-convert.hh stringhandle.hh stringdata.hh\
-textdb.hh textstream.hh unionfind.hh pqueue.hh\
-varray.hh vector.hh vsmat.hh datafile.hh
+hh=assoc.hh assoc-iter.hh choleski.hh compare.hh cursor.hh data-file.hh \
+ dstream.hh\
+ fproto.hh handle.hh interval.hh iterate.hh lgetopt.hh \
+ libc-extension.hh link.hh list.hh\
+ matrix.hh path.hh pcursor.hh plist.hh rational.hh real.hh scalar.hh\
+ smat.hh string.hh string-convert.hh string-handle.hh string-data.hh\
+ text-db.hh text-stream.hh unionfind.hh pqueue.hh\
+ varray.hh vector.hh vsmat.hh
extra=stringtest.cc
- * disable: const pointer->bool->string
+ * shared lib.
+
+ * integrate Make mechanisms of flower & lily
+
+ * disable this auto conv: const pointer -> bool -> string
* PointerVec ?
* extend Interval
- * change String::pos
-
- s[s.pos('%')] == '%'
-
- would be nice
-
* use template handle in handle.hh for strings.
* move towards gnu or STL?
MAJVER=1
MINVER=1
-PATCHLEVEL=3
+PATCHLEVEL=4
PACKAGENAME=flower
#PROFILEFLAG=-pg
#DEBUGFLAG= -g
-OPTIFLAG= -DNPRINT -O2 -DSTRING_UTILS_INLINED -DNDEBUG
+OPTIFLAG= -DNPRINT -O2 -DSTRING_UTILS_INLINED # -DNDEBUG
#########################################
DNAME=$(PACKAGENAME)-$(VERSION)
include Sources.make
+OBJECTDIR=objects
+CCDIR=.
+obs=$(addprefix $(OBJECTDIR)/,$(cc:.cc=.o))
-obs=$(cc:.cc=.o)
staticlib=libflower.a
ALLSOURCES=$(hh) $(cc) $(inl) $(templatecc) $(extra)
DFILES=$(ALLSOURCES) Makefile Variables.make make_version\
Sources.make TODO README NEWS
DDIR=$(DNAME)
+depfile=deps/$(subst .o,.dep,$(notdir $@))
+DODEP=rm -f $(depfile); DEPENDENCIES_OUTPUT="$(depfile) $(OBJECTDIR)/$(notdir $@)"
+OUTPUT_OPTION=$< -o $@
+SUBDIRS=deps objects
#include "varray.hh"
#include <assert.h>
+/**
+ A helper for Assoc
+ */
template<class K, class V>
struct Assoc_ent_ {
bool free;
};
-/** mindblowingly stupid Associative array implementation.Hungarian: map
+/** mindblowingly stupid Associative array implementation.
+ Hungarian: map
*/
template<class K, class V>
struct Assoc {
int i = find_creat(key);
arr[i].val = val;
}
- /*
- should create "set" template
- */
V& operator[](K key) {
return arr[find_creat(key)].val;
}
+++ /dev/null
-/*
- associter.hh -- part of flowerlib
-
- (c) 1996 Han-Wen Nienhuys
-*/
-
-#ifndef ASSOCITER_HH
-#define ASSOCITER_HH
-
-#include "assoc.hh"
-
-/// an iterator for the #Assoc# class
-template<class K, class V>
-struct Assoc_iter {
- int i;
- Assoc<K,V> &assoc_;
- /// we don't want to be bothered by const correctness
- Assoc_iter(const Assoc<K,V> &a) :
- assoc_((Assoc<K,V> &)a)
- {
- i= next(0);
- }
- int next(int j) {
- while (j < assoc_.arr.size() && assoc_.arr[j].free)
- j++;
- return j;
- }
- bool ok() const {
- return i < assoc_.arr.size();
- }
- void OK()const {
- assert(!ok() || !assoc_.arr[i].free);
- }
- void operator++(int) { i++; i = next(i); }
- K key() { return assoc_.arr[i].key; }
- V &val() { return assoc_.arr[i].val; }
-};
-
-#endif
assert((original()-P).norm() / P.norm() < EPS);
#endif
}
-
+
Matrix
Choleski_decomposition::original() const
{
+++ /dev/null
-#include <fstream.h>
-#include <ctype.h>
-
-#include "datafile.hh"
-
-void
-Data_file::gobble_white()
-{
- char c;
-
- while ((c=data_get()) == ' ' ||c == '\t')
- if (eof())
- break;
-
- data_unget(c);
-}
-
-String
-Data_file::get_word()
-{// should handle escape seq's
- String s;
-
- while (1)
- {
- char c = data_get();
-
- if (isspace(c) || eof())
- {
- data_unget(c);
- break;
- }
-
-
- if (c == '\"')
- {
- rawmode= true;
-
- while ((c = data_get()) != '\"')
- if (eof())
- error("EOF in a string");
- else
- s += c;
-
-
- rawmode= false;
- }
- else
- s += c;
- }
-
- return s;
-}
-
-/** get a char
- Only class member who uses text_file::get
- */
-char
-Data_file::data_get() {
- char c = get();
- if (!rawmode && c == '#') // gobble comment
- {
- while ((c = get()) != '\n' && !eof())
- ;
- return '\n';
- }
-
- return c;
-}
-
-/// read line, gobble '\n'
-String Data_file::get_line()
-{
- char c;
- String s;
-
- while ((c = data_get()) != '\n' && !eof())
- s += c;
- return s;
-}
-
-/// gobble stuff before first entry on a line.
-void
-Data_file::gobble_leading_white()
-{
- // eat blank lines.
- while (!eof()) {
- char c = data_get();
- if (!isspace(c)) {
- data_unget(c);
- break;
- }
- }
-}
-
-
+++ /dev/null
-/*
- datafile.hh -- declare Data_file
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-
-#ifndef DATAFILE_HH
-#define DATAFILE_HH
-
-#include "textstream.hh"
-
-/// read a data file
-class Data_file : private Text_stream
-{
-
- public:
- bool rawmode;
-
- Text_stream::line;
- Text_stream::eof;
- Text_stream::get_name;
-
- char data_get();
- void data_unget(char c) {
- unget(c);
- }
-
- /// read line, eat #\n#
- String get_line();
-
- /// read a word till next space, leave space. Also does quotes
- String get_word();
-
- /// gobble horizontal white stuff.
- void gobble_white();
-
- /// gobble empty stuff before first field.
- void gobble_leading_white();
- Data_file(String s) : Text_stream(s) {
- //*mlog << "(" << s << flush;
- rawmode= false;
- }
-
- ~Data_file() {
- // *mlog << ")"<<flush;
- }
-
- warning(String s) {
- message("warning: " + s);
- }
- error(String s){
- message(s);
- exit(1);
- }
-};
-#endif // DATAFILE_HH
#include "assoc.hh"
#include "dstream.hh"
#include "scalar.hh"
-#include "textdb.hh"
+#include "text-db.hh"
+#include "string-convert.hh"
/// indent of each level
-const INDTAB = 3;
+const INDTAB = 2;
/*
should use Regexp library.
*/
static String
-strip_pretty(String pret)
+strip_pretty(String pretty_str)
{
- String cl(pret.left_str(pret.index_i('(')));
- int l = cl.index_last_i(' ');
- cl = cl.right_str(cl.len() - l - 1);
- return cl;
+ int i = pretty_str.index_i('(');
+ if (i>=0)
+ pretty_str = pretty_str.left_str(i);
+
+ int l = pretty_str.index_last_i(' '); // strip until last ' '
+ if (l>=0)
+ pretty_str = pretty_str.nomid_str(0,l+1);
+ return pretty_str;
}
static String
strip_member(String pret)
{
- String cl(pret.left_str(pret.index_last_i(':')-1));
- return cl;
+ int l=pret.index_last_i(':')-1;
+ if (l>=0)
+ pret = pret.left_str(l );
+ return pret;
}
Dstream&
local_silence = (*silent)[idx];
if (classname != idx && !local_silence) {
classname=idx;
- *os << "[" << classname << ":]";
+// *os << "[" << classname << ":]"; // messy.
}
return *this;
}
return (*silent)[s];
}
-/** only output possibility. Delegates all conversion to String class.
- */
+/** Output a string via the Dstream. This is the only output
+ interface. It delegates all conversion to String class. */
Dstream &
Dstream::operator<<(String s)
+{
+ output(s);
+ return *this;
+}
+
+Dstream &
+Dstream::operator<<(const void *v_l)
+{
+ output(String_convert::pointer_str(v_l));
+ return *this;
+}
+
+Dstream &
+Dstream::operator<<(const char *ch_l)
+{
+ output(ch_l);
+ return *this;
+}
+
+void
+Dstream::output(String s)
{
if (local_silence|| !os)
- return *this;
+ return ;
for (const char *cp = s ; *cp; cp++)
- switch(*cp)
- {
+ switch(*cp) {
case '{':
case '[':
case '(': indentlvl += INDTAB;
*os << *cp;
break;
}
- return *this;
+ return ;
}
Dstream::~Dstream()
-{
+{
delete silent;
+ assert(!indentlvl) ;
}
int indentlvl;
bool local_silence;
String classname;
-
+ void output(String s);
Assoc<String, bool> *silent;
public:
Dstream(ostream *r, const char * rcfile);
virtual ~Dstream();
Dstream &identify_as(String s);
-
+
Dstream &operator << (String s);
+ /**
+ Output memory locations.
+ */
+ Dstream &operator << (void const *);
+ Dstream &operator << (char const *);
};
#endif
template<class T> struct Cursor;
template<class T> struct PCursor;
template<class T> struct Link;
-template<class T> struct Handle ;
-template<class T>struct Interval_t ;
+template<class T> struct Handle;
+template<class T>struct Interval_t;
#include "real.hh"
typedef Interval_t<Real> Interval;
-struct Choleski_decomposition ;
+struct Choleski_decomposition;
-struct long_option_init ;
-struct Getopt_long ;
-struct Matrix ;
-struct String_data ;
-struct String_handle ;
+struct Long_option_init;
+struct Getopt_long;
+struct Matrix;
+struct String_data;
+struct String_handle;
struct String_convert;
struct String;
-struct virtual_smat ;
-struct Vector ;
-class Text_stream;
-class Data_file ;
+struct virtual_smat;
+struct Vector ;
+struct Text_stream;
+struct Data_file;
struct Text_db;
struct Scalar;
typedef unsigned char Byte;
/*
process command line, GNU style.
-
this is (Copyleft) 1996, Han-Wen Nienhuys, <hanwen@stack.nl>
*/
#include <stdio.h>
#include "lgetopt.hh"
long
-Getopt_long::intarg() {
+Getopt_long::intarg()
+{
long l;
if (sscanf(optarg, "%ld", &l) != 1)
report(E_ILLEGALARG);
return l;
}
-long_option_init *
-Getopt_long::parselong() {
+
+Long_option_init *
+Getopt_long::parselong()
+{
const char *optnm = argv[optind] + 2 ;
assert(*optnm);
ostream &
-long_option_init::printon(ostream &errorout)
+Long_option_init::printon(ostream &errorout)
{
if (shortname)
errorout <<"-" << shortname;
*errorout << "requires an argument"<<endl;
break;
case E_NOARGEXPECT:
- *errorout << "option `--" << beet->longname << "' does not allow an argument"<<endl;
+ *errorout << "option `--" <<
+ beet->longname << "' does not allow an argument"<<endl;
break;
case E_UNKNOWNOPTION:
exit(2);
}
-long_option_init *
-Getopt_long::parseshort() {
+Long_option_init *
+Getopt_long::parseshort()
+{
char c=argv[optind][optindind];
beet=0;
assert(c);
return beet;
}
-long_option_init *
+Long_option_init *
Getopt_long::operator()() {
if (!next())
return 0;
}
}
-Getopt_long::Getopt_long(int c, char **v, long_option_init *lo) {
+Getopt_long::Getopt_long(int c, char **v, Long_option_init *lo)
+{
the_opts = lo;
errorout = &cerr;
argv = v;
table_len = i;
}
-bool Getopt_long::next() {
+bool
+Getopt_long::next()
+{
+
error = E_NOERROR;
while (optind < argc && !argv[optind][optindind]) {
optind++;
class ostream;
-struct long_option_init {
+/**
+ a struct this for initialising the commandline options.
+ */
+struct Long_option_init {
bool take_arg;
const char* longname;
char shortname;
private:
/// the option info.
- long_option_init *the_opts;
+ Long_option_init *the_opts;
int table_len;
/// if doing short option, argv[optind][optindind] is processed next.
int optindind;
/// the option found
- long_option_init *beet;
+ Long_option_init *beet;
/// get ready for processing next error.
bool next();
- long_option_init *parselong();
- long_option_init *parseshort();
+ Long_option_init *parselong();
+ Long_option_init *parseshort();
ostream *errorout;
/// report an error and abort
void report(Errorcod c);
public:
- /** what to do with errors.
- report messages on #*os#, and abort.
- if #os# is null, then do not report nor abort, just set #error#
- */
-
- void seterror(ostream *os);
+
/// argument. Set to 0 if not present
char* optarg;
+ /// current error status
+ Errorcod error;
/// return an integer (with err. detect)
long intarg();
/// the arg. count
int argc;
+ /* *************** */
+
+ /**
+ What to do with errors.
+ report messages on #*os#, and abort.
+ if #os# is null, then do not report nor abort, just set #error#
+ */
+
+ void seterror(ostream *os);
+
/// construct: pass arguments and option info.
- Getopt_long(int c, char **v, long_option_init *lo);
+ Getopt_long(int c, char **v, Long_option_init *lo);
/** get the next option.
@return pointer to next option found.
0 if error occurred, or next argument is no option.
*/
- long_option_init *operator()();
+ Long_option_init *operator()();
char *current_arg();
char * get_next_arg();
- Errorcod error;
};
#endif
--- /dev/null
+#
+# project LilyPond -- the musical typesetter
+# title makefile for micro-lily-lib
+# file lib/Makefile
+#
+# Copyright (c) 1997 by
+# Jan Nieuwenhuizen <jan@digicash.com>
+# Han-Wen Nienhuys <hanwen@stack.nl>
+#
+
+# subdir level:
+#
+depth = ../..
+#
+
+# identify module:
+#
+NAME = flower
+MODULE_NAME = flower
+include ./$(depth)/flower/.version
+build = ./$(depth)/flower/lib/.build
+#
+
+# generic variables:
+#
+include ./$(depth)/make/Variables.make
+#
+
+# descent order into subdirectories:
+#
+SUBDIRS = include
+#
+
+# to be remade each build:
+#
+VERSION_DEPENDENCY =#
+#
+
+# list of c++ header files:
+#
+HHFILES = # $(shell ls include/*.hh)
+#
+
+# list of c++ source files:
+#
+CCFILES = $(shell ls *.cc)
+#
+
+# list of other source files:
+#
+EXTRA_SOURCE_FILES =# $(shell ls *.y *.l)
+#
+
+# list of distribution files:
+#
+DISTFILES = Makefile $(HHFILES) $(CCFILES) $(EXTRA_SOURCE_FILES)
+#
+
+# list of custom libraries:
+#
+# yes, i know about the -L and -l options,
+# but these libraries get rebuild when needed.
+CUSTOMLIBES = \
+
+LOADLIBES +=
+#
+
+# main target of this module:
+#
+# MAINTARGET = $(EXECUTABLE)
+# MAINTARGET = $(LIBRARY)
+# MAINTARGET = $(bindir)/$(EXECUTABLE)# huh?
+MAINTARGET = $(libdir)/$(LIBRARY)# huh?
+
+default: $(MAINTARGET)
+#
+
+# sic.
+$(include-flower)/flower-config.hh:
+ touch $@
+
+# generic targets and rules:
+#
+include ./$(depth)/make/Targets.make
+include ./$(depth)/make/Rules.make
+#
+
+# auto dependencies:
+#
+-include ./$(outdir)/*.dep
+#
+
--- /dev/null
+#include "choleski.hh"
+const Real EPS = 1e-7; // so sue me. Hard coded
+
+Vector
+Choleski_decomposition::solve(Vector rhs)const
+{
+ int n= rhs.dim();
+ assert(n == L.dim());
+ Vector y(n);
+
+ // forward substitution
+ for (int i=0; i < n; i++) {
+ Real sum(0.0);
+ for (int j=0; j < i; j++)
+ sum += y(j) * L(i,j);
+ y(i) = (rhs(i) - sum)/L(i,i);
+ }
+ for (int i=0; i < n; i++)
+ y(i) /= D(i);
+
+ // backward subst
+ Vector &x(rhs); // using input as return val.
+ for (int i=n-1; i >= 0; i--) {
+ Real sum(0.0);
+ for (int j=i+1; j < n; j++)
+ sum += L(j,i)*x(j);
+ x(i) = (y(i) - sum)/L(i,i);
+ }
+ return x;
+}
+
+/*
+ Standard matrix algorithm.
+ */
+
+Choleski_decomposition::Choleski_decomposition(Matrix P)
+ : L(P.dim()), D(P.dim())
+{
+ int n = P.dim();
+ assert((P-P.transposed()).norm()/P.norm() < EPS);
+
+ L.unit();
+ for (int k= 0; k < n; k++) {
+ for (int j = 0; j < k; j++){
+ Real sum(0.0);
+ for (int l=0; l < j; l++)
+ sum += L(k,l)*L(j,l)*D(l);
+ L(k,j) = (P(k,j) - sum)/D(j);
+ }
+ Real sum=0.0;
+
+ for (int l=0; l < k; l++)
+ sum += sqr(L(k,l))*D(l);
+ Real d = P(k,k) - sum;
+ D(k) = d;
+ }
+
+#ifdef NDEBUG
+ assert((original()-P).norm() / P.norm() < EPS);
+#endif
+}
+
+Matrix
+Choleski_decomposition::original() const
+{
+ Matrix T(L.dim());
+ T.set_diag(D);
+ return L*T*L.transposed();
+}
+
+Matrix
+Choleski_decomposition::inverse() const
+{
+ int n=L.dim();
+ Matrix invm(n);
+ Vector e_i(n);
+ for (int i = 0; i < n; i++) {
+ e_i.set_unit(i);
+ Vector inv(solve(e_i));
+ for (int j = 0 ; j<n; j++)
+ invm(i,j) = inv(j);
+ }
+
+#ifdef NDEBUG
+ Matrix I1(n), I2(original());
+ I1.unit();
+ assert((I1-original()*invm).norm()/original.norm() < EPS);
+#endif
+
+ return invm;
+}
--- /dev/null
+#include <fstream.h>
+#include <ctype.h>
+
+#include "data-file.hh"
+
+void
+Data_file::gobble_white()
+{
+ char c;
+
+ while ((c=data_get()) == ' ' ||c == '\t')
+ if (eof())
+ break;
+
+ data_unget(c);
+}
+
+String
+Data_file::get_word()
+{// should handle escape seq's
+ String s;
+
+ while (1)
+ {
+ char c = data_get();
+
+ if (isspace(c) || eof())
+ {
+ data_unget(c);
+ break;
+ }
+
+
+ if (c == '\"')
+ {
+ rawmode= true;
+
+ while ((c = data_get()) != '\"')
+ if (eof())
+ error("EOF in a string");
+ else
+ s += c;
+
+
+ rawmode= false;
+ }
+ else
+ s += c;
+ }
+
+ return s;
+}
+
+/** get a char
+ Only class member who uses text_file::get
+ */
+char
+Data_file::data_get() {
+ char c = get();
+ if (!rawmode && c == '#') // gobble comment
+ {
+ while ((c = get()) != '\n' && !eof())
+ ;
+ return '\n';
+ }
+
+ return c;
+}
+
+/// read line, gobble '\n'
+String Data_file::get_line()
+{
+ char c;
+ String s;
+
+ while ((c = data_get()) != '\n' && !eof())
+ s += c;
+ return s;
+}
+
+/// gobble stuff before first entry on a line.
+void
+Data_file::gobble_leading_white()
+{
+ // eat blank lines.
+ while (!eof()) {
+ char c = data_get();
+ if (!isspace(c)) {
+ data_unget(c);
+ break;
+ }
+ }
+}
+
+
--- /dev/null
+#include <fstream.h>
+#include "assoc.hh"
+#include "dstream.hh"
+#include "scalar.hh"
+#include "text-db.hh"
+#include "string-convert.hh"
+
+/// indent of each level
+const INDTAB = 2;
+
+/*
+ should use Regexp library.
+ */
+static String
+strip_pretty(String pretty_str)
+{
+ int i = pretty_str.index_i('(');
+ if (i>=0)
+ pretty_str = pretty_str.left_str(i);
+
+ int l = pretty_str.index_last_i(' '); // strip until last ' '
+ if (l>=0)
+ pretty_str = pretty_str.nomid_str(0,l+1);
+ return pretty_str;
+}
+
+static String
+strip_member(String pret)
+{
+ int l=pret.index_last_i(':')-1;
+ if (l>=0)
+ pret = pret.left_str(l );
+ return pret;
+}
+
+Dstream&
+Dstream::identify_as(String name)
+{
+ if (!os)
+ return *this;
+
+ String mem(strip_pretty(name));
+ String cl(strip_member(mem));
+ String idx = cl;
+
+ if (silent->elt_query(mem))
+ idx = mem;
+ else if (silent->elt_query(cl))
+ idx = cl;
+ else {
+ (*silent)[idx] = false;
+ }
+ local_silence = (*silent)[idx];
+ if (classname != idx && !local_silence) {
+ classname=idx;
+// *os << "[" << classname << ":]"; // messy.
+ }
+ return *this;
+}
+
+bool
+Dstream::silence(String s)
+{
+ if (!silent->elt_query(s))
+ return false;
+ return (*silent)[s];
+}
+
+/** Output a string via the Dstream. This is the only output
+ interface. It delegates all conversion to String class. */
+Dstream &
+Dstream::operator<<(String s)
+{
+ output(s);
+ return *this;
+}
+
+Dstream &
+Dstream::operator<<(const void *v_l)
+{
+ output(String_convert::pointer_str(v_l));
+ return *this;
+}
+
+Dstream &
+Dstream::operator<<(const char *ch_l)
+{
+ output(ch_l);
+ return *this;
+}
+
+void
+Dstream::output(String s)
+{
+ if (local_silence|| !os)
+ return ;
+
+ for (const char *cp = s ; *cp; cp++)
+ switch(*cp) {
+ case '{':
+ case '[':
+ case '(': indentlvl += INDTAB;
+ *os << *cp;
+ break;
+
+ case ')':
+ case ']':
+ case '}':
+ indentlvl -= INDTAB;
+ *os << *cp ;
+
+ assert (indentlvl>=0) ;
+ break;
+
+ case '\n':
+ *os << '\n' << String (' ', indentlvl) << flush;
+ break;
+ default:
+ *os << *cp;
+ break;
+ }
+ return ;
+}
+
+
+Dstream::Dstream(ostream *r, const char * cfg_nm )
+{
+ os = r;
+ silent = new Assoc<String,bool>;
+ indentlvl = 0;
+ if (!os)
+ return;
+
+ const char * fn =cfg_nm ? cfg_nm : ".dstreamrc";
+ {
+ ifstream ifs(fn); // can't open
+ if (!ifs)
+ return;
+ }
+
+ Text_db cfg(fn);
+ while (! cfg.eof()){
+ Text_record r( cfg++);
+ if (r.size() != 2) {
+ r.message("not enough fields in Dstream init.");
+ continue;
+ }
+ (*silent)[r[0]] = (bool)(int)(Scalar(r[1]));
+ }
+
+}
+
+
+Dstream::~Dstream()
+{
+ delete silent;
+ assert(!indentlvl) ;
+}
--- /dev/null
+# flower/lib/include/Makefile
+
+# subdir level:
+#
+depth = ../../..
+#
+
+# generic stuff/Makefile
+#
+include ./$(depth)/make/Include.make
+#
+
+# identify module:
+#
+MODULE_NAME = flower
+include ./$(depth)/flower/.version
+build = ./$(depth)/flower/lib/.build
+#
+
--- /dev/null
+/*
+ associter.hh -- part of flowerlib
+
+ (c) 1996 Han-Wen Nienhuys
+*/
+
+#ifndef ASSOCITER_HH
+#define ASSOCITER_HH
+
+#include "assoc.hh"
+
+/// an iterator for the #Assoc# class
+template<class K, class V>
+struct Assoc_iter {
+ int i;
+ Assoc<K,V> &assoc_;
+ /// we don't want to be bothered by const correctness
+ Assoc_iter(const Assoc<K,V> &a) :
+ assoc_((Assoc<K,V> &)a)
+ {
+ i= next(0);
+ }
+ int next(int j) {
+ while (j < assoc_.arr.size() && assoc_.arr[j].free)
+ j++;
+ return j;
+ }
+ bool ok() const {
+ return i < assoc_.arr.size();
+ }
+ void OK()const {
+ assert(!ok() || !assoc_.arr[i].free);
+ }
+ void operator++(int) { i++; i = next(i); }
+ K key() { return assoc_.arr[i].key; }
+ V &val() { return assoc_.arr[i].val; }
+};
+
+#endif
--- /dev/null
+#ifndef ASSOC_HH
+#define ASSOC_HH
+
+#include "varray.hh"
+#include <assert.h>
+
+/**
+ A helper for Assoc
+ */
+template<class K, class V>
+struct Assoc_ent_ {
+ bool free;
+ K key;
+ V val;
+};
+
+
+/** mindblowingly stupid Associative array implementation.
+ Hungarian: map
+ */
+template<class K, class V>
+struct Assoc {
+ Array< Assoc_ent_<K,V> > arr;
+
+ /* ************** */
+
+ int find(K key) const {
+ for (int i = 0; i < arr.size(); i++) {
+ if (!arr[i].free && key == arr[i].key)
+ return i;
+ }
+ return -1;
+ }
+ int find_creat(K key) {
+ int free = -1;
+ for (int i = 0; i < arr.size(); i++) {
+ if (key == arr[i].key) {
+ return i;
+ } else if (arr[i].free ) {
+ free = i;
+ }
+ }
+ if (free >= 0){
+ arr[free].free = false;
+ arr[free].key = key;
+ return free;
+ }
+
+ Assoc_ent_<K,V> ae;
+ ae.free = false;
+ ae.key = key;
+ arr.push(ae);
+ return arr.size() -1;
+ }
+public:
+ bool elt_query(K key) const {
+ return find(key) >= 0;
+ }
+ void del(K key) {
+ assert(elt_query(key));
+ int i= find(key);
+ arr[i].free = true;
+ }
+ void
+ add(K key, V val) {
+ int i = find_creat(key);
+ arr[i].val = val;
+ }
+ V& operator[](K key) {
+ return arr[find_creat(key)].val;
+ }
+ const V& operator[](K key) const {
+ assert(elt_query(key));
+ return arr[find(key)].val;
+ }
+};
+
+#endif
--- /dev/null
+#ifndef CHOLESKI_HH
+#define CHOLESKI_HH
+
+#include "matrix.hh"
+
+/**
+ Choleski decomposition of a matrix
+ structure for using the LU decomposition of a positive definite matrix.
+
+ #P# is split into
+
+ LD transpose(L)
+ */
+struct Choleski_decomposition {
+
+ /// lower triangle of Choleski decomposition
+ Matrix L;
+
+ /// diagonal
+ Vector D;
+
+ /** Create decomposition of P.
+ PRE
+ P needs to be symmetric positive definite
+ */
+
+ Choleski_decomposition(Matrix P);
+
+ /**
+ solve Px = rhs
+ */
+ Vector solve(Vector rhs) const;
+
+ Vector operator * (Vector rhs) const { return solve (rhs); }
+ /**
+ return the inverse of the matrix P.
+ */
+ Matrix inverse() const;
+ /**
+ return P, calc'ed from L and D
+ */
+ Matrix original() const;
+
+
+};
+#endif
--- /dev/null
+/*
+ flowerlib
+
+ (c) 1996 Han-Wen Nienhuys
+ */
+#ifndef COMPARE_HH
+#define COMPARE_HH
+
+#define one_operator(type, function, op) \
+inline bool \
+operator op (type t1, type t2) {\
+ return function(t1, t2) op 0;\
+}\
+
+#define gpp_minmax_operator(type, op, opp) \
+inline type \
+operator op(type t1, type t2)\
+{\
+ return (t1 opp t2) ? t1 : t2;\
+}\
+
+
+#if defined (__GNUG__) && ! defined (__STRICT_ANSI__)
+#define gpp_minmax(type, prefix)\
+ prefix gpp_minmax_operator(type, <?, <)\
+ prefix gpp_minmax_operator(type, >?, >)
+#else
+#define gpp_minmax(type, prefix)
+#endif
+
+/** handy notations for a signed comparison.
+ make the operators{<,<=,==,>=,>} and the MAX and MIN of two.
+ Please fill a & in the type argument if necessary.
+ */
+#define template_instantiate_compare(type, function, prefix) \
+prefix one_operator(type, function, >)\
+prefix one_operator(type, function, >=)\
+prefix one_operator(type, function, ==)\
+prefix one_operator(type, function, !=)\
+prefix one_operator(type, function, <)\
+prefix one_operator(type, function, <=)\
+gpp_minmax(type, prefix)\
+prefix inline type max(type t1, type t2) { return (t1 > t2 )? t1 : t2; }\
+prefix inline type min(type t1, type t2) { return (t1 < t2 )? t1 : t2; }\
+ \
+prefix bool operator<(type t1, type t2) /* stupid fix to allow ; */
+
+
+
+#define instantiate_compare(type, func) template_instantiate_compare(type,func, )
+
+
+
+#endif
+
--- /dev/null
+// cursor.hh
+
+#ifndef __CURSOR_HH
+#define __CURSOR_HH
+
+#include "link.hh"
+template<class T> class List;
+
+/** iterator to List.
+ add and insert extend the list
+ items are always stored as copies in List, but:
+ List<String> : copies of String stored
+ List<String*> : copies of String* stored!
+
+ the operations add and insert actually delegate the work to List class.
+ */
+template<class T>
+class Cursor
+{
+ public:
+ /** create cursor, set at top. The const part isn't true, actually, #list#
+ surely isn't const, but I get tired of the warning messages. */
+ Cursor( const List<T>& list, Link<T>* pointer = 0 );
+
+ Cursor( const Cursor<T>& cursor );
+
+ T& thing();
+
+ /// return current T
+ T& operator *() { return thing(); }
+ operator T() { return thing(); }
+ Cursor<T> operator =( const Cursor<T>& c );
+
+ /// make cursor with #no# items back
+ Cursor<T> operator -( int no) const;
+
+ /// make cursor with #no# items further
+ Cursor<T> operator +( int no) const;
+ int operator -(Cursor<T> op) const;
+ Cursor<T> operator -=(int);
+ Cursor<T> operator +=(int);
+
+ /// return current and move one down
+ Cursor<T> operator ++( int );
+
+ /// return current and move one up
+ Cursor<T> operator --( int );
+
+ /// point to link?
+ bool ok();
+
+ /// ++ items left?
+ bool forward();
+
+ /// -- items left?
+ bool backward();
+
+ /** put (copy) after me in List.
+ analogously to editor. ok() interpreted as at end
+ of line.
+
+ PRE: !ok, POST: added to bottom()
+
+ PRE: ok, POST: added after me
+
+ cursor points to same object, cursor.next() is newly added
+ object.
+ */
+ void add( const T& thing );
+
+ /** put (copy) before me in List.
+ analogously to editor. ok() interpreted as at begin of
+ line.
+
+ PRE: !ok, POST: add to top()
+
+ PRE: ok, POST: add before me
+
+ cursor points to same object, cursor.previous()
+ is newly inserted object.
+ */
+
+ void insert( const T& thing );
+ ///
+ void backspace();
+
+ ///
+ void del();
+
+ /// access the list this came from
+ List<T>& list() const ;
+ Link<T>* pointer();
+ static int compare(Cursor<T> a,Cursor<T>b) { return a-b; }
+private:
+ List<T>& list_;
+ Link<T>* pointer_;
+};
+
+
+/*
+ comparisons.
+ */
+#include "compare.hh"
+
+
+template_instantiate_compare(Cursor<T>, Cursor<T>::compare, template<class T>);
+
+#include "pcursor.hh"
+#include "list.hh"
+#include "cursor.inl"
+#include "iterate.hh"
+
+#endif // CURSOR_HH
--- /dev/null
+ // cursor.inl -*-c++-*-
+#ifndef CURSOR_INL
+#define CURSOR_INL
+#include <assert.h>
+
+
+template<class T>
+inline
+Cursor<T>::Cursor( const List<T>& list, Link<T>* pointer ) :
+ list_((List<T>&) list )
+{
+ if ( list.size() )
+ pointer_ = pointer ? pointer : list.top_;
+ else
+ pointer_ = pointer;
+}
+
+template<class T>
+inline
+Cursor<T>::Cursor( const Cursor<T>& cursor ) :
+ list_( cursor.list_ )
+{
+ pointer_ = cursor.pointer_;
+}
+
+template<class T>
+inline T&
+Cursor<T>::thing()
+{
+ assert( pointer_ );
+ return pointer_->thing();
+}
+
+template<class T>
+Cursor<T>
+Cursor<T>::operator =( const Cursor<T>& c )
+{
+ assert( &list_ == &c.list_ );
+ pointer_ = c.pointer_;
+ return *this;
+}
+
+template<class T>
+inline void
+Cursor<T>::add( const T& th )
+{
+ list_.add( th, *this );
+}
+
+template<class T>
+inline void
+Cursor<T>::insert( const T& th )
+{
+ list_.insert( th, *this );
+}
+
+template<class T>
+inline List<T>&
+Cursor<T>::list() const
+{
+ return list_;
+}
+
+template<class T>
+inline Link<T>*
+Cursor<T>::pointer()
+{
+ return pointer_;
+}
+
+template<class T>
+inline bool
+Cursor<T>::backward()
+{
+ return ( pointer_ != 0 );
+}
+
+template<class T>
+inline bool
+Cursor<T>::forward()
+{
+ return ( pointer_ != 0 );
+}
+
+template<class T>
+inline bool
+Cursor<T>::ok()
+{
+ return ( pointer_ != 0 );
+}
+
+
+template<class T>
+inline Cursor<T>
+Cursor<T>::operator ++( int )
+{
+ Cursor<T> r (*this);
+ assert( pointer_ );
+ pointer_ = pointer_->next();
+ return r;
+}
+
+template<class T>
+inline Cursor<T>
+Cursor<T>::operator --( int )
+{
+ Cursor<T> r (*this);
+ assert( pointer_ );
+ pointer_ = pointer_->previous();
+ return r;
+}
+
+#endif
--- /dev/null
+#ifndef CURSOR_CC
+#define CURSOR_CC
+
+#include "cursor.hh"
+#include <assert.h>
+
+template<class T>
+ void
+Cursor<T>::backspace()
+{
+ Cursor<T> c(*this);
+ if ( c.ok() )
+ c--;
+ list_.remove( *this );
+}
+
+template<class T>
+ void
+Cursor<T>::del()
+{
+ Cursor<T> c(*this);
+ if ( c.ok() )
+ c++;
+ list_.remove( *this );
+ *this = c;
+}
+
+
+template<class T>
+Cursor<T>
+Cursor<T>::operator -=( int j )
+{
+ while (j--)
+ (*this)--;
+ return *this;
+}
+template<class T>
+Cursor<T>
+Cursor<T>::operator +=( int j )
+{
+ while (j++)
+ (*this)++;
+ return *this;
+}
+
+template<class T>
+Cursor<T>
+Cursor<T>::operator +( int i ) const
+{
+ Cursor<T> r = *this;
+
+ if (i<0)
+ return r -(-i);
+
+ while (i--)
+ r++;
+
+ return r;
+}
+
+template<class T>
+Cursor<T>
+Cursor<T>::operator -( int i ) const
+{
+ Cursor<T> r = *this;
+ if (i<0)
+ return r +(-i);
+
+ while (i--)
+ r--;
+
+ return r;
+}
+/*
+ warning: can't use Cursor::operator == (Cursor),
+ since it uses Cursor::operator-(Cursor)
+ */
+template<class T>
+int
+Cursor<T>::operator-(Cursor<T> rhs) const
+{
+ assert(rhs.list == list);
+ int dif = 0;
+
+ // search from *this on further up (positive difference)
+ Cursor<T> c(*this);
+ while (c.ok() && c.pointer_ != rhs.pointer_) {
+ c--;
+ dif++;
+ }
+
+ if (c.ok())
+ goto gotcha; // so, sue me.
+
+ // search in direction of bottom. (negative diff)
+ dif =0;
+ c=*this;
+ while (c.ok() && c.pointer_ !=rhs.pointer_) {
+ dif --;
+ c++;
+ }
+ assert(c.ok());
+
+gotcha:
+ assert((*this - dif).pointer_ == c.pointer_);
+ return dif;
+}
+
+#endif
--- /dev/null
+/*
+ data-file.hh -- declare Data_file
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+
+#ifndef DATAFILE_HH
+#define DATAFILE_HH
+
+#include "text-stream.hh"
+
+/// read a data file
+class Data_file : private Text_stream
+{
+
+ public:
+ bool rawmode;
+
+ Text_stream::line;
+ Text_stream::eof;
+ Text_stream::get_name;
+
+ char data_get();
+ void data_unget(char c) {
+ unget(c);
+ }
+
+ /// read line, eat #\n#
+ String get_line();
+
+ /// read a word till next space, leave space. Also does quotes
+ String get_word();
+
+ /// gobble horizontal white stuff.
+ void gobble_white();
+
+ /// gobble empty stuff before first field.
+ void gobble_leading_white();
+ Data_file(String s) : Text_stream(s) {
+ //*mlog << "(" << s << flush;
+ rawmode= false;
+ }
+
+ ~Data_file() {
+ // *mlog << ")"<<flush;
+ }
+
+ warning(String s) {
+ message("warning: " + s);
+ }
+ error(String s){
+ message(s);
+ exit(1);
+ }
+};
+#endif // DATAFILE_HH
--- /dev/null
+
+#ifndef DSTREAM_HH
+#define DSTREAM_HH
+
+#include "string.hh"
+
+const char eol= '\n';
+
+template<class K,class V>
+struct Assoc;
+
+/** debug stream.
+ a class for providing debug output of nested structures,
+ with indents according to \{\}()[].
+
+ One can turn on and off specific messages using the Assoc silent.
+ This can be done automatically:
+
+ #define DEBUG dstream_.identify_as(__PRETTY_FUNCTION__)
+
+ DEBUG << "a message\n";
+
+ Init for the class names which should be silent can be given in a rc file.
+
+ */
+class Dstream
+{
+ ostream *os;
+ int indentlvl;
+ bool local_silence;
+ String classname;
+ void output(String s);
+ Assoc<String, bool> *silent;
+public:
+
+ bool silence(String);
+
+ /**
+ if rcfile == 0, then do not read any rc file.
+ */
+
+ Dstream(ostream *r, const char * rcfile);
+ virtual ~Dstream();
+ Dstream &identify_as(String s);
+
+ Dstream &operator << (String s);
+ /**
+ Output memory locations.
+ */
+ Dstream &operator << (void const *);
+ Dstream &operator << (char const *);
+};
+#endif
+
--- /dev/null
+/*
+ fproto.hh -- typenames in flowerlib
+
+ (c) 1996 Han-Wen Nienhuys
+*/
+
+#ifndef FPROTO_HH
+#define FPROTO_HH
+
+#include "flower-config.hh"
+
+template<class T> struct Array;
+template<class T> struct sstack;
+template<class T,class K> struct Assoc;
+template<class T> struct List;
+template<class T> struct PointerList;
+template<class T> struct IPointerList;
+template<class T> struct Cursor;
+template<class T> struct PCursor;
+template<class T> struct Link;
+template<class T> struct Handle;
+template<class T>struct Interval_t;
+#include "real.hh"
+
+typedef Interval_t<Real> Interval;
+
+struct Choleski_decomposition;
+
+struct Long_option_init;
+struct Getopt_long;
+struct Matrix;
+struct String_data;
+struct String_handle;
+struct String_convert;
+struct String;
+struct virtual_smat;
+struct Vector ;
+struct Text_stream;
+struct Data_file;
+struct Text_db;
+struct Scalar;
+typedef unsigned char Byte;
+#endif // FPROTO_HH
+
--- /dev/null
+#ifndef HANDLE_HH
+#define HANDLE_HH
+
+/// reference counting handle
+template<class T>
+class Handle {
+ T *obj;
+ int *refs;
+
+ /// let go of ref. Delete if necessary
+ void down() {
+ if (!(*refs--)) {
+ delete obj;
+ delete refs;
+ }
+ obj = 0;
+ refs = 0;
+ }
+ /// point to new object.
+ void up(T *t, int *r) {
+ if (!r) {
+ refs = new int;
+ *refs = 1;
+ } else {
+ refs =r;
+ *refs++;
+ }
+ obj = t;
+ }
+ /// POST: *refs == 1
+ void copy() {
+ if(*refs != 1){
+ T * newobj = new T(*obj );
+ down();
+ up(newobj);
+ }
+ }
+ Handle(Handle const &src) {
+ up(src.obj, src.refs);
+ }
+ Handle(T & o) {
+ up (&o);
+ }
+ void operator=(Handle const& src) {
+ if (this == &src)
+ return;
+ down();
+ up(src.o, src.refs);
+ }
+ operator const T&() {
+ return *obj;
+ }
+ operator T&() {
+ copy();
+ return *obj;
+ }
+}
+#endif
--- /dev/null
+/*
+ interval.hh -- part of flowerlib
+
+ (c) 1996 Han-Wen Nienhuys
+*/
+
+#ifndef INTERVAL_HH
+#define INTERVAL_HH
+
+#include <assert.h>
+#include "fproto.hh"
+#include "real.hh"
+
+
+/** a T interval.
+ this represents the closed interval [left,right].
+ No invariants. T must be a totally ordered ring
+ */
+template<class T>
+struct Interval_t {
+ T left, right;
+
+ /* ************** */
+
+ T center() { return (left + right) / T(2);}
+ void translate(T t) {
+ left += t;
+ right += t;
+ }
+ T& idx(int j) {
+ if (j==-1)
+ return left;
+ else if (j==1)
+ return right;
+ else
+ assert(false);
+ return left;
+ }
+ T& operator[](int j) {
+ return idx(j);
+ }
+ T operator[](int j) const {
+ return ((Interval_t<T> *)this)->idx(j);
+ }
+ T &max() { return right;}
+ T max()const { return right;}
+ T min()const{ return left; }
+ T &min(){ return left; }
+ /**
+ PRE
+ *this and h are comparable
+ */
+ void unite(Interval_t<T> h);
+ void intersect(Interval_t<T> h);
+
+ T length() const;
+ void set_empty() ;
+ bool empty() const { return left > right; }
+ Interval_t() {
+ set_empty();
+ }
+ Interval_t(T m, T M) {
+ left =m;
+ right = M;
+ }
+ Interval_t<T> &operator += (T r) {
+ left += r;
+ right +=r;
+ return *this;
+ }
+ String str() const;
+ bool elt_q(T r);
+};
+
+
+/**
+ inclusion ordering. Crash if not comparable.
+ */
+template<class T>
+int Interval__compare(const Interval_t<T>&,Interval_t<T> const&);
+
+/*
+ INLINE
+ */
+
+#include "compare.hh"
+
+template_instantiate_compare(Interval_t<T>&, Interval__compare, template<class T>);
+
+
+template<class T>
+inline Interval_t<T>
+intersection(Interval_t<T> a, Interval_t<T> const&b)
+{
+ a.intersect(b);
+ return a;
+
+}
+
+
+template<class T>
+inline
+Interval_t<T> operator +(T a,Interval_t<T> i )
+{
+ i += a;
+ return i;
+}
+
+template<class T>
+inline
+Interval_t<T> operator +(Interval_t<T> i,T a ){
+ return a+i;
+}
+
+typedef Interval_t<Real> Interval;
+
+
+#define Interval__instantiate(T) template struct Interval_t<T>;\
+ template int Interval__compare(const Interval_t<T>&,Interval_t<T> const&)
+
+
+#endif // INTERVAL_HH
+
+
+
--- /dev/null
+#include <assert.h>
+#include <math.h>
+#include "interval.hh"
+#include "string.hh"
+
+
+template<class T>
+int
+_Interval__compare(const Interval_t<T>&a,Interval_t<T> const&b)
+{
+ if (a.left == b.left && a.right == b.right)
+ return 0;
+
+ if (a.left <= b.left && a.right >= b.right)
+ return 1;
+
+ if (a.left >= b.left && a.right <= b.right)
+ return -1;
+
+ return -2;
+}
+
+
+template<class T>
+int
+Interval__compare(const Interval_t<T>&a,Interval_t<T> const&b)
+{
+ int i = _Interval__compare(a,b);
+ if (i < -1)
+ assert(false);
+ return i;
+}
+
+#ifdef AIX
+const Real INFTY = 1e8; // ARGh. AIX sucks
+#else
+const Real INFTY = HUGE_VAL;
+#endif
+
+template<class T>
+void
+Interval_t<T>::set_empty()
+{
+ left = INFTY;
+ right = -INFTY;
+}
+
+template<class T>
+T
+Interval_t<T>::length() const {
+ assert(right >= left);
+ return right-left;
+}
+
+template<class T>
+void
+Interval_t<T>::unite(Interval_t<T> h)
+{
+ if (h.left<left)
+ left = h.left;
+ if (h.right>right)
+ right = h.right;
+}
+
+/**
+ smallest Interval which includes *this and #h#
+ */
+
+template<class T>
+void
+Interval_t<T>::intersect(Interval_t<T> h)
+{
+#if defined (__GNUG__) && ! defined (__STRICT_ANSI__)
+ left = h.left >? left;
+ right = h.right <?right;
+#else
+ left = max(h.left, left);
+ right = min(h.right, right);
+#endif
+}
+
+template<class T>
+Interval_t<T>
+intersect(Interval_t<T> x, Interval_t<T> const &y)
+{
+ x.intersect(y);
+ return x;
+}
+
+template<class T>
+String
+Interval_t<T>::str() const
+{
+ if (empty())
+ return "[empty]";
+ String s("[");
+
+ return s + left + "," + right +"]";
+}
+
+template<class T>
+bool
+Interval_t<T>::elt_q(T r)
+{
+ return r >= left && r <= right;
+}
--- /dev/null
+/*
+ iterate.hh -- define some list macros
+
+ source file of the flowerlib
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+
+#ifndef ITERATE_HH
+#define ITERATE_HH
+
+
+
+#define iterator(set) typeof((set).top())
+#define iterator_bot(set) typeof((set).bottom())
+
+// should use top()
+#define iter_top(set,var) iterator(set) var(set)
+#define iter_bot(set,var) iterator(set) var(set.bottom())
+
+#endif // ITERATE_HH
--- /dev/null
+#ifndef LGETOPT_HH
+#define LGETOPT_HH
+
+#include <string.h>
+
+
+class ostream;
+
+/**
+ a struct this for initialising the commandline options.
+ */
+struct Long_option_init {
+ bool take_arg;
+ const char* longname;
+ char shortname;
+
+ ostream &printon(ostream &errorout);
+};
+
+
+/** C++ for version of long_getopt. For processing GNU style command
+ line arguments. No pointer (return values, arguments) contents are
+ copied. */
+class Getopt_long {
+public:
+ /** errorcodes: no error, argument expected, no argument expected,
+ unknown option, illegal argument (eg. int expected). */
+ enum Errorcod { E_NOERROR = 0, E_ARGEXPECT, E_NOARGEXPECT, E_UNKNOWNOPTION,
+ E_ILLEGALARG } ;
+
+
+private:
+
+ /// the option info.
+ Long_option_init *the_opts;
+ int table_len;
+
+ /// if doing short option, argv[optind][optindind] is processed next.
+ int optindind;
+
+ /// the option found
+ Long_option_init *beet;
+
+ /// get ready for processing next error.
+ bool next();
+ Long_option_init *parselong();
+ Long_option_init *parseshort();
+
+ ostream *errorout;
+
+ /// report an error and abort
+ void report(Errorcod c);
+public:
+
+ /// argument. Set to 0 if not present
+ char* optarg;
+
+ /// current error status
+ Errorcod error;
+
+ /// return an integer (with err. detect)
+ long intarg();
+ /// argv[optind] will be processed next.
+ int optind;
+
+ /// the arguments
+ char **argv;
+
+ /// the arg. count
+ int argc;
+
+ /* *************** */
+
+ /**
+ What to do with errors.
+ report messages on #*os#, and abort.
+ if #os# is null, then do not report nor abort, just set #error#
+ */
+
+ void seterror(ostream *os);
+
+ /// construct: pass arguments and option info.
+ Getopt_long(int c, char **v, Long_option_init *lo);
+
+ /** get the next option.
+ @return pointer to next option found.
+ 0 if error occurred, or next argument is no option.
+ */
+ Long_option_init *operator()();
+
+ char *current_arg();
+ char * get_next_arg();
+};
+#endif
--- /dev/null
+/*
+ libc-extension.hh -- declare some string.h extensions
+
+ source file of the flowerlib
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+
+#ifndef LIBC_EXTENSION_HH
+#define LIBC_EXTENSION_HH
+#include "fproto.hh"
+
+char* strnlwr( char* start_l ,int n);
+char* strnupr( char* start_l, int n);
+
+#ifndef HAVE_MEMMEM // GNU extension.
+char *memmem(const Byte * haystack, int haystack_len,
+ const Byte *needle, int needle_len);
+#endif HAVE_MEMMEM
+
+#ifndef HAVE_SNPRINTF // GNU extension.
+int snprintf (char *str, size_t n,
+ const char *format, ... );
+#endif
+
+
+Byte *memrchr(const Byte * p, int n, char c);
+Byte *strrev( Byte* byte_l, int length_i );
+
+
+#endif // LIBC_EXTENSION_HH
--- /dev/null
+// link.hh
+
+#ifndef __LINK_HH
+#define __LINK_HH
+template<class T>
+class List;
+
+
+/// class for List
+template<class T>
+class Link
+{
+// friend class Cursor<T>;
+public:
+ Link( const T& thing );
+
+ Link<T>* previous();
+ Link<T>* next();
+
+ /// put new Link item after me in list
+ void add( const T& thing );
+ /// put new Link item before me in list
+ void insert( const T& thing );
+ void remove(List<T> &l);
+
+ T& thing();
+ void OK() const;
+private:
+ Link( Link<T>* previous, Link<T>* next, const T& thing );
+
+ T thing_;
+ Link<T>* previous_;
+ Link<T>* next_;
+};
+
+#include "link.inl"
+
+#endif // __LINK_HH //
--- /dev/null
+// link.inl -*-c++-*-
+#ifndef LINK_INL
+#define LINK_INL
+#include <assert.h>
+template<class T>
+inline
+void
+Link<T>::OK() const
+{
+#ifndef NDEBUG
+ if (previous_) {
+ assert(previous_->next_ == this);
+ }
+ if (next_) {
+ assert(next_->previous_ == this);
+ }
+#endif
+}
+
+template<class T>
+inline
+Link<T>::Link( const T& thing ) :
+ thing_( thing )
+{
+ previous_ = next_ = 0;
+}
+
+template<class T>
+inline
+Link<T>::Link( Link<T>* previous, Link<T>* next, const T& thing ) :
+ thing_( thing )
+{
+ previous_ = previous;
+ next_ = next;
+}
+
+template<class T>
+inline
+Link<T>*
+Link<T>::next()
+{
+ return next_;
+}
+
+template<class T>
+inline
+Link<T>*
+Link<T>::previous()
+{
+ return previous_;
+}
+
+template<class T>
+inline
+void
+Link<T>::add( const T& thing )
+{
+
+ Link<T>* l = new Link<T>( this, next_, thing );
+ if ( next_ )
+ next_->previous_ = l;
+ next_ = l;
+}
+
+template<class T>
+inline void
+Link<T>::insert( const T& thing )
+{
+ // Link<T>* l = new Link<T>( next_, this, thing );
+ // bugfix hwn 16/9/96
+ Link<T>* l = new Link<T>( previous_, this, thing );
+ if ( previous_ )
+ previous_->next_ = l;
+ previous_ = l;
+}
+
+/*
+ don't forget to adjust #l#'s top_ and bottom_.
+ */
+template<class T>
+inline void
+Link<T>::remove(List<T> &l)
+{
+ if ( previous_ )
+ previous_->next_ = next_;
+ else
+ l.top_ = next_;
+
+ if ( next_ )
+ next_->previous_ = previous_;
+ else
+ l.bottom_ = previous_;
+}
+
+template<class T>
+inline
+T&
+Link<T>::thing()
+{
+ return thing_;
+}
+#endif
--- /dev/null
+#ifndef __LIST_HH
+#define __LIST_HH
+
+class ostream;
+template<class T> class Cursor;
+template<class T> class Link;
+
+/** all-purpose doubly linked list.
+
+ List can be seen as all items written down on paper,
+ from top to bottom
+
+ class Cursor is used to extend List
+
+ items are always stored as copies in List, but:
+ #List<String># : copies of #String# stored
+ #List<String*># : copies of #String*# stored!
+ (do not use, use \Ref{PointerList} #<String*># instead.)
+
+ {\bf note:}
+ retrieving "invalid" cursors, i.e.
+ #top()/bottom()# from empty list, #find()# without success,
+ results in a nonvalid Cursor ( #!ok()# )
+
+
+ INVARIANTEN!
+*/
+
+template<class T>
+class List
+{
+ public:
+ List(List const&src);
+
+ /// construct empty list
+ List();
+ virtual ~List();
+
+ int size() const;
+
+ Cursor<T> bottom() const; // const sucks.
+ Cursor<T> top() const;
+
+ void OK() const; // check list
+
+ protected:
+ friend class Cursor<T>;
+ friend class Link<T>;
+
+ void concatenate(List<T> const &s);
+
+ /** make *this empty.
+
+ POST:
+ size == 0
+
+ WARNING:
+ contents lost, and not deleted.
+ */
+ void set_empty();
+
+ void add( const T& thing, Cursor<T> &after_me );
+
+ /// put thing before #before_me#
+ void insert( const T& thing, Cursor<T> &before_me );
+
+ /** Remove link pointed to by me. Destructor of contents called
+ (nop for pointers)
+
+ POST
+ none;
+
+
+ WARNING: do not use #me# after calling
+ */
+ void remove( Cursor<T> me );
+
+
+ /* ************** */
+
+ int size_;
+ Link<T>* top_;
+ Link<T>* bottom_;
+};
+
+#include "list.inl"
+#include "cursor.hh"
+
+// instantiate a template: explicit instantiation.
+#define L_instantiate(a) template class List<a>; template class Cursor<a>; \
+ template class Link<a>
+
+
+#endif // __LIST_HH //
+
+
+
+
--- /dev/null
+// -*-c++-*-
+
+#ifndef LIST_INL
+#define LIST_INL
+
+template<class T>
+inline
+List<T>::List()
+{
+ set_empty();
+}
+
+template<class T>
+inline void
+List<T>::set_empty()
+{
+ top_ = bottom_ = 0;
+ size_ = 0;
+}
+
+template<class T>
+inline void
+List<T>::remove( Cursor<T> me )
+{
+ if ( me.ok() ){
+ Link<T> *lp = me.pointer();
+ lp->remove(*this);
+ delete lp;
+ size_--;
+ }
+}
+
+template<class T>
+inline int
+List<T>::size() const
+{
+ return size_;
+}
+
+template<class T>
+inline Cursor<T>
+List<T>::top()const
+{
+ return Cursor<T>( *this, top_ );
+}
+
+
+template<class T>
+inline Cursor<T>
+List<T>::bottom()const
+{
+ return Cursor<T>( *this, bottom_ );
+}
+
+
+#endif
--- /dev/null
+#ifndef LIST_CC
+#define LIST_CC
+
+#include "list.hh"
+
+template<class T>
+List<T>::List(List const&src)
+{
+ set_empty();
+ // probably el stupido
+ for (Cursor<T> c(src); c.ok(); c++)
+ bottom().add(c);
+}
+
+template<class T>
+void
+List<T>::OK() const
+{
+ int i = size_;
+ Link<T> *lp = top_;
+ while (i--) {
+ assert(lp);
+ lp->OK();
+ lp = lp->next();
+ }
+ assert(!lp);
+ i = size_;
+ lp = bottom_;
+ while (i--) {
+ assert(lp);
+ lp->OK();
+ lp = lp->previous();
+ }
+ assert(!lp);
+}
+
+
+template<class T>
+List<T>::~List()
+{
+ Cursor<T> c(*this);
+ while (c.ok())
+ c.del();
+}
+
+/**
+
+ add after after_me.
+
+ Procedure:
+ \begin{itemize}
+ \item if #after_me# is #ok()#, add after #after_me#, else
+ \item if list !empty simply add to bottom, else
+ \item list is empty: create first \Ref{Link} and initialize
+ #bottom_# and #top_#.
+ \end{itemize}
+*/
+template<class T>
+void
+List<T>::add( const T& thing, Cursor<T> &after_me )
+{
+ if (!size_) { // not much choice if list is empty
+ bottom_ = top_ = new Link<T>( thing );
+ if (!after_me.ok())
+ after_me = bottom();
+ } else { // add at aprioprate place
+ if (!after_me.ok())
+ after_me = bottom();
+ Link<T> *p =after_me.pointer();
+ p->add(thing);
+ if (p == bottom_) // adjust bottom_ if necessary.
+ bottom_ = p->next();
+ }
+
+ size_++;
+}
+
+template<class T>
+void
+List<T>::insert( const T& thing, Cursor<T> &before_me )
+{
+ if (!size_) {
+ bottom_ = top_ = new Link<T>( thing );
+ if (!before_me.ok())
+ before_me = top();
+
+ } else {
+ if (!before_me.ok())
+ before_me = top();
+
+ Link<T> *p = before_me.pointer() ;
+
+ p->insert(thing);
+ if (p == top_)
+ top_ = p->previous();
+ }
+
+ size_++;
+}
+
+
+template<class T>
+void
+List<T>::concatenate(List<T> const&s)
+{
+ Cursor<T> b(bottom());
+ for (Cursor<T> c(s); c.ok(); c++) {
+ b.add(c);
+ b++;
+ }
+}
+#endif
--- /dev/null
+#ifndef MATRIX_HH
+#define MATRIX_HH
+
+
+#include "vsmat.hh"
+#include "vector.hh"
+
+/** a Real matrix. This is a class for a nonsquare block of #Real#s. The
+ implementation of sparse matrices is done in the appropriate #smat#
+ class. Matrix only does the mathematical actions (adding,
+ multiplying, etc.)
+
+
+ TODO
+ implement ref counting? */
+
+
+class Matrix {
+ virtual_smat *dat;
+
+public:
+ void OK() const { dat->OK(); }
+ int cols() const { return dat->cols(); }
+ int rows() const { return dat->rows(); }
+
+ /** return the size of a matrix.
+ PRE
+ the matrix needs to be square.
+ */
+ int dim() const;
+
+ // Matrix() { dat = 0; }
+ ~Matrix() { delete dat; }
+
+ /// set entries to r
+ void fill(Real r);
+
+ /// set diagonal to d
+ void set_diag(Real d);
+
+ void set_diag(Vector d);
+ /// set unit matrix
+ void unit() { set_diag(1.0); }
+
+ void operator+=(const Matrix&m);
+ void operator-=(const Matrix&m);
+ void operator*=(Real a);
+ void operator/=(Real a) { (*this) *= 1/a; }
+
+ /** add a row.
+ add a row to the matrix before row k
+
+ PRE
+ v.dim() == cols()
+ 0 <= k <= rows()
+ */
+ void insert_row(Vector v,int k);
+ /** .
+ delete a row from this matrix.
+
+ PRE
+ 0 <= k < rows();
+ */
+ void delete_row(int k) { dat->delete_row(k); }
+ void delete_column(int k) { dat->delete_column(k); }
+
+ /**
+ square n matrix, initialised to null
+ */
+ Matrix(int n);
+
+ /**
+ n x m matrix, init to 0
+ */
+ Matrix(int n, int m);
+ Matrix(const Matrix &m);
+
+ /// dyadic product: v * w.transpose
+ Matrix(Vector v, Vector w);
+ void operator=(const Matrix&m);
+
+ /// access an element
+ Real operator()(int i,int j) const { return dat->elem(i,j); }
+
+ /// access an element
+ Real &operator()(int i, int j) { return dat->elem(i,j); }
+
+ /// Matrix multiply with vec (from right)
+ Vector operator *(const Vector &v) const;
+
+ /// set this to m1*m2.
+ void set_product(const Matrix &m1, const Matrix &m2);
+
+
+ Vector left_multiply(Vector const &) const;
+
+ Matrix operator-() const;
+
+ /// transpose this.
+ void transpose();
+
+ /// return a transposed copy.
+ Matrix transposed() const ;
+
+ Real norm() const;
+ /** swap.
+ PRE
+ 0 <= c1,c2 < cols()
+ */
+ void swap_columns(int c1, int c2);
+
+ /** swap.
+ PRE
+ 0 <= c1,c2 < rows()
+ */
+ void swap_rows(int c1, int c2);
+
+
+ Vector row(int ) const;
+ Vector col(int) const;
+
+ operator String() const;
+ void print() const;
+};
+
+inline Vector
+operator *(Vector &v, const Matrix& m) { return m.left_multiply(v); }
+Matrix operator *(const Matrix& m1,const Matrix &m2);
+Matrix operator /(const Matrix &m1,Real a);
+inline Matrix operator -(Matrix m1,const Matrix m2)
+{
+ m1 -= m2;
+ return m1;
+}
+#endif
--- /dev/null
+#ifndef PATH_HH
+#define PATH_HH
+#include "string.hh"
+#include "varray.hh"
+
+
+/** searching directory for file.
+
+ Abstraction of PATH variable. An interface for searching input files.
+ Search a number of dirs for a file.
+
+ Should use kpathsea?
+
+*/
+
+class File_path : private Array<String>
+{
+public:
+ /// locate a file in the search path
+ String find(String nm);
+
+ /// construct using prefix. Normally argv[0].
+ File_path(String);
+
+ /// add to end of path.
+ Array<String>::push;
+ void add(String str) { push(str); }
+};
+/// split path into its components
+void split_path(String path, String &drive, String &dirs, String &filebase, String &extension);
+
+#endif
--- /dev/null
+#include "pcursor.hh"
+
+template<class T>
+void
+PCursor<T>::junk()
+{
+#if !defined(NDEBUG) && defined(PARANOID)
+ list().OK();
+#endif
+
+ delete ptr();
+#if !defined(NDEBUG)&&defined(PARANOID)
+ thing() = 0;
+ list().OK();
+#endif
+}
--- /dev/null
+#include "plist.hh"
+
+template<class T>
+IPointerList<T>::~IPointerList()
+{
+ PCursor<T> c( *this );
+ while (c.ok()) {
+ delete c.remove_p();
+ }
+}
+
+template<class T>
+PCursor<T>
+PointerList<T>::find(T what ) const
+{
+ PCursor<T> i(*this);
+ for (; i.ok(); i++)
+ if (i.ptr() == what)
+ break;
+ return i;
+}
--- /dev/null
+/*
+ pqueue.hh -- declare
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+
+#ifndef PQUEUE_HH
+#define PQUEUE_HH
+
+#include "varray.hh"
+
+/**
+ Stupid Prioq. Should use Lists and STL.
+ Smallest is put at the front.
+ */
+
+template<class V, class I>
+struct PQueue
+{
+ Array<V> value_arr_;
+ Array<I> indices_arr_;
+
+ void enter(V v, I idx) {
+ int j=0;
+ for (; j < value_arr_.size(); j++)
+ if (indices_arr_[j] > idx)
+ break;
+
+ value_arr_.insert(v, j);
+ indices_arr_.insert(idx, j);
+ }
+ int size() { return value_arr_.size(); }
+ V front_val() { return value_arr_[0]; }
+ I front_idx() { return indices_arr_[0]; }
+ V get() {
+ V retval = front_val();
+ value_arr_.del(0);
+ indices_arr_.del(0);
+ return retval;
+ }
+
+};
+#endif // PQUEUE_HH
--- /dev/null
+#include <Rational.h>
--- /dev/null
+#ifndef REAL_HH
+#define REAL_HH
+
+
+#include <builtin.h>
+#include <minmax.h>
+#include <math.h>
+
+typedef double Real;
+
+inline Real
+distance(Real x,Real y)
+{
+ return abs(x-y);
+}
+#endif
--- /dev/null
+/*
+ scalar.hh -- part of LilyPond
+
+ (c) 1996 Han-Wen Nienhuys
+*/
+
+#ifndef SCALAR_HH
+#define SCALAR_HH
+#include "string.hh"
+#include "real.hh"
+
+/// Perl -like scalar type.
+struct Scalar : public String {
+
+ Scalar(Real r) : String(r) {}
+ Scalar(int i) : String(i) {}
+ Scalar(char c) : String(c) {}
+ Scalar(const char *c) : String(c) {}
+ Scalar(String s ):String(s) {}
+ Scalar(Rational );
+ operator Rational();
+ Scalar() {}
+ bool isnum();
+ operator Real();
+ operator int();
+
+ /** perl -like string to bool conversion.
+ */
+ operator bool() const;
+
+};
+
+#endif // SCALAR_HH
+
--- /dev/null
+#ifndef SMAT_HH
+#define SMAT_HH
+#include "varray.hh"
+#include "vsmat.hh"
+#include "real.hh"
+/// simplest matrix storage. refer to its baseclass for the doco.
+class Full_storage : public virtual_smat
+{
+ /// height, width
+ int h,w;
+ /// maxima.
+ int maxh, maxw;
+
+ /// the storage
+ Real** els;
+ void
+ init() {
+ els=0;
+ h=w=maxh=maxw=0;
+
+ }
+
+ bool valid(int i, int j) const {
+ return (i>=0 && i < h)
+ && (j < w && j >=0);
+ }
+
+
+ void resize_rows(int);
+ void resize_cols(int);
+
+public:
+ virtual int rows() const {
+ return h;
+ }
+ virtual int cols() const {
+ return w;
+ }
+
+
+ virtual void set_size(int i, int j)
+ {
+ resize(i,j); //this could be more efficient.
+ }
+
+ virtual void set_size(int i) {
+ set_size(i,i);
+ }
+ virtual void resize(int i, int j);
+ virtual void resize(int i) {
+ resize(i,i);
+ }
+
+ virtual Real& elem(int i,int j) {
+ assert(valid(i,j));
+ return els[i][j];
+ }
+ virtual const Real& elem(int i, int j) const {
+ assert(valid(i,j));
+ return els[i][j];
+ }
+ virtual Array<Real> row(int i) const;
+ virtual Array<Real> column(int j) const;
+
+ Full_storage() {
+ init();
+ }
+ Full_storage(int i, int j) {
+ init();
+ set_size(i,j);
+ }
+ Full_storage(Full_storage&);
+ Full_storage(int i) {
+ init();
+ set_size(i);
+ }
+ void OK() const;
+ void operator=(Full_storage const &);
+
+ virtual void insert_row(int k);
+ virtual void delete_row(int k);
+ virtual void delete_column(int k);
+
+
+ ~Full_storage();
+ virtual bool mult_ok(int i, int j)const;
+ virtual void mult_next(int &i, int &j) const ;
+ virtual bool trans_ok(int i, int j) const;
+ virtual void trans_next(int &i, int &j) const;
+ virtual virtual_smat * clone();
+};
+
+#endif
--- /dev/null
+/*
+ PROJECT: FlowerSoft C++ library
+ FILE : string-convert.hh
+
+*/
+
+#ifndef STRING_CONVERT_HH
+#define STRING_CONVERT_HH
+
+/*
+ ///a class which only has functions.
+//#define functor class // cute. docxx fucks up
+*/
+
+/**
+ The functor String_convert handles all conversions to/from String (some
+ time, anyway).
+ The class is quite empty from data view.
+ */
+class String_convert {
+ static int hex2bin_i( String hex_str, String& bin_str_r );
+ static int hex2nibble_i( Byte byte );
+ static Byte nibble2hex_byte( Byte byte );
+public:
+ static String bin2dec_str( String bin_str );
+ static String bin2hex_str( String bin_str );
+ static String dec2bin_str( String str );
+ static int bin2_i( String str );
+ static String char_str(char c, int n);
+ static int dec2_i( String dec_str );
+ static double dec2_f( String dec_str );
+ static String double_str(double f, char const* fmt=0);
+ static int hex2int_i( String str );
+ static String hex2bin_str( String str );
+ static String int_str(int i, char const *fmt=0 );
+ static String i2hex_str( int i, int length_i, char ch );
+ static String i2dec_str( int i, int length_i, char ch );
+ static String rational_str(Rational);
+ static String pointer_str(const void *);
+ static String longlong_str(long long , char const * fmt = 0);
+};
+
+#endif // __STRING_CONVERT_HH //
--- /dev/null
+/*
+ string-data.hh -- declare String_data
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+
+#ifndef STRINGDATA_HH
+#define STRINGDATA_HH
+
+
+/**Internal String struct.
+ the data itself. Handles simple tasks (resizing, resetting)
+ */
+class String_data {
+ // GNU malloc: storage overhead is 8 bytes anyway.
+
+friend class String_handle;
+ int maxlen; // maxlen is arraysize-1
+
+ int length_i_;
+ Byte* data_byte_p_;
+ int references;
+
+ /// init to ""
+ String_data();
+
+ /// init from src. Conservative allocation.
+ String_data(String_data const &src);
+
+ ~String_data();
+
+ /** POST: maxlen >= j.
+ @param j, maximum stringlength_i_.
+ contents thrown away.
+ */
+ void setmax(int j);
+
+ /** POST: maxlen >= j.
+ @param j, maximum stringlength_i_.
+ contents are kept if it grows.
+ */
+ void remax(int j);
+
+ /// check if writeable.
+ void OKW();
+
+ /// check state.
+ void OK();
+
+ /// reduce memory usage.
+ void tighten();
+
+ // assignment.
+ void set( Byte const* byte_c_l, int length_i );
+
+ void set( char const* ch_c_l );
+
+ /// concatenation.
+ void append( Byte const* byte_c_l, int length_i );
+
+ void operator += ( char const* ch_c_l );
+
+ char const* ch_c_l() const;
+
+ char* ch_l();
+
+ Byte const* byte_c_l() const;
+
+ // idem, non const
+ Byte* byte_l();
+
+ void trunc(int j);
+
+ /** access element. not really safe. Can alter length_i_ without
+ #String_data# knowing it. */
+ Byte &operator [](int j);
+ Byte operator [](int j) const;
+ bool is_binary_bo()const;
+};
+
+
+
+#ifdef STRING_UTILS_INLINED
+#ifndef INLINE
+#define INLINE inline
+#endif
+#include "string-data.inl"
+
+#endif
+
+
+#endif // STRING_DATA_HH
--- /dev/null
+/* -*-C++-*-
+ String_data.inl -- implement String_data
+
+ source file of Flower lib
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#ifndef STRINGDATA_INL
+#define STRINGDATA_INL
+
+#include <assert.h>
+#include <memory.h>
+
+#include "string-data.hh"
+const int INITIALMAX=8;
+
+#include <sys/types.h>
+
+INLINE void
+String_data::OKW()
+{
+ assert (references == 1);
+}
+
+INLINE void
+String_data::OK()
+{
+ assert(maxlen >= length_i_);
+ assert(bool(data_byte_p_));
+ assert(references >= 1);
+}
+
+
+INLINE
+String_data::String_data()
+{
+ references=0;
+ maxlen = INITIALMAX;
+ data_byte_p_ = new Byte[maxlen + 1];
+ data_byte_p_[0] = 0;
+ length_i_ = 0;
+}
+
+INLINE
+String_data::String_data(String_data const &src)
+{
+ references=0;
+ maxlen = length_i_ = src.length_i_;
+ data_byte_p_ = new Byte[maxlen+1]; // should calc GNU 8byte overhead.
+ memcpy( data_byte_p_, src.data_byte_p_, length_i_ + 1 );
+}
+
+INLINE
+String_data::~String_data()
+{
+ assert(references == 0);
+ delete[] data_byte_p_;
+}
+
+INLINE void
+String_data::setmax(int j)
+{
+ OKW();
+ if (j > maxlen) {
+ delete data_byte_p_;
+ maxlen = j;
+ data_byte_p_ = new Byte[maxlen + 1];
+
+ data_byte_p_[0] = 0;
+ length_i_ = 0;
+ }
+}
+
+/* this is all quite hairy:
+ update of length_i_
+ update of maxlen
+ alloc of buffer
+ copying of buffer
+ needs blondification:
+ split tasks
+ define change authority
+*/
+INLINE void
+String_data::remax(int j)
+{
+ OKW();
+ if (j > maxlen) {
+ Byte *p = new Byte[j + 1];
+ memcpy( p, data_byte_p_, ( maxlen <? length_i_ ) + 1 );
+ maxlen = j;
+ delete[] data_byte_p_;
+ data_byte_p_ = p;
+ }
+}
+
+INLINE void
+String_data::tighten()
+{ // should be dec'd const
+ maxlen = length_i_;
+ Byte *p = new Byte[maxlen + 1];
+ memcpy( p, data_byte_p_, length_i_ + 1 );
+ delete[] data_byte_p_;
+ data_byte_p_ = p;
+}
+// assignment.
+INLINE void
+String_data::set( Byte const* byte_c_l, int length_i )
+{
+ OKW();
+
+ assert( byte_c_l && byte_c_l != data_byte_p_);
+
+ length_i_ = length_i;
+ remax( length_i_ ); // copies too
+ memcpy( data_byte_p_, byte_c_l, length_i_ );
+ data_byte_p_[ length_i_ ] = 0;
+}
+
+INLINE
+void
+String_data::set( char const* ch_c_l )
+{
+ set( (Byte const*)ch_c_l, strlen( ch_c_l ) );
+}
+
+
+/// concatenation.
+INLINE void
+String_data::append( Byte const* byte_c_l, int length_i )
+{
+ OK();
+ OKW();
+ int old_i = length_i_;
+
+ length_i_ += length_i;
+ remax( length_i_ );
+ memcpy( data_byte_p_ + old_i, byte_c_l, length_i );
+ data_byte_p_[ length_i_ ] = 0;
+}
+
+INLINE
+void
+String_data::operator += ( char const* ch_c_l )
+{
+ append( (Byte const*)ch_c_l, strlen( ch_c_l ) );
+}
+
+
+
+INLINE
+char const*
+String_data::ch_c_l() const
+{
+ return (char const*)data_byte_p_;
+}
+INLINE char*
+String_data::ch_l()
+{
+ return (char*)data_byte_p_;
+}
+
+INLINE Byte const*
+String_data::byte_c_l() const
+{
+ return data_byte_p_;
+}
+
+INLINE Byte*
+String_data::byte_l()
+{
+ OKW();
+ return data_byte_p_;
+}
+
+INLINE
+void
+String_data::trunc(int j)
+{
+ OKW();
+ assert(j >= 0 && j <= length_i_);
+ data_byte_p_[j] = 0;
+ length_i_ = j;
+}
+
+INLINE bool
+String_data::is_binary_bo()const
+{
+// return !memchr(data_byte_p_, length_i_, 0);
+ return ( (int)strlen( (char const*)data_byte_p_ ) != length_i_ );
+}
+
+INLINE Byte&
+String_data::operator [](int j)
+{
+ assert(j >= 0 && j <= length_i_);
+ return data_byte_p_[j] ;
+}
+
+INLINE Byte
+String_data::operator [](int j) const
+{
+ assert(j >= 0 && j <= length_i_);
+ return data_byte_p_[j];
+}
+
+
+
+
+#endif // __STRING_UTIL_CC //
--- /dev/null
+/*
+ string-handle.hh -- declare String_handle
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+
+#ifndef STRINGHANDLE_HH
+#define STRINGHANDLE_HH
+#include "fproto.hh"
+
+
+/**
+ Reference counting for strings.
+
+ handles ref. counting, and provides a very thin interface using
+ Byte *
+
+ */
+class String_handle {
+ String_data* data;
+
+ /// decrease ref count. Named kind of like a Tanenbaum semafore
+ void down();
+
+ /// increase ref count
+ void up(String_data *d);
+
+ /** make sure data has only one reference.
+ POST: data->references == 1
+ */
+ void copy();
+
+public:
+ String_handle();
+ ~String_handle();
+ String_handle(String_handle const & src);
+
+ Byte const* byte_c_l() const;
+ char const* ch_c_l() const;
+ Byte* byte_l();
+ char* ch_l();
+ bool is_binary_bo()const;
+ void operator =(String_handle const &src);
+ void operator += (char const *s);
+ Byte operator[](int j) const;
+
+ /** Access elements. WARNING: NOT SAFE
+ don't use this for loops. Use byte_c_l()
+ */
+ Byte &operator[](int j);
+ void append( Byte const* byte_c_l, int length_i );
+ void set( Byte const* byte_c_l, int length_i );
+ void operator = (char const *p);
+ void trunc(int j);
+ int length_i() const;
+};
+
+#ifdef STRING_UTILS_INLINED
+#ifndef INLINE
+#define INLINE inline
+#endif
+#include "string-handle.inl"
+/* we should be resetting INLINE. oh well. */
+#endif
+
+
+#endif // STRINGHANDLE_HH
--- /dev/null
+/* -*-c++-*-
+
+ stringhandle.inl -- implement String_handle
+
+ source file of Flower lib
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#ifndef STRINGHANDLE_INL
+#define STRINGHANDLE_INL
+
+#include <assert.h>
+#include <memory.h>
+
+#include "string-data.hh"
+#include "string-handle.hh"
+
+INLINE void
+String_handle::down()
+{
+ if (!(--data->references)) delete data; data = 0;
+}
+
+/// increase ref count
+INLINE void
+String_handle::up(String_data *d)
+{
+ data=d; data->references ++;
+}
+
+INLINE void
+String_handle::copy()
+{
+ if (data->references !=1){
+ String_data *newdata = new String_data(*data);
+ down();
+ up(newdata);
+ }
+}
+
+INLINE
+String_handle::String_handle()
+{
+ up(new String_data);
+}
+
+INLINE
+String_handle::~String_handle()
+{
+ down();
+}
+
+INLINE
+String_handle::String_handle(String_handle const & src)
+{
+ up(src.data);
+}
+
+INLINE Byte*
+String_handle::byte_l()
+{
+ copy();
+ return data->byte_l();
+}
+
+INLINE char*
+String_handle::ch_l()
+{
+ copy();
+ return (char*)data->byte_l();
+}
+
+INLINE Byte
+const* String_handle::byte_c_l() const
+{
+ return data->byte_c_l();
+}
+
+INLINE char const*
+String_handle::ch_c_l() const
+{
+ return (char const*)data->byte_c_l();
+}
+
+INLINE void
+String_handle::operator =(String_handle const &src)
+{
+ if (this == &src)
+ return;
+ down();
+ up(src.data);
+}
+
+INLINE void
+String_handle::operator += (char const *s)
+{
+ copy();
+ *data += s;
+}
+
+
+INLINE Byte
+String_handle::operator[](int j) const
+{
+ return (*data)[j];
+}
+
+// !NOT SAFE!
+// don't use this for loops. Use byte_c_l()
+INLINE Byte &
+String_handle::operator[](int j)
+{
+ copy(); // hmm. Not efficient
+ return data->byte_l()[j];
+}
+
+INLINE void
+String_handle::append( Byte const* byte_c_l, int length_i )
+{
+ copy();
+ data->append( byte_c_l, length_i );
+}
+
+INLINE void
+String_handle::set( Byte const* byte_c_l, int length_i )
+{
+ copy();
+ data->set( byte_c_l, length_i );
+}
+
+INLINE void
+String_handle::operator = (char const *p)
+{
+ copy();
+ data->set( p );
+}
+
+INLINE void
+String_handle::trunc(int j)
+{
+ copy(); data->trunc(j);
+}
+
+INLINE int
+String_handle::length_i() const
+{
+ return data->length_i_;
+}
+
+INLINE bool
+String_handle::is_binary_bo() const {
+ return data->is_binary_bo();
+}
+
+#endif
--- /dev/null
+/*
+
+ FILE : string.hh -- declare String
+
+ Rehacked by HWN 3/nov/95
+ removed String & 's
+ introduced Class String_handle
+ */
+
+#ifndef STRING_HH
+#define STRING_HH
+
+
+#include <string.h>
+#include <iostream.h>
+#include <Rational.h>
+
+#include "string-handle.hh"
+
+/**
+
+ Intuitive string class. provides
+\begin{itemize}
+\item
+ ref counting through #String_handle#
+\item
+ conversion from bool, int, double, char* , char.
+\item
+ to be moved to String_convert:
+ conversion to int, upcase, downcase
+
+\item
+ printable.
+
+\item
+ indexing (index_i, index_any_i, last_index_i)
+
+\item
+ cutting (left_str, right_str, mid_str)
+
+\item
+ concat (+=, +)
+
+\item
+ signed comparison (<, >, ==, etc)
+
+\item
+ No operator[] is provided, since this would be enormously slow. If needed,
+ convert to char const* .
+\end{itemize}
+
+*/
+class String
+{
+protected:
+ String_handle strh_;
+
+ bool null_terminated();
+
+public:
+
+ /** init to empty string. This is needed because other
+ constructors are provided.*/
+ String() { }
+ String(Rational);
+
+ /// String s = "abc";
+ String( char const* source );
+ String( Byte const* byte_c_l, int length_i );
+
+ /// "ccccc"
+ String( char c, int n = 1 );
+
+ String( int i , char const *fmt=0);
+ String ( double f , char const* fmt =0);
+ /// 'true' or 'false'
+ String(bool );
+
+ /// return a "new"-ed copy of contents
+ Byte* copy_byte_p() const; // return a "new"-ed copy of contents
+
+ char const* ch_c_l() const;
+ Byte const* byte_c_l() const;
+ char* ch_l();
+ Byte* byte_l();
+
+ /// deprecated; use ch_c_l()
+ operator char const* () const { return ch_c_l(); }
+
+ String &operator =( const String & source );
+
+ /// concatenate s
+ void operator += (char const* s) { strh_ += s; }
+ void operator += (String s);
+
+ void append(String);
+ void prepend(String);
+
+ char operator []( int n ) const { return strh_[n]; }
+
+ /// return n leftmost chars
+ String left_str( int n ) const;
+
+ /// return n rightmost chars
+ String right_str( int n ) const;
+
+ /// return uppercase of *this
+ String upper_str() const;
+
+ /// return lowercase of *this
+ String lower_str() const;
+
+ /// return the "esrever" of *this
+ String reversed_str() 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_str(int index_i, int n ) const;
+
+ /// signed comparison, analogous to memcmp;
+ static int compare_i(const String& s1,const String& s2);
+
+ /// index of rightmost c
+ int index_last_i( char c) const;
+
+ /// index of rightmost element of string
+ int index_last_i( char const* string ) const;
+
+ int index_i(char c ) const;
+ int index_i(String ) const;
+ int index_any_i(String ) const;
+
+ void to_upper();
+ void to_lower();
+ /// provide Stream output
+ void print_on(ostream& os) const;
+
+ /// the length of the string
+ int length_i() const;
+
+ // ***** 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_i);
+
+// 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==(char const* s1, String s2)
+{
+ return String(s1)==s2;
+}
+inline bool operator!=(String s1, char const* s2 ) {
+ return s1!=String(s2);
+}
+inline bool operator!=(char const* s1,String s2) {
+ return String(s2) !=s1;
+}
+
+
+inline String
+operator + (String s1, String s2)
+{
+ s1 += s2;
+ return s1;
+}
+
+inline ostream &
+operator << ( ostream& os, String d )
+{
+ d.print_on(os);
+ return os;
+}
+
+
+// String quoteString(String message, String quote);
+
+#endif
--- /dev/null
+#ifndef TEXTDB_HH
+#define TEXTDB_HH
+
+#include "data-file.hh"
+
+/**a "const" Array. Contents can't be changed. do "#" comments, read quote enclosed fields */
+
+class Text_record : Array<String>
+{
+ int line_no;
+ String filename;
+
+public:
+ Text_record() { } // needed because of other ctor
+
+ /// report an error in this line.
+ message(String s) {
+ cerr << '\n'<< filename << ": "<< line_no << s << "\n";
+ }
+ String operator[](int j) {
+ return Array<String>::operator[](j);
+ }
+
+ Text_record(Array<String> s, String fn, int j) : Array<String>(s) {
+ filename = fn; line_no = j;
+ }
+ Array<String>::size;
+};
+
+/** abstraction for a datafile.
+ add a subrec/fieldsep/record separator
+ */
+
+class Text_db : private Data_file
+{
+ void gobble_leading_white();
+public:
+ /// get a line with records
+ Text_record get_record();
+
+ Text_db(String fn):Data_file(fn) { }
+ Data_file::error;
+ bool eof();
+
+ /// get next line.
+ Text_record operator++(int) {
+ return get_record();
+ }
+ /// are we done yet?
+ operator bool() {
+ return !eof();
+ }
+};
+
+#endif
--- /dev/null
+
+#ifndef TEXTSTR_HH
+#define TEXTSTR_HH
+
+#include <stdio.h>
+#include <ctype.h>
+#include "string.hh"
+#include "varray.hh"
+
+/**
+ line counting input stream.
+ a stream for textfiles. linecounting. Thin interface getchar and
+ ungetchar. (ungetc is unlimited)
+
+ should protect get and unget against improper use
+*/
+
+
+class Text_stream
+{
+ int line_no;
+
+ // could just have used streams.
+ FILE *f;
+ Array<char> pushback;
+ String name;
+
+ public:
+ Text_stream(String fn);
+ String get_name() { return name; }
+ bool eof() {
+ return feof(f);
+ }
+ bool eol() {
+ return (peek() == '\n');
+ }
+ char peek() {
+ char c = get();
+ unget(c);
+ return c;
+ }
+ int line(){
+ return line_no;
+ }
+
+ char get() {
+ char c;
+
+ if (pushback.empty())
+ c = getc(f);
+ else
+ c = pushback.pop();
+
+ if (c =='\n')
+ line_no++;
+ return c;
+ }
+ void unget(char c) {
+ if (c =='\n')
+ line_no--;
+ pushback.push(c);
+ }
+ ~Text_stream (){
+ if (!eof())
+ cerr <<__FUNCTION__<< ": closing unended file";
+
+ fclose(f);
+ }
+
+ /// GNU format message.
+ void message(String s);
+};
+
+#endif
--- /dev/null
+#ifndef UNIONFIND_HH
+#define UNIONFIND_HH
+#include "varray.hh"
+
+/*
+ which points of a graph are connected?.
+ Union find, a standard algorithm:
+
+ Union_find represents an undirected graph of N points. You can
+ connect two points using #connect()#. #find(i)# finds a uniquely
+ determined representant of the equivalence class of points
+ connected to #i#.
+
+ */
+struct Union_find {
+ void connect(int i, int j);
+ int find(int i);
+ bool equiv(int i, int j) { return find(i) == find(j); }
+ Union_find(int sz);
+
+private:
+ Array<int> classes;
+
+};
+#endif
--- /dev/null
+/*
+ (c) Han-Wen Nienhuys 1995,96
+
+ Distributed under GNU GPL
+*/
+
+#ifndef ARRAY_H
+#define ARRAY_H
+#include <assert.h>
+
+/// copy a bare (C-)array from #src# to #dest# sized #count#
+template<class T>
+inline void arrcpy(T*dest, T*src, int count) {
+ for (int i=0; i < count ; i++)
+ *dest++ = *src++;
+}
+
+
+/**
+ Scaleable array/stack template, for a type T with default constructor.
+
+
+ This template implements a scaleable vector. With (or without) range
+ checking. It may be flaky for objects with complicated con- and
+ destructors. The type T should have a default constructor. It is
+ best suited for simple types, such as int, double or String, it
+ provides a paranoidly safe replacement for the new T[int] construct.
+
+ It uses stack terminology, (push, pop, top), and can be used as a stack.
+
+
+ */
+template<class T>
+class Array {
+protected:
+ /// maximum length of array.
+ int max;
+
+ /// the data itself
+ T *thearray;
+
+ /// stretch or shrink array.
+ void remax(int newmax) {
+ T* newarr = new T[newmax];
+ size_ = (newmax < size_) ? newmax : size_;
+ arrcpy(newarr, thearray, size_);
+
+ delete[] thearray;
+ thearray = newarr;
+ max = newmax;
+ }
+ int size_;
+
+public:
+ /// check invariants
+ void OK() const {
+ assert(max >= size_ && size_ >=0);
+ if (max) assert(thearray);
+ }
+ /** report the size_.
+ @see {setsize_}
+ */
+ int size() const { return size_; }
+
+ /// POST: size() == 0
+ void clear() { size_ = 0; }
+
+ Array() { thearray = 0; max =0; size_ =0; }
+
+
+ /** set the size_ to #s#.
+ POST: size() == s.
+ Warning: contents are unspecified */
+ void set_size(int s) {
+ if (s >= max) remax(s);
+ size_ = s;
+ }
+
+ ~Array() { delete[] thearray; }
+
+ /// return a "new"ed copy of array
+ T* copy_array() const {
+ T* Tarray = new T[size_];
+ arrcpy(Tarray, thearray, size_);
+ return Tarray;
+ }
+ // depracated
+ operator T* () const {
+ return copy_array();
+ }
+ void operator=(Array const & src) {
+ set_size (src.size_);
+ arrcpy(thearray,src.thearray, size_);
+ }
+ Array(const Array & src) {
+ thearray = src.copy_array();
+ max = size_ = src.size_;
+ }
+
+ /// tighten array size_.
+ void precompute () { remax(size_); }
+
+ /// this makes Array behave like an array
+ T &operator[] (const int i) const {
+ assert(i >=0&&i<size_);
+ return ((T*)thearray)[i];
+ }
+
+ /// add to the end of array
+ void push(T x) {
+ if (size_ == max)
+ remax(2*max + 1);
+
+ // T::operator=(T &) is called here. Safe to use with automatic
+ // vars
+ thearray[size_++] = x;
+ }
+ /// remove and return last entry
+ T pop() {
+ assert(!empty());
+ T l = top(0);
+ set_size(size()-1);
+ return l;
+ }
+ /// access last entry
+ T& top(int j=0) {
+ return (*this)[size_-j-1];
+ }
+ /// return last entry
+ T top (int j=0) const {
+ return (*this)[size_-j-1];
+ }
+
+
+ void swap (int i,int j) {
+ T t((*this)[i]);
+ (*this)[i]=(*this)[j];
+ (*this)[j]=t;
+ }
+ bool empty() { return !size_; }
+ void insert(T k, int j) {
+ assert(j >=0 && j<= size_);
+ set_size(size_+1);
+ for (int i=size_-1; i > j; i--)
+ thearray[i] = thearray[i-1];
+ thearray[j] = k;
+ }
+ void del(int i) {
+ assert(i >=0&& i < size_);
+ arrcpy(thearray+i, thearray+i+1, size_-i-1);
+ size_--;
+ }
+ // quicksort.
+ void sort (int (*compare)( T const&,T const&),
+ int lower = -1, int upper = -1 ) {
+ if (lower < 0) {
+ lower = 0 ;
+ upper = size()-1;
+ }
+ if (lower >= upper)
+ return;
+ swap(lower, (lower+upper)/2);
+ int last = lower;
+ for (int i= lower +1; i <= upper; i++)
+ if (compare(thearray[i], thearray[lower]) < 0 )
+ swap( ++last,i);
+ swap(lower, last);
+ sort(compare, lower, last-1);
+ sort(compare, last+1, upper);
+ }
+ void concat(Array<T> const &src) {
+ int s = size_;
+ set_size(size_ + src.size_);
+ arrcpy(thearray+s,src.thearray, src.size_);
+ }
+ Array<T> subvec(int lower, int upper) {
+ assert(lower >= 0 && lower <=upper&& upper <= size_);
+ Array<T> r;
+ int s =upper-lower;
+ r.set_size(s);
+ arrcpy(r.thearray, thearray + lower, s);
+ return r;
+ }
+};
+
+#endif
--- /dev/null
+#ifndef VECTOR_HH
+#define VECTOR_HH
+
+#include <math.h>
+#include "real.hh"
+#include "varray.hh"
+
+class Dstream;
+class String;
+void set_matrix_debug(Dstream&ds);
+
+/** a row of numbers.
+ a vector. Storage is handled in Array, Vector only does the mathematics.
+ */
+class Vector {
+ Array<Real> dat;
+public:
+ void OK() const { dat.OK();}
+ int dim() const { return dat.size(); }
+ Vector() { }
+ Vector(Array<Real> d );
+ Vector(const Vector&n);
+ Vector(int n) {
+ dat.set_size(n);
+ fill(0);
+ }
+ void insert(Real v, int i) {
+ dat.insert(v,i);
+ }
+ void del(int i) { dat.del(i); }
+ operator String() const;
+ void fill(Real r) {
+ for (int i=0; i < dim(); i++)
+ dat[i] =r;
+ }
+
+ void operator +=(Vector v) {
+ assert(v.dim() == dim());
+ for (int i=0; i < dim(); i++)
+ dat[i] += v.dat[i];
+ }
+
+ void operator /=(Real a) {
+ (*this) *= 1/a;
+ }
+
+ void operator *=(Real a) {
+ for (int i=0; i < dim(); i++)
+ dat[i] *= a;
+ }
+
+ void operator -=(Vector v) {
+ assert(v.dim() == dim());
+ for (int i=0; i < dim(); i++)
+ dat[i] -= v(i);
+ }
+
+ Real &operator()(int i) { return dat[i]; }
+ Real operator()(int i) const { return dat[i]; }
+ Real elem(int i) { return dat[i]; }
+ Real operator *(Vector v) const {
+ Real ip=0;
+ assert(v.dim() == dim());
+ for (int i=0; i < dim(); i++)
+ ip += dat[i] *v(i);
+ return ip;
+ }
+ Vector operator-() const;
+ Real norm() {
+ return sqrt(norm_sq() );
+ }
+ Real norm_sq() {
+ return ((*this) * (*this));
+ }
+ operator Array<Real> () { return dat; }
+ void print() const;
+ /// set to j-th element of unit-base
+ void set_unit(int j) ;
+};
+
+inline Vector
+operator+(Vector a, Vector const &b) {
+ a += b;
+ return a;
+}
+
+inline Vector
+operator-(Vector a, Vector const &b) {
+ a -= b;
+ return a;
+}
+
+inline Vector
+operator*(Vector v, Real a) {
+ v *= a;
+ return v;
+}
+
+inline Vector
+operator*( Real a,Vector v) {
+ v *= a;
+ return v;
+}
+
+inline Vector
+operator/(Vector v,Real a) {
+ v *= 1/a;
+ return v;
+}
+
+#endif
--- /dev/null
+#ifndef VSMAT_HH
+#define VSMAT_HH
+#include "varray.hh"
+#include "real.hh"
+/** base class for interface with matrix storageclasses. There are no
+ iterators for matrixclasses, since matrices are (like arrays)
+ explicitly int-indexed.
+
+ Iteration is provided by *_next, *_ok, which update and check both
+ index variables simultaneously.
+
+ TODO
+ determine type of product matrix.
+
+*/
+class virtual_smat {
+
+
+public:
+ /// check invariants
+ virtual void OK() const=0;
+
+ /// height of matrix
+ virtual int rows() const = 0;
+
+ /// width of matrix
+ virtual int cols() const = 0;
+
+
+ /** set the size. contents lost.
+ PRE
+ i >=0, j>=0
+ */
+ virtual void set_size(int i, int j) = 0;
+
+ /**set the size to square dimen. contents lost
+ PRE
+ i>=0
+ */
+ virtual void set_size(int i) = 0;
+ /**set the size to i.
+
+ keep contents. If enlarged contents unspecified
+
+ PRE
+ i>=0, j>=0
+
+ */
+ virtual void resize(int i, int j) = 0;
+
+ /**
+ set the size to square dimen. contents kept
+ Keep contents. If enlarged contents are unspecified
+
+ PRE
+ i>=0
+ */
+ virtual void resize(int i) = 0;
+
+
+ /**
+ access an element.
+
+ Generate an errormessage, if this happens
+ in the 0-part of a sparse matrix.
+ */
+
+ virtual Real& elem(int i,int j) = 0;
+
+ /// access a element, no modify
+ virtual const Real& elem(int i, int j) const = 0;
+
+#if 1
+ virtual Array<Real> row(int i) const = 0;
+ virtual Array<Real> column(int j) const = 0;
+#endif
+
+
+ /**
+ add a row to the matrix before row k. Contents
+ of added row are unspecified
+
+ 0 <= k <= rows()
+ */
+ virtual void insert_row(int k)=0;
+
+
+ /**
+ delete a row from this matrix.
+
+ PRE
+ 0 <= k < rows();
+ */
+ virtual void delete_row(int k)=0;
+ virtual void delete_column(int k)=0;
+ virtual ~virtual_smat() { }
+ virtual virtual_smat *clone()=0;
+
+
+
+ /**
+ at end of matrix?. when doing loop
+
+ for(i=0; i<h; i++)
+ for(j=0; j<w; j++)
+ ..
+
+ */
+ virtual bool mult_ok(int i, int j) const=0;
+
+ /**
+ walk through matrix (regular multiply).
+ get next j for row i, or get next row i and reset j.
+ this will make sparse matrix implementation easy.
+
+ PRE
+ mult_ok(i,j)
+ */
+ virtual void mult_next(int &i, int &j) const = 0;
+
+/**
+ valid matrix entry. return false if at end of row
+ */
+ virtual bool trans_ok(int i, int j) const=0;
+
+ /**
+ walk through matrix (transposed multiply).
+ Get next i (for column j)
+
+ PRE
+ ver_ok(i,j)
+ */
+
+ virtual void trans_next(int &i, int &j) const = 0;
+ /// generate a "Full_storage" matrix
+ static virtual_smat *get_full(int n, int m);
+
+};
+
+
+#endif
--- /dev/null
+/*
+ process command line, GNU style.
+
+ this is (Copyleft) 1996, Han-Wen Nienhuys, <hanwen@stack.nl>
+ */
+#include <stdio.h>
+#include <iostream.h>
+#include <assert.h>
+#include "lgetopt.hh"
+
+long
+Getopt_long::intarg()
+{
+ long l;
+ if (sscanf(optarg, "%ld", &l) != 1)
+ report(E_ILLEGALARG);
+
+ return l;
+}
+
+Long_option_init *
+Getopt_long::parselong()
+{
+ const char *optnm = argv[optind] + 2 ;
+ assert(*optnm);
+
+ char *endopt = strchr(optnm, '=');
+ int searchlen = (endopt) ? endopt - optnm : strlen(optnm);
+
+ beet=0;
+ for (int i=0; i< table_len; i++) {
+ const char *ln = the_opts[i].longname;
+
+ if (ln && !strncmp(ln, optnm, searchlen)) {
+ beet = the_opts+i;
+ break;
+ }
+ }
+
+ if (!beet) {
+ report(E_UNKNOWNOPTION);
+ return 0;
+ }
+ optind++;
+ optindind = 0;
+
+
+ if (beet->take_arg) {
+ if (endopt)
+ optarg = endopt +1; // a '='
+ else {
+ optarg = argv[optind];
+ optind++;
+ }
+ if (!optarg)
+ report(E_ARGEXPECT);
+
+ } else {
+ optarg = 0;
+ if (endopt)
+ report(E_NOARGEXPECT);
+ }
+
+ return beet;
+}
+
+
+ostream &
+Long_option_init::printon(ostream &errorout)
+{
+ if (shortname)
+ errorout <<"-" << shortname;
+ if (shortname && longname)
+ errorout << ", ";
+ if (longname)
+ errorout << "`--" << longname << "'";
+ return errorout;
+}
+
+// report an error, GNU style.
+void
+Getopt_long::report(Errorcod c)
+{
+ error = c;
+ if (!errorout)
+ return;
+
+ *errorout << argv[0] << ": ";
+ switch (c) {
+ case E_ARGEXPECT:
+ *errorout<< "option ";
+ beet->printon(*errorout);
+ *errorout << "requires an argument"<<endl;
+ break;
+ case E_NOARGEXPECT:
+ *errorout << "option `--" <<
+ beet->longname << "' does not allow an argument"<<endl;
+ break;
+
+ case E_UNKNOWNOPTION:
+ *errorout << "unrecognized option ";
+ if (optindind)
+ *errorout << "-" << argv[optind][optindind] << endl;
+ else
+ *errorout << argv[optind] << endl;
+
+ break;
+ case E_ILLEGALARG:
+ *errorout << "illegal argument `" << optarg << "\'to option ";
+ beet->printon(*errorout);
+ *errorout << '\n';
+ default:
+ assert(false);
+ }
+ exit(2);
+}
+
+Long_option_init *
+Getopt_long::parseshort()
+{
+ char c=argv[optind][optindind];
+ beet=0;
+ assert(c);
+
+ for (int i=0; i < table_len; i++)
+ if (the_opts[i].shortname == c) {
+ beet = the_opts+i;
+ break;
+ }
+
+ if (!beet){
+ report(E_UNKNOWNOPTION);
+ return 0;
+ }
+
+ optindind++;
+ if (!beet->take_arg){
+ optarg = 0;
+ return beet;
+ }
+ optarg = argv[optind] + optindind;
+
+ optind ++;
+ optindind = 0;
+
+ if (!optarg[0]) {
+ optarg = argv[optind];
+ optind ++;
+ }
+ if (!optarg) {
+ report(E_ARGEXPECT);
+ }
+
+ return beet;
+}
+
+Long_option_init *
+Getopt_long::operator()() {
+ if (!next())
+ return 0;
+
+ if (optindind)
+ return parseshort();
+
+ if (argv[optind][0] != '-')
+ return 0;
+
+ if (argv[optind][1] == '-') {// what to do with "command -- bla"
+ return parselong();
+ } else {
+ optindind = 1;
+ return parseshort();
+ }
+}
+
+Getopt_long::Getopt_long(int c, char **v, Long_option_init *lo)
+{
+ the_opts = lo;
+ errorout = &cerr;
+ argv = v;
+ argc = c;
+ optind = 1;
+ optindind = 0;
+
+ // reached end of option table?
+ int i;
+ for (i = 0; the_opts[i].longname ||the_opts[i].shortname; i++)
+ ;
+ table_len = i;
+}
+
+bool
+Getopt_long::next()
+{
+
+ error = E_NOERROR;
+ while (optind < argc && !argv[optind][optindind]) {
+ optind++;
+ optindind = 0;
+ }
+ return (optind < argc);
+}
+
+char *
+Getopt_long::current_arg()
+{
+ if (optind >= argc)
+ return 0;
+ char * a = argv[optind];
+ return a + optindind;
+}
+
+char *
+Getopt_long::get_next_arg()
+{
+ char * a = current_arg();
+ if ( a) {
+ optind ++;
+ optindind = 0;
+ }
+ return a;
+}
--- /dev/null
+/*
+ libc-extension.cc -- implement some string.h extensions
+
+ source file of the flowerlib
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+#include <stdarg.h>
+#include <string.h>
+#include <ctype.h>
+#include "libc-extension.hh"
+
+/*
+ compensate for lacking libc functions.
+ */
+char*
+strnlwr( char* start_l ,int n)
+{
+ char * p = start_l + n;
+ while ( --p >= start_l) {
+ *p = tolower( *p ); /* a macro on some compilers */
+ }
+ return start_l;
+}
+
+char*
+strnupr( char* start_l, int n)
+{
+ char * p = start_l + n;
+ while ( --p >= start_l) {
+ *p = toupper( *p ); /* a macro on some compilers */
+ }
+ return start_l;
+}
+
+#ifndef HAVE_MEMMEM
+
+/** locate a substring. #memmem# finds the first occurrence of
+ #needle# in #haystack#
+ */
+
+char *
+memmem(const Byte * haystack, int haystack_len,
+ const Byte *needle,int needle_len)
+{
+ const Byte * end_haystack = haystack + haystack_len - needle_len;
+ const Byte * end_needle = needle + needle_len ;
+
+ /* Ahhh ... Some minimal lowlevel stuff. This *is* nice; Varation
+ is the spice of life */
+ while (haystack < end_haystack) {
+ const Byte *subneedle_l = needle;
+ const Byte *subhaystack_l = haystack;
+ while (subneedle_l < end_needle) {
+ if (*subneedle_l++ != *subhaystack_l++)
+ goto next; // yeah. I should be prosecuted.
+ }
+
+ // completed the needle. Gotcha.
+ return (char*) haystack;
+ next:
+ haystack++;
+ }
+ return 0;
+}
+#endif
+
+Byte *
+memrchr(const Byte * p, int n, char c)
+{
+ const Byte * q = p+n;
+ while (q > p) {
+ if (*--q == c)
+ return (Byte*)q;
+ }
+ return 0;
+}
+
+
+template<class T>
+inline void
+my_swap(T &t1, T &t2, T &tmp)
+{
+ tmp = t1;
+ t1 = t2;
+ t2 = tmp;
+}
+
+Byte*
+strrev( Byte* byte_l, int length_i )
+{
+ Byte tmp_byte;
+
+ Byte* left_l = byte_l;
+ Byte* right_l = byte_l + length_i;
+
+ while ( right_l > left_l ) {
+ my_swap(*right_l-- , *left_l++ , tmp_byte);
+ }
+ return byte_l;
+}
+
+#ifndef HAVE_SNPRINTF
+int snprintf ( char *str, size_t n,
+ const char *format, ... )
+{
+ va_list ap;
+ va_start(ap, format);
+ int i = vsprintf(str, format, ap);
+ va_end(ap);
+ return i;
+}
+#endif
--- /dev/null
+#include "dstream.hh"
+#include "matrix.hh"
+
+static Dstream *dout = 0;
+
+/**
+ Set the debugging output. Will not delete/swallow argument.
+ */
+void set_matrix_debug(Dstream&ds)
+{
+ dout = &ds;
+}
+
+Matrix::operator String() const
+{
+ String s;
+#ifndef NPRINT
+ s="matrix {\n";
+ for (int i=0; i< rows(); i++){
+ for (int j = 0; j < cols(); j++) {
+ s+= String(dat->elem(i,j), "%6f ");
+ }
+ s+="\n";
+ }
+ s+="}\n";
+#endif
+ return s;
+}
+
+
+void
+Matrix::print() const
+{
+#ifndef NPRINT
+ if (!dout)
+ return;
+ *dout << *this;
+#endif
+}
+
+Vector::operator String() const
+{
+ String s;
+#ifndef NPRINT
+ s="vector [";
+ for (int i=0; i < dim(); i++) {
+ s += String(dat[i], "%6f") + String(' ');
+ }
+ s+="]";
+#endif
+ return s;
+}
+
+
+void
+Vector::print() const
+{
+#ifndef NDEBUG
+ if (!dout)
+ return;
+ *dout << *this<<'\n';
+#endif
+}
--- /dev/null
+#include "matrix.hh"
+
+Real
+Matrix::norm() const
+{
+ Real r =0.0;
+ for (int i=0, j=0; dat->mult_ok(i,j); dat->mult_next(i,j))
+ r += sqr(dat->elem(i,j));
+ return sqrt(r);
+}
+
+void
+Matrix::fill(Real r)
+{
+ for (int i=0, j=0; dat->mult_ok(i,j); dat->mult_next(i,j))
+ dat->elem(i,j)=r;
+}
+
+void
+Matrix::set_diag(Real r)
+{
+ for (int i=0, j=0; dat->mult_ok(i,j); dat->mult_next(i,j))
+ dat->elem(i,j)=(i==j) ? r: 0.0;
+}
+
+void
+Matrix::set_diag(Vector d)
+{
+ for (int i=0, j=0; dat->mult_ok(i,j); dat->mult_next(i,j))
+ dat->elem(i,j)=(i==j) ? d(i): 0.0;
+}
+
+void
+Matrix::operator+=(const Matrix&m)
+{
+ assert(m.cols() == cols());
+ assert(m.rows() == rows());
+ for (int i=0, j=0; dat->mult_ok(i,j); dat->mult_next(i,j))
+ dat->elem(i,j) += m(i,j);
+}
+
+void
+Matrix::operator-=(const Matrix&m)
+{
+ assert(m.cols() == cols());
+ assert(m.rows() == rows());
+ for (int i=0, j=0; dat->mult_ok(i,j); dat->mult_next(i,j))
+ dat->elem(i,j) -= m(i,j);
+}
+
+
+void
+Matrix::operator*=(Real a)
+{
+ for (int i=0, j=0; dat->mult_ok(i,j); dat->mult_next(i,j))
+ dat->elem(i,j) *= a;
+}
+
+void
+Matrix::operator=(const Matrix&m)
+{
+ if (&m == this)
+ return ;
+ delete dat;
+ dat = m.dat->clone();
+}
+
+Matrix::Matrix(const Matrix &m)
+{
+ m.OK();
+
+ dat = m.dat->clone();
+}
+
+
+Matrix::Matrix(int n, int m)
+{
+ dat = virtual_smat::get_full(n,m);
+ fill(0);
+}
+
+Matrix::Matrix(int n)
+{
+ dat = virtual_smat::get_full(n,n);
+ fill(0);
+}
+
+Matrix::Matrix(Vector v, Vector w)
+{
+ dat = virtual_smat::get_full(v.dim(), w.dim());
+ for (int i=0, j=0; dat->mult_ok(i,j); dat->mult_next(i,j))
+ dat->elem(i,j)=v(i)*w(j);
+}
+
+
+Vector
+Matrix::row(int k) const
+{
+ int n=cols();
+
+
+ Vector v(n);
+ for(int i=0; i < n; i++)
+ v(i)=dat->elem(k,i);
+
+ return v;
+}
+
+Vector
+Matrix::col(int k) const
+{
+ int n=rows();
+ Vector v(n);
+ for(int i=0; i < n; i++)
+ v(i)=dat->elem(i,k);
+ return v;
+}
+
+Vector
+Matrix::left_multiply(const Vector& v) const
+{
+ Vector dest(v.dim());
+ assert(dat->cols()==v.dim());
+ for (int i=0, j=0; dat->mult_ok(i,j); dat->mult_next(i,j))
+ dest(i)+= dat->elem(j,i)*v(j);
+ return dest;
+}
+
+Vector
+Matrix::operator *(const Vector& v) const
+{
+ Vector dest(rows());
+ assert(dat->cols()==v.dim());
+ for (int i=0, j=0; dat->mult_ok(i,j); dat->mult_next(i,j))
+ dest(i)+= dat->elem(i,j)*v(j);
+ return dest;
+}
+
+Matrix
+operator /(Matrix const& m1,Real a)
+{
+ Matrix m(m1);
+ m /= a;
+ return m;
+}
+
+void
+Matrix::transpose() // delegate to storage?
+{
+ for (int i=0, j=0; dat->mult_ok(i,j); dat->mult_next(i,j)) {
+ if (i >= j)
+ continue;
+ Real r=dat->elem(i,j);
+ dat->elem(i,j) = dat->elem(j,i);
+ dat->elem(j,i)=r;
+ }
+}
+
+Matrix
+Matrix::operator-() const
+{
+ OK();
+ Matrix m(*this);
+ m*=-1.0;
+ return m;
+}
+
+Matrix
+Matrix::transposed() const
+{
+ Matrix m(*this);
+ m.transpose();
+ return m;
+}
+
+
+/* should do something smarter: bandmatrix * bandmatrix is also banded matrix. */
+Matrix
+operator *(const Matrix &m1, const Matrix &m2)
+{
+ Matrix result(m1.rows(), m2.cols());
+ result.set_product(m1,m2);
+ return result;
+}
+
+void
+Matrix::set_product(const Matrix &m1, const Matrix &m2)
+{
+ assert(m1.cols()==m2.rows());
+ assert(cols()==m2.cols() && rows()==m1.rows());
+
+ for (int i=0, j=0; dat->mult_ok(i,j);
+ dat->mult_next(i,j)) {
+ Real r=0.0;
+ for (int k = 0; k < m1.cols(); k++)
+ r += m1(i,k)*m2(k,j);
+ dat->elem(i,j)=r;
+ }
+}
+
+void
+Matrix::insert_row(Vector v, int k)
+{
+ assert(v.dim()==cols());
+ dat->insert_row(k);
+ for (int j=0; j < cols(); j++)
+ dat->elem(k,j)=v(j);
+}
+
+
+void
+Matrix::swap_columns(int c1, int c2)
+{
+ assert(c1>=0&& c1 < cols()&&c2 < cols() && c2 >=0);
+ for (int i=0; i< rows(); i++) {
+ Real r=dat->elem(i,c1);
+ dat->elem(i,c1) = dat->elem(i,c2);
+ dat->elem(i,c2)=r;
+ }
+}
+
+void
+Matrix::swap_rows(int c1, int c2)
+{
+ assert(c1>=0&& c1 < rows()&&c2 < rows() && c2 >=0);
+ for (int i=0; i< cols(); i++) {
+ Real r=dat->elem(c1,i);
+ dat->elem(c1,i) = dat->elem(c2,i);
+ dat->elem(c2,i)=r;
+ }
+}
+
+
+int
+Matrix::dim() const
+{
+ assert(cols() == rows());
+ return rows();
+}
+
--- /dev/null
+/*
+ path.cc - manipulation of paths and filenames.
+*/
+#include <stdio.h>
+#include "path.hh"
+
+#ifndef PATHSEP
+#define PATHSEP '/'
+#endif
+
+/**
+ @param path the original full filename
+ @return 4 components of the path. They can be empty
+*/
+void
+split_path(String path,
+ String &drive, String &dirs, String &filebase, String &extension)
+{
+ // peel off components, one by one.
+ int di = path.index_i(':');
+ if (di >= 0)
+ {
+ drive = path.left_str(di + 1);
+ path = path.right_str(path.len() - di -1);
+ }
+ else
+ drive = "";
+
+ di = path.index_last_i(PATHSEP);
+ if (di >=0)
+ {
+ dirs = path.left_str(di + 1);
+ path = path.right_str(path.len()-di -1);
+ }
+ else
+ dirs = "";
+
+ di = path.index_last_i('.');
+ if (di >= 0)
+ {
+ filebase = path.left_str(di);
+ extension =path.right_str(path.len()-di);
+ }
+ else
+ {
+ extension = "";
+ filebase = path;
+ }
+}
+
+File_path::File_path(String pref)
+{
+ add(".");
+ add(pref);
+}
+
+
+/** find a file.
+ It will search in the current dir, in the construction-arg, and
+ in any other added path, in this order.
+ */
+String
+File_path::find(String nm)
+{
+ for (int i=0; i < size(); i++) {
+ String path = (*this)[i];
+ path+= "/"+nm;
+
+
+ FILE *f = fopen(path, "r"); // ugh!
+ if (f) {
+ fclose(f);
+ return path;
+ }
+ }
+ return "";
+}
--- /dev/null
+#include <assert.h>
+#include <stdio.h>
+#include "scalar.hh"
+
+Scalar::Scalar(Rational r)
+ :String(r)
+{
+
+}
+
+Scalar::operator Rational()
+{
+ int p = index_i('/');
+ if (p == -1)
+ return int(*this);
+
+ String s2 = right_str(len()-p-1);
+ String s1 = left_str(p);
+
+ return Rational(s1.value_i(), s2.value_i());
+}
+
+bool
+Scalar::isnum()
+{
+ int conv = false;
+ if (len()) {
+ long l =0;
+ conv = sscanf(strh_.ch_c_l(), "%ld", &l);
+ }
+ return len() && conv;
+}
+
+Scalar::operator Real()
+{
+ assert (isnum());
+ return value_f();
+}
+
+Scalar::operator int()
+{
+ assert (isnum());
+ return value_i();
+}
+
+
+Scalar::operator bool() const
+{
+ if (!len())
+ return false;
+ if (*this == "0")
+ return false;
+ String u (*this);
+ if ( u.upper_str() == "FALSE")
+ return false;
+ return true;
+}
--- /dev/null
+#include "smat.hh"
+
+void
+Full_storage::operator=(Full_storage const &fs)
+{
+ resize(fs.h, fs.w);
+ OK();
+ fs.OK();
+ for (int i=0; i<h; i++)
+ for (int j=0; j<w; j++)
+ els[i][j]= fs.els[i][j];
+}
+
+void
+Full_storage::OK() const
+{
+#ifndef NDEBUG
+ // static Real dummy;
+ assert(maxh >= h && maxw >= w);
+ assert(h >= 0 && w >= 0);
+ assert(els||!maxh);
+#endif
+}
+void
+Full_storage::resize_cols(int newh)
+{
+ if (newh <= maxh) {
+ h=newh;
+ return;
+ }
+
+ Real ** newa=new Real*[newh];
+ int j=0;
+ for (; j < h; j++)
+ newa[j] = els[j];
+ for (; j < newh; j++)
+ newa[j] = new Real[maxw];
+ delete[] els;
+ els=newa;
+
+ h = maxh = newh;
+}
+
+void
+Full_storage::resize_rows(int neww)
+{
+ if (neww <= maxw) {
+ w=neww;
+ return;
+ }
+ for (int i=0; i < maxh ; i++) {
+ Real* newa = new Real[neww];
+ for (int k=0; k < w; k++)
+ newa[k] = els[i][k];
+
+ delete[] els[i];
+ els[i] = newa;
+ }
+ w = maxw = neww;
+}
+
+Full_storage::~Full_storage() {
+ for (int i=0; i < maxh; i++)
+ delete [] els[i];
+ delete[] els;
+}
+
+void
+Full_storage::resize(int rows, int cols)
+{
+ OK();
+ resize_cols(rows);
+ resize_rows(cols);
+
+}
+
+
+bool
+Full_storage::mult_ok(int i, int j) const
+{
+ return valid(i,j);
+}
+
+bool
+Full_storage::trans_ok(int i, int j) const
+{
+ return valid(i,j);
+}
+
+
+void
+Full_storage::trans_next(int &i, int &j) const
+{
+ assert(trans_ok(i,j));
+ i++;
+ if (i >= h) {
+ i=0;
+ j ++;
+ }
+}
+
+void
+Full_storage::mult_next(int &i, int &j) const
+{
+ assert(mult_ok(i,j));
+ j++;
+ if (j >= w) {
+ j=0;
+ i++;
+ }
+}
+
+void
+Full_storage::delete_column(int k)
+{
+ assert(0 <= k &&k<w);
+ for (int i=0; i< h ; i++)
+ for (int j=k+1; j <w; j++)
+ els[i][j-1]=els[i][j];
+ w--;
+}
+void
+Full_storage::delete_row(int k)
+{
+ assert(0 <= k &&k<h);
+ for (int i=k+1; i < h ; i++)
+ for (int j=0; j < w; j++)
+ els[i-1][j]=els[i][j];
+ h--;
+}
+
+
+void
+Full_storage::insert_row(int k)
+{
+ assert(0 <= k&& k <=h);
+ resize_cols(h+1);
+ for (int i=h-1; i > k ; i--)
+ for (int j=0; j <w; j++)
+ els[i][j]=els[i-1][j];
+
+}
+
+
+Array<Real>
+Full_storage::row(int n) const
+{
+ Array<Real> r;
+ for (int j = 0; j < w; j++)
+ r.push(els[n][j]);
+ return r;
+}
+
+Array<Real>
+Full_storage::column(int n) const
+{
+
+ Array<Real> r;
+ for (int i = 0; i<h; i++)
+ r.push(els[i][n]);
+ return r;
+}
+
+
+Full_storage::Full_storage(Full_storage&s)
+{
+ init();
+ (*this) = s;
+}
+virtual_smat*
+Full_storage::clone()
+{
+ return new Full_storage(*this);
+}
+
+
+virtual_smat *
+virtual_smat::get_full(int n, int m)
+{
+ return new Full_storage(n,m);
+}
--- /dev/null
+/*
+ PROJECT: FlowerSoft C++ library
+ FILE : string-convert.cc
+
+--*/
+
+
+#include <assert.h>
+#include "libc-extension.hh"
+#include "string.hh"
+#include "string-convert.hh"
+
+/**
+ a safe length for stringconversion buffers
+
+ worst case would be %f printing HUGE (or 1/HUGE), which is approx
+ 2e318, this number would have approx 318 zero's in its string.
+
+ Should enlarge buff dynamically.
+ @see
+ man 3 snprintf
+ */
+static const int STRING_BUFFER_LEN=1024;
+
+String
+String_convert::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_byte( *byte_c_l >> 4 );
+ str += (char)nibble2hex_byte( *byte_c_l++ );
+ }
+ return str;
+}
+
+int
+String_convert::bin2_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 += (Byte)bin_str[ i ];
+ }
+ return result_i;
+}
+
+// breendet imp from String
+int
+String_convert::dec2_i( String dec_str )
+{
+ if ( !dec_str.length_i() )
+ return 0;
+
+ long l = 0;
+ int conv = sscanf( dec_str.ch_c_l(), "%ld", &l );
+ assert( conv );
+
+ return (int)l;
+}
+
+String
+String_convert::longlong_str(long long ll, char const* fmt)
+{
+ char buffer[STRING_BUFFER_LEN];
+ snprintf(buffer, STRING_BUFFER_LEN,
+ (fmt ? fmt : "%Ld"), ll ); // assume radix 10
+ return String(buffer);
+
+}
+// breendet imp from String
+double
+String_convert::dec2_f( String dec_str )
+{
+ if ( !dec_str.length_i() )
+ return 0;
+ double d = 0;
+ int conv = sscanf( dec_str.ch_c_l(), "%lf", &d );
+ assert( conv );
+ return d;
+}
+
+int
+String_convert::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
+String_convert::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
+String_convert::hex2nibble_i( Byte byte )
+{
+ if ( byte >= '0' && byte <= '9' )
+ return byte - '0';
+ if ( byte >= 'A' && byte <= 'F' )
+ return byte - 'A' + 10;
+ if ( byte >= 'a' && byte <= 'f')
+ return byte - 'a' + 10;
+ return -1;
+}
+
+// stupido. Should use int_str()
+String
+String_convert::i2dec_str( int i, int length_i, char ch )
+{
+ char fill_ch = ch;
+ if ( fill_ch)
+ fill_ch = '0';
+
+ // ugh
+ String dec_str( i );
+
+ // ugh
+ return String( fill_ch, length_i - dec_str.length_i() ) + dec_str;
+}
+
+
+// stupido. Should use int_str()
+String
+String_convert::i2hex_str( int i, int length_i, char ch )
+{
+ String str;
+ if ( !i )
+ str = "0";
+ while ( i ) {
+ str = String( ( i % 16 )["0123456789abcdef"] ) + str;
+ i /= 16;
+ }
+ if ( str.length_i() < length_i )
+ str = String( ch, length_i - str.length_i() ) + str;
+ return str;
+}
+
+Byte
+String_convert::nibble2hex_byte( Byte byte )
+{
+ if ( ( byte & 0x0f ) <= 9 )
+ return ( byte & 0x0f ) + '0';
+ else
+ return ( byte & 0x0f ) - 10 + 'a';
+}
+/**
+ Convert an integer to a string
+
+ @param
+ #fmt# is a printf style format, default assumes "%d" as format.
+ */
+String
+String_convert::int_str(int i, char const* fmt)
+{
+ char buffer[STRING_BUFFER_LEN];
+ snprintf(buffer, STRING_BUFFER_LEN,
+ (fmt ? fmt : "%d"), i ); // assume radix 10
+ return String(buffer);
+}
+
+/**
+ Convert a double to a string.
+
+ @param #fmt# is a printf style format, default assumes "%lf" as format
+ */
+String
+String_convert::double_str(double f, char const* fmt)
+{
+ char buf[STRING_BUFFER_LEN];
+
+ snprintf(buf, STRING_BUFFER_LEN, fmt ? fmt : "%f", f);
+ return buf;
+}
+
+/**
+ Make a string from a single character.
+
+ @param
+ #n# is a repetition count, default value is 1
+ */
+String
+String_convert::char_str(char c, int n)
+{
+ n = n >= 0 ? n : 0;
+ char* ch_p = new char[ n ];
+ memset( ch_p, c, n );
+ String s((Byte*)ch_p, n);
+ delete ch_p;
+ return s;
+}
+
+String
+String_convert::rational_str(Rational r)
+{
+ char * n = Itoa(r.numerator()); // LEAK????
+
+ String s = n;
+ if (r.denominator() != 1) {
+ char * d = Itoa(r.denominator());
+ s += String( '/' ) + String(d);
+ //delete d;
+ }
+/* delete n;
+ */
+ return s;
+}
+
+String
+String_convert::pointer_str(const void *l)
+{
+ long long int ill = (long long int )l;
+ return String_convert::longlong_str(ill, "0x%0Lx");
+}
--- /dev/null
+#ifdef STRING_TEST
+/*
+ stupid test program to verify stringlib
+ stringtest.cc
+ */
+#include <iostream.h>
+#include "string.hh"
+#include "varray.hh"
+#include "string-convert.hh"
+
+void
+ctors()
+{
+ cout << "constructors"<<endl;
+
+ String str( "hai" );
+ String def;
+ String fromi(10);
+ String fromc('c');
+ String fromf(1.32e-2, "%g");
+
+ cout << str << endl;
+ cout << def << endl;
+ cout << fromi<< endl;
+ cout << fromc<< endl;
+ cout << fromf<< endl;
+}
+
+void
+cmp()
+{
+ Array<String> a;
+ a.push("abcd");
+ a.push("zxy");
+ a.push("abc");
+ a.push("");
+ a.sort(String::compare_i);
+ cout << "compares: "<<endl;
+ for (int i=0; i < a.size(); i++)
+ cout << a[i] << endl;
+}
+
+
+void
+searching()
+{
+ String hay = "foobarbazblub";
+
+ char c = 'b';
+ String cstr =c;
+ String set = "bar";
+ cout << "hay = \"" << hay << "\" len="<< hay.length_i()<<endl;
+ cout << "index_i('"<< c<<"') " << c << "= " << hay.index_i(c) <<endl;
+ cout << "last_index_i('"<< c<<"') " << c << "= " << hay.index_last_i(c) <<endl;
+// cout << "last index of cstr " << c << ": " << hay.index_last_i(cstr) <<endl;
+// cout << "index_last_i(\""<<set<<"\"): " << hay.index_last_i(set) <<endl;
+ cout << "index_i(\""<<set<<"\"): " << hay.index_i(set) <<endl;
+ cout << "index_any(\"" << set << "\"): " << cstr << ": " << hay.index_any_i(cstr) <<endl;
+
+
+
+}
+
+
+void
+kutenpeer()
+{
+ String str( "hai" );
+ for (int i=-1; i < str.length_i()+2; i++) {
+ cout<<" left_str(" << i<<"): " << str.left_str( i ) << endl;
+ cout<<" right_str( "<<i<<"): " << str.right_str( i ) << endl;
+ }
+ str = "blonde haren";
+ cout << str<<endl;
+ cout << "mid(2,6)="<<str.mid_str(2,3)<<endl;
+ cout << "nomid(2,6)="<<str.nomid_str(2,3)<<endl;
+}
+
+int
+main()
+{
+ ctors();
+ cmp();
+ searching();
+ kutenpeer();
+ String str( "hai" );
+ cout << str << endl;
+ cout << "left" << endl;
+ str += " daar";
+ cout << str << endl;
+
+ str = String( "Hallo" ) + " daaR" + '!';
+ cout << str << endl;
+
+ cout << "up: " << str.upper_str() << " down: " << str.lower_str()<<endl;
+
+ if ( str == String( "" ) )
+ cout << str << " is empty" << endl;
+ else
+ cout << str << " is not empty"<<endl;
+
+
+ String fn = "";
+ if ( fn == "" )
+ cout << fn << " is empty" << endl;
+ else
+ assert(false);
+
+ fn = "";
+ fn += "";
+ delete fn.copy_byte_p();
+ delete str.copy_byte_p();
+
+ cout << String_convert::bin2hex_str( String( (char)0xff ) ) << endl;
+}
+
+#endif STRING_TEST
+
--- /dev/null
+/*
+ stringutil.cc -- generate non-inline members.
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#ifdef STRING_DEBUG
+#include <sys/types.h>
+#include <memory.h>
+void*
+mymemmove( void* dest, void const* src, size_t n )
+{
+ return memcpy( dest, src, n ); // wohltempererit: 69006
+}
+#define memmove mymemmove
+#endif
+
+#ifdef STRING_UTILS_INLINED
+#undef STRING_UTILS_INLINED
+#endif
+
+#ifdef INLINE
+#undef INLINE
+#endif
+
+#define INLINE
+
+#include "string-handle.hh"
+#include "string-data.hh"
+#include "string-data.inl"
+#include "string-handle.inl"
--- /dev/null
+#include "text-db.hh"
+bool
+Text_db::eof()
+{
+ Data_file::gobble_leading_white();
+ return Data_file::eof();
+}
+
+void
+Text_db::gobble_leading_white()
+{
+ while (1) {
+ Data_file::gobble_leading_white();
+ if (eof())
+ return ;
+ char c;
+ if ((c = data_get()) !='\n'){
+ data_unget (c);
+ return ;
+ }
+ }
+}
+
+
+Text_record
+Text_db::get_record()
+{
+ while (1) {
+ String s;
+ Array<String> fields;
+ assert(!eof());
+
+ while ((s = get_word()) != "")
+ {
+ fields.push(s);
+ gobble_white();
+ }
+
+
+ if (get_line() != "")
+ assert(false);
+
+ assert (fields.size());
+ return Text_record(fields, get_name(), line());
+ }
+}
+
+
--- /dev/null
+#include "text-stream.hh"
+
+Text_stream::Text_stream(String fn)
+{
+ ios::sync_with_stdio();
+ if (fn == "")
+ {
+ name = "<STDIN>";
+ f = stdin;
+ }
+
+ else
+ {
+ name = fn;
+ f = fopen(fn, "r");
+ }
+
+ if (!f) {
+ cerr <<__FUNCTION__<< ": can't open `" << fn << "'\n";
+ exit(1);
+ }
+
+ line_no = 1;
+ }
+
+void
+Text_stream::message(String s)
+{
+ cerr << "\n"<<get_name() << ": " << line()<<": "<<s<<endl;
+}
+
--- /dev/null
+#include "unionfind.hh"
+/*
+ see a book on data structures
+ */
+
+Union_find::Union_find(int n)
+{
+ classes.set_size(n);
+
+ for (int i=0; i < n; i++) {
+ classes[i] = i;
+ }
+}
+
+int
+Union_find::find(int i)
+{
+ int rep = i;
+ while (classes[rep] != rep)
+ rep = classes[rep];
+ while (classes[i] != rep) {
+ int next =classes[i];
+ classes[i] = rep;
+ i = next;
+ }
+ return rep;
+}
+
+void
+Union_find::connect(int i, int j)
+{
+ i = find(i);
+ j = find(j);
+ classes[i] = j;
+}
--- /dev/null
+#include "vector.hh"
+Vector::Vector(Array<Real> d)
+ : dat(d)
+{
+
+}
+Vector::Vector(const Vector&n)
+ : dat(n.dat)
+{
+}
+
+Vector
+Vector::operator-() const
+{
+ Vector v(*this);
+ v*=-1;
+ return v;
+}
+
+void
+Vector::set_unit(int j)
+{
+ fill(0.0);
+ dat[j] = 1.0;
+}
#include "matrix.hh"
static Dstream *dout = 0;
+
/**
Set the debugging output. Will not delete/swallow argument.
*/
Cursor<void*>::ok;
Cursor<void*>::del;
Cursor<void*>::backspace;
- T get() {
+ T get_p() {
T p = ptr();
Cursor<void*>::del();
return p;
}
T get_prev() {
(*this)--;
- return get();
+ return get_p();
}
PointerList<T> &list() { return (PointerList<T>&)Cursor<void*>::list(); }
{
PCursor<T> c( *this );
while (c.ok()) {
- delete c.get();
+ delete c.get_p();
}
}
assert(maxh >= h && maxw >= w);
assert(h >= 0 && w >= 0);
assert(els||!maxh);
- if (maxh>0) { // access outer elts.
- Real *r = els[maxh -1];
- #if 0
- if (maxw>0) {
- assert(r);
- Real s = r[maxw -1]; // accessing unitialised memory.
- s = sin(s);
- }
- #endif
- }
#endif
}
void
return;
}
for (int i=0; i < maxh ; i++) {
- Real* newa=new Real[neww];
+ Real* newa = new Real[neww];
for (int k=0; k < w; k++)
newa[k] = els[i][k];
#include <assert.h>
#include "string.hh"
+#include "string-convert.hh"
+
+/**
+ a safe length for stringconversion buffers
+
+ worst case would be %f printing HUGE (or 1/HUGE), which is approx
+ 2e318, this number would have approx 318 zero's in its string.
+
+ Should enlarge buff dynamically.
+ @see
+ man 3 snprintf
+ */
+static const int STRING_BUFFER_LEN=1024;
String
String_convert::bin2hex_str( String bin_str )
return (int)l;
}
+String
+String_convert::longlong_str(long long ll, char const* fmt)
+{
+ char buffer[STRING_BUFFER_LEN];
+ snprintf(buffer, STRING_BUFFER_LEN,
+ (fmt ? fmt : "%Ld"), ll ); // assume radix 10
+ return String(buffer);
+
+}
// breendet imp from String
double
String_convert::dec2_f( String dec_str )
return byte - 'a' + 10;
return -1;
}
-
+
+// stupido. Should use int_str()
String
String_convert::i2dec_str( int i, int length_i, char ch )
{
return String( fill_ch, length_i - dec_str.length_i() ) + dec_str;
}
+
+// stupido. Should use int_str()
String
String_convert::i2hex_str( int i, int length_i, char ch )
{
else
return ( byte & 0x0f ) - 10 + 'a';
}
+/**
+ Convert an integer to a string
+
+ @param
+ #fmt# is a printf style format, default assumes "%d" as format.
+ */
+String
+String_convert::int_str(int i, char const* fmt)
+{
+ char buffer[STRING_BUFFER_LEN];
+ snprintf(buffer, STRING_BUFFER_LEN,
+ (fmt ? fmt : "%d"), i ); // assume radix 10
+ return String(buffer);
+}
+
+/**
+ Convert a double to a string.
+
+ @param #fmt# is a printf style format, default assumes "%lf" as format
+ */
+String
+String_convert::double_str(double f, char const* fmt)
+{
+ char buf[STRING_BUFFER_LEN];
+
+ snprintf(buf, STRING_BUFFER_LEN, fmt ? fmt : "%f", f);
+ return buf;
+}
+
+/**
+ Make a string from a single character.
+
+ @param
+ #n# is a repetition count, default value is 1
+ */
+String
+String_convert::char_str(char c, int n)
+{
+ n = n >= 0 ? n : 0;
+ char* ch_p = new char[ n ];
+ memset( ch_p, c, n );
+ String s((Byte*)ch_p, n);
+ delete ch_p;
+ return s;
+}
+
+String
+String_convert::rational_str(Rational r)
+{
+ char * n = Itoa(r.numerator()); // LEAK????
+
+ String s = n;
+ if (r.denominator() != 1) {
+ char * d = Itoa(r.denominator());
+ s += String( '/' ) + String(d);
+ //delete d;
+ }
+/* delete n;
+ */
+ return s;
+}
+
+String
+String_convert::pointer_str(const void *l)
+{
+ long long int ill = (long long int )l;
+ return String_convert::longlong_str(ill, "0x%0Lx");
+}
#ifndef STRING_CONVERT_HH
#define STRING_CONVERT_HH
-///
-#define functor class // :-)
+/*
+ ///a class which only has functions.
+//#define functor class // cute. docxx fucks up
+*/
+
/**
The functor String_convert handles all conversions to/from String (some
time, anyway).
The class is quite empty from data view.
*/
-functor String_convert {
- static int hex2bin_i( String hex_str, String& bin_str_r );
- static int hex2nibble_i( Byte byte );
- static Byte nibble2hex_byte( Byte byte );
+class String_convert {
+ static int hex2bin_i( String hex_str, String& bin_str_r );
+ static int hex2nibble_i( Byte byte );
+ static Byte nibble2hex_byte( Byte byte );
public:
- static String bin2dec_str( String dec_str );
- static String bin2hex_str( String bin_str );
- static String dec2bin_str( String str );
- static int bin2_i( String str );
- static int dec2_i( String dec_str );
- static double dec2_f( String dec_str );
- static int hex2int_i( String str );
- static String hex2bin_str( String str );
- static String i2hex_str( int i, int length_i, char ch );
- static String i2dec_str( int i, int length_i, char ch );
+ static String bin2dec_str( String bin_str );
+ static String bin2hex_str( String bin_str );
+ static String dec2bin_str( String str );
+ static int bin2_i( String str );
+ static String char_str(char c, int n);
+ static int dec2_i( String dec_str );
+ static double dec2_f( String dec_str );
+ static String double_str(double f, char const* fmt=0);
+ static int hex2int_i( String str );
+ static String hex2bin_str( String str );
+ static String int_str(int i, char const *fmt=0 );
+ static String i2hex_str( int i, int length_i, char ch );
+ static String i2dec_str( int i, int length_i, char ch );
+ static String rational_str(Rational);
+ static String pointer_str(const void *);
+ static String longlong_str(long long , char const * fmt = 0);
};
#endif // __STRING_CONVERT_HH //
/*
- PROJECT: FlowerSoft C++ library
- FILE : string.cc
- Rehacked by HWN 3/nov/95
- removed String &
- introduced class String_handle
- */
+ string.cc - implement String
+
+ (c) 1997 Han-Wen Nienhuys & Jan Nieuwenhuizen
+
+ */
-#include <string.h>
#include <stdlib.h>
#include <stdio.h>
-#include <ctype.h>
+
#include <assert.h>
+#include <string.h>
#include "string.hh"
+#include "libc-extension.hh"
+#include "string-convert.hh"
#ifdef STRING_DEBUG
void* mymemmove( void* dest, void const* src, size_t n );
#define memmove mymemmove
#endif
-static char*
-strlwr( char* s )
-{
- char* p = s;
-
- while( *p ) {
- *p = tolower( *p ); /* a macro on some compilers */
- p++;
- }
- return s;
-}
-
-static char*
-strupr( char* s )
-{
- char* p = s;
-
- while( *p ) {
- *p = toupper( *p ); /* a macro on some compilers */
- p++;
- }
- return s;
-}
-
-String::String(Rational r)
-{
- char * n = Itoa(r.numerator()); // LEAK????
-
- *this = n;
- if (r.denominator() != 1) {
- char * d = Itoa(r.denominator());
- *this += String( '/' ) + String(d);
- //delete d;
- }
-/* delete n;
- */
-}
-
// return array, alloced with new.
Byte*
String::copy_byte_p() const
{
Byte const* src = strh_.byte_c_l();
Byte* dest = new Byte[strh_.length_i() + 1];
- memmove( dest, src, strh_.length_i() + 1 );
+ memcpy( dest, src, strh_.length_i() + 1 );
return dest;
}
-
void
String::print_on(ostream& os) const
{
- if ( length_i() == strlen( ch_c_l() ) )
+ if (strh_.null_terminated_b())
os << ch_c_l();
else
for ( int i = 0; i < length_i(); i++ )
os << (Byte)(*this)[ i ];
}
+\f
+/*
+ copying, constructing.
+ */
+String&
+String::operator = (String const&source )
+{
+ strh_ = source.strh_;
+ return *this;
+}
+
+
+String::String(Rational r)
+{
+ *this = String_convert::rational_str(r);
+}
+
+String::String (double f, char const* fmt)
+{
+ *this= String_convert::double_str(f,fmt);
+}
+
+String::String( char c, int n )
+{
+ *this = String_convert::char_str (c,n);
+}
+
+/**
+ @see
+ String_convert::int_str
+ */
+String::String(int i, const char * format )
+{
+ *this = String_convert::int_str(i,format);
+}
String::String (bool b)
{
*this = (char const* ) (b ? "true" : "false");
}
+
String::String( char const* source )
{
assert(source);
String::String( Byte const* byte_l, int length_i )
{
-// assert( !length_i || byte_l );// ugh. Storing null pointers?
strh_.set( byte_l, length_i );
}
-
+\f
void
-String::operator +=(String s)
+String::append(String s)
{
strh_.append( s.byte_c_l(), s.length_i() );
}
-
-int
-String::length_i() const
-{
- return strh_.length_i();
-}
-
-// will go away, fixed anyway
-String::String( char c, int n )
+void
+String::operator +=(String s)
{
- n = n >= 0 ? n : 0;
- char* ch_p = new char[ n ];
- memset( ch_p, c, n );
- strh_.set( (Byte*)ch_p, n );
- delete ch_p;
+ append(s);
}
-String::String(int i)
+void
+String::prepend(String s)
{
- char digits[ 81 ]; // who the fuck is 80???
- digits[ 0 ] = '\0';
- sprintf(digits, "%d", i ); // assume radix 10
- strh_ = digits;
+ s += *this;
+ *this = s;
}
-String::String( const int i, const int n, char const c )
+int
+String::length_i() const
{
- char fill_ch = c;
- if ( fill_ch)
- fill_ch = '0';
-
- String v( i );
-
- String str = String( fill_ch, n - v.length_i() ) + String( v );
- strh_.set( str.byte_c_l(), str.length_i() );
+ return strh_.length_i();
}
Byte const*
return strh_.ch_l();
}
-// signed comparison, analogous to memcmp;
+/**
+ Do a signed comparison, analogous to memcmp;
+ */
int
String::compare_i(String const& s1, String const& s2 )
{
return result ? result : i1-i2;
}
-
+\f
int
String::index_last_i( char const c ) const
{
- // 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 )
- return p - me;
+ if ( !length_i() )
return -1;
+
+ char const* me = strh_.ch_c_l();
+ char const* p = memrchr(me, length_i(), c );
+ if ( p )
+ return p - me;
+ return -1;
}
int
-String::index_last_i( char const* string ) const
-{
- // 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;
+String::index_last_i( char const* string ) const // UGK!
+{
+ assert(false); // broken
+ int length = strlen( string ); // ugrh
+ 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 -1 if not found.
+/** find a character.
+
+ @return
+ the index of the leftmost character #c# (0 <= return < length_i()),
+ or -1 if not found.
-// ? should return length_i()?, as in string.left_str(index_i(delimiter))
+ ? should return length_i()?, as in string.left_str(index_i(delimiter))
+*/
int
String::index_i(char c ) const
{
- // 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 )
- return p - me;
- return -1;
+ char const* me = strh_.ch_c_l();
+ char const* p = (char const *) memchr( me,c, length_i());
+ if ( p )
+ return p - me;
+ return -1;
}
-// find searchfor. (what if this == "" && searchfor == "") ???
+/**
+ find the substring.
+
+ @return
+ index of leftmost occurrence of #searchfor#
+ */
int
-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 )
- return p - me;
+String::index_i( String searchfor ) const
+{
+ char const* me = strh_.ch_c_l();
+ char const* p = (char const *) memmem(me, length_i(), searchfor.ch_c_l(),
+ searchfor.length_i());
+
+ if ( p )
+ return p - me;
+ else
return -1;
}
-// find chars of a set.
+/** find chars of a set.
+
+ @return
+ the index of the leftmost occurance of an element of #set#
+ */
int
-String::index_any_i( char const* string ) const
-{
- // 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 )
- return p - s;
+String::index_any_i( String set ) const
+{
+ int n = length_i();
+ if ( !n )
return -1;
-}
+ const void * me_l = (const void*) strh_.ch_c_l();
+ for (int i=0; i < set.length_i(); i++) {
+ char * found=(char*) memchr(me_l, set[i], n );
+ if (found) {
+ return found - me_l;
+ }
+ }
+ return -1;
+}
+\f
String
String::left_str( int n ) const
{
return retval;
}
-
-// n rightmst chars
String
String::right_str( int n ) const
{
return *this;
if ( n < 1)
- String();
+ return "";
return String( strh_.byte_c_l() + length_i() - n, n );
}
String
String::nomid_str( int index_i, int n ) const
{
- if ( index_i < 0 )
- return String();
- if ( index_i >= length_i() )
- return *this;
+ if ( index_i < 0 ) {
+ n += index_i;
+ index_i = 0;
+ }
+ if ( n <= 0)
+ return *this;
- return String( String( left_str( index_i ) ) + right_str( length_i() - index_i - n ));
+ return
+ left_str( index_i ) +
+ right_str( length_i() - index_i - n ) ;
}
-
+/*
+ proposal: change to "cut()"
+ */
String
String::mid_str( int index_i, int n ) const
{
- if ( !length_i() || ( index_i < 0 ) || ( index_i >= length_i() ) || ( n < 1 ) )
- return String();
+ if ( !length_i() || ( index_i < 0 ) || ( index_i >= length_i() ) || ( n < 1 ) )
+ return String();
- if ( ( n > length_i() ) || ( index_i + n > length_i() ) )
- n = length_i() - index_i;
+ if ( ( n > length_i() ) || ( index_i + n > length_i() ) )
+ n = length_i() - index_i;
- return String( byte_c_l() + index_i, n );
+ return String( byte_c_l() + index_i, n );
}
-
-
-// return uppercase
+\f
String
String::upper_str() const
{
- // not binary safe
- assert( length_i() == strlen( ch_c_l() ) );
String str = *this;
- char *s = str.strh_.byte_l();
- strupr( s );
+ str.to_upper();
return str;
}
+void
+String::to_upper()
+{
+ char *s = (char*)strh_.byte_l();
+ strnupr( s ,length_i());
+}
+
+void
+String::to_lower()
+{
+ char* s = strh_.ch_l();
+ strnlwr(s,length_i());
+}
-// return lowercase
String
String::lower_str() const
{
- // not binary safe
- assert( length_i() == strlen( ch_c_l() ) );
String str = *this;
- char* s = str.strh_.ch_l();
- strlwr(s);
+ str.to_lower();
return str;
}
-
-String::String (double f, char const* fmt)
+String
+String::reversed_str() const
{
- /* worst case would be printing HUGE (or 1/HUGE), which is approx
- 2e318, this number would have approx 318 zero's in its string.
-
- 1024 is a safe length for the buffer
- */
-
- char buf[1024];
- if (!fmt)
- sprintf(buf, "%f", f);
- else
- sprintf(buf, fmt,f);
- *this = buf;
+ String str = *this;
+ strrev( str.byte_l(), str.length_i() );
+ return str;
}
int
String::value_i() const
{
- return String_convert::dec2_i( *this );
+ return String_convert::dec2_i( *this );
}
double
String::value_f() const
{
- return String_convert::dec2_f( *this );
+ return String_convert::dec2_f( *this );
}
-#if 0
-String
-quoteString( String msg, String quote)
-{
- return msg + " `" + quote + "' ";
-}
-#endif // 0
-
-Byte*
-strrev( Byte* byte_l, int length_i )
-{
- Byte byte;
- Byte* left_byte_l = byte_l;
- Byte* right_byte_l = byte_l + length_i;
-
- while ( right_byte_l > left_byte_l ) {
- byte = *left_byte_l;
- *left_byte_l++ = *right_byte_l;
- *right_byte_l-- = byte;
- }
- return byte_l;
-}
-
-
-String
-String::reversed_str() const
-{
- String str = *this;
- strrev( str.byte_l(), str.length_i() );
- return str;
-}
#include <iostream.h>
#include <Rational.h>
-#include "stringhandle.hh"
+#include "string-handle.hh"
/**
\item
ref counting through #String_handle#
\item
-
- conversion from bool, int, double, char* , char.
+ conversion from bool, int, double, char* , char.
\item
-
to be moved to String_convert:
conversion to int, upcase, downcase
\item
-
printable.
\item
No operator[] is provided, since this would be enormously slow. If needed,
convert to char const* .
\end{itemize}
+
*/
class String
{
protected:
- String_handle strh_; // should derive String from String_handle?
+ String_handle strh_;
+ bool null_terminated();
+
public:
- /** init to "". needed because other constructors are provided.*/
+ /** init to empty string. This is needed because other
+ constructors are provided.*/
String() { }
String(Rational);
+
/// String s = "abc";
String( char const* source );
-
String( Byte const* byte_c_l, int length_i );
/// "ccccc"
String( char c, int n = 1 );
- /// String s( 10 );
- String( int i );
-
+ String( int i , char const *fmt=0);
+ String ( double f , char const* fmt =0);
/// 'true' or 'false'
String(bool );
- /// String s( 3.14, 6, '#' );
- String ( double f , char const* fmt =0);
- String( int i, int n, char c = ' ' );
-
/// return a "new"-ed copy of contents
Byte* copy_byte_p() const; // return a "new"-ed copy of contents
/// deprecated; use ch_c_l()
operator char const* () const { return ch_c_l(); }
- String operator =( const String & source ) { strh_ = source.strh_; return *this; }
+ String &operator =( const String & source );
/// concatenate s
void operator += (char const* s) { strh_ += s; }
void operator += (String s);
+ void append(String);
+ void prepend(String);
+
char operator []( int n ) const { return strh_[n]; }
/// return n leftmost chars
/// index of rightmost element of string
int index_last_i( char const* string ) const;
- /**
- index of leftmost c.
-
- @return
- -1 if not found, else index
- */
int index_i(char c ) const;
- int index_i(char const* string ) const;
- int index_any_i(char const* string ) const;
-
+ int index_i(String ) const;
+ int index_any_i(String ) const;
+ void to_upper();
+ void to_lower();
/// provide Stream output
void print_on(ostream& os) const;
/// convert to a double
double value_f() const;
- // *****
};
#include "compare.hh"
// String quoteString(String message, String quote);
-#include "string-convert.hh"
-
#endif
+++ /dev/null
-/*
- stringdata.hh -- declare String_data
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-
-#ifndef STRINGDATA_HH
-#define STRINGDATA_HH
-
-
-/**Internal String struct.
- the data itself. Handles simple tasks (resizing, resetting)
- */
-class String_data {
- // GNU malloc: storage overhead is 8 bytes anyway.
-
-friend class String_handle;
- int maxlen; // maxlen is arraysize-1
-
- int length_i_;
- Byte* data_byte_p_;
- int references;
-
- /// init to ""
- String_data();
-
- /// init from src. Conservative allocation.
- String_data(String_data const &src);
-
- ~String_data();
-
- /** POST: maxlen >= j.
- @param j, maximum stringlength_i_.
- contents thrown away.
- */
- void setmax(int j);
-
- /** POST: maxlen >= j.
- @param j, maximum stringlength_i_.
- contents are kept if it grows.
- */
- void remax(int j);
-
- /// check if writeable.
- void OKW();
-
- /// check state.
- void OK();
-
- /// reduce memory usage.
- void tighten();
-
- // assignment.
- void set( Byte const* byte_c_l, int length_i );
-
- void set( char const* ch_c_l );
-
- /// concatenation.
- void append( Byte const* byte_c_l, int length_i );
-
- void operator += ( char const* ch_c_l );
-
- char const* ch_c_l() const;
-
- char* ch_l();
-
- Byte const* byte_c_l() const;
-
- // idem, non const
- Byte* byte_l();
-
- void trunc(int j);
-
- /** access element. not really safe. Can alter length_i_ without
- #String_data# knowing it. */
- Byte &operator [](int j);
- Byte operator [](int j) const;
-};
-
-
-
-#ifdef STRING_UTILS_INLINED
-#ifndef INLINE
-#define INLINE inline
-#endif
-#include "stringdata.inl"
-
-#endif
-
-
-#endif // STRING_DATA_HH
+++ /dev/null
-/* -*-C++-*-
- String_data.inl -- implement String_data
-
- source file of Flower lib
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-#ifndef STRINGDATA_INL
-#define STRINGDATA_INL
-
-#include <assert.h>
-#include <memory.h>
-
-#include "stringdata.hh"
-const int INITIALMAX=8;
-
-#include <sys/types.h>
-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
-
-INLINE void
-String_data::OKW()
-{
- assert (references == 1);
-}
-
-INLINE void
-String_data::OK()
-{
- assert(maxlen >= length_i_);
- assert(bool(data_byte_p_));
- assert(references >= 1);
-}
-
-
-INLINE
-String_data::String_data()
-{
- references=0;
- maxlen = INITIALMAX;
- data_byte_p_ = new Byte[maxlen + 1];
- data_byte_p_[0] = 0;
- length_i_ = 0;
-}
-
-INLINE
-String_data::String_data(String_data const &src)
-{
- references=0;
- maxlen = length_i_ = src.length_i_;
- data_byte_p_ = new Byte[maxlen+1]; // should calc GNU 8byte overhead.
- memmove( data_byte_p_, src.data_byte_p_, length_i_ + 1 );
-}
-
-INLINE
-String_data::~String_data()
-{
- assert(references == 0);
- delete[] data_byte_p_;
-}
-
-INLINE void
-String_data::setmax(int j)
-{
- OKW();
- if (j > maxlen) {
- delete data_byte_p_;
- maxlen = j;
- data_byte_p_ = new Byte[maxlen + 1];
-
- data_byte_p_[0] = 0;
- length_i_ = 0;
- }
-}
-
-/* this is all quite hairy:
- update of length_i_
- update of maxlen
- alloc of buffer
- copying of buffer
- needs blondification:
- split tasks
- define change authority
-*/
-INLINE void
-String_data::remax(int j)
-{
- OKW();
- if (j > maxlen) {
-// maxlen = j; oeps
-// Byte *p = new Byte[maxlen + 1];
- Byte *p = new Byte[j + 1];
- memmove( p, data_byte_p_, ( maxlen <? length_i_ ) + 1 );
- maxlen = j;
- delete[] data_byte_p_;
- data_byte_p_ = p;
- }
-}
-
-INLINE void
-String_data::tighten()
-{ // should be dec'd const
- maxlen = length_i_;
- Byte *p = new Byte[maxlen + 1];
- memmove( p, data_byte_p_, length_i_ + 1 );
- delete[] data_byte_p_;
- data_byte_p_ = p;
-}
-// assignment.
-INLINE void
-String_data::set( Byte const* byte_c_l, int length_i )
-{
- OKW();
-
- assert( byte_c_l && byte_c_l != data_byte_p_);
-
- length_i_ = length_i;
- remax( length_i_ ); // copies too
- memmove( data_byte_p_, byte_c_l, length_i_ );
- data_byte_p_[ length_i_ ] = 0;
-}
-
-INLINE
-void
-String_data::set( char const* ch_c_l )
-{
- set( (Byte const*)ch_c_l, strlen( ch_c_l ) );
-}
-
-
-/// concatenation.
-INLINE void
-String_data::append( Byte const* byte_c_l, int length_i )
-{
- OK();
- OKW();
- int old_i = length_i_;
-
- length_i_ += length_i;
- remax( length_i_ );
- memmove( data_byte_p_ + old_i, byte_c_l, length_i );
- data_byte_p_[ length_i_ ] = 0;
-}
-
-INLINE
-void
-String_data::operator += ( char const* ch_c_l )
-{
- append( (Byte const*)ch_c_l, strlen( ch_c_l ) );
-}
-
-
-
-INLINE
-char const*
-String_data::ch_c_l() const
-{
- return (char const*)data_byte_p_;
-}
-INLINE char*
-String_data::ch_l()
-{
- return (char*)data_byte_p_;
-}
-
-INLINE Byte const*
-String_data::byte_c_l() const
-{
- return data_byte_p_;
-}
-
-INLINE Byte*
-String_data::byte_l()
-{
- OKW();
- return data_byte_p_;
-}
-
-INLINE
-void
-String_data::trunc(int j)
-{
- OKW();
- assert(j >= 0 && j <= length_i_);
- data_byte_p_[j] = 0;
- length_i_ = j;
-}
-
-INLINE Byte&
-String_data::operator [](int j)
-{
- assert(j >= 0 && j <= length_i_);
- return data_byte_p_[j] ;
-}
-
-INLINE Byte
-String_data::operator [](int j) const
-{
- assert(j >= 0 && j <= length_i_);
- return data_byte_p_[j];
-}
-
-
-
-
-#endif // __STRING_UTIL_CC //
+++ /dev/null
-/*
- stringhandle.hh -- declare String_handle
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-
-#ifndef STRINGHANDLE_HH
-#define STRINGHANDLE_HH
-#include "fproto.hh"
-
-
-/**
- Reference counting for strings.
-
- handles ref. counting, and provides a very thin interface using
- Byte *
-
- */
-class String_handle {
- String_data* data;
-
- /// decrease ref count. Named kind of like a Tanenbaum semafore
- void down();
-
- /// increase ref count
- void up(String_data *d);
-
- /** make sure data has only one reference.
- POST: data->references == 1
- */
- void copy();
-
-public:
- String_handle();
- ~String_handle();
- String_handle(String_handle const & src);
-
- Byte const* byte_c_l() const;
- char const* ch_c_l() const;
- Byte* byte_l();
- char* ch_l();
-
- void operator =(String_handle const &src);
- void operator += (char const *s);
- Byte operator[](int j) const;
-
- /** Access elements. WARNING: NOT SAFE
- don't use this for loops. Use byte_c_l()
- */
- Byte &operator[](int j);
- void append( Byte const* byte_c_l, int length_i );
- void set( Byte const* byte_c_l, int length_i );
- void operator = (char const *p);
- void trunc(int j);
- int length_i() const;
-};
-
-#ifdef STRING_UTILS_INLINED
-#ifndef INLINE
-#define INLINE inline
-#endif
-#include "stringhandle.inl"
-/* we should be resetting INLINE. oh well. */
-#endif
-
-
-#endif // STRINGHANDLE_HH
+++ /dev/null
-/* -*-c++-*-
-
- stringhandle.inl -- implement String_handle
-
- source file of Flower lib
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-#ifndef STRINGHANDLE_INL
-#define STRINGHANDLE_INL
-
-#include <assert.h>
-#include <memory.h>
-
-#include "stringdata.hh"
-#include "stringhandle.hh"
-
-INLINE void
-String_handle::down()
-{
- if (!(--data->references)) delete data; data = 0;
-}
-
-/// increase ref count
-INLINE void
-String_handle::up(String_data *d)
-{
- data=d; data->references ++;
-}
-
-INLINE void
-String_handle::copy()
-{
- if (data->references !=1){
- String_data *newdata = new String_data(*data);
- down();
- up(newdata);
- }
-}
-
-INLINE
-String_handle::String_handle()
-{
- up(new String_data);
-}
-
-INLINE
-String_handle::~String_handle()
-{
- down();
-}
-
-INLINE
-String_handle::String_handle(String_handle const & src)
-{
- up(src.data);
-}
-
-INLINE Byte*
-String_handle::byte_l()
-{
- copy();
- return data->byte_l();
-}
-
-INLINE char*
-String_handle::ch_l()
-{
- copy();
- return (char*)data->byte_l();
-}
-
-INLINE Byte
-const* String_handle::byte_c_l() const
-{
- return data->byte_c_l();
-}
-
-INLINE char const*
-String_handle::ch_c_l() const
-{
- return (char const*)data->byte_c_l();
-}
-
-INLINE void
-String_handle::operator =(String_handle const &src)
-{
- if (this == &src)
- return;
- down();
- up(src.data);
-}
-
-INLINE void
-String_handle::operator += (char const *s)
-{
- copy();
- *data += s;
-}
-
-
-INLINE Byte
-String_handle::operator[](int j) const
-{
- return (*data)[j];
-}
-
-// !NOT SAFE!
-// don't use this for loops. Use byte_c_l()
-INLINE Byte &
-String_handle::operator[](int j)
-{
- copy(); // hmm. Not efficient
- return data->byte_l()[j];
-}
-
-INLINE void
-String_handle::append( Byte const* byte_c_l, int length_i )
-{
- copy();
- data->append( byte_c_l, length_i );
-}
-
-INLINE void
-String_handle::set( Byte const* byte_c_l, int length_i )
-{
- copy();
- data->set( byte_c_l, length_i );
-}
-
-INLINE void
-String_handle::operator = (char const *p)
-{
- copy();
- data->set( p );
-}
-
-INLINE void
-String_handle::trunc(int j)
-{
- copy(); data->trunc(j);
-}
-
-INLINE int
-String_handle::length_i() const
-{
- return data->length_i_;
-}
-
-#endif
-// stringtest.cc
-
+/*
+ stupid test program to verify stringlib
+ stringtest.cc
+ */
#include <iostream.h>
#include "string.hh"
+#include "varray.hh"
+#include "string-convert.hh"
+
+void
+ctors()
+{
+ cout << "constructors"<<endl;
+
+ String str( "hai" );
+ String def;
+ String fromi(10);
+ String fromc('c');
+ String fromf(1.32e-2, "%g");
+
+ cout << str << endl;
+ cout << def << endl;
+ cout << fromi<< endl;
+ cout << fromc<< endl;
+ cout << fromf<< endl;
+}
+
+void
+cmp()
+{
+ Array<String> a;
+ a.push("abcd");
+ a.push("zxy");
+ a.push("abc");
+ a.push("");
+ a.sort(String::compare_i);
+ cout << "compares: "<<endl;
+ for (int i=0; i < a.size(); i++)
+ cout << a[i] << endl;
+}
+
+
+void
+searching()
+{
+ String hay = "foobarbazblub";
+
+ char c = 'b';
+ String cstr =c;
+ String set = "bar";
+ cout << "hay = \"" << hay << "\" len="<< hay.length_i()<<endl;
+ cout << "index_i('"<< c<<"') " << c << "= " << hay.index_i(c) <<endl;
+ cout << "last_index_i('"<< c<<"') " << c << "= " << hay.index_last_i(c) <<endl;
+// cout << "last index of cstr " << c << ": " << hay.index_last_i(cstr) <<endl;
+// cout << "index_last_i(\""<<set<<"\"): " << hay.index_last_i(set) <<endl;
+ cout << "index_i(\""<<set<<"\"): " << hay.index_i(set) <<endl;
+ cout << "index_any(\"" << set << "\"): " << cstr << ": " << hay.index_any_i(cstr) <<endl;
+
+
+
+}
+
+
+void
+kutenpeer()
+{
+ String str( "hai" );
+ for (int i=-1; i < str.length_i()+2; i++) {
+ cout<<" left_str(" << i<<"): " << str.left_str( i ) << endl;
+ cout<<" right_str( "<<i<<"): " << str.right_str( i ) << endl;
+ }
+ str = "blonde haren";
+ cout << str<<endl;
+ cout << "mid(2,6)="<<str.mid_str(2,3)<<endl;
+ cout << "nomid(2,6)="<<str.nomid_str(2,3)<<endl;
+}
int
main()
{
+ ctors();
+ cmp();
+ searching();
+ kutenpeer();
String str( "hai" );
cout << str << endl;
cout << "left" << 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_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;
- str = String( "hallo" ) + " daar" + '!';
+ str = String( "Hallo" ) + " daaR" + '!';
cout << str << endl;
+ cout << "up: " << str.upper_str() << " down: " << str.lower_str()<<endl;
+
if ( str == String( "" ) )
cout << str << " is empty" << endl;
+ else
+ cout << str << " is not empty"<<endl;
+
+
String fn = "";
if ( fn == "" )
cout << fn << " is empty" << endl;
-
+ else
+ assert(false);
+
fn = "";
fn += "";
delete fn.copy_byte_p();
-
delete str.copy_byte_p();
cout << String_convert::bin2hex_str( String( (char)0xff ) ) << endl;
#define INLINE
-#include "stringhandle.hh"
-#include "stringdata.hh"
-#include "stringdata.inl"
-#include "stringhandle.inl"
+#include "string-handle.hh"
+#include "string-data.hh"
+#include "string-data.inl"
+#include "string-handle.inl"
+++ /dev/null
-#include "textdb.hh"
-bool
-Text_db::eof()
-{
- Data_file::gobble_leading_white();
- return Data_file::eof();
-}
-
-void
-Text_db::gobble_leading_white()
-{
- while (1) {
- Data_file::gobble_leading_white();
- if (eof())
- return ;
- char c;
- if ((c = data_get()) !='\n'){
- data_unget (c);
- return ;
- }
- }
-}
-
-
-Text_record
-Text_db::get_record()
-{
- while (1) {
- String s;
- Array<String> fields;
- assert(!eof());
-
- while ((s = get_word()) != "")
- {
- fields.push(s);
- gobble_white();
- }
-
-
- if (get_line() != "")
- assert(false);
-
- assert (fields.size());
- return Text_record(fields, get_name(), line());
- }
-}
-
-
+++ /dev/null
-#ifndef TEXTDB_HH
-#define TEXTDB_HH
-
-#include "datafile.hh"
-
-/**a "const" Array. Contents can't be changed. do "#" comments, read quote enclosed fields */
-
-class Text_record : Array<String>
-{
- int line_no;
- String filename;
-
-public:
- Text_record() { } // needed because of other ctor
-
- /// report an error in this line.
- message(String s) {
- cerr << '\n'<< filename << ": "<< line_no << s << "\n";
- }
- String operator[](int j) {
- return Array<String>::operator[](j);
- }
-
- Text_record(Array<String> s, String fn, int j) : Array<String>(s) {
- filename = fn; line_no = j;
- }
- Array<String>::size;
-};
-
-/** abstraction for a datafile.
- add a subrec/fieldsep/record separator
- */
-
-class Text_db : private Data_file
-{
- void gobble_leading_white();
-public:
- /// get a line with records
- Text_record get_record();
-
- Text_db(String fn):Data_file(fn) { }
- Data_file::error;
- bool eof();
-
- /// get next line.
- Text_record operator++(int) {
- return get_record();
- }
- /// are we done yet?
- operator bool() {
- return !eof();
- }
-};
-
-#endif
+++ /dev/null
-#include "textstream.hh"
-
-Text_stream::Text_stream(String fn)
-{
- ios::sync_with_stdio();
- if (fn == "")
- {
- name = "<STDIN>";
- f = stdin;
- }
-
- else
- {
- name = fn;
- f = fopen(fn, "r");
- }
-
- if (!f) {
- cerr <<__FUNCTION__<< ": can't open `" << fn << "'\n";
- exit(1);
- }
-
- line_no = 1;
- }
-
-void
-Text_stream::message(String s)
-{
- cerr << "\n"<<get_name() << ": " << line()<<": "<<s<<endl;
-}
-
+++ /dev/null
-
-#ifndef TEXTSTR_HH
-#define TEXTSTR_HH
-
-#include <stdio.h>
-#include <ctype.h>
-#include "string.hh"
-#include "varray.hh"
-
-/**
- line counting input stream.
- a stream for textfiles. linecounting. Thin interface getchar and
- ungetchar. (ungetc is unlimited)
-
- should protect get and unget against improper use
-*/
-
-
-class Text_stream
-{
- int line_no;
-
- // could just have used streams.
- FILE *f;
- Array<char> pushback;
- String name;
-
- public:
- Text_stream(String fn);
- String get_name() { return name; }
- bool eof() {
- return feof(f);
- }
- bool eol() {
- return (peek() == '\n');
- }
- char peek() {
- char c = get();
- unget(c);
- return c;
- }
- int line(){
- return line_no;
- }
-
- char get() {
- char c;
-
- if (pushback.empty())
- c = getc(f);
- else
- c = pushback.pop();
-
- if (c =='\n')
- line_no++;
- return c;
- }
- void unget(char c) {
- if (c =='\n')
- line_no--;
- pushback.push(c);
- }
- ~Text_stream (){
- if (!eof())
- cerr <<__FUNCTION__<< ": closing unended file";
-
- fclose(f);
- }
-
- /// GNU format message.
- void message(String s);
-};
-
-#endif
/**
- scaleable array/stack template, for T with def ctor.
+ Scaleable array/stack template, for a type T with default constructor.
+
+
This template implements a scaleable vector. With (or without) range
checking. It may be flaky for objects with complicated con- and
destructors. The type T should have a default constructor. It is
- best suited for simple types, such as int, double or String
+ best suited for simple types, such as int, double or String, it
+ provides a paranoidly safe replacement for the new T[int] construct.
It uses stack terminology, (push, pop, top), and can be used as a stack.
+
+
*/
template<class T>
class Array {
size_--;
}
// quicksort.
- void sort (int (*compare)(T& , T& ),
+ void sort (int (*compare)( T const&,T const&),
int lower = -1, int upper = -1 ) {
if (lower < 0) {
lower = 0 ;
+++ /dev/null
-#!/usr/bin/perl -w
-
-die "arg needed\n" if (!($#ARGV+1));
-my $fn = $ARGV[0];
-my $hh_q = ($fn =~ /hh$/ );
-my $MAILADRESS=$ENV{MAILADRESS};
-my @pw=(getpwuid($<));
-my $username=$pw[6];
-my $what="implement ";
-$what = "declare " if ($hh_q);
-my $headstr ="/*
- $fn -- $what
-
- source file of the LilyPond music typesetter
-
- (c) 1997 $username <$MAILADRESS>
-*/\n";
-
-my $startdef= $fn;
-$startdef =~ s/[\.-]/_/g;
-$startdef =~ tr/a-z/A-Z/;
-my $terminatestr="\n";
-if ($hh_q) {
- $headstr .= "\n\n#ifndef $startdef\n#define $startdef\n";
- $terminatestr .= "#endif // $startdef\n"
-}
-
-print $headstr, $terminatestr;
-
-
-
+++ /dev/null
-default:
- $(MAKE) -C ..
-DISTFILES=Makefile $(allhdr)
-dist:
- ln $(DISTFILES) $(DDIR)/$(SUBDIR)
-
-
-TAGS: $(hdr)
- $(TAGSACTION) $^
-
-clean:
- rm -f parser.hh
- rm -f midi-parser.hh
+++ /dev/null
-/*
- bar-reg.hh -- declare Bar_register
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-
-#ifndef BARREG_HH
-#define BARREG_HH
-#include "register.hh"
-
-/**
- generate bars. Either user ("|:"), or default (new measure)
- */
-class Bar_register : public Request_register {
- void split_bar(Bar *& pre, Bar * no, Bar * &post);
-public:
- Bar_req * bar_req_l_;
- Bar * bar_p_;
-
- virtual bool try_request(Request *req_l);
- virtual void process_requests();
- virtual void pre_move_processing();
- virtual void post_move_processing();
- Bar_register();
- NAME_MEMBERS(Bar_register);
-};
-
-#endif // BARREG_HH
+++ /dev/null
-/*
- bar.hh -- part of LilyPond
-
- (c) 1996,97 Han-Wen Nienhuys
-*/
-
-#ifndef BAR_HH
-#define BAR_HH
-#include "item.hh"
-
-struct Bar: Item {
- String type;
-
- Bar(String type);
-NAME_MEMBERS(Bar);
- void do_print() const;
- Molecule*brew_molecule_p()const;
-};
-#endif // BAR_HH
-
+++ /dev/null
-/*
- beam.hh -- part of LilyPond
-
- (c) 1996,97 Han-Wen Nienhuys
-*/
-
-#ifndef BEAM_HH
-#define BEAM_HH
-#include "proto.hh"
-#include "directional-spanner.hh"
-#include "plist.hh"
-
-/** a beam connects multiple stems Beam adjusts the stems its owns to
- make sure that they reach the beam and that point in the correct
- direction */
-struct Beam: public Directional_spanner {
- PointerList<Stem*> stems;
- /// the slope of the beam in posns / point (dimension)
- Real slope;
-
- /// position of leftmost end of beam
- Real left_pos;
-
-
- /* *************** */
-NAME_MEMBERS(Beam);
-
- virtual Interval width()const;
- Offset center() const;
- Spanner *do_break_at(PCol *, PCol *) const;
- Beam();
- void add(Stem*);
-
-
- void set_default_dir();
- void do_pre_processing();
- void do_post_processing();
-
- void do_print() const;
- void set_grouping(Rhythmic_grouping def, Rhythmic_grouping current);
- void set_stemlens();
- ~Beam();
-
-private:
- Molecule stem_beams(Stem *here, Stem *next, Stem *prev)const;
- void solve_slope();
- Molecule*brew_molecule_p()const;
-};
-
-#endif // BEAM_HH
-
+++ /dev/null
-/*
- some 2D geometrical concepts
-*/
-
-#ifndef BOXES_HH
-#define BOXES_HH
-
-#include "fproto.hh"
-#include "real.hh"
-#include "interval.hh"
-#include "offset.hh"
-
-/// a square subset of Real^2
-struct Box {
- Interval x, y;
-
- void translate(Offset o) {
- x.translate(o.x);
- y.translate(o.y);
- }
- /// smallest box enclosing #b#
- void unite(Box b) {
- x.unite(b.x);
- y.unite(b.y);
- }
- Box();
- Box(Interval ix, Interval iy);
-};
-
-
-#endif
+++ /dev/null
-/*
- break.hh -- part of LilyPond
-
- (c) 1996,97 Han-Wen Nienhuys
-*/
-
-#ifndef BREAK_HH
-#define BREAK_HH
-#include "varray.hh"
-#include "proto.hh"
-#include "colhpos.hh"
-
-/** Class representation of an algorithm which decides where to put
- the column, and where to break lines. */
-struct Break_algorithm {
- PScore &pscore_;
- Real linelength;
-
- /* *************** */
-
- Break_algorithm(PScore&);
-
- /// check if the spacing/breaking problem is well-stated
- void problem_OK()const;
-
- /// search all pcols which are breakable.
- Line_of_cols find_breaks() const;
-
- /// helper: solve for the columns in #curline#.
- Col_hpositions solve_line(Line_of_cols) const;
-
- /// does curline fit on the paper?
- bool feasible(Line_of_cols)const;
-
- virtual Array<Col_hpositions> solve()=0;
-};
-
-/// wordwrap type algorithm: move to next line if current is optimal.
-struct Word_wrap : Break_algorithm {
- virtual Array<Col_hpositions> solve();
- Word_wrap(PScore&);
-};
-#endif // BREAK_HH
-
+++ /dev/null
-/*
- class-name.hh -- declare
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-
-#ifndef CLASS_NAME_HH
-#define CLASS_NAME_HH
-
-/// a macro to declare the classes name as a static and virtual function.
-#define NAME_MEMBERS(c) \
-static const char *static_name(){ return #c; }\
-virtual const char *name() const{ return c::static_name(); } \
-int a_stupid_nonexistent_function_to_allow_the_semicolon_come_out()
-
-#endif // CLASS-NAME_HH
+++ /dev/null
-
-/*
- clef-item.hh -- declare Clef_item
-
- (c) 1996,97 Han-Wen Nienhuys
-*/
-
-#ifndef CLEFITEM_HH
-#define CLEFITEM_HH
-#include "item.hh"
-
-
-struct Clef_item : Item {
- String type;
- int y_off;
-
- /// is this a change clef (smaller size)?
- bool change;
-
-
- /* *************** */
-NAME_MEMBERS(Clef_item);
- Clef_item();
- void read(Clef_register const&);
- void read(String);
- Molecule* brew_molecule_p()const;
-};
-
-#endif // CLEFITEM_HH
-
-
+++ /dev/null
-/*
- clef.hh -- part of LilyPond
-
- (c) 1996,97 Han-Wen Nienhuys
-*/
-
-#ifndef CLEF_HH
-#define CLEF_HH
-
-#include "scalar.hh"
-#include "varray.hh"
-#include "register.hh"
-
-/// where is c-0 in the staff?
-class Clef_register : public Request_register {
- Clef_item *clef_p_;
- Clef_change_req * clef_req_l_;
-
-public:
- int c0_position_i_;
- String clef_type_str_;
-
- /* ************** */
- virtual void process_requests();
- virtual void pre_move_processing();
- virtual void post_move_processing();
- virtual bool try_request(Request*);
- Clef_register();
- NAME_MEMBERS(Clef_register);
- void read_req(Clef_change_req*);
- bool set_type(String);
-};
-#endif // CLEF_HH
-
+++ /dev/null
-/*
- colhpos.hh -- part of LilyPond
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-#ifndef COLHPOS_HH
-#define COLHPOS_HH
-#include "varray.hh"
-#include "proto.hh"
-
-typedef Array<PCol*> Line_of_cols;
-
-struct Col_hpositions {
- Line_of_cols cols;
- Array<Real> config;
- Real energy;
-
- /* ************** */
- void OK()const;
-
- Col_hpositions();
- void add( PCol*c);
- void print() const;
-};
-
-
-#endif // COLHPOS_HH
-
+++ /dev/null
-/*
- commandrequest.hh -- declare Non musical requests
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-
-#ifndef COMMANDREQUEST_HH
-#define COMMANDREQUEST_HH
-
-#include "request.hh"
-#include "varray.hh"
-
-/** Request which are assumed to be "happening" before the
- musical requests. */
-struct Command_req : virtual Request {
- REQUESTMETHODS(Command_req, command);
-
- virtual Measure_grouping_req * measuregrouping() { return 0; }
- virtual Clef_change_req * clefchange() { return 0; }
- virtual Key_change_req * keychange() { return 0; }
- virtual Partial_measure_req * partial() { return 0; }
- virtual Meter_change_req * meterchange() { return 0; }
- virtual Bar_req *bar() { return 0; }
- virtual Cadenza_req *cadenza() { return 0; }
- virtual Timing_req*timing() { return 0; }
-};
-
-
-/** Baseclass for meter/partial req. It has to be handled by
- Staff_{walker,column} baseclass. */
-struct Timing_req : Command_req {
- REQUESTMETHODS(Timing_req, timing);
-};
-
-
-struct Partial_measure_req : Timing_req {
- Moment duration_;
-
- Partial_measure_req(Moment);
- REQUESTMETHODS(Partial_measure_req, partial);
-};
-
-/**
- todo: allow C meter
- */
-struct Meter_change_req : Timing_req {
- int beats_i_, one_beat_i_;
-
- Meter_change_req();
- void set(int,int);
- REQUESTMETHODS(Meter_change_req, meterchange);
-};
-
-/// toggle Cadenza mode
-struct Cadenza_req : Timing_req {
- /// turn on?
- bool on_b_;
- Cadenza_req(bool);
- REQUESTMETHODS(Cadenza_req,cadenza);
-};
-
-/// check if we're at start of a measure.
-struct Barcheck_req : Timing_req {
-
- REQUESTMETHODS(Barcheck_req,barcheck);
-};
-
-struct Measure_grouping_req: Timing_req {
- Array<int> beat_i_arr_;
- Array<Moment> elt_length_arr_;
-
- REQUESTMETHODS(Measure_grouping_req, measuregrouping);
-};
-
-struct Group_change_req : Command_req {
- String newgroup_str_;
- REQUESTMETHODS(Group_change_req, groupchange);
-};
-
-/** draw a (repeat)-bar. This something different than #Barcheck_req#,
- the latter should only happen at the start of a measure. */
-struct Bar_req : Command_req {
- String type_str_;
- Bar_req(String);
- int compare(const Bar_req&)const;
- REQUESTMETHODS(Bar_req,bar);
-};
-struct Terminate_voice_req : Command_req {
- REQUESTMETHODS(Terminate_voice_req,terminate);
-};
-
-struct Group_feature_req : Command_req {
- int stemdir_i_;
- Group_feature_req();
- REQUESTMETHODS(Group_feature_req, groupfeature);
-};
-
-
-struct Key_change_req : Command_req {
- Array<Melodic_req*> melodic_p_arr_;
-
- Key_change_req();
- Key_change_req(Key_change_req const&);
- ~Key_change_req();
- REQUESTMETHODS(Key_change_req, keychange);
-};
-
-struct Clef_change_req : Command_req {
- String clef_str_;
- Clef_change_req(String);
- REQUESTMETHODS(Clef_change_req, clefchange);
-};
-
-#endif // COMMANDREQUEST_HH
+++ /dev/null
-/*
- complex-staff.hh -- declare Complex_staff
-
- (c) 1996,1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-#ifndef COMPLEXSTAF_HH
-#define COMPLEXSTAF_HH
-
-
-#include "key.hh"
-#include "staff.hh"
-#include "staff-walker.hh"
-
-///
-struct Complex_staff : Staff {
-
- /* *************** */
-
- virtual void set_output(PScore *);
- virtual Staff_walker *get_walker_p();
-};
-
-#endif // COMPLEXSTAF_HH
-
+++ /dev/null
-/*
- complex-walker.hh -- declare Complex_walker
-
- (c) 1996,97 Han-Wen Nienhuys
-*/
-
-#ifndef COMPLEXWALKER_HH
-#define COMPLEXWALKER_HH
-
-#include "proto.hh"
-#include "staff-walker.hh"
-#include "staff-elem-info.hh"
-
-/**
- A staff walker which uses registers to decide what to print
- */
-class Complex_walker: public Staff_walker {
- bool try_command_request(Command_req *req_l);
- void do_announces();
- void try_request(Request*req);
-
-
-
-public:
- int c0_position_i_;
- Walker_registers *walk_regs_p_;
-
- /* *************** */
-
- void regs_process_requests();
- void typeset_element(Staff_elem *elem_p);
- void announce_element(Staff_elem_info);
- virtual void process_requests();
- virtual void do_post_move();
- virtual void do_pre_move();
-
- Complex_walker(Complex_staff*);
- ~Complex_walker();
-
- Complex_staff *staff();
-private:
-};
-
-
-#endif // COMPLEXWALKER_HH
-
-
+++ /dev/null
-/*
- global constants
- */
-#ifndef CONST_HH
-#define CONST_HH
-#include <math.h>
-#include "real.hh"
-
-const Real EPS=1e-7; // qlpsolve.hh
-const int MAXITER=100; // qlpsolve.hh
-const Real INFTY=HUGE_VAL;
-#endif
+++ /dev/null
-#ifndef DEBUG_HH
-#define DEBUG_HH
-
-#include <assert.h>
-#include <iostream.h>
-#include "dstream.hh"
-#include "real.hh"
-#include "proto.hh"
-
-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 );
-void error(String s); // errors
-void error_t(const String& s, Time_description const & t_tdes);
-void error_t(String const &s, const Moment &when);
-// warnings
-//void warning(String s);
-#define WARN warnout << "warning: "<<__FUNCTION__ << "(): "
-extern ostream &warnout ;
-
-// progress
-extern ostream *mlog;
-
-// debugging
-extern Dstream *monitor; // monitor
-
-#ifdef NPRINT
-#define mtor if (0) *monitor // clever hack
-#else
-#define mtor if (check_debug) monitor->identify_as(__PRETTY_FUNCTION__)
-#endif
-
-extern bool check_debug;
-
-#endif
+++ /dev/null
-#ifndef DIMEN_HH
-#define DIMEN_HH
-
-#include "real.hh"
-#include "string.hh"
-
-const Real INCH_TO_PT=72.0;
-const Real CM_TO_PT=INCH_TO_PT/2.54;
-const Real MM_TO_PT=CM_TO_PT/10;
-const Real PT_TO_PT =1.0;
-
-#define PT *PT_TO_PT
-#define MM *MM_TO_PT
-#define CM *CM_TO_PT
-#define INCH *INCH_TO_PT
-
-Real parse_dimen(String);
-String print_dimen(Real);
-Real convert_dimen(Real, String);
-#endif
-
+++ /dev/null
-/*
- directional-spanner.hh -- part of LilyPond
-
- (c) 1996,97 Han-Wen Nienhuys
-*/
-
-#ifndef DIRECTIONALSPANNER_HH
-#define DIRECTIONALSPANNER_HH
-
-#include "spanner.hh"
-
-/// a spanner which can be pointing "up" or "down"
-struct Directional_spanner : Spanner{
-
- /// -1 below heads, +1 above heads.
- int dir_i_;
-
- /// offset of "center" relative to left-column/0-pos of staff
- virtual Offset center() const=0;
- virtual void set_default_dir()=0;
- Directional_spanner();
-
-};
-
-#endif // DIRECTIONALSPANNER_HH
-
+++ /dev/null
-//
-// duration.hh -- declare Duration, Plet, Duration_convert Duration_iterator
-//
-// copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
-
-// split into 4?
-
-#ifndef DURATION_HH
-#define DURATION_HH
-
-/// (dur)
-struct Duration {
- // actually i hate it when other people use default arguments,
- // because it makes you easily loose track of what-s really
- // happening; in the routine-s implementation you-re not aware
- // of this defaultness (who sets this stupid value?).
- Duration( int type_i = 1, int dots_i = 0, Plet* plet_p = 0 );
- Duration( Duration const& dur_c_r );
- ~Duration();
-
- Duration const& operator =( Duration const& dur_c_r );
-
- void set_plet( Plet* plet_l ); // handiger: newt zelf
-
-// int i_; // balltype -> type!
- int type_i_;
- int dots_i_;
- Plet* plet_p_;
-};
-
-/// (plet)
-struct Plet {
- Plet( int replace_i, int type_i );
- Plet( Plet const& plet_c_r );
-
-// int i_;
- int iso_i_; // 2/3; 2 is not duration, maar of count!
- int type_i_;
-};
-
-/**
- Duration_convert handles all conversions to -n fro Duration (dur).
- That is including (integer + division) representation for MIDI,
- and conversion from unexact time representation (best guess :-).
-
- A Moment (mom) is a Rational that holds the time fraction
- compared to a whole note (before also called wholes).
-
- SUGGESTION: currently a moment in time is called moment too;
- let-s typedef Rational When too, so that we get
- When Staff_column::when(), Moment Voice_element::mom().
-*/
-struct Duration_convert {
- /// Most used division in MIDI, all fine with me.
- static int const division_1_c_i = 384;
-
- /// Return (integer, division) representation.
- static int dur2_i( Duration dur, int division_1_i = division_1_c_i );
-
- /// Return Moment representation (fraction of whole note).
- static Moment dur2_mom( Duration dur );
-
- /// Return Mudela string representation.
- static String dur2_str( Duration dur );
-
- /// Return Moment from (integer, division) representation.
- static Moment i2_mom( int i, int division_1_i = division_1_c_i );
-
- /// Return Moment (fraction of whole) representation, best guess.
- static Duration mom2_dur( Moment mom );
-
- /// Return plet factor (not a Moment: should use Rational?).
- static Moment plet_factor_mom( Duration dur );
-
- /** Return synchronisation factor for mom, so that
- mom2_dur( mom / sync_f ) will return the duration dur.
- */
- static Real sync_f( Duration dur, Moment mom );
-};
-
-/// (iter_dur)
-struct Duration_iterator {
- /// start at shortest: 128:2/3
- Duration_iterator();
-
- // **** what about these three here ?
- /// return forward_dur();
- Duration operator ++(int);
-
- /// return ok()
- operator bool();
-
- /// return dur()
- Duration operator ()();
- // ****
-
- /// return current dur
- Duration dur();
-
- /// return dur(), step to next
- Duration forward_dur();
-
- /// durations left?
- bool ok();
-
-private:
- Duration cursor_dur_;
-};
-
-#endif // DURATION_HH
-
+++ /dev/null
-#ifndef GLOB_HH
-#define GLOB_HH
-#include <assert.h>
-#include <math.h>
-#include "real.hh"
-
-#include "proto.hh"
-#include "const.hh"
-#endif
+++ /dev/null
-/*
- grouping.hh -- part of LilyPond
-
- (c) 1996,97 Han-Wen Nienhuys
-*/
-
-#ifndef GROUPING_HH
-#define GROUPING_HH
-
-#include "moment.hh"
-#include "interval.hh"
-#include "varray.hh"
-
-typedef Interval_t<Moment> MInterval;
-
-/** data structure which represents rhythmic units this is a tree. It groupes notes according to rules
- */
-struct Rhythmic_grouping {
- Array<Rhythmic_grouping*> children;
- MInterval *interval_;
-
- /* *************** */
-
- Array<MInterval> intervals();
- MInterval interval()const;
- Moment length() const;
- void intersect(MInterval);
-
- void operator=(Rhythmic_grouping const&);
- Rhythmic_grouping(Rhythmic_grouping const&);
- Rhythmic_grouping(MInterval, int n=1);
- Rhythmic_grouping();
- Rhythmic_grouping(Array<Rhythmic_grouping*>);
- ~Rhythmic_grouping();
-
- void add_child(Moment start, Moment len);
- bool child_fit_query(Moment start);
- void split(Rhythmic_grouping r);
- void split(Array<MInterval>);
- void split(int n);
-
- void print() const;
- void OK() const;
-
- Array<int> generate_beams(Array<int>, int&);
-
- /** multiply self to span #i#.
- In implementation, this isn't really const, but conceptually it is.
- */
- void extend(MInterval i) const;
- void translate(Moment);
-private:
- void init();
- void junk();
- void copy(Rhythmic_grouping const&);
-};
-
-
-Rhythmic_grouping parse_grouping(Array<int> beat_i_arr, Array<Moment> elt_length_arr);
-
-
-#endif
+++ /dev/null
-/*
- headreg.hh -- part of LilyPond
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-
-#ifndef HEADREG_HH
-#define HEADREG_HH
-#include "register.hh"
-
-struct Notehead_register : Request_register {
- Item* note_p_;
- Rhythmic_req * note_req_l_;
- int dir_i_;
-
- /* *************** */
- Notehead_register();
- virtual bool try_request(Request *req_l) ;
- virtual void process_requests();
- virtual void pre_move_processing();
- virtual void post_move_processing();
- void set_feature(Features);
- NAME_MEMBERS(Notehead_register);
-};
-
-
-#endif // HEADREG_HH
+++ /dev/null
-/*
- idealspacing.hh -- part of LilyPond
-
- (c) 1996,97 Han-Wen Nienhuys
-*/
-
-#ifndef IDEALSPACING_HH
-#define IDEALSPACING_HH
-#include "proto.hh"
-
-/// ideal spacing between two columns
-struct Idealspacing {
-
- /// the ideal distance
- Real space;
-
- /// Hooke's constant: how strong are the "springs" attached to columns
- Real hooke;
-
- /// the two columns
- const PCol *left, *right;
-
- void print()const;
- void OK() const ;
- Idealspacing(const PCol *left,const PCol *right);
-};
-
-
-#endif // IDEALSPACING_HH
-
+++ /dev/null
-
-/*
- identifier.hh -- part of LilyPond
-
- (c) 1996,97 Han-Wen Nienhuys
-*/
-
-#ifndef IDENTIFIER_HH
-#define IDENTIFIER_HH
-#include "identparent.hh"
-#include "symtable.hh"
-#include "input-staff.hh"
-#include "input-music.hh"
-#include "notename.hh"
-#include "lookup.hh"
-#include "script-def.hh"
-
-#define make_id_class(Idclass, Class, accessor) \
-struct Idclass : Identifier {\
- virtual const char *classname() { return #Class; }\
- Idclass(String s, Class*st):Identifier(s) { data = st; }\
- virtual Class* accessor(bool copy) {\
- if (copy)\
- return new Class(* (Class*) data);\
- else\
- return (Class*) data;\
- }\
- ~Idclass() { delete accessor(false); }\
- virtual void do_print()const; \
-}\
-
-make_id_class(Real_id, Real, real);
-make_id_class(Script_id, Script_def, script);
-make_id_class(Lookup_id, Lookup, lookup);
-make_id_class(Symtables_id, Symtables, symtables);
-make_id_class(Staff_id, Input_staff, staff);
-make_id_class(M_chord_id, Music_general_chord, mchord);
-make_id_class(M_voice_id, Music_voice, mvoice);
-make_id_class(Notetab_id, Notename_tab, notename_tab);
-
-#endif // IDENTIFIER_HH
-
+++ /dev/null
-/*
- identparent.hh -- part of LilyPond
-
- (c) 1996,97 Han-Wen Nienhuys
-*/
-
-#ifndef IDENTPARENT_HH
-#define IDENTPARENT_HH
-
-#include "proto.hh"
-#include "string.hh"
-
-/* boolean argument to accesor is copy_b..*/
-#define IDACCESSOR( Input_staff, staff)\
- virtual Input_staff * staff(bool) { error(#Input_staff); return 0; }
-
-struct Identifier {
- void *data;
- String name;
-
- Identifier(String n) : name(n) { }
- virtual ~Identifier() {}
-
- void print()const;
- virtual const char*classname() { return "new Identifier"; }
- void error(String);
- IDACCESSOR(Input_staff, staff)
- IDACCESSOR(Input_music, music)
- IDACCESSOR(Music_voice, mvoice)
- IDACCESSOR(Script_def, script)
- IDACCESSOR(Symtables, symtables)
- IDACCESSOR(Music_general_chord, mchord)
- IDACCESSOR(Lookup,lookup)
- IDACCESSOR(Real,real)
- IDACCESSOR(Notename_tab, notename_tab)
-protected:
- virtual void do_print()const=0;
-private:
- Identifier(Identifier const&){}
-
-};
-#endif // IDENTPARENT_HH
-
-
-
+++ /dev/null
-/*
- input-file.hh -- declare Input_file
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-#ifndef INPUT_FILE_HH
-#define INPUT_FILE_HH
-#include <FlexLexer.h>
-#include "proto.hh"
-#include "fproto.hh"
-#include "varray.hh"
-#include "string.hh"
-
-struct Input_file {
- istream* is;
- char const* defined_ch_c_l_;
- Source_file* sourcefile_l_;
- int line;
- String name;
-
- Input_file(String);
- ~Input_file();
-};
-
-#endif // INPUT_FILE_HH
+++ /dev/null
-/*
- input-music.hh -- part of LilyPond
-
- (c) 1996,97 Han-Wen Nienhuys
-*/
-
-#ifndef INPUTMUSIC_HH
-#define INPUTMUSIC_HH
-
-#include "plist.hh"
-#include "proto.hh"
-#include "voice.hh"
-#include "moment.hh"
-
-struct Voice_list : public PointerList<Voice*> {
- void translate_time(Moment dt);
-};
-
-/**
-
- A set voices.
- Input_music is anything that can simply be regarded as/converted to
- a set of voices "cooperating" or independant. It has some basic
- characteristics that real music has too:
-
- - it is rhythmic (it has a length, and can be translated horizontally)
- - a pitch (it can be transposed)
-
- */
-struct Input_music {
- virtual Voice_list convert()const=0;
- void check_plet(Voice_element* velt_l);
- virtual Moment length()const=0;
- virtual void translate_time(Moment dt)=0;
- virtual ~Input_music(){}
- virtual void print() const =0;
- virtual void set_default_group(String)=0;
- virtual bool find_plet_start_bo(char c, Moment& moment_r) = 0;
- virtual void set_plet_backwards(Moment& now_moment_r, Moment until_moment, int num_i, int den_i) = 0;
- // virtual void transpose(...) const =0;
-
-
- virtual Input_music *clone() const = 0;
- virtual Simple_music *simple() { return 0; }
-};
-
-/// Simple music consists of one voice
-struct Simple_music : Input_music {
- Voice voice_;
-
- /* *** */
- virtual Simple_music*simple() { return this; }
- void add(Voice_element*);
- virtual void set_default_group(String g) { voice_.set_default_group(g); }
- virtual Moment length()const;
- virtual Voice_list convert()const;
- virtual void translate_time(Moment dt);
- virtual void print() const;
- virtual bool find_plet_start_bo(char c, Moment& moment_r);
- virtual void set_plet_backwards(Moment& now_moment_r, Moment until_moment, int num_i, int den_i);
- virtual Input_music *clone() const {
- return new Simple_music(*this);
- }
-
-};
-
-/// Complex_music consists of multiple voices
-struct Complex_music : Input_music {
- IPointerList<Input_music*> elts;
- /* *************** */
- virtual void set_default_group(String g);
- void add(Input_music*);
- Complex_music();
- Complex_music(Complex_music const &);
- virtual void print() const ;
- void concatenate(Complex_music*);
- virtual bool find_plet_start_bo(char c, Moment& moment_r);
- virtual void set_plet_backwards(Moment& now_moment_r, Moment until_moment, int num_i, int den_i);
-
-};
-
-
-/**
- A voice like list of music.
-
- different music forms which start after each other ( concatenated,
- stacked "horizontally )
-
- */
-
-struct Music_voice : Complex_music {
-
-
- /* *************** */
- Moment length()const;
- virtual void translate_time(Moment dt);
- virtual Voice_list convert()const;
- void add_elt(Voice_element*);
- virtual Input_music *clone() const {
- return new Music_voice(*this);
- }
- virtual void print() const ;
-};
-
-/**
- Multiple musicstuff stacked on top of each other
- chord like :
-
- - different music forms which start at the same time ( stacked "vertically" )
-
- */
-struct Music_general_chord : Complex_music {
-
-
- /* *************** */
-
- virtual Moment length()const;
- virtual Voice_list convert()const;
- virtual void translate_time(Moment dt);
- void add_elt(Voice_element*);
- virtual Input_music *clone() const {
- return new Music_general_chord(*this);
- }
-
- virtual void print() const ;
-};
-
-struct Multi_voice_chord : Music_general_chord {
- void set_default_group(String);
- virtual Input_music *clone() const {
- return new Multi_voice_chord(*this);
- }
-};
-struct Voice_group_chord : Music_general_chord {
-
- virtual Input_music *clone() const {
- return new Voice_group_chord(*this);
- }
-};
-#endif // INPUTMUSIC_HH
+++ /dev/null
-/*
- input-score.hh -- declare
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-
-#ifndef INPUTSCORE_HH
-#define INPUTSCORE_HH
-
-#include "varray.hh"
-#include "proto.hh"
-#include "plist.hh"
-#include "string.hh"
-
-
-/// the total music def of one movement
-struct Input_score {
- /// defined where?
- const char* defined_ch_c_l_;
- int errorlevel_i_;
-
- /// paper_, staffs_ and commands_ form the problem definition.
- Paper_def *paper_p_;
- Midi_def* midi_p_;
- IPointerList<Input_staff*> staffs_;
-
- Input_music * score_wide_music_p_;
-
- /* *************************************************************** */
- Input_score();
- Input_score(Input_score const&);
-
- void add(Input_staff*);
- ~Input_score();
- /// construction
- void set(Paper_def*);
- void set(Midi_def* midi_p);
- void print() const;
- Score*parse();
- void set(Input_music*);
-};
-
-#endif
+++ /dev/null
-/*
- input-staff.hh -- declare Input_staff
-
- (c) 1996,97 Han-Wen Nienhuys
-*/
-
-#ifndef INPUTSTAFF_HH
-#define INPUTSTAFF_HH
-
-#include "string.hh"
-#include "plist.hh"
-#include "varray.hh"
-#include "proto.hh"
-
-struct Input_staff {
-
- const char * defined_ch_c_l_;
- String type;
-
- IPointerList<Input_music*> music_;
- Input_music * score_wide_music_p_;
-
- /* *************** */
- ~Input_staff();
- void add(Input_music*m);
- Input_staff(Input_staff const&);
- Input_staff(String);
- void set_score_wide(Input_music*m);
- Staff* parse(Score*, Input_music *score_wide);
- void print() const;
-};
-
-
-#endif // INPUTSTAFF_HH
-
+++ /dev/null
-#ifndef ITEM_HH
-#define ITEM_HH
-
-#include "glob.hh"
-#include "boxes.hh"
-#include "string.hh"
-#include "staff-elem.hh"
-
-/**
- a horizontally fixed size element of the score
-
- Item is the datastructure for printables whose width is known
- before the spacing is calculated
-
- NB. This doesn't mean an Item has to initialize the output field before
- spacing calculation.
-
-*/
-struct Item : Staff_elem {
- /// indirection to the column it is in
- PCol * pcol_l_;
-
- /* *************** */
- virtual Item *item() { return this; }
- Item();
- void do_print()const;
-
- NAME_MEMBERS(Item);
-};
-
-
-#endif
+++ /dev/null
-/*
- key-item.hh -- part of LilyPond
-
- (c) 1996,97 Han-Wen Nienhuys
-*/
-
-#ifndef KEYITEM_HH
-#define KEYITEM_HH
-
-#include "item.hh"
-#include "varray.hh"
-
-
-/// An item which places accidentals at the start of the line
-struct Key_item : Item {
- Array<int> pitch;
- Array<int> acc;
- int c_position;
-
-
- /* *************** */
-NAME_MEMBERS(Key_item);
- Key_item(int cposition);
- void add(int pitch, int acc);
- void read(const Key_register&);
- void set_c_position(int);
- void preprocess();
- Molecule* brew_molecule_p()const;
-};
-
-#endif // KEYITEM_HH
+++ /dev/null
-/*
- key-reg.hh -- declare Key_register
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-
-#ifndef KEYREG_HH
-#define KEYREG_HH
-
-#include "register.hh"
-#include "key.hh"
-
-struct Key_register : Request_register {
- Key key_;
- Key_change_req * keyreq_l_;
- Key_item * kit_p_;
- Array<int> accidental_idx_arr_;
- bool default_key_b_;
-
- virtual bool try_request(Request *req_l);
- virtual void process_requests();
- virtual void pre_move_processing();
- virtual void post_move_processing();
- virtual void acknowledge_element(Staff_elem_info);
- Key_register();
- NAME_MEMBERS(Key_register);
-private:
-
- void read_req(Key_change_req * r);
-};
-
-#endif // KEYREG_HH
+++ /dev/null
-/*
- key.hh -- declare Key
-
- (c) 1996,97 Han-Wen Nienhuys
-*/
-
-#ifndef KEY_HH
-#define KEY_HH
-
-#include "varray.hh"
-#include "scalar.hh"
-
-/// administration of current key
-class Key {
- Array<int> accidental_i_arr_;
-
- /* *************** */
-
-public:
-
- Key();
- void set(int i, int acc);
- int acc(int i)const { return accidental_i_arr_[i]; }
-};
-
-/// administration of accidentals
-struct Local_key
-{
- void reset(Key);
- Key& oct(int);
- Local_key();
-
-private:
- Array<Key> octaves;
-};
-
-#endif // KEY_HH
-
-
+++ /dev/null
-/*
- keyword.hh -- part of LilyPond
-
- (c) 1996,97 Han-Wen Nienhuys
-*/
-
-#ifndef KEYWORD_HH
-#define KEYWORD_HH
-
-/* for the keyword table */
-struct Keyword_ent
-{
- const char *name;
- int tokcode;
-};
-
-struct Keyword_table
-{
- Keyword_ent *table;
- int maxkey;
- Keyword_table(Keyword_ent *);
- int lookup(const char *s) const;
-};
-
-
-#endif // KEYWORD_HH
-
+++ /dev/null
-/*
- leastsquare.hh -- part of LilyPond
-
- (c) 1996,97 Han-Wen Nienhuys
-*/
-
-#ifndef LEASTSQUARE_HH
-#define LEASTSQUARE_HH
-#include "varray.hh"
-#include "offset.hh"
-
-
-/**
- Least squares minimisation in 2 variables.
- */
-struct Least_squares {
- Array<Offset> input;
- void minimise(Real &coef, Real &offset);
- void OK() const;
-};
-
-
-#endif // LEASTSQUARE_HH
-
+++ /dev/null
-/*
- lexer.hh -- declare My_flex_lexer
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-#ifndef LEXER_HH
-#define LEXER_HH
-#include <FlexLexer.h>
-#include "proto.hh"
-#include "fproto.hh"
-#include "varray.hh"
-#include "string.hh"
-
-int yylex();
-void yyerror(const char *s);
-bool busy_parsing();
-void kill_lexer();
-void set_lexer();
-
-/// lexer with provisions for include files.
-struct My_flex_lexer : yyFlexLexer {
-
- Array<Input_file*> include_stack;
- Assoc<String, Identifier*> *the_id_tab;
- Keyword_table * keytable;
- Notename_tab * defaulttab;
- int errorlevel_i_;
- /* *************** */
- int ret_notename(int *p, String text, int octave_mod);
- char const* here_ch_c_l();
- void set(Notename_tab *n);
- int lookup_keyword(String);
- void lookup_notename(int &large, int &small, String s);
- void LexerError(const char *);
- String spot() const;
- Identifier*lookup_identifier(String s);
- My_flex_lexer();
- void add_identifier(Identifier*i);
- ~My_flex_lexer();
- void new_input(String s);
- bool close_input();
- int yylex();
- void print_declarations() const;
-};
-
-extern My_flex_lexer *lexer;
-
-#endif
+++ /dev/null
-//
-// lily-stream.hh -- part of LilyPond
-//
-// copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
-
-// should i be named Mudela_stream?
-
-#ifndef LILY_STREAM_HH
-#define LILY_STREAM_HH
-
-/// Lily output
-struct Lily_stream {
- ostream* os_p_;
- String filename_str_;
-
- Lily_stream( String filename_str );
- ~Lily_stream();
-
- Lily_stream& operator <<( String str );
- Lily_stream& operator <<( Midi_event& midi_event_r );
-
- void header();
- void open();
-};
-
-#endif // LILY_STREAM_HH
-
+++ /dev/null
-#ifndef PROBLEM_HH
-#define PROBLEM_HH
-
-#include "glob.hh"
-#include "plist.hh"
-#include "varray.hh"
-#include "vector.hh"
-#include "interval.hh"
-
-/// helper struct for #Spacing_problem#
-struct Colinfo {
- const PCol *pcol_;
- const Real* fixpos;
- Interval width;
-
- /* *************** */
- Colinfo();
- void operator=(Colinfo const&);
- Colinfo(Colinfo const&);
- ~Colinfo();
- Colinfo(const PCol*,const Real*);
- void print() const;
- bool fixed() const { return fixpos;}
- Real fixed_position()const { return *fixpos; }
- Real minright() const { return width.right; }
- Real minleft() const { return -width.left; }
-};
-
-
-/** the problem, given by the columns (which include constraints) and
- intercolumn spacing. The problem is:
-
- Generate a spacing which
- \begin{itemize}
- \item
- Satisfies spacing constraints (notes can't be printed through each other)
- \item
- Looks good, ie tries to conform to an ideal spacing as much as possible.
- \end{itemize}
- This is converted by regarding idealspacing as "springs" attached
- to columns. The equilibrium of one spring is the ideal
- distance. The columns have a size, this imposes "hard" constraints
- on the distances. This transforms the problem into a quadratic
- programming problem with linear constraints.
-
- The quality is given by the total potential energy in the
- springs. The lower the energy, the better the configuration.
-*/
-class Spacing_problem {
- Array<const Idealspacing*> ideals;
- Array<Colinfo> cols;
-
- /// the index of #c# in #cols#
- int col_id(const PCol *c) const;
-
- /// generate an (nonoptimal) solution
- Vector find_initial_solution() const;
-
- /// check if problem is too tight
- bool check_feasible() const;
-
- /// does #this# contain the column #w#?
- bool contains(const PCol *w);
-
- /// make the energy function
- void make_matrices(Matrix &quad, Vector &lin,Real&) const;
-
- /// generate the LP constraints
- void make_constraints(Mixed_qp& lp) const;
-
-public:
- /** solve the spacing problem
-
- @return the column positions, and the energy (last element)
-
- */
- Array<Real> solve() const;
-
-
- /**
- add a idealspacing to the problem.
-
- One pair of columns can have no, one or more idealspacings,
- since they can be "summed" if the columns to which #i# refers are
- not in this problem, the spacing is ignored.
- */
- void add_ideal(const Idealspacing *i);
-
-
- /** add a col to the problem. columns have to be added left to right. The column contains
- info on it's minimum width.
- */
- void add_column(const PCol *, bool fixed=false, Real fixpos=0.0);
-
-
-
- bool check_constraints(Vector v) const;
-
- Vector try_initial_solution() const;
- void OK() const;
- void print() const;
- void print_ideal(const Idealspacing*)const;
-};
-
-
-#endif
+++ /dev/null
-/*
- local-key-item.hh -- part of LilyPond
-
- (c) 1996,97 Han-Wen Nienhuys
-*/
-
-#ifndef LOCALKEYITEM_HH
-#define LOCALKEYITEM_HH
-#include "item.hh"
-#include "varray.hh"
-
-struct Local_acc {
- int name , acc, octave;
- static int compare(Local_acc&, Local_acc&);
-};
-
-struct Local_key_item : Item {
-NAME_MEMBERS(Local_key_item);
- Array<Local_acc> accs;
- Array<Item*> support_items_;
- int c0_position;
-
- /* *************** */
-
- Local_key_item(int c0position);
- void add(Item*);
- void add(int oct, int pitch, int acc);
- void add(Melodic_req*);
- void do_pre_processing();
- Molecule* brew_molecule_p()const;
-};
-#endif // LOCALKEYITEM_HH
-
+++ /dev/null
-/*
- local-key-reg.hh -- declare Local_key_register
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-
-#ifndef LOCALKEYREG_HH
-#define LOCALKEYREG_HH
-#include "register.hh"
-#include "key.hh"
-
-struct Local_key_register : Request_register {
- Local_key local_key_;
- Local_key_item* key_item_p_;
- const Key *key_c_l_;
- /* *************** */
- virtual void process_requests();
- virtual void acknowledge_element(Staff_elem_info);
- virtual void pre_move_processing();
- Local_key_register();
- NAME_MEMBERS(Local_key_register);
-};
-
-#endif // LOCALKEYREG_HH
+++ /dev/null
-/*
- lilypond, (c) 1996,97 Han-Wen Nienhuys
-*/
-#ifndef LOOKUPSYMS_HH
-#define LOOKUPSYMS_HH
-
-#include "symbol.hh"
-#include "fproto.hh"
-#include "scalar.hh"
-
-/// intuitive interface to symbol table
-struct Lookup {
- Symtables *symtables_;
- String texsetting;
- /* *************** */
- void add(String, Symtable*);
- void print()const;
- Real internote();
-
- Symbol linestaff(int n, Real w);
- Symbol fill(Box b);
- Symbol beam_element(int,int,Real=0);
-
- /// round slope to closest TeXslope
- Symbol beam(Real&,Real);
-
- /**
- pos == 3 : 3 lines above staff (extending below note)
-
- pos == -3: below staff
- */
- Symbol streepjes(int pos);
-
- Symbol meter(Array<Scalar>);
- Symbol stem(Real y1_pos, Real y2_pos);
- Symbol rule_symbol(Real height, Real width);
- Symbol accidental(int);
- Symbol ball(int);
- Symbol flag(int);
- Symbol rest(int);
- Symbol clef(String);
- Symbol bar(String);
- Symbol dots(int);
- Symbol slur(int dy, Real &dx, int dir);
- Symbol half_slur(int dy, Real &dx, int dir, int xpart);
- Symbol half_slur_middlepart(Real &dx, int dir);
- Symbol big_slur(int dy, Real &dx, int dir);
- Symbol text(String style, String text, int align = 1);
- Symbol script(String idx);
- Symbol hairpin(Real & width, bool decresc);
-
- Lookup();
- Lookup(Lookup const &);
- ~Lookup();
-};
-
-#endif
+++ /dev/null
-//
-// lyric-item.hh -- part of LilyPond
-//
-// copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
-
-#ifndef LYRIC_ITEM_HH
-#define LYRIC_ITEM_HH
-
-#include "textitem.hh"
-
-struct Lyric_item : Text_item {
- /* *************** */
- Lyric_item(Lyric_req* lreq_l, int voice_count_i);
- virtual void do_pre_processing();
-};
-
-
-#endif // LYRIC_ITEM_HH //
-
+++ /dev/null
-#ifndef MAIN_HH
-#define MAIN_HH
-#include "proto.hh"
-
-void debug_init();
-void set_debug(bool);
-void do_scores();
-void add_score(Input_score * s);
-void set_default_output(String s);
-Input_score* current_iscore_l();
-String find_file(String);
-const char *get_version();
-extern Source* source_l_g;
-extern bool only_midi;
-
-extern String default_out_fn;
-
-#endif
+++ /dev/null
-/*
- meter-reg.hh -- declare Meter_register
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-
-#ifndef METERREG_HH
-#define METERREG_HH
-#include "register.hh"
-
-/**
- generate meters.
- */
-class Meter_register : public Request_register {
-public:
- Meter_change_req * meter_req_l_;
- Meter * meter_p_;
-
- virtual bool try_request(Request *req_l);
- virtual void process_requests();
- virtual void pre_move_processing();
- virtual void post_move_processing();
- Meter_register();
- NAME_MEMBERS(Meter_register);
-};
-#endif // METERREG_HH
+++ /dev/null
-/*
- meter.hh -- declare Meter
-
- (c) 1996,97 Han-Wen Nienhuys
-*/
-
-#ifndef METER_HH
-#define METER_HH
-#include "item.hh"
-#include "varray.hh"
-#include "scalar.hh"
-
-struct Meter: Item {
- Array<Scalar> args;
- /* *************** */
-NAME_MEMBERS(Meter);
-
- Meter(Array<Scalar> args) ;
- Molecule*brew_molecule_p() const;
-};
-#endif // METER_HH
-
+++ /dev/null
-//
-// midi-event.hh -- declare midi_event
-//
-// copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
-
-#ifndef MIDI_EVENT_HH
-#define MIDI_EVENT_HH
-
-
-// should these:
-// * be Midi_items
-// * be Voice_elements/requests
-// * get a name-change
-// ?
-
-/// (midi_event)
-class Midi_event {
-public:
- Midi_event();
- virtual ~Midi_event();
-
- virtual String mudela_str(); // = 0;
- virtual void output_mudela( Lily_stream& lily_stream_r );
- virtual Moment mom();
-
-protected:
- String mudela_str_;
-};
-
-class Midi_key : public Midi_event {
-public:
- Midi_key( int accidentals_i, int minor );
- virtual ~Midi_key();
-
- String notename_str( int pitch_i );
-
-private:
- int accidentals_i_;
- int minor_i_;
- int key_i_;
-};
-
-class Midi_note : public Midi_event {
- 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 {
-public:
- Midi_tempo( int useconds_per_4_i );
- virtual ~Midi_tempo();
-
- int get_tempo_i( Moment moment );
-
-private:
- int useconds_per_4_i_;
- Real seconds_per_1_f_;
-};
-
-class Midi_time : public Midi_event {
-public:
- Midi_time( int num_i, int den_i, int division_4_i, int count_32_i );
- virtual ~Midi_time();
-
- Duration i2_dur( int time_i, int division_1_i );
- int clocks_1_i();
-
-private:
- Real sync_f_;
- Duration sync_dur_;
- int clocks_1_i_;
- int num_i_;
- int den_i_;
-};
-
-#endif // MIDI_EVENT_HH
-
+++ /dev/null
-//
-// midi-item.hh -- part of LilyPond
-//
-// copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
-
-#ifndef MIDI_ITEM_HH
-#define MIDI_ITEM_HH
-#include "string.hh"
-#include "proto.hh"
-
-struct Midi_item {
- /* *************** */
- static String i2varint_str( int i );
- virtual void output_midi( Midi_stream& midi_stream_r );
- virtual String str() = 0;
-};
-
-struct Midi_note : public Midi_item {
- /* *************** */
- int const c0_pitch_i_c_ = 60;
- Byte dynamic_byte_;
-
- /**
- Generate a note-event on a channel pitch.
-
- @param #melreq_l# is the pitch.
- */
- Midi_note( Melodic_req* melreq_l, int channel_i, bool on_b );
-
- virtual String str();
-
- int channel_i_;
- int on_b_;
- int pitch_i_;
-};
-
-struct Midi_duration : public Midi_item {
- /* *************** */
- Midi_duration( Real seconds_f );
-
- virtual String str();
-
- Real seconds_f_;
-};
-
-struct Midi_chunk : Midi_item {
- /* *************** */
- Midi_chunk();
-
- void add( String str );
- void set( String header_str, String data_str, String footer_str );
- virtual String str();
-
-private:
- String data_str_;
- String footer_str_;
- String header_str_;
-};
-
-struct Midi_header : Midi_chunk {
- /* *************** */
- Midi_header( int format_i, int tracks_i, int clocks_per_4_i );
-};
-
-struct Midi_tempo : Midi_item {
- /* *************** */
- Midi_tempo( int tempo_i );
-
- virtual String str();
-
- int tempo_i_;
-};
-
-struct Midi_track : Midi_chunk {
- /* *************** */
- int number_i_;
- Midi_track( int number_i );
-
- void add( int delta_time_i, String event );
-// void add( Moment delta_time_moment, Midi_item& mitem_r );
- void add( Moment delta_time_moment, Midi_item* mitem_l );
-};
-
-#endif // MIDI_ITEM_HH //
-
+++ /dev/null
-//
-// midi-main.hh -- global (sic) m2m stuff
-//
-// copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
-#include "string.hh"
-
-#define monitor_p_g &cout
-enum Verbose { QUIET_ver, BRIEF_ver, NORMAL_ver, VERBOSE_ver, DEBUG_ver };
-extern Verbose level_ver;
-#ifdef NPRINT
-#define dtor if ( 0 ) *monitor_p_g
-#define mtor if ( 0 ) *monitor_p_g
-#else
-#define dtor if ( level_ver >= DEBUG_ver ) *monitor_p_g
-#define vtor if ( level_ver >= VERBOSE_ver ) *monitor_p_g
-#define mtor if ( level_ver >= NORMAL_ver ) *monitor_p_g
-#define btor if ( level_ver >= BRIEF_ver ) *monitor_p_g
-#define qtor if ( level_ver >= QUIET_ver ) *monitor_p_g
-#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();
+++ /dev/null
-/*
- midi-output.hh -- declare Midi_output
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-
-#ifndef MIDIOUTPUT_HH
-#define MIDIOUTPUT_HH
-#include "pscore.hh"
-
-struct Midi_output {
- Midi_stream* midi_stream_l_;
- Midi_output(Score* score_l, Midi_def* );
- void do_staff(Staff*st_l, int count);
-
- Midi_def* midi_l_;
-};
-#endif // MIDIOUTPUT_HH
+++ /dev/null
-//
-// midi-score.hh -- declare midi_score
-//
-// copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
-
-#ifndef MIDI_SCORE_HH
-#define MIDI_SCORE_HH
-
-/// (midi_score)
-class Midi_score {
-public:
- Midi_score( int format_i, int tracks_i, int tempo_i );
- ~Midi_score();
-
- void add_track( Midi_track* midi_track_p );
-
- int output_mudela( String filename_str );
-
-private:
- IPointerList<Midi_track*> midi_track_p_list_;
- int format_i_;
- int tracks_i_;
- int tempo_i_;
-};
-
-#endif // MIDI_SCORE_HH
-
+++ /dev/null
-//
-// midi-stream.hh -- part of LilyPond
-//
-// copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
-
-#ifndef MIDI_STREAM_HH
-#define MIDI_STREAM_HH
-
-#include <iostream.h>
-#include "string.hh"
-
-/// Midi output
-struct Midi_stream {
- ostream* os_p_;
- String filename_str_;
- int clocks_per_4_i_;
- int tracks_i_;
-
- Midi_stream( String filename_str, int tracks_i, int clocks_per_4_i_ );
- ~Midi_stream();
-
- Midi_stream& operator <<( String str );
- Midi_stream& operator <<( Midi_item& mitem_r );
- Midi_stream& operator <<( int i );
-
- void header();
- void open();
-
-//private:
-// Midi_stream(Midi_stream const&);
-};
-#endif // MIDI_STREAM_HH //
+++ /dev/null
-//
-// midi-track.hh -- declare midi_track
-//
-// copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
-
-#ifndef MIDI_TRACK_HH
-#define MIDI_TRACK_HH
-
-/// (midi_track)
-class Midi_track {
-public:
- Midi_track( int track_i );
- ~Midi_track();
-
- 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<Track_column*> tcol_p_list_;
- String name_str_;
-};
-
-#endif // MIDI_TRACK_HH
-
+++ /dev/null
-#ifndef MISC_HH
-#define MISC_HH
-
-#include "proto.hh"
-#include "real.hh"
-#include "moment.hh"
-#include "scalar.hh"
-#include "grouping.hh"
-
-Moment wholes(int dur, int dots);
-double log_2(double x) ;
-int intlog2(int d);
-inline int
-abs(int i){
- return (i < 0)?-i:i;
-}
-inline int
-sign(int i) {
- if (i<0) return -1;
- else if (i) return 1;
- else return 0;
-}
-
-Interval itemlist_width(const Array<Item*> &its);
-
-#endif
+++ /dev/null
-#ifndef MOLECULE_HH
-#define MOLECULE_HH
-
-#include "proto.hh"
-#include "plist.hh"
-#include "boxes.hh"
-#include "symbol.hh"
-
-/// a symbol which can be translated, and freely copied
-struct Atom {
- Offset off;
- Symbol sym;
-
- /* *************** */
-
- void translate(Offset o) {
- off += o;
- }
-
- /// how big is #this#?
- Box extent() const;
- Atom(Symbol s);
-
- void print() const;
-
- String TeXstring() const;
-};
-
-
-/** a group of individually translated symbols. You can add molecules
- to the top, to the right, etc. */
-struct Molecule {
- IPointerList<Atom*> ats; // change to List<Atom>?
-
- /* *************** */
-
- Molecule() { }
- Molecule(Atom a) { add(a) ; }
-
- void add_right(const Molecule &m);
- void add_left(const Molecule &m);
- void add_top(const Molecule &m);
- void add_bottom(const Molecule &m);
- void add(Molecule const &m);
- void translate(Offset);
- void add(Atom a) { ats.bottom().add(new Atom(a)); }
- /// how big is #this#?
- Box extent() const;
-
- String TeXstring() const;
-
- Molecule(const Molecule&s);
- void print() const;
-private:
- void operator=(const Molecule&);
-};
-#endif
+++ /dev/null
-/*
- (c) 1996,97 Han-Wen Nienhuys
-*/
-
-#ifndef MOMENT_HH
-#define MOMENT_HH
-
-#include "rational.hh"
-class String;
-typedef Rational Moment;
-
-
-#endif //
-
+++ /dev/null
-/*
- musicalrequests.hh -- declare Musical requests
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-
-#ifndef MUSICALREQUESTS_HH
-#define MUSICALREQUESTS_HH
-
-#include "request.hh"
-
-
-/**
- A request which is coupled to a #Voice_element# with nonzero duration.
- Base class only
- */
-struct Musical_req : virtual Request {
- virtual Skip_req* skip() { return 0; }
- REQUESTMETHODS(Musical_req, musical);
-};
-
-
-struct Skip_req : Musical_req {
- Moment duration_;
-
- virtual Moment duration() const;
- REQUESTMETHODS(Skip_req, skip);
-};
-/** a request with a duration.
- This request is used only a base class.
- */
-struct Rhythmic_req : virtual Musical_req {
- int balltype;
- int dots;
- Moment plet_factor;
- /* *************** */
- static int compare(const Rhythmic_req &, const Rhythmic_req &);
- virtual Moment duration() const;
- Rhythmic_req();
- Rhythmic_req(int,int);
- REQUESTMETHODS(Rhythmic_req, rhythmic);
-};
-
-struct Spacing_req :virtual Request {
- Moment next;
- Real distance;
- Real strength;
- /* *************** */
- Spacing_req();
- REQUESTMETHODS(Spacing_req, spacing);
-};
-
-struct Blank_req : Spacing_req, Rhythmic_req {
- REQUESTMETHODS(Spacing_req, spacing);
-
-};
-
-/// Put a text above or below (?) this staff.
-struct Text_req : virtual Musical_req {
- /// preferred position (above/below)
- int dir_i_;
- /// the characteristics of the text
- Text_def *tdef_p_;
- /* *************** */
- Text_req(int d, Text_def*);
- ~Text_req();
- Text_req(Text_req const&);
- static int compare(const Text_req&,const Text_req&);
- REQUESTMETHODS(Text_req,text);
-};
-
-/** Put a text in lyric_staff
- @see Lyric_staff
- */
-struct Lyric_req : public Rhythmic_req, Text_req {
- Lyric_req(Text_def* t_p);
- REQUESTMETHODS(Lyric_req, lreq_l);
-};
-
-/// request which has some kind of pitch
-struct Melodic_req :virtual Musical_req
-{
- /// 0 is c, 6 is b
- int notename_i_;
- /// 0 is central c
- int octave_i_;
-
- /// 0 natural, 1 sharp, etc
- int accidental_i_;
-
- /// force/supress printing of accidental.
- bool forceacc_b_;
-
- /// return height from central c (in halflines)
- int height()const;
- /// return pitch from central c (in halfnotes)
- int pitch()const;
- Melodic_req();
-
- REQUESTMETHODS(Melodic_req,melodic);
-};
-
-/// Put a note of specified type, height, and with accidental on the staff.
-struct Note_req : Rhythmic_req, virtual Melodic_req {
-
-
- Rhythmic_req* rhythmic() { return Rhythmic_req::rhythmic(); }
- REQUESTMETHODS(Note_req, note);
- };
-
-/**
-Put a rest on the staff. Why a request? It might be a good idea to not typeset the rest, if the paper is too crowded.
-*/
-class Rest_req : public Rhythmic_req {
-public:
- REQUESTMETHODS(Rest_req,rest);
-};
-
-/**
- attach a stem to the noteball.
- Rhythmic_req parent needed to determine if it will fit inside a beam.
- */
-struct Stem_req : Rhythmic_req {
- /// preferred direction for the stem
- int dir_i_;
- Stem_req(int s, int dots);
- REQUESTMETHODS(Stem_req,stem);
-};
-
-/**
- Requests to start or stop something.
- This type of request typically results in the creation of a #Spanner#
-*/
-struct Span_req : Musical_req {
- /// should the spanner start or stop, or is it unwanted?
- enum {
- NOSPAN, START, STOP
- } spantype ;
- static int compare(const Span_req &r1, const Span_req &r2);
- REQUESTMETHODS(Span_req,span);
-
- Span_req();
-
-};
-
-/// request for backward plet generation
-struct Plet_req : Request {
- char type_c_;
- int dur_i_;
- int type_i_;
- Plet_req();
-
- REQUESTMETHODS(Plet_req,plet);
-};
-/**
-*/
-
-/** Start / stop a beam at this note. if #nplet# is set, the staff will try to put an
-appropriate number over the beam
- */
-struct Beam_req : Span_req {
- int nplet;
-
- /* *************** */
- REQUESTMETHODS(Beam_req,beam);
-
- Beam_req();
-};
-
-/// a slur
-struct Slur_req : Span_req {
- REQUESTMETHODS(Slur_req,slur);
-
-};
-
-
-/**Put a script above or below this ``note''. eg upbow, downbow. Why a
-request? These symbols may conflict with slurs and brackets, so this
-also a request */
-struct Script_req : Musical_req {
- int dir_i_;
- Script_def *scriptdef_p_;
-
- /* *************** */
- static int compare(const Script_req &, const Script_req &);
- Script_req(int d, Script_def*);
- REQUESTMETHODS(Script_req,script);
- ~Script_req();
- Script_req(Script_req const&);
-};
-
-
-
-
-#endif // MUSICALREQUESTS_HH
+++ /dev/null
-//
-// my-midi-parser.hh -- declare My_midi_parser
-//
-// copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
-
-#ifndef MY_MIDI_PARSER_HH
-#define MY_MIDI_PARSER_HH
-
-// #include "proto.hh"
-// #include "string.hh"
-
-int yyparse();
-
-/// (midi_parser)
-class My_midi_parser {
-public:
- My_midi_parser( String filename_str );
- ~My_midi_parser();
- void add_score( Midi_score* midi_score_p );
- void error( char const* sz_l );
- int parse();
- 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_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:
- Int64 now_i64_; // 31 bits yields tipically about 1000 bars
-
- static int const CHANNELS_i = 16;
- static int const PITCHES_i = 128;
- Int64 running_i64_i64_a_[ CHANNELS_i ][ PITCHES_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_;
-
- char const* defined_ch_c_l_;
- int fatal_error_i_;
- My_midi_lexer* midi_lexer_p_;
-};
-
-extern My_midi_parser* midi_parser_l_g;
-
-#endif // MY_MIDI_PARSER_HH
-
+++ /dev/null
-/*
- notehead.hh -- part of LilyPond
-
- (c) 1996,97 Han-Wen Nienhuys
-*/
-
-#ifndef NOTEHEAD_HH
-#define NOTEHEAD_HH
-#include "item.hh"
-
-/**
- ball at the end of the stem
-takes care of:
-
- * help lines
- * proper placing of dots
-
- */
-
-struct Notehead : Item {
- NAME_MEMBERS(Notehead);
-
- int position;
- /// -1 = lowest, 0 = inside, 1 = top
- int extremal;
- /// needed for the help-lines
- int staff_size;
- int dots;
- int balltype;
- int x_dir;
-
- /* *************** */
-
- void set_rhythmic(Rhythmic_req *);
-
- /**
- position of top line (5 linestaff: 8)
- */
- Notehead(int staff_size);
- void do_print()const;
- static int compare(Notehead * const &a, Notehead *const &b) ;
- Molecule* brew_molecule_p()const;
-};
-#endif // NOTEHEAD_HH
-
+++ /dev/null
-/*
- notename.hh -- part of LilyPond
-
- (c) 1996,97 Han-Wen Nienhuys
-*/
-
-#ifndef NOTENAME_HH
-#define NOTENAME_HH
-
-#include "string.hh"
-
-struct Notename_tab {
- String notetab[7*5];
-
- void set(int l, int s, String nm);
- void lookup(int &large, int &small, String s);
-};
-
-void set_notename_tab(Notename_tab*n);
-void lookup_notename(int &large, int &small, String s);
-
-
-#endif // NOTENAME_HH
-
+++ /dev/null
-/*
- offset.hh -- part of LilyPond
-
- (c) 1996,97 Han-Wen Nienhuys
-*/
-
-#ifndef OFFSET_HH
-#define OFFSET_HH
-#include "real.hh"
-
-/// 2d vector
-struct Offset {
- Real x,y;
-
- Offset operator+(Offset o)const {
- Offset r(*this);
- r+=o;
- return r;
- }
-
- Offset operator+=(Offset o) {
- x+=o.x;
- y+=o.y;
- return *this;
- }
- Offset(Real ix , Real iy) {
- x=ix;
- y=iy;
- }
- Offset() {
- x=0.0;
- y=0.0;
- }
-};
-
-#endif // OFFSET_HH
-
-
+++ /dev/null
-/*
- paper-def.hh -- declare
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-
-#ifndef Paper_def_HH
-#define Paper_def_HH
-#include "proto.hh"
-#include "real.hh"
-#include "string.hh"
-#include "moment.hh"
-
-
-/** symbols, dimensions and constants
-
- This struct takes care of all kinds of symbols, dimensions and
- constants. Most of them are related to the point-size of the fonts,
- so therefore, the lookup table for symbols is also in here.
-
- see TODO
- */
-struct Paper_def {
- Lookup *lookup_p_;
- String outfile;
-
- Real linewidth;
-
- /// how much space does a whole note take (ideally?)
- Real whole_width;
-
- /// ideal = geometric_ ^ log2(duration)
- Real geometric_;
-
- /* *************** */
- void reinit();
- Paper_def(Lookup*);
- void set(Lookup*);
- ~Paper_def();
- Paper_def(Paper_def const&);
- Real interline()const;
- Real internote()const;
- Real rule_thickness()const;
- Real standard_height()const;
- Real note_width() const;
- void print() const;
- Real duration_to_dist(Moment);
-};
-
-#endif // Paper_def_HH
-
+++ /dev/null
-/*
- parseconstruct.hh -- part of LilyPond
-
- (c) 1996,97 Han-Wen Nienhuys
-*/
-
-#ifndef PARSECONSTRUCT_HH
-#define PARSECONSTRUCT_HH
-
-#include "proto.hh"
-
-extern char const* defined_ch_c_l;
-extern char const* req_defined_ch_c_l;
-void set_default_duration(int *);
-void last_duration(int n);
-void set_duration_mode(String s);
-void get_default_duration(int *);
-void set_default_octave(String);
-void set_plet(int,int);
-Voice_element * get_note_element(String,int * ,int *);
-Voice_element* get_rest_element(String,int *);
-Voice_element* get_word_element(Text_def*, int*);
-void add_requests( Voice_element*v, Array<Request*>&req);
-Request* get_request(char);
-void set_text_style(String);
-Script_def* get_scriptdef(char);
-Text_def*get_text(String s);
-Request* get_plet_request( char c, int dur_i, int type_i );
-Request*get_script_req(int d , Script_def*def);
-Request*get_text_req(int d , Text_def*def);
-Request* get_stemdir_req(int);
-
-
-
-
-Request*get_grouping_req(Array<int> i_arr);
-
-#endif // PARSECONSTRUCT_HH
-
+++ /dev/null
-#ifndef COLS_HH
-#define COLS_HH
-
-#include "glob.hh"
-#include "boxes.hh"
-#include "plist.hh"
-#include "item.hh"
-
-
-/**
- stuff grouped vertically.
- This is a class to address items vertically. It contains the data for:
- \begin{itemize}
- \item
- unbroken score
- \item
- broken score
- \item
- the linespacing problem
- \end{itemize}
- */
-
-struct PCol {
- PointerList<const Item*> its;
- PointerList<const Spanner*> stoppers, starters;
-
-
-
- /** prebreak is put before end of line.
- if broken here, then (*this) column is discarded, and prebreak
- is put at end of line, owned by Col
- */
- PCol *prebreak_p_;
-
- /// postbreak at beginning of the new line
- PCol *postbreak_p_;
-
- /** if this column is pre or postbreak, then this field points to
- the parent. */
- PCol *daddy_l_;
-
- /// if lines are broken then this column is in #line#
- const Line_of_score *line_l_;
-
- /// if lines are broken then this column x-coord #hpos#
- Real hpos;
-
- PScore * pscore_l_;
-
- /* *************** */
- /// which one (left =0)
- int rank() const;
-
- /// does this column have items
- bool used_b() const;
-
- void add(Item *i);
-
- /// Can this be broken? true eg. for bars.
- bool breakable_b()const;
-
- Interval width() const;
- ~PCol();
- PCol(PCol * parent);
-
- /**
- which col comes first?.
- signed compare on columns.
-
- @return < 0 if c1 < c2.
- */static int compare(const PCol &c1, const PCol &c2);
-
-
- void OK() const;
- void set_breakable();
- void print()const;
-private:
- PCol(PCol const&){}
-};
-
-
-#include "compare.hh"
-instantiate_compare(PCol &, PCol::compare);
-
-
-#endif
+++ /dev/null
-/*
- proto.hh -- part of LilyPond
-
- (c) 1996,97 Han-Wen Nienhuys
-*/
-
-#ifndef PROTO_HH
-#define PROTO_HH
-
-#include "fproto.hh"
-#include "real.hh"
-
-/// (i64)
-typedef long long Int64;
-
-struct Absdynamic_req;
-struct Accidental;
-struct Atom;
-struct Bar;
-struct Bar_register;
-struct Barcheck_req;
-struct Bar_req;
-struct Beam;
-struct Beam_req;
-struct Box;
-struct Bracket_req;
-struct Cadenza_req;
-struct Chord;
-struct Clef_change_req;
-struct Clef_register;
-struct Clef_item;
-struct Col_hpositions;
-struct Colinfo;
-struct Complex_music;
-struct Complex_staff;
-struct Complex_walker;
-struct Cresc_req;
-struct Directional_spanner;
-struct Decresc_req;
-struct Duration;
-struct Duration_iterator;
-struct Durational_req;
-struct Dynamic;
-struct Group_change_req;
-struct Group_feature_req;
-struct Idealspacing;
-struct Identifier;
-struct Input_file;
-struct Input_music;
-struct Input_score;
-struct Input_staff;
-struct Item;
-struct Key;
-struct Key_register;
-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;
-struct Local_key;
-struct Local_key_register;
-struct Local_key_item;
-struct Lookup;
-struct Lyric_item;
-struct Lyric_req;
-struct Melodic_req;
-struct Measure_grouping_req;
-struct Meter_change_req;
-struct Meter;
-struct Meter_register;
-struct Midi_def;
-struct Midi_duration;
-struct Midi_event;
-struct Midi_header;
-struct Midi_item;
-struct Midi_key;
-struct Midi_note;
-struct Midi_output;
-struct Midi_pitch;
-struct Midi_staff;
-struct Midi_stream;
-struct Midi_tempo;
-struct Midi_time;
-struct Midi_track;
-struct Midi_walker;
-struct Mixed_qp;
-class My_midi_lexer;
-class My_midi_parser;
-class Midi_event;
-class Midi_score;
-class Midi_track;
-struct Molecule;
-struct Musical_req;
-struct Music_general_chord;
-struct Music_voice;
-struct Command_req;
-struct Note_req;
-struct Notehead;
-struct Notehead_register;
-struct Notename_tab;
-struct Offset;
-struct Output;
-struct PCol;
-struct Plet_req;
-struct Plet;
-struct PScore;
-struct PStaff;
-struct Paper_def;
-struct Partial_measure_req;
-struct Rational;
-struct Register_group_register;
-struct Request;
-struct Request_register;
-struct Rest;
-struct Rest_req;
-struct Rhythmic_grouping;
-struct Rhythmic_grouping_req;
-struct Rhythmic_req;
-struct Score;
-struct Score_column;
-struct Score_walker;
-struct Script_def;
-struct Script;
-struct Script_register;
-struct Script_req;
-struct Simple_music;
-struct Skip_req;
-struct Slur;
-struct Slur_register;
-struct Slur_req;
-struct Source;
-struct Source_file;
-struct Spacing_req ;
-struct Span_req;
-struct Spanner;
-struct Blank_req;
-struct Staff;
-struct Staff_column;
-struct Staff_elem;
-struct Staff_elem_info;
-struct Staff_symbol;
-struct Staff_walker;
-struct Stem;
-struct Stem_req;
-struct Stem_beam_register;
-struct String;
-struct Symbol;
-struct Symtable;
-struct Symtables;
-struct Tex_stream;
-struct Terminate_voice_req;
-struct Text_item ;
-struct Text_def;
-struct Text_gob;
-struct Text_register;
-struct Text_req;
-struct Timing_req;
-struct Time_description;
-struct Track_column;
-struct Voice;
-struct Voice_element;
-struct Voice_group_registers;
-struct Voice_list;
-struct Voice_registers;
-struct Voicegroup;
-struct Walker_registers;
-typedef Rational Moment;
-#endif // PROTO_HH
+++ /dev/null
-// the breaking problem for a score.
-
-#ifndef PSCORE_HH
-#define PSCORE_HH
-
-#include "colhpos.hh"
-#include "varray.hh"
-#include "pcol.hh"
-#include "pstaff.hh"
-
-
-/** all stuff which goes onto paper. notes, signs, symbols in a score can be grouped in two ways:
- horizontally (staffwise), and vertically (columns). #PScore#
- contains the items, the columns and the staffs.
- */
-
-struct PScore {
- Paper_def *paper_l_;
-
- /// the columns, ordered left to right
- IPointerList<PCol *> cols;
-
- /// the idealspacings, no particular order
- IPointerList<Idealspacing*> suz;
-
- /// the staffs ordered top to bottom
- IPointerList<PStaff*> staffs;
-
- /// all symbols in score. No particular order.
- IPointerList<Item*> its;
-
- /// if broken, the different lines
- IPointerList<Line_of_score*> lines;
-
- /// crescs etc; no particular order
- IPointerList<Spanner *> spanners;
-
- /// broken spanners
- IPointerList<Spanner*> broken_spans;
-
- /* *************** */
- /* CONSTRUCTION */
-
- PScore(Paper_def*);
- /// add a line to the broken stuff. Positions given in #config#
- void set_breaking(Array<Col_hpositions>);
-
- void add(PStaff *);
-
-
- /** add an item.
- add the item in specified containers. If breakstatus is set
- properly, add it to the {pre,post}break of the pcol.
- */
- void typeset_item(Item *item_p, PCol *pcol_l,PStaff*pstaf_l,int breakstatus=1);
-
- /// add a Spanner
- void typeset_spanner(Spanner*, PStaff*);
-
- /// add to bottom of pcols
- void add(PCol*);
- void add_broken(Spanner*);
-
- /* INSPECTION */
- Array<Item*> select_items(PStaff*, PCol*);
-
- /**
- @return argument as a cursor of the list
- */
- PCursor<PCol *> find_col(const PCol *)const;
-
- /* MAIN ROUTINES */
- void process();
-
- /// last deed of this struct
- void output(Tex_stream &ts);
-
- /* UTILITY ROUTINES */
-
- /// get the spacing between c1 and c2, create one if necessary.
- Idealspacing* get_spacing(PCol *c1, PCol *c2);
-
- /// connect c1 and c2
- void do_connect(PCol *c1, PCol *c2, Real distance_f, Real strength_f);
-
- /// connect c1 and c2 and any children of c1 and c2
- void connect(PCol* c1, PCol *c2, Real distance_f,Real strength_f= 1.0);
-
- /* STANDARD ROUTINES */
- void OK()const;
- void print() const;
-private:
- /// before calc_breaking
- void preprocess();
-
- /// calculate where the lines are to be broken, and use results
- void calc_breaking();
-
- /// after calc_breaking
- void postprocess();
-
- /// delete unused columns
- void clean_cols();
-};
-
-#endif
+++ /dev/null
-#ifndef PSTAFF_HH
-#define PSTAFF_HH
-
-#include "proto.hh"
-#include "plist.hh"
-#include "item.hh"
-#include "symbol.hh"
-
-/// items grouped horizontally
-struct PStaff {
- PScore * pscore_l_;
-
-
- PointerList<const Spanner*> spans;
- PointerList<Item*> its;
-
- /* *************** */
- void add(Item*i);
- PStaff(PScore*);
-
-private:
- PStaff(PStaff const&);
-};
-
-#endif
+++ /dev/null
-/*
- qlp.hh -- declare Ineq_constrained_qp, Mixed_qp
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-#ifndef QLP_HH
-#define QLP_HH
-
-#include "matrix.hh"
-
-/// inequality constrained quadratic program
-class Ineq_constrained_qp {
- friend class Active_constraints;
-
- Array<Vector> cons;
- Array<Real> consrhs;
-public:
- Matrix quad;
- Vector lin;
- Real const_term;
-
-
- /**
- use a KKT method to assert optimality of sol
- */
- void assert_solution(Vector sol) const;
- /// solve the problem using a projected gradient method
- Vector solve(Vector start) const;
-
- /**
- @return the number of variables in the problem
- */
- int dim() const{
- return lin.dim();
- }
-
- /**
- add a constraint
-
-
- c*vars >= r
-
- PRE
- c.dim() == dim();
-
- */
- void add_inequality_cons(Vector c, double r);
-
- /** set up matrices to go with the problem. */
- Ineq_constrained_qp(int novars);
-
- /**
- evaluate the quadratic function for input #v#
- */
- Real eval(Vector v);
-
- void eliminate_var(int idx, Real value);
- void OK()const;
- void print() const;
-
-};
-
-
-/**
- Quadratic programming with mixed linear constraints.
- problem definition of a quadratic optimisation problem with linear
- inequality and equality constraints
-
-
- x^T QUAD x /2 + b^T x
-*/
-class Mixed_qp :public Ineq_constrained_qp {
- Array<int> eq_cons;
- Array<Real> eq_consrhs;
-public:
- Mixed_qp(int n);
- void OK() const;
- void print() const;
-
- Vector solve(Vector start) const;
- void add_fixed_var(int i , Real value);
-
-
- /**
- add a constraint,
-
- c*vars == r
-
- PRE
- c.dim()==dim();
- */
- void add_equality_cons(Vector c, double r);
-};
-#endif
+++ /dev/null
-/*
- qlpsolve.hh -- declare Active_constraints, Inactive_iter
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-
-#ifndef QLPSOLVE_HH
-#define QLPSOLVE_HH
-#include "qlp.hh"
-#include "matrix.hh"
-
-
-/**
- This class represents the set of active (binding) constraints
- which can be active while the QLP algorithm is in a feasible
- point. The active constraints are numbered.
- If the constraints are of the form
-
- A^T*x >= b
-
- then the binding constraints are those where the >= is equality.
-
- */
-
-class Active_constraints {
- friend class Inactive_iter;
-
-
- Matrix A,H;
- Array<int> active;
- Array<int> inactive; // actually this is a set, not an array.
- const Ineq_constrained_qp *opt;
-
-public:
- String status()const;
-
- Vector vec(int k) const { return opt->cons[k]; }
- Real rhs(int k) const { return opt->consrhs[k]; }
-
-
- /** drop constraint. drop constraint k from the active set. k is the index of the
- constraint in #active#
-
- */
- void drop (int k);
-
-
- /** add constraint j.
- add constraint j to the active set j is the index of the
- constraint in #inactive#
- */
- void add(int j);
-
- /// exchange in and out.
- void exchange(int in, int out) { add(in); drop (out); }
-
-
- Vector find_active_optimum(Vector g);
-
- /// get lagrange multipliers.
- Vector get_lagrange(Vector v);
-
- Active_constraints(Ineq_constrained_qp const *op);
- /** construct: no constraints active, n vars. Put the equalities
- into the constraints. */
-
- /// check invariants
- void OK();
-};
-
-
-/**
- loop through the inactive constraints.
- */
-class Inactive_iter {
- int j;
- Active_constraints const* ac;
-public:
- Inactive_iter(Active_constraints const &c) { ac=&c; j=0; }
- int idx() const { return j; }
- void operator ++(int) { j++; }
- int constraint_id() const { return ac->inactive[j]; }
- Vector vec() const { return ac->vec(constraint_id()); }
- Real rhs() const { return ac->rhs(constraint_id()); }
- bool ok() const { return j < ac->inactive.size(); }
-};
-
-#endif // QLPSOLVE_HH
+++ /dev/null
-/*
- register.hh -- part of LilyPond
-
- (c) 1996,1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-#ifndef REGISTER_HH
-#define REGISTER_HH
-
-#include "proto.hh"
-#include "varray.hh"
-#include "request.hh"
-#include "staff-elem-info.hh"
-
-/**
- a struct which processes requests, and creates the #Staff_elem#s.
- It may use derived classes. Hungarian postfix: register
- */
-class Request_register {
- friend class Register_group_register;
- /**
- You cannot copy a Request_register
- */
- Request_register(const Request_register&){}
-protected:
-
- /// utility
- virtual Paper_def * paper() const;
-
- /**
- try to fit the request in this register
-
- @return
- false: not noted, not taken.
-
- true: request swallowed. Don't try to put the request elsewhere.
-
-
- Default: always return false
- */
- virtual bool try_request(Request *req_l);
-
- /// make items/spanners with the requests you got
- virtual void process_requests(){}
-
- /** typeset any items/spanners. Default: do nothing
- */
- virtual void pre_move_processing(){}
- /** reset any appropriate data. Default: do nothing
- */
- virtual void post_move_processing(){}
-
- /**
- Is this request eligible to be processed? Default: return false.
- */
- virtual bool acceptable_request_b(Request*) const;
-
- /**
- typeset a "command" item. Default: pass on to daddy.
- If the column is not breakable, #pre_p# and #post_p# are junked
- */
- virtual void typeset_breakable_item(Item * pre_p ,
- Item * nobreak_p, Item * post_p);
- /**
- Invoke walker method to typeset element. Default: pass on to daddy.
- */
- virtual void typeset_element(Staff_elem*elem_p);
-
- /**
- take note of item/spanner
- put item in spanner. Adjust local key; etc.
-
- Default: ignore the info
- */
- virtual void acknowledge_element(Staff_elem_info) {}
- /**
- Announce element. Default: pass on to daddy. Utility
- */
- virtual void announce_element(Staff_elem_info);
- /**
- Set features of the register(s). Default: ignore features.
- */
- virtual void set_feature(Features){}
- /**
- Does this equal or contain a certain register?
- */
- virtual bool contains_b(Request_register*reg_l);
- /**
- Get information on the staff. Default: ask daddy.
- */
- virtual Staff_info get_staff_info();
-
- virtual void do_print()const;
-public:
- /** Every Request_register (except for the 'top' which is directly
- inside the Staff_walker, is a element of a group. */
- Register_group_register * daddy_reg_l_;
-
- Request_register();
- virtual ~Request_register(){}
- NAME_MEMBERS(Request_register);
- void print() const;
-};
-
-
-#endif // REGISTER_HH
-
+++ /dev/null
-/*
- registergroup.hh -- declare
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-
-#ifndef REGISTERGROUP_HH
-#define REGISTERGROUP_HH
-
-
-#include "plist.hh"
-#include "staff-elem-info.hh"
-#include "register.hh"
-
-/**
- Group a number of registers. Usually delegates everything to its contents.
- Postfix: group
- */
-class Register_group_register : public Request_register {
-protected:
- IPointerList<Request_register*> reg_list_;
- virtual void do_print()const;
-public:
-
- /**
- Junk #reg_l#.
-
- Pre:
- #reg_l# is in #reg_list_#
- */
- virtual void terminate_register(Request_register * reg_l);
-
- /**
- Remove #reg_l# from the list, and return it.
- */
- Request_register * get_register_p(Request_register*reg_l);
- virtual void set_feature(Features i);
- virtual bool acceptable_request_b(Request*);
- virtual void pre_move_processing();
- virtual void post_move_processing();
- virtual void acknowledge_element(Staff_elem_info info);
- virtual bool try_request(Request*);
- virtual void process_requests();
- virtual ~Register_group_register();
- virtual void add(Request_register* reg_p);
- virtual bool contains_b(Request_register*);
-};
-
-#endif // REGISTERGROUP_HH
-
-
+++ /dev/null
-#if 0
-
-
-
-/**Draw a (Guitar) chord above or below this ``note''.
-Why a request?
-Because everything else is done in requests.
-*/
-struct Chord : Request {
- // don't know how this looks.
-};
-
-
-/// for absolute dynamics
-enum Loudness {
- FFF, FF, F, MF, MP, P, PP, PPP
-} ;
-
-
-/**
-Start/stop a bracket at this note. if #nplet# is set, the staff will
-try to put an appropriate number over the bracket
-*/
-struct Bracket_req : Span_req {
- int nplet; // print a number over the beam.
-};
-
-struct Subtle_req {
- Moment subtime;
-};
-
-
-/** helper in the hierarchy. Each dynamic is bound to one note ( a
- crescendo spanning multiple notes is thought to be made of two
- "dynamics": a start and a stop). Dynamic changes can occur in a
- smaller time than the length of its note, therefore fore each
- Dynamic request carries a time, measured from the start of its
- note.
-
- This subfield would come in handy, if mpp96 was adapted for midi
- support.
-
- Dynamic should have been derived from request, but I don't want to
- fuss with virtual baseclasses. */
-
-struct Dynamic:Subtle_req {
-
-};
-/// do a crescendo
-struct Cresc_req : Span_req, Dynamic {
-
-};
-
-/// do a decrescendo
-struct Decresc_req : Span_req, Dynamic {
-
-};
-
-/// do a dynamic like "fff" or "mp"
-struct Absdynamic_req : Request, Dynamic {
- Loudness loudness;
-};
-
-struct Grace_req : Subtle_req {
-
-};
-
-struct Grace_turn_req : Grace_turn {
-
-};
-
-struct Grace_note : Melodic_req {
-
-};
-
-struct Grace_notes {
-
-};
-
-struct Glissando_req : Span_req {
-
-};
-#endif
+++ /dev/null
-/*
- request.hh -- declare Request baseclasses.
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-#ifndef REQUEST_HH
-#define REQUEST_HH
-// LilyPond's second egg of columbus!
-
-#include "glob.hh"
-#include "string.hh"
-#include "moment.hh"
-#include "class-name.hh"
-
-/**
- a voice element wants something printed.
- Hungarian postfix: req
- @see lilygut manpage
- */
-class Request {
-public:
- Voice_element*elt_l_;
- char const* defined_ch_c_l_;
-
- /* *************** */
- Voice * voice_l();
- Request();
- Request(Request const&);
- virtual ~Request(){}
-
- NAME_MEMBERS(Request);
- virtual Request* clone() const { return new Request(*this); }
- void print()const ;
-
- virtual Moment duration() const { return 0; }
-
- /* accessors for children
- maybe checkout RTTI
- */
- virtual Barcheck_req *barcheck() { return 0; }
- virtual Note_req *note() { return 0;}
- virtual Script_req *script() { return 0;}
- virtual Stem_req *stem() { return 0;}
- virtual Text_req*text() { return 0; }
- virtual Rest_req *rest() { return 0; }
- virtual Span_req *span() { return 0; }
- virtual Beam_req *beam() { return 0 ; }
- virtual Plet_req* plet() { return 0; }
- virtual Slur_req *slur() { return 0 ; }
- virtual Rhythmic_req*rhythmic() { return 0; }
- virtual Lyric_req* lreq_l() { return 0; }
- virtual Melodic_req *melodic() { return 0; }
- virtual Terminate_voice_req *terminate() {return 0;}
- virtual Group_change_req * groupchange() { return 0;}
- virtual Group_feature_req * groupfeature() { return 0; }
- virtual Spacing_req * spacing() { return 0; }
- virtual Blank_req * blank() { return 0; }
- virtual Musical_req *musical() { return 0; }
- virtual Command_req * command() { return 0; }
-protected:
- virtual void do_print()const ;
-};
-
-#define REQUESTMETHODS(T,accessor) \
-virtual T * accessor() { return this;}\
-NAME_MEMBERS(T);\
-virtual Request *clone() const { return new T(*this); } \
-virtual void do_print() const
-
-#endif
+++ /dev/null
-/*
- rest.hh -- part of LilyPond
-
- (c) 1996,97 Han-Wen Nienhuys
-*/
-
-#ifndef REST_HH
-#define REST_HH
-#include "item.hh"
-
-struct Rest : Item {
-
- int dots;
- int balltype;
-
- /* *************** */
-
-
- Rest(int dur,int dots);
- void do_print()const;
-NAME_MEMBERS(Rest);
- Molecule* brew_molecule_p()const;
-};
-#endif
-
+++ /dev/null
-/*
- sccol.hh -- part of LilyPond
-
- (c) 1996,97 Han-Wen Nienhuys
-*/
-
-#ifndef SCCOL_HH
-#define SCCOL_HH
-#include "proto.hh"
-#include "varray.hh"
-#include "moment.hh"
-
-
-/**
-
- When typesetting hasn't started on PScore yet, the columns which
- contain data have a rhythmical position. Score_column is the type
- with a rhythmical time attached to it. The calculation of
- idealspacing is done with data in these columns. (notably: the
- #durations# field)
-
- */
-
-class Score_column {
- friend class Score;
- friend class Score_walker;
-
- bool musical_b_;
- Moment when_;
- void set_breakable();
-public:
- /// indirection to column
- PCol * pcol_l_;
-
- /// length of notes/rests in this column
- Array<Moment> durations;
-
- /* *************** */
-
- Moment when() { return when_; }
- Score_column(Moment when);
- static int compare(Score_column & c1, Score_column &c2);
- void add_duration(Moment );
- void preprocess();
- bool breakable_b();
- bool musical_b() { return musical_b_; }
- bool used_b();
- void print() const;
-
-
-};
-
-instantiate_compare(Score_column&, Score_column::compare);
-
-#endif // SCCOL_HH
-
-
-
-
+++ /dev/null
-/*
- score-walker.hh -- declare Score_walker
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-
-#ifndef SCOREWALKER_HH
-#define SCOREWALKER_HH
-#include "pcursor.hh"
-#include "proto.hh"
-#include "varray.hh"
-
-
-/**
- walk through the score_columns, and while doing so, walk all staffs in a score.
- */
-class Score_walker : public PCursor<Score_column *>
-{
- Score* score_l_;
- /// walkers for the individual staves.
- Array<Staff_walker *> walker_p_arr_;
- Array<Staff_walker *> disallow_break_walk_l_arr;
- int disallow_break_count_;
- void reinit();
-public:
- void allow_break(Staff_walker*w);
- Score_walker(Score*);
- ~Score_walker();
- Moment when();
- void operator++(int);
- /// process staff walkers.
- void process();
-};
-#endif // SCOREWALKER_HH
+++ /dev/null
-/*
- score.hh -- declare Score
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-
-#ifndef SCORE_HH
-#define SCORE_HH
-
-#include "varray.hh"
-#include "proto.hh"
-#include "plist.hh"
-#include "moment.hh"
-#include "assoc.hh"
-#include "string.hh"
-
-/// the total music def of one movement
-struct Score {
- /// paper_, staffs_ and commands_ form the problem definition.
- Paper_def *paper_p_;
- Midi_def *midi_p_;
- IPointerList<Staff*> staffs_;
-
- /// "runtime" fields for setting up spacing
- IPointerList<Score_column*> cols_;
- PScore *pscore_p_;
-
- const char *defined_ch_c_l_;
- int errorlevel_i_;
-
- /* *************************************************************** */
-
- /// construction
- Score();
- ~Score();
- void add(Staff*);
-
- /// do everything except outputting to file
- void process();
-
- /// output to file
- void output(String fn);
-
-
- ///
- void set(Midi_def* midi_p);
- ///
- void set(Paper_def* midi_p);
-
- // standard
- void OK() const;
- void print() const;
-
- /// find a column.
- PCursor<Score_column *> find_col(Moment,bool);
-
- /// when does the last *musical* element finish?
- Moment last() const;
-
-private:
- void paper_output();
- void setup_music();
- void process_music();
- /// do midi stuff
- void midi();
-
- /// do paper stuff
- void paper();
-
- // utils:
- PCursor<Score_column*> create_cols(Moment);
-
- Score(Score const&){}
-
- /**
- make the pcol_l_ fields of each Score_column point to the correct PCol,
- remove any unnecessary Score_column's
- */
- void do_cols();
-
- /// remove unused cols
- void clean_cols();
-
- /// add #Idealspacings# to #pscore_#
- void calc_idealspacing();
-};
-#endif
+++ /dev/null
-/*
- scoreline.hh -- part of LilyPond
-
- (c) 1996,97 Han-Wen Nienhuys
-*/
-
-#ifndef SCORELINE_HH
-#define SCORELINE_HH
-#include "proto.hh"
-#include "plist.hh"
-#include "varray.hh"
-
-/// the columns of a score that form one line.
-struct
-Line_of_score {
- PointerList<PCol *> cols;
-
- // need to store height of each staff.
- IPointerList<Line_of_staff*> staffs;
- PScore * pscore_l_; // needed to generate staffs
-
- /* *************** */
- void process() ;
- Line_of_score(Array<PCol *> sv, PScore *);
-
- String TeXstring() const;
-
- // is #c# contained in #*this#?
- bool element(const PCol *c);
-};
-
-#endif
-
+++ /dev/null
-/*
- script-def.hh -- part of LilyPond
-
- (c) 1996,97 Han-Wen Nienhuys
-*/
-
-#ifndef SCRIPTDEF_HH
-#define SCRIPTDEF_HH
-#include "string.hh"
-struct Script_def{
- int stemdir;
- int staffdir;
-
- bool invertsym;
- String symidx;
-
- /* *************** */
- int compare(Script_def const &);
- void print() const;
- Script_def(String, int, int ,bool);
-};
-
-
-#endif // SCRIPTDEF_HH
-
+++ /dev/null
-/*
- script-reg.hh -- part of LilyPond
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-
-#ifndef SCRIPTREG_HH
-#define SCRIPTREG_HH
-
-#include "register.hh"
-
-
-struct Script_register : Request_register {
- Script * script_p_;
- Script_req * script_req_l_;
- int dir_i_;
- /* *************** */
- void set_feature(Features dir_i_);
- Script_register();
- virtual bool try_request(Request*);
- virtual void process_requests();
- virtual void acknowledge_element(Staff_elem_info);
- virtual void pre_move_processing();
- virtual void post_move_processing();
- NAME_MEMBERS(Script_register);
-};
-
-#endif // SCRIPTREG_HH
+++ /dev/null
-/*
- script.hh -- part of LilyPond
-
- (c) 1996,97 Han-Wen Nienhuys
-*/
-
-#ifndef SCRIPT_HH
-#define SCRIPT_HH
-
-#include "script-def.hh"
-#include "item.hh"
-
-struct Script : Item {
- int dir;
- int symdir;
- int pos;
- int staffsize;
- Script_def *specs_l_;
- Stem *stem_l_;
- Array<Item *> support;
-
- /* *************** */
- NAME_MEMBERS(Script);
- Molecule *brew_molecule_p()const;
- virtual void do_post_processing();
- virtual void do_pre_processing();
- Script(Script_req*, int staffsize);
- void set_support(Item*);
- void set_stem(Stem*);
- Interval support_height()const;
- virtual Interval width() const;
-private:
- void set_symdir();
- void set_default_dir();
- void set_default_index();
- Symbol symbol()const;
-};
-
-
-#endif // SCRIPT_HH
-
+++ /dev/null
-/*
- slur-reg.hh -- declare Slur_register
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-
-#ifndef SLURREG_HH
-#define SLURREG_HH
-
-#include "register.hh"
-
-struct Slur_register : Request_register {
- Array<Slur_req*> requests_arr_;
- Array<Slur_req*> new_slur_req_l_arr_;
- Array<Slur *> slur_l_stack_;
- Array<Slur*> end_slur_l_arr_;
-
- int dir_i_;
-
- /* *************** */
- ~Slur_register();
- Slur_register();
- virtual bool try_request(Request*);
- virtual void process_requests();
- virtual void acknowledge_element(Staff_elem_info);
- virtual void pre_move_processing();
- virtual void post_move_processing();
- virtual void set_feature(Features);
- NAME_MEMBERS(Slur_register);
-};
-
-#endif // SLURREG_HH
+++ /dev/null
-/*
- slur.hh -- part of LilyPond
-
- (c) 1996,97 Han-Wen Nienhuys
-*/
-
-#ifndef SLUR_HH
-#define SLUR_HH
-
-#include "directional-spanner.hh"
-#include "fproto.hh"
-#include "varray.hh"
-
-struct Slur : Directional_spanner {
-
- Array<Notehead*> encompass;
-
- bool open_left, open_right;
-
- /* *************** */
- Offset center() const;
- Slur();
- void do_post_processing();
- void do_pre_processing();
- void add(Notehead*);
- void set_default_dir();
-
- Spanner* do_break_at( PCol*, PCol*) const;
- void process();
-private:
- Molecule*brew_molecule_p()const;
- NAME_MEMBERS(Slur);
-};
-
-#endif // SLUR_HH
-
-
+++ /dev/null
-/*
- spanner.hh -- part of LilyPond
-
- (c) 1996,97 Han-Wen Nienhuys
-*/
-
-#ifndef SPANNER_HH
-#define SPANNER_HH
-
-#include "proto.hh"
-#include "staff-elem.hh"
-
-
-/** a symbol which is attached between two columns. A spanner is a symbol which spans across several columns, so its
- final appearance can only be calculated after the breaking problem
- is solved.
-
- Examples
-
- - (de)crescendo
- - slur
- - beam
- - bracket
-
-
- Spanner should know about the items which it should consider:
- e.g. slurs should be steep enough to "enclose" all those items. This
- is absolutely necessary for beams, since they have to adjust the
- length of stems of notes they encompass.
-
- */
-struct Spanner:Staff_elem {
- PCol *left, *right;
-
-
- /* *************** */
-
- Spanner();
- virtual Interval width()const;
- void do_print()const;
-
- Spanner *broken_at(PCol *c1, PCol *c2) const;
- virtual Spanner* spanner() { return this; }
-protected:
-
- /**
- clone a piece of this spanner.
- PRE
- c1 >= start, c2 <= stop
- */
- virtual Spanner *do_break_at( PCol *c1, PCol *c2) const=0;
- NAME_MEMBERS(Spanner);
-};
-#endif
+++ /dev/null
-/*
- staff-column.hh -- declare Staff_column
-
- (c) 1996,97 Han-Wen Nienhuys
-*/
-
-#ifndef STAFFCOLUMN_HH
-#define STAFFCOLUMN_HH
-#include "proto.hh"
-#include "varray.hh"
-#include "moment.hh"
-
-/// store simultaneous requests
-class Staff_column {
-
- Staff_column(Staff_column const&);
-
-public:
- Array<Request*> creationreq_l_arr_;
- Array<Request*> musicalreq_l_arr_;
- Array<Request*> commandreq_l_arr_;
- Staff * staff_l_;
-
- /// fields to collect timing data vertically.
- Array<Timing_req*> timing_req_l_arr_;
- Score_column *musical_column_l_, *command_column_l_;
-
- /* *************** */
-
- Staff_column();
-
- Moment when() const;
- void set_cols(Score_column *c1, Score_column *c2);
- void add(Voice_element*ve);
- void OK() const;
- ~Staff_column();
- void typeset_breakable_items(Array<Item *> &pre_p_arr,
- Array<Item *> &nobreak_p_arr,
- Array<Item *> &post_p_arr);
- void typeset_musical_item(Item *i);
-protected:
- void setup_one_request(Request*);
-};
-
-
-
-#endif // STAFFCOLUMN_HH
-
+++ /dev/null
-/*
- staff-elem-info.hh -- declare Staff_elem_info
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-
-#ifndef STAFFELEMINFO_HH
-#define STAFFELEMINFO_HH
-
-#include "proto.hh"
-#include "varray.hh"
-/// data container.
-struct Staff_elem_info {
- Staff_elem * elem_p_;
- Request*req_l_;
- const Voice * voice_l_;
- Array<Request_register*> origin_reg_l_arr_;
-
-
- /* *** */
- Staff_elem_info(Staff_elem*, Request*);
- Staff_elem_info();
-};
-
-struct Staff_info {
- int *c0_position_i_;
- Staff_walker *walk_l_;
- const Time_description *time_c_l_;
- const Rhythmic_grouping *rhythmic_c_l_;
-};
-
-
-struct Features {
- bool initialiser_b_;
- int direction_i_;
-
- Features();
- static Features dir(int);
-};
-#endif // STAFFELEMINFO_HH
+++ /dev/null
-/*
- staff-elem.hh -- part of LilyPond
-
- (c) 1996,97 Han-Wen Nienhuys
-*/
-
-#ifndef STAFFELEM_HH
-#define STAFFELEM_HH
-#include "varray.hh"
-#include "proto.hh"
-#include "offset.hh"
-#include "molecule.hh"
-#include "class-name.hh"
-
-
-/** Both Spanner and Item are Staff_elem's. Most Staff_elem's depend
- on other Staff_elem's, eg, Beam needs to know and set direction of
- Stem. So the Beam has to be calculated *before* Stem. This is
- accomplished with the dependencies field of struct Staff_elem.
-
- */
-struct Staff_elem {
- enum Status {
- ORPHAN, // not yet added to pstaff
- VIRGIN, // added to pstaff
- PRECALCING,
- PRECALCED, // calcs before spacing done
- POSTCALCING,
- POSTCALCED, // after spacing calcs done
- OUTPUT, // molecule has been output
- } status;
-
- /// the pstaff it is in
- PStaff *pstaff_l_;
-
- /* *************** */
- Staff_elem(Staff_elem const&);
- String TeXstring () const ;
- virtual void print() const;
- virtual Interval width() const;
- virtual Interval height() const;
- Paper_def *paper() const;
- virtual ~Staff_elem();
- Staff_elem();
- NAME_MEMBERS(Staff_elem);
- void translate(Offset);
- void add_processing();
- void pre_processing();
- void post_processing();
- void molecule_processing();
-
- virtual Spanner* spanner() { return 0; }
- virtual Item * item() { return 0; }
- void add_dependency(Staff_elem* );
- void substitute_dependency(Staff_elem* old, Staff_elem * newdep);
-
-protected:
-
- /// do printing of derived info.
- virtual void do_print() const=0;
- /// generate the molecule
- virtual Molecule* brew_molecule_p()const=0;
- ///executed directly after the item is added to the PScore
- virtual void do_add_processing();
- /// do calculations before determining horizontal spacing
- virtual void do_pre_processing();
-
- /// do calculations after determining horizontal spacing
- virtual void do_post_processing();
-
- Array<Staff_elem*> dependants;
-
-private:
- /// member: the symbols
- Molecule *output; // should scrap, and use temp var?
-
-
- /**
- This is needed, because #output# may still be
- NULL.
- */
- Offset offset_;
- Array<Staff_elem*> dependencies;
-};
-
-
-#endif // STAFFELEM_HH
-
+++ /dev/null
-/*
- staff-walker.hh -- declare Staff_walker
-
- (c) 1996,97 Han-Wen Nienhuys
-*/
-
-#ifndef STAFFWALKER_HH
-#define STAFFWALKER_HH
-
-#include "proto.hh"
-#include "time-description.hh"
-#include "pcursor.hh"
-
-/**
- manage run-time info when walking staffcolumns such as: key,
- meter, pending beams & slurs
- */
-struct Staff_walker : public PCursor<Staff_column*> {
- Staff * staff_l_;
- PScore * pscore_l_;
- Score_walker *score_walk_l_;
- Time_description time_;
- Rhythmic_grouping *default_grouping;
-
- /* *************** */
-
- Moment when() const;
- virtual ~Staff_walker();
- Staff_walker(Staff*, PScore*);
- void process() ;
-
- void operator++(int);
- void allow_break();
-
-protected:
- /// every time before ++ is called
- virtual void do_pre_move(){}
- /// every time after ++ is called
- virtual void do_post_move(){}
- virtual void process_requests()=0;
-private:
- void process_timing_reqs();
- Staff_walker(Staff_walker const&);
-};
-
-#endif // STAFFWALKER_HH
-
+++ /dev/null
-/*
- staff.hh -- declare Staff
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-#ifndef STAFF_HH
-#define STAFF_HH
-
-#include "plist.hh"
-#include "proto.hh"
-#include "moment.hh"
-
-/// base class for a collection of voices.
-class Staff {
- Staff(const Staff&src);
-
- /// synchronous horizontal stuff
- IPointerList<Voice*> voice_list_;
- Staff_column *get_col(Moment, PCursor<Staff_column*> * last= 0);
-
-public:
-
- /// runtime field
- IPointerList<Staff_column*> cols_;
-
- Score *score_l_;
- PScore *pscore_l_;
- PStaff *pstaff_l_;
-
- /* *************************************************************** */
-
- void add(const PointerList<Voice*> &s);
-
- void add_voice(Voice *v);
- Paper_def*paper()const;
-
- void setup_staffcols();
-
- void OK() const;
- void print() const;
-
- /// when does the last *musical* element finish?
- Moment last() const;
-
-// /// extract midi info
-// Midi_track* midi_track_p();
-
- /// remove unused cols
- void clean_cols() ;
- Staff();
-
- virtual void set_output(PScore * destination)=0;
- virtual Staff_walker *get_walker_p()=0;
- virtual ~Staff() { }
-protected:
-
-};
-#endif
+++ /dev/null
-/*
- staffline.hh -- horizontal structures for broken scores.
-
- (c) 1996,97 Han-Wen Nienhuys
-*/
-
-#ifndef STAFFLINE_HH
-#define STAFFLINE_HH
-
-#include "proto.hh"
-#include "real.hh"
-#include "plist.hh"
-#include "varray.hh"
-#include "glob.hh"
-#include "pstaff.hh"
-
-/// one broken line of staff.
-struct Line_of_staff {
-
- Line_of_score * line_of_score_l_;
- PStaff *pstaff_l_;
-
- /* *************** */
-
- String TeXstring() const;
- Line_of_staff(Line_of_score*, PStaff *);
- Interval height() const;
- void process();
-};
-
-#endif
+++ /dev/null
-/*
- staffsym.hh -- declare Staff_symbol
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-
-#ifndef STAFFSYM_HH
-#define STAFFSYM_HH
-#include "spanner.hh"
-/**
- This spanner draws the lines of a pstaff.
- The bottom line is position 0.
- */
-class Staff_symbol : public Spanner
-{
-public:
- /// this many lines.
- int no_lines_i_;
-
- NAME_MEMBERS(Staff_symbol);
- Staff_symbol(int lines);
- virtual Molecule* brew_molecule_p() const;
- void set_extent(PCol* p1, PCol* p2);
- virtual void do_print()const;
- virtual Spanner *do_break_at( PCol *c1, PCol *c2) const;
-};
-#endif // STAFFSYM_HH
+++ /dev/null
-/*
- stem-beam-reg.hh -- part of LilyPond
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-
-#ifndef STEMBEAMREG_HH
-#define STEMBEAMREG_HH
-#include "register.hh"
-
-struct Stem_beam_register : Request_register {
- Stem * stem_p_;
- Beam * beam_p_;
- Beam_req * beam_req_l_;
- Stem_req * stem_req_l_;
- Beam_req * start_req_l_;
- bool end_beam_b_;
- Rhythmic_grouping *current_grouping;
- int default_dir_i_;
-
- /* *************** */
- Stem_beam_register();
- ~Stem_beam_register();
- virtual void set_feature(Features dir_i_);
- virtual bool try_request(Request*);
- virtual void process_requests();
- virtual void acknowledge_element(Staff_elem_info);
- virtual void pre_move_processing();
- virtual void post_move_processing();
- NAME_MEMBERS(Stem_beam_register);
-};
-#endif // STEMBEAMREG_HH
+++ /dev/null
-/*
- stem.hh -- declare Stem
-
- (c) 1996,97 Han-Wen Nienhuys
-*/
-
-#ifndef STEM_HH
-#define STEM_HH
-#include "item.hh"
-#include "varray.hh"
-#include "moment.hh"
-
-
-/**the rule attached to the ball.
- takes care of:
-
- \begin{itemize}
- \item the rule
- \item the flag
- \item up/down position.
- \end{itemize}
- */
-
-struct Stem : Item {
- /// heads that the stem encompasses (positions)
- int minnote, maxnote;
-
- /// false if in beam
- bool print_flag;
-
- int beams_left;
- int beams_right;
-
- /// needed for determining direction/length
- int staff_center;
-
-
- /**extent of the stem (positions).
- fractional, since Beam has to adapt them.
- */
-
- Real bot, top;
- Real stemlen;
-
- /// flagtype? 4 none, 8 8th flag, 0 = beam.
- int flag;
-
-
- /**
- geen gedonder, jij gaat onder.
- -1 stem points down, +1: stem points up
- */
-
- int dir;
- Real stem_xoffset;
-
- Array<Notehead*> heads;
-
- /* *************** */
- Stem(int center); //, Moment duration);
-
- /// ensure that this Stem also encompasses the Notehead #n#
- void add(Notehead*n);
-
- NAME_MEMBERS(Stem);
-
- Real hindex()const;
- void do_print() const;
- void set_stemend(Real);
- int get_default_dir();
- void set_default_dir();
- void set_default_stemlen();
- void set_default_extents();
- void set_noteheads();
- void do_pre_processing();
-
- Interval width() const;
-
- Molecule* brew_molecule_p() const;
-};
-#endif
+++ /dev/null
-#ifndef SYMBOL_HH
-#define SYMBOL_HH
-
-#include "string.hh"
-#include "boxes.hh"
-#include "proto.hh"
-
-struct Symbol {
- String tex;
- Box dim;
-
- Symbol (String, Box);
- Symbol();
- String str()const; // for printing.
-};
-
-#endif
+++ /dev/null
-/*
- lilypond, (c) 1996,97 Han-Wen Nienhuys
-*/
-#ifndef SYMTABLE_HH
-#define SYMTABLE_HH
-#include "assoc.hh"
-#include "string.hh"
-#include "symbol.hh"
-
-struct Symtable : public Assoc<String, Symbol> {
- Symbol lookup(String)const;
- void print()const;
-};
-
-
-struct Symtables : private Assoc<String, Symtable*> {
-
- Symtable* operator()(String s);
- ~Symtables();
- Symtables();
- Symtables(Symtables const&);
- Assoc<String, Symtable*>::add;
- void print()const;
-};
-
-
-#endif
-
+++ /dev/null
-#ifndef TSTREAM__HH
-#define TSTREAM__HH
-
-#include <iostream.h>
-#include "string.hh"
-
-
-/** TeX output.
- Use this class for writing to a TeX file.
- It counts braces to prevent nesting errors, and
- it will add a comment sign before each newline.
- */
-struct Tex_stream {
- bool outputting_comment;
- ostream *os;
- int nest_level;
-
- /// open a file for writing
- Tex_stream(String filename);
- void header();
- /// delegate conversion to string class.
- Tex_stream &operator<<(String);
-
- /// close the file
- ~Tex_stream();
-private:
- Tex_stream(Tex_stream const&);
-};
-#endif
+++ /dev/null
-#ifndef TEX_HH
-#define TEX_HH
-
-#include "string.hh"
-#include "boxes.hh"
-#include "scalar.hh"
-
-/** parameter substitution in TeXstrings.
- this function provides a simple macro mechanism:
-
- if source == "tex%bla%", then
- substitute_args(source, {"X","Y"}) == "texXblaY"
- */
-String
-substitute_args(String source, Array<String> args);
-
-/// parameter substitution in TeXstrings
-String
-substitute_args(String source, Array<Scalar> args);
-
-/// #h# is in points
-String vstrut(Real h);
-
-
-#endif
+++ /dev/null
-/*
- text-def.hh -- part of LilyPond
-
- (c) 1996,97 Han-Wen Nienhuys
-*/
-
-#ifndef TEXTDEF_HH
-#define TEXTDEF_HH
-
-#include "string.hh"
-#include "proto.hh"
-
-struct Text_def {
- int align_i_;
- String text_str_;
- String style_str_;
- char const* defined_ch_c_l_;
-
-
- /* ****************/
- virtual ~Text_def() {};
- bool compare(const Text_def&);
- Text_def();
- virtual void print() const;
- virtual Atom create_atom(Paper_def*) const;
-};
-
-#endif // TEXTDEF_HH
-
+++ /dev/null
-/*
- text-reg.hh -- part of LilyPond
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-
-#ifndef TEXTREG_HH
-#define TEXTREG_HH
-#include "register.hh"
-
-struct Text_register : Request_register{
- Text_item * text_p_;
- Text_req * text_req_l_;
- int dir_i_;
- /* *************** */
- virtual void set_feature(Features );
- Text_register();
- virtual bool try_request(Request*);
- virtual void process_requests();
- virtual void pre_move_processing();
- virtual void post_move_processing();
- NAME_MEMBERS(Text_register);
-};
-
-#endif // TEXTREG_HH
+++ /dev/null
-/*
- text.hh -- part of LilyPond
-
- (c) 1996,97 Han-Wen Nienhuys
-*/
-
-#ifndef TEXT_ITEM_HH
-#define TEXT_ITEM_HH
-
-#include "text-def.hh"
-#include "item.hh"
-
-struct Text_item : Item {
- int pos_i_;
- int staffsize_i_;
- int dir_i_;
- Text_def* tdef_l_;
-
- /* ***************/
- NAME_MEMBERS(Text_item);
- virtual void set_default_index();
- Molecule* brew_molecule_p() const;
- void do_pre_processing();
-
- Text_item(Text_req*,int);
-};
-
-
-#endif // TEXT_HH
-
+++ /dev/null
-/*
- textspanner.hh -- part of LilyPond
-
- (c) 1996,97 Han-Wen Nienhuys
-*/
-
-#ifndef TEXTSPANNER_HH
-#define TEXTSPANNER_HH
-
-#include "string.hh"
-#include "directional-spanner.hh"
-#include "text-def.hh"
-
-/** a spanner which puts texts on top of other spanners. Use for
- triplets, eentweetjes, ottava, etc. */
-struct Text_spanner : Spanner {
- Text_def spec;
- Offset text_off_;
- Directional_spanner*support;
-
- /* *************** */
-
- NAME_MEMBERS(Text_spanner);
- virtual void do_pre_processing();
- virtual void do_post_processing();
- virtual Interval height() const ;
- virtual Molecule* brew_molecule_p()const;
- virtual void do_print() const;
- virtual Spanner* do_break_at(PCol*,PCol*)const;
- Text_spanner();
- void set_support(Directional_spanner*);
-};
-#endif // TEXTSPANNER_HH
-
+++ /dev/null
-/*
- moment.hh -- part of LilyPond
-
- (c) 1996,97 Han-Wen Nienhuys
-*/
-
-#ifndef tdes_HH
-#define tdes_HH
-
-#include "moment.hh"
-
-/// full info on where we are
-struct Time_description {
- Moment when_;
-
- /// if true, no bars needed, no reduction of whole_in_measure
- bool cadenza_b_;
-
- /// current measure info
- Moment whole_per_measure_;
-
- /// where am i
- Moment whole_in_measure_;
-
- /// how long is one beat?
- Moment one_beat_;
-
- /// idem
- int bars_i_;
-
- /* *************** */
- void set_cadenza(bool);
- void OK() const;
- Time_description();
- void add(Moment dt);
- String str()const;
- void print() const;
- void setpartial(Moment p);
- Moment barleft();
- void set_meter(int,int);
- static int compare (Time_description&, Time_description&);
-};
-
-#include "compare.hh"
-
-
-instantiate_compare(Time_description&,Time_description::compare);
-
-#endif // Time_description_HH
-
+++ /dev/null
-//
-// track-column.hh -- declare Track_column
-//
-// copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
-
-#ifndef TRACK_COLUMN_HH
-#define TRACK_COLUMN_HH
-
-/// (tcol)
-class Track_column {
-public:
- Track_column( Moment mom );
- ~Track_column();
-
- void add_event( Midi_event* midi_event_p );
- Moment mom();
-
-//private:
- IPointerList<Midi_event*> midi_event_p_list_;
- Moment mom_;
-};
-
-#endif // TRACK_COLUMN_HH
-
+++ /dev/null
-/*
- voice-element.hh -- declare Voice_element
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-
-#ifndef VOICE_ELEMENT_HH
-#define VOICE_ELEMENT_HH
-
-#include "proto.hh"
-#include "plist.hh"
-#include "moment.hh"
-
-/** one horizontal bit. Voice_element is nothing but a container for
- *the requests, */
-struct Voice_element {
- Moment duration;
- char const* defined_ch_c_l_;
- const Voice *voice_l_;
- IPointerList<Request*> reqs;
-
- /* *************** */
-
- Voice_element();
- Voice_element(Voice_element const & src );
-
- void add(Request*);
- bool find_plet_start_bo(char c, Moment& moment_r);
- void print ()const;
- void set_default_group(String id);
- void set_plet_backwards(Moment& now_moment_r, Moment until_moment, int num_i, int den_i);
-};
-
-#endif // VOICE-ELEMENT_HH
+++ /dev/null
-/*
- voice-group-regs.hh -- declare Voice_group_registers
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-
-#ifndef VOICEGROUPREGS_HH
-#define VOICEGROUPREGS_HH
-
-#include "registergroup.hh"
-
-struct Voice_group_registers : Register_group_register {
- String group_id_str_;
- Array<Voice_registers*> voice_regs_l_;
-
- /* *************** */
-
- NAME_MEMBERS(Voice_group_registers);
- static bool static_acceptable_request_b(Request*);
- virtual void terminate_register(Request_register*);
- virtual void do_print() const;
- virtual void add(Request_register*);
- Voice_group_registers(String id);
- virtual bool try_request(Request*);
-};
-#endif // VOICEGROUPREGS_HH
+++ /dev/null
-/*
- voice-regs.hh -- declare Voice_registers
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-
-#ifndef VOICEREGS_HH
-#define VOICEREGS_HH
-
-#include "registergroup.hh"
-
-class Voice_registers : public Register_group_register {
-
-
-public:
- Voice *voice_l_;
- /* *************** */
-
- NAME_MEMBERS(Voice_registers);
- virtual bool acceptable_request_b(Request*);
- virtual void acknowledge_element(Staff_elem_info info);
- virtual bool try_request(Request*);
- Voice_registers(Voice*);
- virtual void do_print() const;
-};
-
-
-#endif // VOICEREGS_HH
+++ /dev/null
-#ifndef VOICE_HH
-#define VOICE_HH
-
-#include "proto.hh"
-#include "plist.hh"
-#include "moment.hh"
-
-/** class for horizontal stuff.
-
- Voice is a ordered row of Voice_elements. It is strictly
- horizontal: you cannot have two rhythmic elements running parallel
- in a Voice. For proper processing, each Voice should have
- Group_change_req as a first element.
-
- */
-
-struct Voice {
- IPointerList<Voice_element *> elts;
- Moment start;
-
- /* *************** */
- Voice();
- Voice(Voice const&);
-
- Moment when(const Voice_element*)const;
- Moment last() const;
-
- void add(Voice_element*);
- bool find_plet_start_bo(char c, Moment& moment_r);
- void print() const;
- void set_default_group(String id);
- void set_plet_backwards(Moment& now_moment_r, Moment until_moment, int num_i, int den_i);
-};
-
-#endif
+++ /dev/null
-/*
- walkregs.hh -- declare Walker_registers
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-
-#ifndef WALKREGS_HH
-#define WALKREGS_HH
-
-
-#include "registergroup.hh"
-
-/**
- Top level registers: the interface to Complex_walker.
-
- [sigh. Sometimes I wish C++ could do better late binding.]
- */
-struct Walker_registers : Register_group_register {
- Array<Item*> prebreak_item_p_arr_;
- Array<Item*> nobreak_item_p_arr_;
- Array<Item*> postbreak_item_p_arr_;
- Array<Staff_elem_info> announce_info_arr_;
- Array<Voice_group_registers*> group_l_arr_;
- Complex_walker * walk_l_;
-
- /* *************** */
- void change_group(Group_change_req * greq_l,
- Voice_registers *voice_regs_l,
- Voice_group_registers * old_group);
- Voice_group_registers * get_group(String id);
- void typeset_musical_item(Staff_elem * elem_p);
- Walker_registers(Complex_walker*);
- void do_announces();
- void terminate_register(Request_register * reg);
- virtual bool try_request(Request * r);
- virtual Staff_info get_staff_info();
-
- virtual void announce_element(Staff_elem_info);
- virtual void acknowledge_element(Staff_elem_info);
- virtual void typeset_breakable_item(Item * pre_p , Item * nobreak_p, Item * post_p);
- virtual void typeset_element(Staff_elem*elem_p);
- virtual void pre_move_processing();
- virtual void post_move_processing();
- virtual Paper_def * paper() const;
-};
-
-#endif // WALKREGS_HH
-DFILES=dutch.ini table_sixteen.ini table_twenty.ini\
- english.ini script.ini symbol.ini bare.ini swedish.ini
+# init/Makefile
-default:
- echo huh?
+# subdir level:
+#
+depth = ..
+#
+
+build = ./$(depth)/lily/.build
+
+# generic stuff/Makefile
+#
+include ./$(depth)/make/Stuff.make
+#
+
+# list of distribution files:
+#
+INIFILES = $(shell ls *.ini)
+DISTFILES = Makefile $(INIFILES)
+#
-dist:
- ln Makefile $(DFILES) $(DDIR)/$(INITDIR)
include "dutch.ini" # do not include init/ path
-include "script.ini"
-include "table_sixteen.ini" # not needed if doing MIDI
+include "script.ini"
+include "table_sixteen.ini"
-default: ;
+# input/Makefile
-DISTFILES=Makefile kortjakje.ly maartje.ly\
- cadenza.ly scales.ly standchen.ly twinkle.ly\
- wohltemperirt.ly\
- error.ly midi.ly plet.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\
- pre1.midi.ly fugue1.midi.ly
+# subdir level:
+#
+depth = ..
+#
+build = ./$(depth)/lily/.build
+
+# generic stuff/Makefile
+#
+include ./$(depth)/make/Stuff.make
+#
+
+# list of distribution files:
+#
+LYFILES = $(shell ls *.ly)
+TEXFILES = $(shell ls *.tex)
+DISTFILES = Makefile $(LYFILES) $(TEXFILES)
+#
-dist:
- ln $(DISTFILES) $(DDIR)/$(SUBDIR)
melodie = music {
$\clef\violin
c c | g g | a a | g2
- f f | e e | d d8. e16 | c2 | % :|
+ f f | e e | d d8.( e16 | )c2 | % :|
$
}
commands {
meter { 2 * 4}
}
- paper{}
midi {
tempo 4:120
}
music{ $
\duration { 8 }
\octave{ }
- |[ a a a a a a a a a ]8/9
+ |[ a a a a a a a a a ]
\octave{ ' }
- |[ a a a a a a a a a ]8/9
+ |[ a a a a a a a a a ]
\octave { ` }
- [ `c `g d a 'e 'b ''f '''c '''g ] 8/9
- [ '''g '''c ''f 'b 'e a d `g `c ] 8/9
+ [ `c `g d a 'e 'b ''f '''c '''g ]
+ [ '''g '''c ''f 'b 'e a d `g `c ]
\octave{ ' }
- [ `c `g d a 'e 'b ''f '''c '''g ] 8/9
- [ '''g '''c ''f 'b 'e a d `g `c ] 8/9
+ [ `c `g d a 'e 'b ''f '''c '''g ]
+ [ '''g '''c ''f 'b 'e a d `g `c ]
\octave { }
[ c g 'd ]2/3
[ 'd g c ]2/3
}
commands {
meter {6*8}
- skip {36*8}
+ skip 36*8
meter {4*4}
}
}
--- /dev/null
+#
+# project LilyPond -- the musical typesetter
+# title makefile for micro-lily-lib
+# file lib/Makefile
+#
+# Copyright (c) 1997 by
+# Jan Nieuwenhuizen <jan@digicash.com>
+# Han-Wen Nienhuys <hanwen@stack.nl>
+#
+
+# subdir level:
+#
+depth = ..
+#
+
+# identify module:
+#
+NAME = lily
+MAJOR_VERSION = $(TOPLEVEL_MAJOR_VERSION)
+MINOR_VERSION = $(TOPLEVEL_MINOR_VERSION)
+PATCH_LEVEL = $(TOPLEVEL_PATCH_LEVEL)
+# use to send patches, always empty for released version:
+MY_PATCH_LEVEL = $(TOPLEVEL_MY_PATCH_LEVEL)
+build = ./$(depth)/lily/.build
+#
+
+# generic variables:
+#
+include ./$(depth)/make/Variables.make
+#
+
+# descent order into subdirectories:
+#
+SUBDIRS = include
+#
+
+# to be remade each build:
+#
+VERSION_DEPENDENCY = $(lily-version)
+#
+
+# list of c++ header files:
+#
+HHFILES = # $(shell ls include/*.hh)
+#
+
+# list of c++ source files:
+#
+CCFILES = $(shell ls *.cc)
+#
+
+# list of other source files:
+#
+EXTRA_SOURCE_FILES = # $(shell ls *.y *.l)
+#
+
+# list of distribution files:
+#
+DISTFILES = Makefile $(HHFILES) $(CCFILES) $(EXTRA_SOURCE_FILES)
+#
+
+# list of custom libraries:
+#
+# yes, i know about the -L and -l options,
+# but these libraries get rebuild when needed.
+CUSTOMLIBES = \
+
+LOADLIBES +=
+#
+
+# main target of this module:
+#
+# MAINTARGET = $(EXECUTABLE)
+# MAINTARGET = $(LIBRARY)
+# MAINTARGET = $(bindir)/$(EXECUTABLE)# huh?
+MAINTARGET = $(libdir)/$(LIBRARY)# huh?
+
+default: $(MAINTARGET)
+#
+
+# generic targets and rules:
+#
+include ./$(depth)/make/Targets.make
+include ./$(depth)/make/Rules.make
+#
+
+# auto dependencies:
+#
+-include ./$(outdir)/*.dep
+#
+
--- /dev/null
+# lib/include/Makefile
+
+# subdir level:
+#
+depth = ../..
+#
+
+# identify module:
+#
+MODULE_NAME = lilypond
+MAJOR_VERSION = $(TOPLEVEL_MAJOR_VERSION)
+MINOR_VERSION = $(TOPLEVEL_MINOR_VERSION)
+PATCH_LEVEL = $(TOPLEVEL_PATCH_LEVEL)
+# use to send patches, always empty for released version:
+MY_PATCH_LEVEL = $(TOPLEVEL_MY_PATCH_LEVEL)
+build = ./$(depth)/lily/.build
+#
+
+# generic stuff/Makefile
+#
+include ./$(depth)/make/Include.make
+#
+
--- /dev/null
+#define LIBDIR "./"
--- /dev/null
+#ifndef DEBUG_HH
+#define DEBUG_HH
+
+#include <assert.h>
+#include <iostream.h>
+#include "dstream.hh"
+#include "real.hh"
+#include "proto.hh"
+
+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 );
+void error(String s); // errors
+void error_t(const String& s, Time_description const & t_tdes);
+void error_t(String const &s, const Moment &when);
+// warnings
+//void warning(String s);
+#define WARN warnout << "warning: "<<__FUNCTION__ << "(): "
+extern ostream &warnout ;
+
+// progress
+extern ostream *mlog;
+
+// debugging
+extern Dstream *monitor; // monitor
+
+#ifdef NPRINT
+#define mtor if (0) *monitor // clever hack
+#else
+#define mtor if (check_debug) monitor->identify_as(__PRETTY_FUNCTION__)
+#endif
+
+extern bool check_debug;
+
+#endif
--- /dev/null
+/*
+ input-file.hh -- declare Input_file
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#ifndef INPUT_FILE_HH
+#define INPUT_FILE_HH
+#include <FlexLexer.h>
+#include "proto.hh"
+#include "fproto.hh"
+#include "varray.hh"
+#include "string.hh"
+
+struct Input_file {
+ istream* is;
+ char const* defined_ch_c_l_;
+ Source_file* sourcefile_l_;
+ int line;
+ String name;
+
+ Input_file(String);
+ ~Input_file();
+};
+
+#endif // INPUT_FILE_HH
--- /dev/null
+/*
+ (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef MOMENT_HH
+#define MOMENT_HH
+
+#include "rational.hh"
+class String;
+typedef Rational Moment;
+
+
+#endif //
+
--- /dev/null
+/*
+ proto.hh -- part of LilyPond
+
+ (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef PROTO_HH
+#define PROTO_HH
+
+#include "fproto.hh"
+#include "real.hh"
+
+/// (i64)
+typedef long long Int64;
+
+struct Absdynamic_req;
+struct Accidental;
+struct Atom;
+struct Bar;
+struct Bar_register;
+struct Barcheck_req;
+struct Bar_req;
+struct Beam;
+struct Beam_req;
+struct Box;
+struct Bracket_req;
+struct Cadenza_req;
+struct Chord;
+struct Clef_change_req;
+struct Clef_register;
+struct Clef_item;
+struct Col_hpositions;
+struct Colinfo;
+struct Complex_music;
+struct Complex_staff;
+struct Complex_walker;
+struct Cresc_req;
+struct Directional_spanner;
+struct Decresc_req;
+struct Duration;
+struct Duration_iterator;
+struct Durational_req;
+struct Dynamic;
+struct Group_change_req;
+struct Group_feature_req;
+struct Idealspacing;
+struct Identifier;
+struct Input_file;
+struct Input_music;
+struct Input_score;
+struct Input_staff;
+struct Item;
+struct Key;
+struct Key_register;
+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;
+struct Local_key;
+struct Local_key_register;
+struct Local_key_item;
+struct Lookup;
+struct Lyric_item;
+struct Lyric_req;
+struct Melodic_req;
+struct Measure_grouping_req;
+struct Meter_change_req;
+struct Meter;
+struct Meter_register;
+struct Midi_def;
+struct Midi_duration;
+struct Midi_event;
+struct Midi_header;
+struct Midi_item;
+struct Midi_key;
+struct Midi_note;
+struct Midi_output;
+struct Midi_pitch;
+struct Midi_staff;
+struct Midi_stream;
+struct Midi_tempo;
+struct Midi_time;
+struct Midi_track;
+struct Midi_voice;
+struct Midi_walker;
+struct Mixed_qp;
+class My_midi_lexer;
+class My_midi_parser;
+class Midi_event;
+class Midi_score;
+class Midi_track;
+struct Molecule;
+struct Musical_req;
+struct Music_general_chord;
+struct Music_voice;
+struct Command_req;
+struct Note_req;
+struct Notehead;
+struct Notehead_register;
+struct Notename_tab;
+struct Offset;
+struct Output;
+struct PCol;
+struct Plet_req;
+struct Plet;
+struct PScore;
+struct PStaff;
+struct Paper_def;
+struct Partial_measure_req;
+struct Rational;
+struct Register_group_register;
+struct Request;
+struct Request_register;
+struct Rest;
+struct Rest_req;
+struct Rhythmic_grouping;
+struct Rhythmic_grouping_req;
+struct Rhythmic_req;
+struct Score;
+struct Score_column;
+struct Score_walker;
+struct Script_def;
+struct Script;
+struct Script_register;
+struct Script_req;
+struct Simple_music;
+struct Skip_req;
+struct Slur;
+struct Slur_register;
+struct Slur_req;
+struct Source;
+struct Source_file;
+struct Spacing_req ;
+struct Span_req;
+struct Spanner;
+struct Blank_req;
+struct Staff;
+struct Staff_column;
+struct Staff_elem;
+struct Staff_elem_info;
+struct Staff_symbol;
+struct Staff_walker;
+struct Stem;
+struct Stem_req;
+struct Stem_beam_register;
+struct String;
+struct Symbol;
+struct Symtable;
+struct Symtables;
+struct Tex_stream;
+struct Terminate_voice_req;
+struct Text_item ;
+struct Text_def;
+struct Text_gob;
+struct Text_register;
+struct Text_req;
+struct Timing_req;
+struct Time_description;
+struct Track_column;
+struct Voice;
+struct Voice_element;
+struct Voice_group_registers;
+struct Voice_list;
+struct Voice_registers;
+struct Voicegroup;
+struct Walker_registers;
+typedef Rational Moment;
+#endif // PROTO_HH
--- /dev/null
+//
+// windhoos-suck-suck-suck-thank-you-cygnus.hh
+//
+#ifdef _WIN32
+#ifndef WINDHOOS_SUCK_SUCK_SUCK_HH
+#define WINDHOOS_SUCK_SUCK_SUCK_HH
+
+caddr_t mmap(caddr_t addr, size_t len, int prot, int flags, int fd, off_t offset);
+
+int munmap(caddr_t addr, size_t len);
+
+#endif // WINDHOOS_SUCK_SUCK_SUCK_HH
+#endif // _WIN32 //
--- /dev/null
+//
+// source-file.cc
+//
+
+#include <sys/types.h> // open, mmap
+#include <sys/stat.h> // open
+#include <sys/mman.h> // mmap
+#include <limits.h> // INT_MAX
+#include <fcntl.h> // open
+#include <unistd.h> // close, stat
+#include <stdio.h> // fdopen
+#include <string.h> // strerror
+#include <errno.h> // errno
+#include <assert.h>
+#include <strstream.h>
+
+#include "string.hh"
+#include "proto.hh"
+#include "plist.hh"
+
+//#include "lexer.hh"
+
+#include "debug.hh"
+#include "windhoos-suck-suck-suck-thank-you-cygnus.hh"
+// #include "parseconstruct.hh" // defined_ch_c_l
+extern char const* defined_ch_c_l;
+
+// ugh
+// #include "main.hh" // find_file
+String find_file(String);
+
+#include "source-file.hh"
+
+Source_file::Source_file( String &filename_str )
+{
+ data_caddr_ = 0;
+ fildes_i_ = 0;
+ size_off_ = 0;
+ name_str_ = filename_str;
+ istream_p_ = 0;
+
+ open();
+ map();
+ // ugh!?, should call name_str() !
+ filename_str = name_str_;
+}
+
+Source_file::~Source_file()
+{
+ delete istream_p_;
+ istream_p_ = 0;
+ unmap();
+ close();
+}
+
+char const*
+Source_file::ch_c_l()
+{
+ assert( this );
+ return (char const*)data_caddr_;
+}
+
+void
+Source_file::close()
+{
+ if ( fildes_i_ ) {
+ ::close( fildes_i_ );
+ fildes_i_ = 0;
+ }
+}
+
+String
+Source_file::error_str( char const* pos_ch_c_l )
+{
+ assert( this );
+ if ( !in_b( pos_ch_c_l ) )
+ return "";
+
+ char const* begin_ch_c_l = pos_ch_c_l;
+ char const* data_ch_c_l = ch_c_l();
+ while ( begin_ch_c_l > data_ch_c_l )
+ if ( *--begin_ch_c_l == '\n' ) {
+ begin_ch_c_l++;
+ break;
+ }
+
+ char const* end_ch_c_l = pos_ch_c_l;
+ while ( end_ch_c_l < data_ch_c_l + size_off_ )
+ if ( *end_ch_c_l++ == '\n' ) {
+ break;
+ }
+ end_ch_c_l--;
+
+#if 1
+// String( char const* p, int length ) is missing!?
+ String line_str( (Byte const*)begin_ch_c_l, end_ch_c_l - begin_ch_c_l );
+#else
+ int length_i = end_ch_c_l - begin_ch_c_l;
+ char* ch_p = new char[ length_i + 1 ];
+ strncpy( ch_p, begin_ch_c_l, length_i );
+ ch_p[ length_i ] = 0;
+ String line_str( ch_p );
+ delete ch_p;
+#endif
+
+ int error_col_i = 0;
+ char const* scan_ch_c_l = begin_ch_c_l;
+ while ( scan_ch_c_l < pos_ch_c_l )
+ if ( *scan_ch_c_l++ == '\t' )
+ error_col_i = ( error_col_i / 8 + 1 ) * 8;
+ else
+ error_col_i++;
+
+ String str = line_str.left_str( pos_ch_c_l - begin_ch_c_l )
+ + String( '\n' )
+ + String( ' ', error_col_i )
+ + line_str.mid_str( pos_ch_c_l - begin_ch_c_l, INT_MAX ); // String::mid should take 0 arg..
+ return str;
+}
+
+bool
+Source_file::in_b( char const* pos_ch_c_l )
+{
+ return ( pos_ch_c_l && ( pos_ch_c_l >= ch_c_l() ) && ( pos_ch_c_l < ch_c_l() + size_off_ ) );
+}
+
+istream*
+Source_file::istream_l()
+{
+ assert( fildes_i_ );
+ if ( !istream_p_ ) {
+ if ( size_off_ ) // can-t this be done without such a hack?
+ istream_p_ = new istrstream( ch_c_l(), size_off_ );
+ else {
+ istream_p_ = new istrstream( "", 0 );
+ istream_p_->set(ios::eofbit);
+ }
+ }
+ return istream_p_;
+}
+
+off_t
+Source_file::length_off()
+{
+ return size_off_;
+}
+
+int
+Source_file::line_i( char const* pos_ch_c_l )
+{
+ if ( !in_b( pos_ch_c_l ) )
+ return 0;
+
+ int i = 1;
+ char const* scan_ch_c_l = ch_c_l();
+ while ( scan_ch_c_l < pos_ch_c_l )
+ if ( *scan_ch_c_l++ == '\n' )
+ i++;
+ return i;
+}
+
+void
+Source_file::map()
+{
+ if ( fildes_i_ == -1 )
+ return;
+
+ data_caddr_ = (caddr_t)mmap( (void*)0, size_off_, PROT_READ, MAP_SHARED, fildes_i_, 0 );
+
+ if ( (int)data_caddr_ == -1 )
+ // ugh: defined_ch_c_l...
+ warning( String( "can't map: " ) + name_str_ + String( ": " ) + strerror( errno ), defined_ch_c_l ); //lexer->here_ch_c_l() );
+}
+
+String
+Source_file::name_str()
+{
+ return name_str_;
+}
+
+void
+Source_file::open()
+{
+ String name_str = find_file( name_str_ );
+ if ( name_str != "" )
+ name_str_ = name_str;
+
+ fildes_i_ = ::open( name_str_, O_RDONLY );
+
+ if ( fildes_i_ == -1 ) {
+ warning( String( "can't open: " ) + name_str_ + String( ": " ) + strerror( errno ), defined_ch_c_l ); // lexer->here_ch_c_l() );
+ return;
+ }
+
+ struct stat file_stat;
+ fstat( fildes_i_, &file_stat );
+ size_off_ = file_stat.st_size;
+}
+
+void
+Source_file::unmap()
+{
+ if ( data_caddr_ ) {
+ munmap( data_caddr_, size_off_ );
+ data_caddr_ = 0;
+ size_off_ = 0;
+ }
+}
+String
+Source_file::file_line_no_str(char const *ch_c_l )
+{
+ return name_str() + ": "
+ + String( line_i( ch_c_l ) );
+}
--- /dev/null
+//
+// source.cc
+//
+
+#include <assert.h>
+
+#include "string.hh"
+#include "proto.hh"
+#include "plist.hh"
+
+#include "source-file.hh"
+#include "source.hh"
+
+Source::Source()
+{
+}
+
+Source::~Source()
+{
+}
+
+void
+Source::add( Source_file* sourcefile_p )
+{
+ sourcefile_p_iplist_.bottom().add( sourcefile_p );
+}
+
+Source_file*
+Source::sourcefile_l( char const* ch_c_l )
+{
+ PCursor<Source_file*> sourcefile_l_pcur( sourcefile_p_iplist_.top() );
+ for ( ; sourcefile_l_pcur.ok(); sourcefile_l_pcur++ )
+ if ( sourcefile_l_pcur->in_b( ch_c_l ) )
+ return *sourcefile_l_pcur;
+ return 0;
+}
--- /dev/null
+//
+// windhoos.cc
+//
+#ifdef _WIN32
+
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <winbase.h>
+#include "windhoos-suck-suck-suck-thank-you-cygnus.hh"
+
+/*
+HANDLE CreateFileMapping(
+ HANDLE hFile, // handle to file to map
+ LPSECURITY_ATTRIBUTES lpFileMappingAttributes, // optional security attributes
+ DWORD flProtect, // protection for mapping object
+ DWORD dwMaximumSizeHigh, // high-order 32 bits of object size
+ DWORD dwMaximumSizeLow, // low-order 32 bits of object size
+ LPCTSTR lpName // name of file-mapping object
+ );
+
+
+LPVOID MapViewOfFile(
+ HANDLE hFileMappingObject, // file-mapping object to map into address space
+ DWORD dwDesiredAccess, // access mode
+ DWORD dwFileOffsetHigh, // high-order 32 bits of file offset
+ DWORD dwFileOffsetLow, // low-order 32 bits of file offset
+ DWORD dwNumberOfBytesToMap // number of bytes to map
+ );
+
+
+io.h:
+long _get_osfhandle( int filehandle );
+*/
+
+// cygnus's gnu-win32-b17.1 does not have _get_osfhandle
+// however, after some hacking, it turns out that:
+
+static const int OSF_OFFSET_i = 72;
+static const int OSF_BASE_i = -3;
+static const int OSF_FACTOR_i = 8;
+// let-s hope bill doesn-t change his mind any time soon :-)
+
+// so that, while waiting for cygnus's mmap, we can write:
+
+// #define HAVE_GET_OSFHANDLE // no we still cannot; works only with cl.exe
+long
+_get_osfhandle( int filedes_i )
+{
+ return (long)( OSF_OFFSET_i + ( filedes_i + OSF_BASE_i ) * OSF_FACTOR_i );
+}
+
+#ifdef HAVE_GET_OSFHANDLE
+
+#include <iostream.h>
+
+caddr_t
+mmap(caddr_t addr, size_t len, int prot, int flags, int fd, off_t offset)
+{
+ (void)flags;
+ (void)prot;
+ (void)addr;
+ HANDLE osf = (HANDLE)_get_osfhandle( fd );
+ HANDLE file_handle = CreateFileMapping( osf, (void*)0, PAGE_READONLY,
+ 0, len, 0 );
+ return (caddr_t)MapViewOfFile( file_handle, FILE_MAP_READ, 0, offset, len );
+}
+
+
+int
+munmap(caddr_t addr, size_t len)
+{
+ (void)len;
+ return UnmapViewOfFile( addr );
+}
+
+#else // ! HAVE_GET_OSFHANDLE //
+
+caddr_t
+mmap(caddr_t addr, size_t len, int prot, int flags, int fd, off_t offset)
+{
+ (void)flags;
+ (void)prot;
+ (void)addr;
+ (void)offset;
+ char* ch_p = new char[ len ];
+ if ( ch_p )
+ read( fd, (void*)ch_p, len );
+ return ch_p;
+}
+
+
+int
+munmap(caddr_t addr, size_t len)
+{
+ (void)len;
+ delete (char*)addr;
+ return 0;
+}
+
+#endif // !HAVE_GET_OSFHANDLE //
+
+
+#endif // _WIN32 //
--- /dev/null
+#
+# project LilyPond -- the musical typesetter
+# title makefile for lilypond
+# file lily/Makefile
+#
+# Copyright (c) 1997 by
+# Jan Nieuwenhuizen <jan@digicash.com>
+# Han-Wen Nienhuys <hanwen@stack.nl>
+#
+
+# subdir level:
+#
+depth = ..
+#
+
+# identify module:
+#
+NAME = lilypond
+MAJOR_VERSION = $(TOPLEVEL_MAJOR_VERSION)
+MINOR_VERSION = $(TOPLEVEL_MINOR_VERSION)
+PATCH_LEVEL = $(TOPLEVEL_PATCH_LEVEL)
+# use to send patches, always empty for released version:
+MY_PATCH_LEVEL = $(TOPLEVEL_MY_PATCH_LEVEL)
+build = ./$(depth)/lily/.build
+#
+
+# generic variables:
+#
+include ./$(depth)/make/Variables.make
+#
+
+# descent order into subdirectories:
+#
+SUBDIRS = include
+#
+
+# to be remade each build:
+#
+VERSION_DEPENDENCY = $(lily-version)
+#
+
+# list of c++ header files:
+#
+HHFILES = # $(shell ls include/*.hh)
+#
+
+# list of c++ source files:
+#
+CCFILES = $(shell ls *.cc)
+#
+
+# list of other source files:
+#
+EXTRA_SOURCE_FILES = $(shell ls *.y *.l)
+#
+
+# list of distribution files:
+#
+DISTFILES = Makefile $(HHFILES) $(CCFILES) $(EXTRA_SOURCE_FILES)
+#
+
+# list of custom libraries:
+#
+# yes, i know about the -L and -l options,
+# but these libraries get rebuild when needed.
+CUSTOMLIBES = $(LIBLILY) $(LIBFLOWER)
+
+LOADLIBES +=
+#
+
+# main target of this module:
+#
+# MAINTARGET = $(EXECUTABLE)
+# MAINTARGET = $(LIBRARY)
+MAINTARGET = $(bindir)/$(EXECUTABLE)# huh?
+# MAINTARGET = $(libdir)/$(LIBRARY)# huh?
+
+default: $(MAINTARGET)
+#
+
+# generic targets and rules:
+#
+include ./$(depth)/make/Targets.make
+include ./$(depth)/make/Rules.make
+#
+
+# explicit dependencies: (how to do auto?)
+#
+# ugh
+$(outdir)/version.cc: check-flower-version $(lily-version)
+mylexer.cc: $(outdir)/parser.hh # sic
+lexer.l: $(outdir)/parser.hh
+#
+
+# auto dependencies:
+#
+-include ./$(outdir)/*.dep
+#
+
--- /dev/null
+/*
+ bar-reg.cc -- implement Bar_register
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include "bar-reg.hh"
+#include "bar.hh"
+#include "commandrequest.hh"
+#include "score-column.hh"
+#include "time-description.hh"
+
+Bar_register::Bar_register()
+{
+ post_move_processing();
+}
+
+bool
+Bar_register::try_request(Request*r_l)
+{
+ Command_req* c_l = r_l->command();
+ if (!c_l|| !c_l->bar())
+ return false;
+
+ assert(!bar_req_l_);
+ bar_req_l_ = c_l->bar();
+
+ return true;
+}
+
+void
+Bar_register::process_requests()
+{
+ if (bar_req_l_ ) {
+ bar_p_ = new Bar(bar_req_l_->type_str_);
+ } else if (!get_staff_info().time_c_l_->whole_in_measure_) {
+ bar_p_ = new Bar("|");
+ }
+
+ if (bar_p_){
+ announce_element(Staff_elem_info(bar_p_, bar_req_l_) );
+ }
+}
+
+void
+Bar_register::split_bar(Bar *& pre, Bar * no, Bar * &post)
+{
+ String s= no->type;
+ if (s == ":|:") {
+ pre = new Bar(":|");
+ post = new Bar("|:");
+ }else if (s=="|:") {
+ post = new Bar(s);
+ } else {
+ pre = new Bar(*no);
+ }
+}
+
+void
+Bar_register::pre_move_processing()
+{
+ if (bar_p_) {
+ Bar * post_p =0;
+ Bar * pre_p =0;
+ split_bar(pre_p, bar_p_, post_p);
+
+ typeset_breakable_item(pre_p, bar_p_, post_p);
+ bar_p_ =0;
+ }
+}
+
+void
+Bar_register::post_move_processing()
+{
+ bar_req_l_ = 0;
+ bar_p_ =0;
+}
--- /dev/null
+#include "bar.hh"
+#include "string.hh"
+#include "molecule.hh"
+#include "paper-def.hh"
+#include "lookup.hh"
+#include "debug.hh"
+
+
+
+Bar::Bar( String t)
+{
+ type = t;
+}
+
+void
+Bar::do_print()const
+{
+ mtor << type;
+}
+
+Molecule*
+Bar::brew_molecule_p()const
+{
+ Symbol s = paper()->lookup_p_->bar(type);
+ Molecule*output = new Molecule(Atom(s));
+ return output;
+}
+
--- /dev/null
+#include "varray.hh"
+
+#include "dimen.hh"
+#include "beam.hh"
+#include "misc.hh"
+#include "debug.hh"
+#include "symbol.hh"
+#include "molecule.hh"
+#include "leastsquares.hh"
+#include "pcol.hh"
+#include "stem.hh"
+#include "paper-def.hh"
+#include "lookup.hh"
+#include "grouping.hh"
+
+
+
+struct Stem_info {
+ Real x;
+ Real idealy;
+ Real miny;
+ int no_beams;
+
+
+ Stem_info(){}
+ Stem_info(const Stem*);
+};
+
+Stem_info::Stem_info(const Stem*s)
+{
+ x = s->hindex();
+ int dir = s->dir;
+ idealy = max(dir*s->top, dir*s->bot);
+ miny = max(dir*s->minnote, dir*s-> maxnote);
+ assert(miny <= idealy);
+
+}
+
+/* *************** */
+
+Offset
+Beam::center()const
+{
+ assert(status >= POSTCALCED);
+
+ Real w=(paper()->note_width() + width().length())/2.0;
+ return Offset(w, (left_pos + w* slope)*paper()->internote());
+}
+
+
+Beam::Beam()
+{
+ slope = 0;
+ left_pos = 0.0;
+}
+
+void
+Beam::add(Stem*s)
+{
+ stems.bottom().add(s);
+ s->add_dependency(this);
+ s->print_flag = false;
+}
+
+void
+Beam::set_default_dir()
+{
+ int dirs[2];
+ dirs[0]=0; dirs[1] =0;
+ for (iter_top(stems,i); i.ok(); i++) {
+ int d = i->get_default_dir();
+ dirs[(d+1)/2] ++;
+ }
+ dir_i_ = (dirs[0] > dirs[1]) ? -1 : 1;
+ for (iter_top(stems,i); i.ok(); i++) {
+ i->dir = dir_i_;
+ }
+}
+
+/*
+ should use minimum energy formulation (cf linespacing)
+ */
+void
+Beam::solve_slope()
+{
+ Array<Stem_info> sinfo;
+ for (iter_top(stems,i); i.ok(); i++) {
+ i->set_default_extents();
+ Stem_info info(i);
+ sinfo.push(info);
+ }
+ Real leftx = sinfo[0].x;
+ Least_squares l;
+ for (int i=0; i < sinfo.size(); i++) {
+ sinfo[i].x -= leftx;
+ l.input.push(Offset(sinfo[i].x, sinfo[i].idealy));
+ }
+
+ l.minimise(slope, left_pos);
+ Real dy = 0.0;
+ for (int i=0; i < sinfo.size(); i++) {
+ Real y = sinfo[i].x * slope + left_pos;
+ Real my = sinfo[i].miny;
+
+ if (my - y > dy)
+ dy = my -y;
+ }
+ left_pos += dy;
+ left_pos *= dir_i_;
+ slope *= dir_i_;
+
+ // URG
+ Real sl = slope*paper()->internote();
+ paper()->lookup_p_->beam(sl, 20 PT);
+ slope = sl /paper()->internote();
+}
+
+void
+Beam::set_stemlens()
+{
+ iter_top(stems,s);
+ Real x0 = s->hindex();
+ for (; s.ok() ; s++) {
+ Real x = s->hindex()-x0;
+ s->set_stemend(left_pos + slope * x);
+ }
+}
+
+
+void
+Beam::do_post_processing()
+{
+ solve_slope();
+ set_stemlens();
+}
+
+void
+Beam::set_grouping(Rhythmic_grouping def, Rhythmic_grouping cur)
+{
+ def.OK();
+ cur.OK();
+ assert(cur.children.size() == stems.size());
+
+ cur.split(def);
+
+ Array<int> b;
+ {
+ iter_top(stems,s);
+ Array<int> flags;
+ for (; s.ok(); s++) {
+ int f = intlog2(abs(s->flag))-2;
+ assert(f>0);
+ flags.push(f);
+ }
+ int fi =0;
+ b= cur.generate_beams(flags, fi);
+ b.insert(0,0);
+ b.push(0);
+ assert(stems.size() == b.size()/2);
+ }
+
+ iter_top(stems,s);
+ for (int i=0; i < b.size() && s.ok(); i+=2, s++) {
+ s->beams_left = b[i];
+ s->beams_right = b[i+1];
+ }
+}
+
+
+// todo.
+Spanner *
+Beam::do_break_at( PCol *, PCol *) const
+{
+ Beam *beam_p= new Beam(*this);
+
+ return beam_p;
+}
+
+void
+Beam::do_pre_processing()
+{
+ left = (*stems.top()) ->pcol_l_;
+ right = (*stems.bottom())->pcol_l_;
+ assert(stems.size()>1);
+ if (!dir_i_)
+ set_default_dir();
+
+}
+
+
+Interval
+Beam::width() const
+{
+ Beam * me = (Beam*) this; // ugh
+ return Interval( (*me->stems.top()) ->hindex(),
+ (*me->stems.bottom()) ->hindex() );
+}
+
+/*
+ beams to go with one stem.
+ */
+Molecule
+Beam::stem_beams(Stem *here, Stem *next, Stem *prev)const
+{
+ 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();
+ paper()->lookup_p_->beam(sl, 20 PT);
+
+ Molecule leftbeams;
+ Molecule rightbeams;
+
+ /* half beams extending to the left. */
+ if (prev) {
+ int lhalfs= lhalfs = here->beams_left - prev->beams_right ;
+ int lwholebeams= here->beams_left <? prev->beams_right ;
+ Real w = (here->hindex() - prev->hindex())/4;
+ Symbol dummy;
+ Atom a(dummy);
+ if (lhalfs) // generates warnings if not
+ a = paper()->lookup_p_->beam(sl, w);
+ a.translate(Offset (-w, -w * sl));
+ for (int j = 0; j < lhalfs; j++) {
+ Atom b(a);
+ b.translate(Offset(0, -dir_i_ * dy * (lwholebeams+j)));
+ leftbeams.add( b );
+ }
+ }
+
+ if (next){
+ int rhalfs = here->beams_right - next->beams_left;
+ int rwholebeams = here->beams_right <? next->beams_left;
+
+ Real w = next->hindex() - here->hindex();
+ Atom a = paper()->lookup_p_->beam(sl, w + stemdx);
+
+ int j = 0;
+ for (; j < rwholebeams; j++) {
+ Atom b(a);
+ b.translate(Offset(0, -dir_i_ * dy * j));
+ rightbeams.add( b );
+ }
+
+ w /= 4;
+ if (rhalfs)
+ a = paper()->lookup_p_->beam(sl, w);
+
+ for (; j < rwholebeams + rhalfs; j++) {
+ Atom b(a);
+ b.translate(Offset(0, -dir_i_ * dy * j));
+ rightbeams.add(b );
+ }
+
+ }
+ leftbeams.add(rightbeams);
+ return leftbeams;
+}
+
+
+Molecule*
+Beam::brew_molecule_p() const return out;
+{
+ Real inter=paper()->internote();
+ out = new Molecule;
+ Real x0 = stems.top()->hindex();
+
+ for (iter_top(stems,i); i.ok(); i++) {
+ PCursor<Stem*> p(i-1);
+ PCursor<Stem*> n(i+1);
+ Stem * prev = p.ok() ? p.ptr() : 0;
+ Stem * next = n.ok() ? n.ptr() : 0;
+
+ Molecule sb = stem_beams(i, next, prev);
+ Real x = i->hindex()-x0;
+ sb.translate(Offset(x, (x * slope + left_pos)* inter));
+ out->add(sb);
+ }
+ out->translate(Offset(x0 - left->hpos,0));
+}
+
+void
+Beam::do_print()const
+{
+#ifndef NPRINT
+ mtor << "slope " <<slope << "left ypos " << left_pos;
+ Spanner::print();
+#endif
+}
+
+Beam::~Beam()
+{
+
+}
--- /dev/null
+#include "boxes.hh"
+#include "const.hh"
+#include "varray.hh"
+
+
+Box::Box()
+{
+}
+
+Box::Box(Interval ix, Interval iy)
+{
+ x = ix;
+ y = iy;
+}
+
--- /dev/null
+/*
+ do calculations for breaking problem
+ */
+#include "break.hh"
+#include "paper-def.hh"
+#include "linespace.hh"
+#include "debug.hh"
+#include "scoreline.hh"
+#include "pscore.hh"
+
+
+/*
+ return all breakable columns
+ */
+Line_of_cols
+Break_algorithm::find_breaks() const
+{
+ Line_of_cols retval;
+ for (iter_top(pscore_.cols,c); c.ok(); c++)
+ if (c->breakable_b())
+ retval.push(c);
+ assert(retval.top() == pscore_.cols.bottom().ptr());
+ return retval;
+}
+
+// construct an appropriate Spacing_problem and solve it.
+Col_hpositions
+Break_algorithm::solve_line(Line_of_cols curline) const
+{
+ Spacing_problem sp;
+
+ sp.add_column(curline[0], true, 0.0);
+ for (int i=1; i< curline.size()-1; i++)
+ sp.add_column(curline[i]);
+ sp.add_column(curline.top(), true, linelength);
+
+ // misschien moeven uit Spacing_problem?
+ for (iter_top(pscore_.suz,i); i.ok(); i++) {
+ sp.add_ideal(i);
+ }
+ Array<Real> the_sol=sp.solve();
+ Col_hpositions col_hpos;
+ col_hpos.cols = curline;
+ col_hpos.energy = the_sol.pop();
+ col_hpos.config = the_sol;
+ col_hpos.OK();
+ return col_hpos;
+}
+
+Break_algorithm::Break_algorithm(PScore&s)
+ :pscore_(s)
+{
+ linelength = s.paper_l_->linewidth;
+}
+
+bool
+Break_algorithm::feasible(Line_of_cols curline) const
+{
+ Real l =0;
+ for (int i=0; i < curline.size(); i++)
+ l +=curline[i]->width().length();
+ return l < linelength;
+}
+
+void
+Break_algorithm::problem_OK() const
+{
+ if (!pscore_.cols.size())
+ error("Score does not have any columns");
+#ifndef NDEBUG
+ iter_top(pscore_.cols,start);
+ PCursor<PCol *> end (pscore_.cols.bottom());
+
+ assert(start->breakable_b());
+ assert(end->breakable_b());
+#endif
+}
--- /dev/null
+#include "idealspacing.hh"
+#include "score.hh"
+#include "pscore.hh"
+#include "paper-def.hh"
+#include "score-column.hh"
+#include "dimen.hh"
+
+
+/**
+ this needs A LOT of rethinking.
+
+ generate springs between columns.
+
+ */
+void
+Score::calc_idealspacing()
+{
+ iter_top(cols_,i);
+
+ for (; i.ok(); i++) {
+ assert(i->used_b());
+ PCursor<Score_column*> j(i+1);
+ if (i->musical_b()) {
+ assert(j.ok());
+ for (int n=0; n < i->durations.size(); n++) {
+ Moment d = i->durations[n];
+ Real dist = paper_p_->duration_to_dist(d);
+ Real strength = i->durations[0]/i->durations[n];
+ assert(strength <= 1.0);
+
+ while (j->when() < d + i->when())
+ j++;
+ Moment delta_desired = j->when() - (d+i->when());
+ dist += paper_p_->duration_to_dist(delta_desired);
+
+ pscore_p_->connect(i->pcol_l_, j->pcol_l_, dist, strength);
+ }
+ } else if (j.ok()) {
+
+ /* attach i to the next column in use. This exists, since
+ the last col is breakable, and therefore in use
+ */
+
+ Moment d = j->when() - i->when();
+ Real dist = (d) ? paper_p_->duration_to_dist(d) : 2 PT; // todo
+
+ pscore_p_->connect(i->pcol_l_, j->pcol_l_, dist, (d) ? 1.0:1.0);
+ }
+ // !j.ok() might hold if we're at the last col.
+ }
+}
+
+
--- /dev/null
+/*
+ clef-item.cc -- implement Clef_item
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include "clef-item.hh"
+#include "string.hh"
+#include "molecule.hh"
+#include "paper-def.hh"
+#include "lookup.hh"
+#include "clef-reg.hh"
+
+
+
+Clef_item::Clef_item()
+{
+ change = true;
+ read("violin");
+}
+
+void
+Clef_item::read(String t)
+{
+ type = t;
+ if (type == "violin")
+ y_off = 2;
+ if (type == "alto")
+ y_off = 4;
+ if (type == "tenor")
+ y_off = 6;
+ if (type == "bass")
+ y_off = 6;
+}
+void
+Clef_item::read(Clef_register const &k)
+{
+ read(k.clef_type_str_);
+}
+
+Molecule*
+Clef_item::brew_molecule_p()const
+{
+ String t = type;
+ if (change)
+ t += "_change";
+ Symbol s = paper()->lookup_p_->clef(t);
+ Molecule*output = new Molecule(Atom(s));
+ output->translate(Offset(0, paper()->internote() * y_off));
+ return output;
+}
+
--- /dev/null
+/*
+ clef.cc -- implement Clef_register
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>,
+ Mats Bengtsson <matsb@s3.kth.se>
+*/
+
+#include "clef-reg.hh"
+#include "clef-item.hh"
+#include "debug.hh"
+#include "commandrequest.hh"
+#include "time-description.hh"
+#include "staff-column.hh"
+
+Clef_register::Clef_register()
+{
+ clef_p_ = 0;
+
+ /* ugly hack to prevent segfault (daddy_reg_l_ == 0 at construction) */
+ clef_type_str_ = "";
+}
+
+bool
+Clef_register::set_type(String s)
+{
+ clef_type_str_ = s;
+ if (clef_type_str_ == "violin") {
+ c0_position_i_= -2;
+ } else if (clef_type_str_ == "alto") {
+ c0_position_i_= 4;
+ } else if (clef_type_str_ == "tenor") {
+ c0_position_i_= 6;
+ } else if (clef_type_str_ == "bass") {
+ c0_position_i_= 10;
+ }else
+ return false;
+ *get_staff_info().c0_position_i_ = c0_position_i_;
+
+ return true;
+}
+
+void
+Clef_register::read_req(Clef_change_req*c_l)
+{
+ if (!set_type(c_l->clef_str_))
+ error("unknown clef type ", c_l->defined_ch_c_l_);
+}
+
+bool
+Clef_register::try_request(Request * r_l)
+{
+ Command_req* creq_l= r_l->command();
+ if (!creq_l || !creq_l->clefchange())
+ return false;
+
+ clef_req_l_ = creq_l->clefchange();
+
+ // do it now! Others have to read c0_pos.
+ read_req(creq_l->clefchange());
+ return true;
+}
+
+void
+Clef_register::process_requests()
+{
+ const Time_description *time_l = get_staff_info().time_c_l_;
+ if (!clef_req_l_ && (!time_l->whole_in_measure_|| !time_l->when_)) {
+ clef_p_ = new Clef_item;
+ clef_p_->change = false;
+ } else if (clef_req_l_) {
+ clef_p_ = new Clef_item;
+ clef_p_->change = true;
+ }
+ if (clef_p_) {
+ clef_p_->read(*this);
+ announce_element(Staff_elem_info(clef_p_,
+ clef_req_l_));
+ }
+}
+
+void
+Clef_register::pre_move_processing()
+{
+ if (!clef_p_)
+ return;
+ if (clef_p_->change) {
+ Clef_item* post_p = new Clef_item(*clef_p_);
+ post_p->change = false;
+ typeset_breakable_item(new Clef_item(*clef_p_),
+ clef_p_, post_p);
+ } else {
+ typeset_breakable_item(0, 0, clef_p_);
+ }
+ clef_p_ = 0;
+}
+
+void
+Clef_register::post_move_processing()
+{
+ clef_req_l_ = 0;
+ /* not in ctor, since the reg might not be linked in.*/
+ if (clef_type_str_ == "") {
+ set_type("violin");
+ }
+}
--- /dev/null
+#include "colhpos.hh"
+#include "real.hh"
+#include "debug.hh"
+#include "const.hh"
+#include "vector.hh"
+
+Col_hpositions::Col_hpositions()
+{
+ energy = INFTY;
+}
+
+void
+Col_hpositions::add( PCol*c)
+{
+ cols.push(c);
+}
+
+void
+Col_hpositions::print() const
+{
+#ifndef NPRINT
+ mtor << "energy : " << energy << '\n';
+ mtor << "line of " << config.size() << " cols\n";
+ Vector v(config);
+ mtor << v;
+#endif
+}
+
+void
+Col_hpositions::OK()const
+{
+#ifndef NDEBUG
+ assert(config.size() == cols.size());
+#endif
+}
--- /dev/null
+/*
+ commandrequest.cc -- implement Nonmusical reqs
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include "commandrequest.hh"
+#include "debug.hh"
+#include "musicalrequest.hh"
+
+
+void
+Cadenza_req::do_print()const
+{
+ mtor << on_b_;
+}
+
+Cadenza_req::Cadenza_req(bool b)
+{
+ on_b_ =b;
+}
+/* *************** */
+
+
+int
+Bar_req::compare(const Bar_req &c1)const
+{
+ return type_str_ == c1.type_str_;
+}
+
+void
+Bar_req::do_print() const
+{
+ mtor << type_str_;
+}
+
+Bar_req::Bar_req(String s)
+{
+ type_str_ = s;
+}
+
+Partial_measure_req::Partial_measure_req(Moment m)
+{
+ duration_ =m;
+}
+/* *************** */
+Meter_change_req::Meter_change_req()
+{
+ beats_i_ = 0;
+ one_beat_i_ =0;
+}
+void
+Meter_change_req::set(int b,int o)
+{
+ beats_i_=b;
+ one_beat_i_=o;
+}
+
+void
+Timing_req::do_print()const{}
+
+void
+Command_req::do_print()const{}
+/* *************** */
+void
+Barcheck_req::do_print() const{}
+
+/* *************** */
+void
+Clef_change_req::do_print() const
+{
+ mtor << clef_str_ ;
+}
+
+Clef_change_req::Clef_change_req(String s)
+{
+ clef_str_ = s;
+}
+/* *************** */
+void
+Group_feature_req::do_print() const
+{
+ mtor << "stemdir " << stemdir_i_;
+}
+
+Group_feature_req::Group_feature_req()
+{
+ stemdir_i_ = 0;
+}
+
+void
+Group_change_req::do_print()const
+{
+ mtor << "id : " << newgroup_str_;
+}
+/* *************** */
+void
+Terminate_voice_req::do_print()const
+{
+}
+
+/* *************** */
+void
+Partial_measure_req::do_print() const
+{
+ mtor << duration_;
+}
+
+void
+Meter_change_req::do_print() const
+{
+ mtor << beats_i_ << "*" << one_beat_i_;
+}
+
+/* *************** */
+
+void
+Measure_grouping_req::do_print() const
+{
+ for (int i=0; i < elt_length_arr_.size(); i++) {
+ mtor << beat_i_arr_[i] <<"*" << elt_length_arr_[i]<<" ";
+ }
+}
+/* *************** */
+void
+Key_change_req::do_print() const
+{
+ for (int i=0; i < melodic_p_arr_.size(); i++) {
+ melodic_p_arr_[i]->print();
+ }
+}
+
+Key_change_req::Key_change_req()
+{
+}
+Key_change_req::Key_change_req(Key_change_req const&c)
+{
+ for (int i=0; i < c.melodic_p_arr_.size(); i++) {
+ melodic_p_arr_.push( c.melodic_p_arr_[i]->clone()->melodic() );
+ }
+}
+
+Key_change_req::~Key_change_req()
+{
+ for (int i=0; i < melodic_p_arr_.size(); i++)
+ delete melodic_p_arr_[i];
+}
--- /dev/null
+#include "complex-staff.hh"
+#include "complex-walker.hh"
+#include "score.hh"
+#include "pscore.hh"
+#include "staffsym.hh"
+#include "score-column.hh"
+
+const NO_LINES = 5;
+
+/** Aside from putting fields right, this generates the staff symbol.
+ */
+void
+Complex_staff::set_output(PScore* pscore_l )
+{
+ pstaff_l_ = new PStaff(pscore_l);
+ pscore_l_ = pscore_l;
+ pscore_l_->add(pstaff_l_);
+
+ Staff_symbol *span_p = new Staff_symbol(NO_LINES);
+
+ Score_column* col_last
+ =score_l_->find_col(score_l_->last(), false);
+ Score_column* col_first=
+ score_l_->find_col(0, false);
+
+ span_p->set_extent(col_first->pcol_l_->postbreak_p_,
+ col_last->pcol_l_->prebreak_p_);
+
+ pscore_l_->typeset_spanner(span_p, pstaff_l_);
+}
+
+
+Staff_walker *
+Complex_staff::get_walker_p()
+{
+ return new Complex_walker(this);
+}
--- /dev/null
+/*
+ complex-walker.cc -- implement Complex_walker
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include "musicalrequest.hh"
+#include "staff-column.hh"
+#include "voice.hh"
+#include "pscore.hh"
+#include "complex-staff.hh"
+#include "debug.hh"
+#include "voice-group-regs.hh"
+#include "voice-regs.hh"
+#include "complex-walker.hh"
+//#include "misc.hh"
+#include "commandrequest.hh"
+#include "walk-regs.hh"
+
+void
+Complex_walker::do_post_move()
+{
+ walk_regs_p_->post_move_processing();
+}
+
+void
+Complex_walker::do_pre_move()
+{
+ walk_regs_p_->pre_move_processing();
+}
+
+void
+Complex_walker::do_announces()
+{
+ walk_regs_p_->do_announces();
+}
+
+bool
+Complex_walker::try_command_request(Command_req *req_l)
+{
+ return walk_regs_p_->try_request(req_l);
+}
+
+void
+Complex_walker::try_request(Request*req)
+{
+ walk_regs_p_->try_request(req);
+}
+
+void
+Complex_walker::process_requests()
+{
+ Staff_column*c =ptr();
+
+ for (int i=0; i < c->creationreq_l_arr_.size(); i++) {
+ try_request(c->creationreq_l_arr_[i]);
+ }
+ for (int i=0; i < c->commandreq_l_arr_.size(); i++) {
+ try_request(c->commandreq_l_arr_[i]);
+ }
+
+ for (int i=0; i < c->musicalreq_l_arr_.size(); i++) {
+ try_request(c->musicalreq_l_arr_[i]);
+ }
+
+ regs_process_requests();
+ do_announces();
+}
+
+void
+Complex_walker::regs_process_requests()
+{
+ walk_regs_p_->process_requests();
+}
+
+void
+Complex_walker::typeset_element(Staff_elem *elem_p)
+{
+ if (!elem_p)
+ return;
+ if (elem_p->spanner())
+ pscore_l_->typeset_spanner(elem_p->spanner(), staff()->pstaff_l_);
+ else
+ ptr()->typeset_musical_item(elem_p->item());
+}
+
+Complex_walker::Complex_walker(Complex_staff*s)
+ : Staff_walker(s, s->pstaff_l_->pscore_l_)
+{
+ walk_regs_p_ = new Walker_registers(this);
+ do_post_move();
+}
+
+
+Complex_walker::~Complex_walker()
+{
+}
+
+Complex_staff*
+Complex_walker::staff()
+{
+ return (Complex_staff*) staff_l_;
+}
+
+
+
--- /dev/null
+#include <fstream.h>
+#include <signal.h>
+#include <std/new.h>
+#include <stdlib.h>
+#include "debug.hh"
+#include "dstream.hh"
+#include "vector.hh"
+
+Dstream *monitor=0;
+ostream * nulldev =0;
+
+struct _Dinit {
+ _Dinit() {
+ nulldev = new ofstream("/dev/null");
+ monitor = new Dstream(&cout,".dstreamrc");
+ }
+ ~_Dinit() {
+ delete nulldev;
+ delete monitor;
+ }
+} dinit;
+
+
+
+/*
+ want to do a stacktrace .
+ */
+void
+mynewhandler()
+{
+ assert(false);
+}
+
+void
+float_handler(int)
+{
+ cerr << "Floating point exception .. \n"<< flush;
+ assert(false);
+}
+
+void
+debug_init()
+{
+#ifndef NDEBUG
+ set_new_handler(&mynewhandler);
+#endif
+ set_matrix_debug(*monitor);
+ signal(SIGFPE, float_handler);
+}
+
+bool check_debug=false;
+
+void
+set_debug(bool b)
+{
+ check_debug =b;
+}
+
+
--- /dev/null
+#include <ctype.h>
+#include "dimen.hh"
+#include "debug.hh"
+#include "string.hh"
+
+Real
+parse_dimen(String dim)
+{
+ int i=dim.length_i()-1;
+ const char *s = dim;
+ while (i > 0 && (isspace(s[i]) || isalpha(s[i])) ){
+ i--;
+ }
+ String unit(s + i+1);
+ return convert_dimen(dim.value_f(), unit);
+}
+
+
+Real
+convert_dimen(Real quant, String unit)
+{
+ if (unit == "cm")
+ return quant * CM_TO_PT;
+ if (unit == "pt")
+ return quant;
+ if (unit == "mm")
+ return quant*CM_TO_PT/10;
+ if (unit == "in")
+ return quant * INCH_TO_PT;
+ error ("unknown length unit: `" + unit+"'");
+}
+
+String
+print_dimen(Real r)
+{
+ String s(r);
+ s += "pt ";
+ return s;
+}
--- /dev/null
+#include "directional-spanner.hh"
+
+Directional_spanner::Directional_spanner()
+{
+ dir_i_ = 0;
+}
--- /dev/null
+/*
+ grouping.cc -- implement Rhythmic_grouping
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include "debug.hh"
+#include "grouping.hh"
+#include "interval.hh"
+
+void
+Rhythmic_grouping::init()
+{
+ interval_ = 0;
+ children.set_size(0);
+}
+
+void
+Rhythmic_grouping::OK()const
+{
+#ifndef NDEBUG
+ assert(bool(children.size()) != bool(interval_));
+
+ for (int i= 0; i < children.size(); i++) {
+ children[i]->OK();
+ if (i>0)
+ assert(children[i-1]->interval().right ==
+ children[i]->interval().left);
+ }
+#endif
+}
+
+Moment
+Rhythmic_grouping::length() const
+{
+ return interval().length();
+}
+
+MInterval
+Rhythmic_grouping::interval()const
+{
+ if (interval_)
+ return *interval_;
+ else
+ return
+ MInterval(children[0]->interval().left,
+ children.top()->interval().right);
+}
+
+void
+Rhythmic_grouping::split(Rhythmic_grouping r)
+{
+ if (interval_)
+ return ;
+
+ r.intersect(interval());
+ split(r.intervals());
+
+ for (int i= 0; i < children.size(); i++) {
+ if (!children[i]->interval_) {
+ Rhythmic_grouping here(r);
+ children[i]->split(here);
+ }
+ }
+}
+
+
+Array<MInterval>
+Rhythmic_grouping::intervals()
+{
+ Array<MInterval> r;
+ if (interval_ || children.size() == 1) {
+ MInterval i(interval());
+ MInterval r1(i), r2(i);
+ r1.right = r2.left = i.center();
+ r.push(r1); r.push(r2);
+ } else {
+ for (int i=0; i < children.size(); i++)
+ r.push(children[i]->interval());
+ }
+ return r;
+}
+
+void
+Rhythmic_grouping::intersect(MInterval t)
+{
+ if (interval_) {
+ interval_->intersect(t);
+ return;
+ }
+
+ for (int i=0; i < children.size(); i++) {
+ MInterval inter = intersection(t, children[i]->interval());
+ if (inter.empty() || inter.length() <= Rational( 0 )) {
+ delete children[i];
+ children[i] =0;
+ } else {
+ children[i]->intersect(t);
+ }
+ }
+ for (int i=0; i < children.size(); ) {
+ if (!children[i])
+ children.del(i);
+ else
+ i++;
+ }
+
+}
+
+/**
+ Put our children in branches of #this#.
+ The min and max time intervals coincide with elements of #splitpoints#
+
+ I really should be documenting what is happening here, but I find
+ that difficult, since I don't really understand what's going on here.
+
+ */
+void
+Rhythmic_grouping::split(Array<MInterval> splitpoints)
+{
+ //check on splitpoints..
+ int j = 0, i = 0, starti = 0, startj = 0;
+
+ Array<Rhythmic_grouping*> ch;
+ while (1) {
+ if ( i >= children.size() || j >= splitpoints.size())
+ break;
+
+ assert(
+ children[starti]->interval().left== splitpoints[startj].left);
+ if (children[i]->interval().right < splitpoints[j].right) {
+ i ++;
+ } else if (children[i]->interval().right > splitpoints[j].right ) {
+ j ++;
+ } else {
+
+ if (i == starti) {
+ ch.push(children[i]);
+ } else {
+ Rhythmic_grouping *newchild=new Rhythmic_grouping(
+ children.subvec(starti, i+1));
+
+ ch.push(newchild);
+ }
+ i ++;
+ j++;
+ starti = i;
+ startj = j;
+
+
+ }
+ }
+ if (ch.size() != 1)
+ children = ch;
+ }
+
+
+Rhythmic_grouping::Rhythmic_grouping(MInterval t, int n)
+{
+ init();
+ if (n == 1 || !n) {
+ interval_ = new MInterval(t);
+ return;
+ }
+ Moment dt = t.length()/Rational(n);
+ MInterval basic = MInterval(t.left, t.left+dt);
+ for (int i= 0; i < n; i++)
+ children.push(new Rhythmic_grouping( dt*Rational(i) + basic ));
+}
+
+
+Rhythmic_grouping::Rhythmic_grouping(Array<Rhythmic_grouping*> r)
+ :children(r)
+{
+ interval_ =0;
+}
+
+Rhythmic_grouping::~Rhythmic_grouping()
+{
+ junk();
+}
+
+void
+Rhythmic_grouping::copy(Rhythmic_grouping const&s)
+{
+ interval_ = (s.interval_)? new MInterval(*s.interval_) : 0;
+ for (int i=0; i < s.children.size(); i++)
+ children.push(new Rhythmic_grouping(*s.children[i]));
+}
+
+void
+Rhythmic_grouping::operator=(Rhythmic_grouping const &s)
+{
+ junk();
+ copy(s);
+}
+
+Rhythmic_grouping::Rhythmic_grouping(Rhythmic_grouping const&s)
+{
+ init();
+ copy(s);
+}
+
+void
+Rhythmic_grouping::junk()
+{
+ delete interval_;
+ for (int i=0; i < children.size(); i++)
+ delete children[i];
+ init();
+}
+
+void
+Rhythmic_grouping::print()const
+{
+#ifndef NPRINT
+ mtor << "{ \n";
+ if (interval_)
+ mtor<<" Interval "<< interval_->str();
+ for (int i=0; i < children.size(); i++) {
+ children[i]->print();
+ }
+ mtor << "}\n";
+#endif
+}
+
+bool
+Rhythmic_grouping::child_fit_query(Moment start)
+{
+ if (children.size())
+ return ( children.top()->interval().right== start);
+
+ return true;
+}
+
+void
+Rhythmic_grouping::add_child(Moment start, Moment len)
+{
+ Moment stop = start+len;
+
+ assert(child_fit_query(start));
+ children.push(new Rhythmic_grouping(MInterval(start, stop)));
+}
+
+Rhythmic_grouping::Rhythmic_grouping()
+{
+ interval_ =0;
+}
+
+int
+min_elt(Array<int> v)
+{
+ int i = 1000; // ugh
+ for (int j = 0 ; j < v.size(); j++)
+ i = i <? v[j];
+ return i;
+}
+
+Array<int>
+Rhythmic_grouping::generate_beams(Array<int> flags, int &flagidx)
+{
+ assert (!interval_) ;
+
+ Array< Array<int> > children_beams;
+ for (int i=0; i < children.size(); i++) {
+ Array<int> child_beams;
+ if (children[i]->interval_) {
+ int f = flags[flagidx++];
+ child_beams.push(f);
+ } else {
+ child_beams = children[i]->
+ generate_beams(flags, flagidx);
+ }
+ children_beams.push(child_beams);
+ }
+ Array<int> beams;
+ int lastm, m, nextm;
+ for (int i=0; i < children_beams.size(); i++) {
+ bool add_left = (i >0);
+ bool add_right = (i < children_beams.size() -1);
+
+ if (!i)
+ m = min_elt(children_beams[i]);
+ if (add_right)
+ nextm = min_elt(children_beams[i+1]);
+
+ if (children_beams[i].size() == 1) {
+ if (add_right)
+ beams.push(m);
+ if (add_left)
+ beams.push(m);
+ } else {
+ if (add_left)
+ beams.push(lastm <? m);
+ beams.concat(children_beams[i]);
+ if (add_right)
+ beams.push(m <? nextm);
+ }
+ lastm = m;
+ m = nextm;
+ }
+ assert(!(beams.size()%2));
+ return beams;
+}
+
+void
+Rhythmic_grouping::translate(Moment m)
+{
+ if (interval_)
+ *interval_ += m;
+ else
+ for (int i=0; i < children.size(); i++)
+ children[i]->translate(m);
+}
+
+void
+Rhythmic_grouping::extend(MInterval m)const
+{
+ assert(m.left >= interval().left);
+ while (m.right >interval().right ) {
+ Array<Rhythmic_grouping*> a(children);
+ for (int i=0; i < a.size(); i++) {
+ a[i] =new Rhythmic_grouping(*children[i]);
+ a[i]->translate(children.top()->interval().right);
+ }
+ ((Rhythmic_grouping*)this)->children.concat(a);
+ }
+ assert(m.right <= interval().right);
+ OK();
+}
+
+Rhythmic_grouping
+parse_grouping(Array<int> beat_i_arr, Array<Moment> elt_length_arr)
+{
+ Moment here =0;
+ assert(beat_i_arr.size() == elt_length_arr.size());
+
+ Array<Rhythmic_grouping*> children;
+ for (int i=0; i < beat_i_arr.size(); i++) {
+ Moment last = here;
+ here += elt_length_arr[i] * Moment(beat_i_arr[i]);
+ children.push(
+ new Rhythmic_grouping(MInterval(last, here),
+ beat_i_arr[i] ));
+ }
+ return Rhythmic_grouping(children);
+}
+
--- /dev/null
+/*
+ headreg.cc -- part of LilyPond
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+#include "rest.hh"
+#include "notehead.hh"
+#include "headreg.hh"
+#include "paper-def.hh"
+#include "complex-walker.hh"
+#include "musicalrequest.hh"
+
+Notehead_register::Notehead_register()
+{
+ note_p_ = 0;
+ set_feature(Features::dir(0));
+ post_move_processing();
+}
+
+bool
+Notehead_register::try_request(Request *req_l)
+{
+ if (req_l->note() || req_l->rest())
+ note_req_l_=req_l->rhythmic();
+ else
+ return false;
+
+ return true;
+}
+void
+Notehead_register::set_feature(Features d)
+{
+ if(d.direction_i_ || d.initialiser_b_)
+ dir_i_ = d.direction_i_;
+}
+
+void
+Notehead_register::process_requests()
+{
+ if (!note_req_l_)
+ return;
+
+
+ if (note_req_l_->note()) {
+ Notehead*n_p = new Notehead(8); // ugh
+ note_p_ = n_p;
+ n_p->set_rhythmic(note_req_l_->rhythmic());
+ n_p->position = note_req_l_->note()->height() +
+ *get_staff_info().c0_position_i_;
+ } else {
+ note_p_ = new Rest ( note_req_l_->rhythmic()->balltype,
+ note_req_l_->rhythmic()->dots);
+ if (note_req_l_->rhythmic()->balltype <= 2)
+ note_p_->translate(
+ Offset(0,
+ 6 * paper()->internote()));
+ }
+ Staff_elem_info itinf(note_p_,note_req_l_);
+ announce_element(itinf);
+}
+
+void
+Notehead_register::pre_move_processing()
+{
+ if (note_p_) {
+ if (dir_i_ && note_p_->name() == Rest::static_name())
+ note_p_->translate(Offset(0, 4*dir_i_ * paper()->internote()));
+ typeset_element(note_p_);
+ note_p_ = 0;
+ }
+}
+void
+Notehead_register::post_move_processing()
+{
+ note_req_l_ = 0;
+}
--- /dev/null
+#include "idealspacing.hh"
+#include "pcol.hh"
+#include "pscore.hh"
+#include "pstaff.hh"
+#include "debug.hh"
+
+void
+Idealspacing::print() const
+{
+#ifndef NPRINT
+ mtor << "idealspacing {" ;
+ mtor << "distance "<<space<< " strength " << hooke ;
+ mtor << "left " << left->rank() << " right " << right->rank() << "}\n";
+#endif
+}
+
+Idealspacing::Idealspacing(const PCol * l,const PCol * r)
+{
+ space = 0.0;
+ hooke = 0.0;
+ left = l;
+ right = r;
+}
+
+void
+Idealspacing::OK() const
+{
+#ifndef NDEBUG
+ assert(hooke >= 0 && left && right);
+#endif
+}
--- /dev/null
+/*
+ identifier.cc -- implement identifier and derived classes
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include <assert.h>
+
+#include "identifier.hh"
+#include "lexer.hh"
+#include "debug.hh"
+
+void
+Identifier::error(String expect)
+{
+ String e("Wrong identifier type: ");
+ e += String(classname()) + "(expected " + expect + ")";
+ ::error(e);
+}
+
+void
+Identifier::print()const
+{
+ mtor << "identifier \'" << name << "\'=";
+ do_print();
+}
+
+/* ugh. */
+#define DEFAULT_PRINT(Class, Content_type, accessor) \
+void \
+Class::do_print() const { \
+ ((Class*)this)->accessor(false)->print(); \
+} \
+class Class
+
+DEFAULT_PRINT(Script_id, Script_def, script);
+DEFAULT_PRINT(Lookup_id, Lookup, lookup);
+DEFAULT_PRINT(Symtables_id, Symtables, symtables);
+DEFAULT_PRINT(Staff_id, Input_staff, staff);
+DEFAULT_PRINT(M_chord_id, Music_general_chord, mchord);
+DEFAULT_PRINT(M_voice_id, Music_voice, mvoice);
+
+void
+Real_id::do_print() const
+{
+ Identifier::print();
+ mtor << *((Real_id*)this)->real(false)<< "\n";
+}
+
+void
+Notetab_id::do_print() const
+{
+ mtor << "unknown" << "\n";
+}
--- /dev/null
+# lily/include/Makefile
+
+# subdir level:
+#
+depth = ../..
+#
+
+# identify module:
+#
+MODULE_NAME = lilypond
+MAJOR_VERSION = $(TOPLEVEL_MAJOR_VERSION)
+MINOR_VERSION = $(TOPLEVEL_MINOR_VERSION)
+PATCH_LEVEL = $(TOPLEVEL_PATCH_LEVEL)
+# use to send patches, always empty for released version:
+MY_PATCH_LEVEL = $(TOPLEVEL_MY_PATCH_LEVEL)
+build = ./$(depth)/lily/.build
+#
+
+# generic stuff/Makefile
+#
+include ./$(depth)/make/Include.make
+#
+
--- /dev/null
+/*
+ bar-reg.hh -- declare Bar_register
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+
+#ifndef BARREG_HH
+#define BARREG_HH
+#include "register.hh"
+
+/**
+ generate bars. Either user ("|:"), or default (new measure)
+ */
+class Bar_register : public Request_register {
+ void split_bar(Bar *& pre, Bar * no, Bar * &post);
+public:
+ Bar_req * bar_req_l_;
+ Bar * bar_p_;
+
+ virtual bool try_request(Request *req_l);
+ virtual void process_requests();
+ virtual void pre_move_processing();
+ virtual void post_move_processing();
+ Bar_register();
+ NAME_MEMBERS(Bar_register);
+};
+
+#endif // BARREG_HH
--- /dev/null
+/*
+ bar.hh -- part of LilyPond
+
+ (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef BAR_HH
+#define BAR_HH
+#include "item.hh"
+
+struct Bar: Item {
+ String type;
+
+ Bar(String type);
+NAME_MEMBERS(Bar);
+ void do_print() const;
+ Molecule*brew_molecule_p()const;
+};
+#endif // BAR_HH
+
--- /dev/null
+/*
+ beam.hh -- part of LilyPond
+
+ (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef BEAM_HH
+#define BEAM_HH
+#include "proto.hh"
+#include "directional-spanner.hh"
+#include "plist.hh"
+
+/** a beam connects multiple stems Beam adjusts the stems its owns to
+ make sure that they reach the beam and that point in the correct
+ direction */
+struct Beam: public Directional_spanner {
+ PointerList<Stem*> stems;
+ /// the slope of the beam in posns / point (dimension)
+ Real slope;
+
+ /// position of leftmost end of beam
+ Real left_pos;
+
+
+ /* *************** */
+NAME_MEMBERS(Beam);
+
+ virtual Interval width()const;
+ Offset center() const;
+ Spanner *do_break_at(PCol *, PCol *) const;
+ Beam();
+ void add(Stem*);
+
+
+ void set_default_dir();
+ void do_pre_processing();
+ void do_post_processing();
+
+ void do_print() const;
+ void set_grouping(Rhythmic_grouping def, Rhythmic_grouping current);
+ void set_stemlens();
+ ~Beam();
+
+private:
+ Molecule stem_beams(Stem *here, Stem *next, Stem *prev)const;
+ void solve_slope();
+ Molecule*brew_molecule_p()const;
+};
+
+#endif // BEAM_HH
+
--- /dev/null
+/*
+ some 2D geometrical concepts
+*/
+
+#ifndef BOXES_HH
+#define BOXES_HH
+
+#include "fproto.hh"
+#include "real.hh"
+#include "interval.hh"
+#include "offset.hh"
+
+/// a square subset of Real^2
+struct Box {
+ Interval x, y;
+
+ void translate(Offset o) {
+ x.translate(o.x);
+ y.translate(o.y);
+ }
+ /// smallest box enclosing #b#
+ void unite(Box b) {
+ x.unite(b.x);
+ y.unite(b.y);
+ }
+ Box();
+ Box(Interval ix, Interval iy);
+};
+
+
+#endif
--- /dev/null
+/*
+ break.hh -- part of LilyPond
+
+ (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef BREAK_HH
+#define BREAK_HH
+#include "varray.hh"
+#include "proto.hh"
+#include "colhpos.hh"
+
+/** Class representation of an algorithm which decides where to put
+ the column, and where to break lines. */
+struct Break_algorithm {
+ PScore &pscore_;
+ Real linelength;
+
+ /* *************** */
+
+ Break_algorithm(PScore&);
+
+ /// check if the spacing/breaking problem is well-stated
+ void problem_OK()const;
+
+ /// search all pcols which are breakable.
+ Line_of_cols find_breaks() const;
+
+ /// helper: solve for the columns in #curline#.
+ Col_hpositions solve_line(Line_of_cols) const;
+
+ /// does curline fit on the paper?
+ bool feasible(Line_of_cols)const;
+
+ virtual Array<Col_hpositions> solve()=0;
+};
+
+/// wordwrap type algorithm: move to next line if current is optimal.
+struct Word_wrap : Break_algorithm {
+ virtual Array<Col_hpositions> solve();
+ Word_wrap(PScore&);
+};
+#endif // BREAK_HH
+
--- /dev/null
+/*
+ class-name.hh -- declare
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+
+#ifndef CLASS_NAME_HH
+#define CLASS_NAME_HH
+
+/// a macro to declare the classes name as a static and virtual function.
+#define NAME_MEMBERS(c) \
+static const char *static_name(){ return #c; }\
+virtual const char *name() const{ return c::static_name(); } \
+int a_stupid_nonexistent_function_to_allow_the_semicolon_come_out()
+
+#endif // CLASS-NAME_HH
--- /dev/null
+
+/*
+ clef-item.hh -- declare Clef_item
+
+ (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef CLEFITEM_HH
+#define CLEFITEM_HH
+#include "item.hh"
+
+
+struct Clef_item : Item {
+ String type;
+ int y_off;
+
+ /// is this a change clef (smaller size)?
+ bool change;
+
+
+ /* *************** */
+NAME_MEMBERS(Clef_item);
+ Clef_item();
+ void read(Clef_register const&);
+ void read(String);
+ Molecule* brew_molecule_p()const;
+};
+
+#endif // CLEFITEM_HH
+
+
--- /dev/null
+/*
+ clef.hh -- part of LilyPond
+
+ (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef CLEF_HH
+#define CLEF_HH
+
+#include "scalar.hh"
+#include "varray.hh"
+#include "register.hh"
+
+/// where is c-0 in the staff?
+class Clef_register : public Request_register {
+ Clef_item *clef_p_;
+ Clef_change_req * clef_req_l_;
+
+public:
+ int c0_position_i_;
+ String clef_type_str_;
+
+ /* ************** */
+ virtual void process_requests();
+ virtual void pre_move_processing();
+ virtual void post_move_processing();
+ virtual bool try_request(Request*);
+ Clef_register();
+ NAME_MEMBERS(Clef_register);
+ void read_req(Clef_change_req*);
+ bool set_type(String);
+};
+#endif // CLEF_HH
+
--- /dev/null
+/*
+ colhpos.hh -- part of LilyPond
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#ifndef COLHPOS_HH
+#define COLHPOS_HH
+#include "varray.hh"
+#include "proto.hh"
+
+typedef Array<PCol*> Line_of_cols;
+
+struct Col_hpositions {
+ Line_of_cols cols;
+ Array<Real> config;
+ Real energy;
+
+ /* ************** */
+ void OK()const;
+
+ Col_hpositions();
+ void add( PCol*c);
+ void print() const;
+};
+
+
+#endif // COLHPOS_HH
+
--- /dev/null
+/*
+ commandrequest.hh -- declare Non musical requests
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+
+#ifndef COMMANDREQUEST_HH
+#define COMMANDREQUEST_HH
+
+#include "request.hh"
+#include "varray.hh"
+
+/** Request which are assumed to be "happening" before the
+ musical requests. */
+struct Command_req : virtual Request {
+ REQUESTMETHODS(Command_req, command);
+
+ virtual Measure_grouping_req * measuregrouping() { return 0; }
+ virtual Clef_change_req * clefchange() { return 0; }
+ virtual Key_change_req * keychange() { return 0; }
+ virtual Partial_measure_req * partial() { return 0; }
+ virtual Meter_change_req * meterchange() { return 0; }
+ virtual Bar_req *bar() { return 0; }
+ virtual Cadenza_req *cadenza() { return 0; }
+ virtual Timing_req*timing() { return 0; }
+};
+
+
+/** Baseclass for meter/partial req. It has to be handled by
+ Staff_{walker,column} baseclass. */
+struct Timing_req : Command_req {
+ REQUESTMETHODS(Timing_req, timing);
+};
+
+
+struct Partial_measure_req : Timing_req {
+ Moment duration_;
+
+ Partial_measure_req(Moment);
+ REQUESTMETHODS(Partial_measure_req, partial);
+};
+
+/**
+ todo: allow C meter
+ */
+struct Meter_change_req : Timing_req {
+ int beats_i_, one_beat_i_;
+
+ Meter_change_req();
+ void set(int,int);
+ REQUESTMETHODS(Meter_change_req, meterchange);
+};
+
+/// toggle Cadenza mode
+struct Cadenza_req : Timing_req {
+ /// turn on?
+ bool on_b_;
+ Cadenza_req(bool);
+ REQUESTMETHODS(Cadenza_req,cadenza);
+};
+
+/// check if we're at start of a measure.
+struct Barcheck_req : Timing_req {
+
+ REQUESTMETHODS(Barcheck_req,barcheck);
+};
+
+struct Measure_grouping_req: Timing_req {
+ Array<int> beat_i_arr_;
+ Array<Moment> elt_length_arr_;
+
+ REQUESTMETHODS(Measure_grouping_req, measuregrouping);
+};
+
+struct Group_change_req : Command_req {
+ String newgroup_str_;
+ REQUESTMETHODS(Group_change_req, groupchange);
+};
+
+/** draw a (repeat)-bar. This something different than #Barcheck_req#,
+ the latter should only happen at the start of a measure. */
+struct Bar_req : Command_req {
+ String type_str_;
+ Bar_req(String);
+ int compare(const Bar_req&)const;
+ REQUESTMETHODS(Bar_req,bar);
+};
+struct Terminate_voice_req : Command_req {
+ REQUESTMETHODS(Terminate_voice_req,terminate);
+};
+
+struct Group_feature_req : Command_req {
+ int stemdir_i_;
+ Group_feature_req();
+ REQUESTMETHODS(Group_feature_req, groupfeature);
+};
+
+
+struct Key_change_req : Command_req {
+ Array<Melodic_req*> melodic_p_arr_;
+
+ Key_change_req();
+ Key_change_req(Key_change_req const&);
+ ~Key_change_req();
+ REQUESTMETHODS(Key_change_req, keychange);
+};
+
+struct Clef_change_req : Command_req {
+ String clef_str_;
+ Clef_change_req(String);
+ REQUESTMETHODS(Clef_change_req, clefchange);
+};
+
+#endif // COMMANDREQUEST_HH
--- /dev/null
+/*
+ complex-staff.hh -- declare Complex_staff
+
+ (c) 1996,1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#ifndef COMPLEXSTAF_HH
+#define COMPLEXSTAF_HH
+
+
+#include "key.hh"
+#include "staff.hh"
+#include "staff-walker.hh"
+
+///
+struct Complex_staff : Staff {
+
+ /* *************** */
+
+ virtual void set_output(PScore *);
+ virtual Staff_walker *get_walker_p();
+};
+
+#endif // COMPLEXSTAF_HH
+
--- /dev/null
+/*
+ complex-walker.hh -- declare Complex_walker
+
+ (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef COMPLEXWALKER_HH
+#define COMPLEXWALKER_HH
+
+#include "proto.hh"
+#include "staff-walker.hh"
+#include "staff-elem-info.hh"
+
+/**
+ A staff walker which uses registers to decide what to print
+ */
+class Complex_walker: public Staff_walker {
+ bool try_command_request(Command_req *req_l);
+ void do_announces();
+ void try_request(Request*req);
+
+
+
+public:
+ int c0_position_i_;
+ Walker_registers *walk_regs_p_;
+
+ /* *************** */
+
+ void regs_process_requests();
+ void typeset_element(Staff_elem *elem_p);
+ void announce_element(Staff_elem_info);
+ virtual void process_requests();
+ virtual void do_post_move();
+ virtual void do_pre_move();
+
+ Complex_walker(Complex_staff*);
+ ~Complex_walker();
+
+ Complex_staff *staff();
+private:
+};
+
+
+#endif // COMPLEXWALKER_HH
+
+
--- /dev/null
+#define LIBDIR "./"
--- /dev/null
+/*
+ global constants
+ */
+#ifndef CONST_HH
+#define CONST_HH
+#include <math.h>
+#include "real.hh"
+
+const Real EPS=1e-7; // qlpsolve.hh
+const int MAXITER=100; // qlpsolve.hh
+const Real INFTY=HUGE_VAL;
+#endif
--- /dev/null
+#ifndef DIMEN_HH
+#define DIMEN_HH
+
+#include "real.hh"
+#include "string.hh"
+
+const Real INCH_TO_PT=72.0;
+const Real CM_TO_PT=INCH_TO_PT/2.54;
+const Real MM_TO_PT=CM_TO_PT/10;
+const Real PT_TO_PT =1.0;
+
+#define PT *PT_TO_PT
+#define MM *MM_TO_PT
+#define CM *CM_TO_PT
+#define INCH *INCH_TO_PT
+
+Real parse_dimen(String);
+String print_dimen(Real);
+Real convert_dimen(Real, String);
+#endif
+
--- /dev/null
+/*
+ directional-spanner.hh -- part of LilyPond
+
+ (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef DIRECTIONALSPANNER_HH
+#define DIRECTIONALSPANNER_HH
+
+#include "spanner.hh"
+
+/// a spanner which can be pointing "up" or "down"
+struct Directional_spanner : Spanner{
+
+ /// -1 below heads, +1 above heads.
+ int dir_i_;
+
+ /// offset of "center" relative to left-column/0-pos of staff
+ virtual Offset center() const=0;
+ virtual void set_default_dir()=0;
+ Directional_spanner();
+
+};
+
+#endif // DIRECTIONALSPANNER_HH
+
--- /dev/null
+#ifndef GLOB_HH
+#define GLOB_HH
+#include <assert.h>
+#include <math.h>
+#include "real.hh"
+
+#include "proto.hh"
+#include "const.hh"
+#endif
--- /dev/null
+/*
+ grouping.hh -- part of LilyPond
+
+ (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef GROUPING_HH
+#define GROUPING_HH
+
+#include "moment.hh"
+#include "interval.hh"
+#include "varray.hh"
+
+typedef Interval_t<Moment> MInterval;
+
+/** data structure which represents rhythmic units this is a tree. It groupes notes according to rules
+ */
+struct Rhythmic_grouping {
+ Array<Rhythmic_grouping*> children;
+ MInterval *interval_;
+
+ /* *************** */
+
+ Array<MInterval> intervals();
+ MInterval interval()const;
+ Moment length() const;
+ void intersect(MInterval);
+
+ void operator=(Rhythmic_grouping const&);
+ Rhythmic_grouping(Rhythmic_grouping const&);
+ Rhythmic_grouping(MInterval, int n=1);
+ Rhythmic_grouping();
+ Rhythmic_grouping(Array<Rhythmic_grouping*>);
+ ~Rhythmic_grouping();
+
+ void add_child(Moment start, Moment len);
+ bool child_fit_query(Moment start);
+ void split(Rhythmic_grouping r);
+ void split(Array<MInterval>);
+ void split(int n);
+
+ void print() const;
+ void OK() const;
+
+ Array<int> generate_beams(Array<int>, int&);
+
+ /** multiply self to span #i#.
+ In implementation, this isn't really const, but conceptually it is.
+ */
+ void extend(MInterval i) const;
+ void translate(Moment);
+private:
+ void init();
+ void junk();
+ void copy(Rhythmic_grouping const&);
+};
+
+
+Rhythmic_grouping parse_grouping(Array<int> beat_i_arr, Array<Moment> elt_length_arr);
+
+
+#endif
--- /dev/null
+/*
+ headreg.hh -- part of LilyPond
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+
+#ifndef HEADREG_HH
+#define HEADREG_HH
+#include "register.hh"
+
+struct Notehead_register : Request_register {
+ Item* note_p_;
+ int dir_i_;
+ /* *************** */
+ Notehead_register(Complex_walker*);
+ virtual bool try_request(Request *req_l) ;
+ virtual void process_request();
+ virtual void do_pre_move_process();
+ void set_dir(int);
+};
+
+
+#endif // HEADREG_HH
--- /dev/null
+/*
+ headreg.hh -- part of LilyPond
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+
+#ifndef HEADREG_HH
+#define HEADREG_HH
+#include "register.hh"
+
+struct Notehead_register : Request_register {
+ Item* note_p_;
+ Rhythmic_req * note_req_l_;
+ int dir_i_;
+
+ /* *************** */
+ Notehead_register();
+ virtual bool try_request(Request *req_l) ;
+ virtual void process_requests();
+ virtual void pre_move_processing();
+ virtual void post_move_processing();
+ void set_feature(Features);
+ NAME_MEMBERS(Notehead_register);
+};
+
+
+#endif // HEADREG_HH
--- /dev/null
+/*
+ idealspacing.hh -- part of LilyPond
+
+ (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef IDEALSPACING_HH
+#define IDEALSPACING_HH
+#include "proto.hh"
+
+/// ideal spacing between two columns
+struct Idealspacing {
+
+ /// the ideal distance
+ Real space;
+
+ /// Hooke's constant: how strong are the "springs" attached to columns
+ Real hooke;
+
+ /// the two columns
+ const PCol *left, *right;
+
+ void print()const;
+ void OK() const ;
+ Idealspacing(const PCol *left,const PCol *right);
+};
+
+
+#endif // IDEALSPACING_HH
+
--- /dev/null
+
+/*
+ identifier.hh -- part of LilyPond
+
+ (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef IDENTIFIER_HH
+#define IDENTIFIER_HH
+#include "identparent.hh"
+#include "symtable.hh"
+#include "input-staff.hh"
+#include "input-music.hh"
+#include "notename.hh"
+#include "lookup.hh"
+#include "script-def.hh"
+
+#define make_id_class(Idclass, Class, accessor) \
+struct Idclass : Identifier {\
+ virtual const char *classname() { return #Class; }\
+ Idclass(String s, Class*st):Identifier(s) { data = st; }\
+ virtual Class* accessor(bool copy) {\
+ if (copy)\
+ return new Class(* (Class*) data);\
+ else\
+ return (Class*) data;\
+ }\
+ ~Idclass() { delete accessor(false); }\
+ virtual void do_print()const; \
+}\
+
+make_id_class(Real_id, Real, real);
+make_id_class(Script_id, Script_def, script);
+make_id_class(Lookup_id, Lookup, lookup);
+make_id_class(Symtables_id, Symtables, symtables);
+make_id_class(Staff_id, Input_staff, staff);
+make_id_class(M_chord_id, Music_general_chord, mchord);
+make_id_class(M_voice_id, Music_voice, mvoice);
+make_id_class(Notetab_id, Notename_tab, notename_tab);
+
+#endif // IDENTIFIER_HH
+
--- /dev/null
+/*
+ identparent.hh -- part of LilyPond
+
+ (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef IDENTPARENT_HH
+#define IDENTPARENT_HH
+
+#include "proto.hh"
+#include "string.hh"
+
+/* boolean argument to accesor is copy_b..*/
+#define IDACCESSOR( Input_staff, staff)\
+ virtual Input_staff * staff(bool) { error(#Input_staff); return 0; }
+
+struct Identifier {
+ void *data;
+ String name;
+
+ Identifier(String n) : name(n) { }
+ virtual ~Identifier() {}
+
+ void print()const;
+ virtual const char*classname() { return "new Identifier"; }
+ void error(String);
+ IDACCESSOR(Input_staff, staff)
+ IDACCESSOR(Input_music, music)
+ IDACCESSOR(Music_voice, mvoice)
+ IDACCESSOR(Script_def, script)
+ IDACCESSOR(Symtables, symtables)
+ IDACCESSOR(Music_general_chord, mchord)
+ IDACCESSOR(Lookup,lookup)
+ IDACCESSOR(Real,real)
+ IDACCESSOR(Notename_tab, notename_tab)
+protected:
+ virtual void do_print()const=0;
+private:
+ Identifier(Identifier const&){}
+
+};
+#endif // IDENTPARENT_HH
+
+
+
--- /dev/null
+/*
+ input-music.hh -- part of LilyPond
+
+ (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef INPUTMUSIC_HH
+#define INPUTMUSIC_HH
+
+#include "plist.hh"
+#include "proto.hh"
+#include "voice.hh"
+#include "moment.hh"
+
+struct Voice_list : public PointerList<Voice*> {
+ void translate_time(Moment dt);
+};
+
+/**
+
+ A set voices.
+ Input_music is anything that can simply be regarded as/converted to
+ a set of voices "cooperating" or independant. It has some basic
+ characteristics that real music has too:
+
+ - it is rhythmic (it has a length, and can be translated horizontally)
+ - a pitch (it can be transposed)
+
+ */
+struct Input_music {
+ virtual Voice_list convert()const=0;
+ void check_plet(Voice_element* velt_l);
+ virtual Moment length()const=0;
+ virtual void translate_time(Moment dt)=0;
+ virtual ~Input_music(){}
+ virtual void print() const =0;
+ virtual void set_default_group(String)=0;
+ virtual bool find_plet_start_bo(char c, Moment& moment_r) = 0;
+ virtual void set_plet_backwards(Moment& now_moment_r, Moment until_moment, int num_i, int den_i) = 0;
+ // virtual void transpose(...) const =0;
+
+
+ virtual Input_music *clone() const = 0;
+ virtual Simple_music *simple() { return 0; }
+};
+
+/// Simple music consists of one voice
+struct Simple_music : Input_music {
+ Voice voice_;
+
+ /* *** */
+ virtual Simple_music*simple() { return this; }
+ void add(Voice_element*);
+ virtual void set_default_group(String g) { voice_.set_default_group(g); }
+ virtual Moment length()const;
+ virtual Voice_list convert()const;
+ virtual void translate_time(Moment dt);
+ virtual void print() const;
+ virtual bool find_plet_start_bo(char c, Moment& moment_r);
+ virtual void set_plet_backwards(Moment& now_moment_r, Moment until_moment, int num_i, int den_i);
+ virtual Input_music *clone() const {
+ return new Simple_music(*this);
+ }
+
+};
+
+/// Complex_music consists of multiple voices
+struct Complex_music : Input_music {
+ IPointerList<Input_music*> elts;
+ /* *************** */
+ virtual void set_default_group(String g);
+ void add(Input_music*);
+ Complex_music();
+ Complex_music(Complex_music const &);
+ virtual void print() const ;
+ void concatenate(Complex_music*);
+ virtual bool find_plet_start_bo(char c, Moment& moment_r);
+ virtual void set_plet_backwards(Moment& now_moment_r, Moment until_moment, int num_i, int den_i);
+
+};
+
+
+/**
+ A voice like list of music.
+
+ different music forms which start after each other ( concatenated,
+ stacked "horizontally )
+
+ */
+
+struct Music_voice : Complex_music {
+
+
+ /* *************** */
+ Moment length()const;
+ virtual void translate_time(Moment dt);
+ virtual Voice_list convert()const;
+ void add_elt(Voice_element*);
+ virtual Input_music *clone() const {
+ return new Music_voice(*this);
+ }
+ virtual void print() const ;
+};
+
+/**
+ Multiple musicstuff stacked on top of each other
+ chord like :
+
+ - different music forms which start at the same time ( stacked "vertically" )
+
+ */
+struct Music_general_chord : Complex_music {
+
+
+ /* *************** */
+
+ virtual Moment length()const;
+ virtual Voice_list convert()const;
+ virtual void translate_time(Moment dt);
+ void add_elt(Voice_element*);
+ virtual Input_music *clone() const {
+ return new Music_general_chord(*this);
+ }
+
+ virtual void print() const ;
+};
+
+struct Multi_voice_chord : Music_general_chord {
+ void set_default_group(String);
+ virtual Input_music *clone() const {
+ return new Multi_voice_chord(*this);
+ }
+};
+struct Voice_group_chord : Music_general_chord {
+
+ virtual Input_music *clone() const {
+ return new Voice_group_chord(*this);
+ }
+};
+#endif // INPUTMUSIC_HH
--- /dev/null
+/*
+ input-score.hh -- declare
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+
+#ifndef INPUTSCORE_HH
+#define INPUTSCORE_HH
+
+#include "varray.hh"
+#include "proto.hh"
+#include "plist.hh"
+#include "string.hh"
+
+
+/// the total music def of one movement
+struct Input_score {
+ /// defined where?
+ const char* defined_ch_c_l_;
+ int errorlevel_i_;
+
+ /// paper_, staffs_ and commands_ form the problem definition.
+ Paper_def *paper_p_;
+ Midi_def* midi_p_;
+ IPointerList<Input_staff*> staffs_;
+
+ Input_music * score_wide_music_p_;
+
+ /* *************************************************************** */
+ Input_score();
+ Input_score(Input_score const&);
+
+ void add(Input_staff*);
+ ~Input_score();
+ /// construction
+ void set(Paper_def*);
+ void set(Midi_def* midi_p);
+ void print() const;
+ Score*parse();
+ void set(Input_music*);
+};
+
+#endif
--- /dev/null
+/*
+ input-staff.hh -- declare Input_staff
+
+ (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef INPUTSTAFF_HH
+#define INPUTSTAFF_HH
+
+#include "string.hh"
+#include "plist.hh"
+#include "varray.hh"
+#include "proto.hh"
+
+struct Input_staff {
+
+ const char * defined_ch_c_l_;
+ String type;
+
+ IPointerList<Input_music*> music_;
+ Input_music * score_wide_music_p_;
+
+ /* *************** */
+ ~Input_staff();
+ void add(Input_music*m);
+ Input_staff(Input_staff const&);
+ Input_staff(String);
+ void set_score_wide(Input_music*m);
+ Staff* parse(Score*, Input_music *score_wide);
+ void print() const;
+};
+
+
+#endif // INPUTSTAFF_HH
+
--- /dev/null
+#ifndef ITEM_HH
+#define ITEM_HH
+
+#include "glob.hh"
+#include "boxes.hh"
+#include "string.hh"
+#include "staff-elem.hh"
+
+/**
+ a horizontally fixed size element of the score
+
+ Item is the datastructure for printables whose width is known
+ before the spacing is calculated
+
+ NB. This doesn't mean an Item has to initialize the output field before
+ spacing calculation.
+
+*/
+struct Item : Staff_elem {
+ /// indirection to the column it is in
+ PCol * pcol_l_;
+
+ /* *************** */
+ virtual Item *item() { return this; }
+ Item();
+ void do_print()const;
+
+ NAME_MEMBERS(Item);
+};
+
+
+#endif
--- /dev/null
+/*
+ key-item.hh -- part of LilyPond
+
+ (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef KEYITEM_HH
+#define KEYITEM_HH
+
+#include "item.hh"
+#include "varray.hh"
+
+
+/// An item which places accidentals at the start of the line
+struct Key_item : Item {
+ Array<int> pitch;
+ Array<int> acc;
+ int c_position;
+
+
+ /* *************** */
+NAME_MEMBERS(Key_item);
+ Key_item(int cposition);
+ void add(int pitch, int acc);
+ void read(const Key_register&);
+ void set_c_position(int);
+ void preprocess();
+ Molecule* brew_molecule_p()const;
+};
+
+#endif // KEYITEM_HH
--- /dev/null
+/*
+ key-reg.hh -- declare Key_register
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+
+#ifndef KEYREG_HH
+#define KEYREG_HH
+
+#include "register.hh"
+#include "key.hh"
+
+struct Key_register : Request_register {
+ Key key_;
+ Key_change_req * keyreq_l_;
+ Key_item * kit_p_;
+ Array<int> accidental_idx_arr_;
+ bool default_key_b_;
+
+ virtual bool try_request(Request *req_l);
+ virtual void process_requests();
+ virtual void pre_move_processing();
+ virtual void post_move_processing();
+ virtual void acknowledge_element(Staff_elem_info);
+ Key_register();
+ NAME_MEMBERS(Key_register);
+private:
+
+ void read_req(Key_change_req * r);
+};
+
+#endif // KEYREG_HH
--- /dev/null
+/*
+ key.hh -- declare Key
+
+ (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef KEY_HH
+#define KEY_HH
+
+#include "varray.hh"
+#include "scalar.hh"
+
+/// administration of current key
+class Key {
+ Array<int> accidental_i_arr_;
+
+ /* *************** */
+
+public:
+
+ Key();
+ void set(int i, int acc);
+ int acc(int i)const { return accidental_i_arr_[i]; }
+};
+
+/// administration of accidentals
+struct Local_key
+{
+ void reset(Key);
+ Key& oct(int);
+ Local_key();
+
+private:
+ Array<Key> octaves;
+};
+
+#endif // KEY_HH
+
+
--- /dev/null
+/*
+ keyword.hh -- part of LilyPond
+
+ (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef KEYWORD_HH
+#define KEYWORD_HH
+
+/* for the keyword table */
+struct Keyword_ent
+{
+ const char *name;
+ int tokcode;
+};
+
+struct Keyword_table
+{
+ Keyword_ent *table;
+ int maxkey;
+ Keyword_table(Keyword_ent *);
+ int lookup(const char *s) const;
+};
+
+
+#endif // KEYWORD_HH
+
--- /dev/null
+/*
+ leastsquare.hh -- part of LilyPond
+
+ (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef LEASTSQUARE_HH
+#define LEASTSQUARE_HH
+#include "varray.hh"
+#include "offset.hh"
+
+
+/**
+ Least squares minimisation in 2 variables.
+ */
+struct Least_squares {
+ Array<Offset> input;
+ void minimise(Real &coef, Real &offset);
+ void OK() const;
+};
+
+
+#endif // LEASTSQUARE_HH
+
--- /dev/null
+/*
+ lexer.hh -- declare My_flex_lexer
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#ifndef LEXER_HH
+#define LEXER_HH
+#include <FlexLexer.h>
+#include "proto.hh"
+#include "fproto.hh"
+#include "varray.hh"
+#include "string.hh"
+
+int yylex();
+void yyerror(const char *s);
+bool busy_parsing();
+void kill_lexer();
+void set_lexer();
+
+/// lexer with provisions for include files.
+struct My_flex_lexer : yyFlexLexer {
+
+ Array<Input_file*> include_stack;
+ Assoc<String, Identifier*> *the_id_tab;
+ Keyword_table * keytable;
+ Notename_tab * defaulttab;
+ int errorlevel_i_;
+ /* *************** */
+ int ret_notename(int *p, String text, int octave_mod);
+ char const* here_ch_c_l();
+ void set(Notename_tab *n);
+ int lookup_keyword(String);
+ void lookup_notename(int &large, int &small, String s);
+ void LexerError(const char *);
+ String spot() const;
+ Identifier*lookup_identifier(String s);
+ My_flex_lexer();
+ void add_identifier(Identifier*i);
+ ~My_flex_lexer();
+ void new_input(String s);
+ bool close_input();
+ int yylex();
+ void print_declarations() const;
+};
+
+extern My_flex_lexer *lexer;
+
+#endif
--- /dev/null
+#ifndef PROBLEM_HH
+#define PROBLEM_HH
+
+#include "glob.hh"
+#include "plist.hh"
+#include "varray.hh"
+#include "vector.hh"
+#include "interval.hh"
+
+/// helper struct for #Spacing_problem#
+struct Colinfo {
+ const PCol *pcol_;
+ const Real* fixpos;
+ Interval width;
+
+ /* *************** */
+ Colinfo();
+ void operator=(Colinfo const&);
+ Colinfo(Colinfo const&);
+ ~Colinfo();
+ Colinfo(const PCol*,const Real*);
+ void print() const;
+ bool fixed() const { return fixpos;}
+ Real fixed_position()const { return *fixpos; }
+ Real minright() const { return width.right; }
+ Real minleft() const { return -width.left; }
+};
+
+
+/** the problem, given by the columns (which include constraints) and
+ intercolumn spacing. The problem is:
+
+ Generate a spacing which
+ \begin{itemize}
+ \item
+ Satisfies spacing constraints (notes can't be printed through each other)
+ \item
+ Looks good, ie tries to conform to an ideal spacing as much as possible.
+ \end{itemize}
+ This is converted by regarding idealspacing as "springs" attached
+ to columns. The equilibrium of one spring is the ideal
+ distance. The columns have a size, this imposes "hard" constraints
+ on the distances. This transforms the problem into a quadratic
+ programming problem with linear constraints.
+
+ The quality is given by the total potential energy in the
+ springs. The lower the energy, the better the configuration.
+*/
+class Spacing_problem {
+ Array<const Idealspacing*> ideals;
+ Array<Colinfo> cols;
+
+ /// the index of #c# in #cols#
+ int col_id(const PCol *c) const;
+
+ /// generate an (nonoptimal) solution
+ Vector find_initial_solution() const;
+
+ /// check if problem is too tight
+ bool check_feasible() const;
+
+ /// does #this# contain the column #w#?
+ bool contains(const PCol *w);
+
+ /// make the energy function
+ void make_matrices(Matrix &quad, Vector &lin,Real&) const;
+
+ /// generate the LP constraints
+ void make_constraints(Mixed_qp& lp) const;
+
+public:
+ /** solve the spacing problem
+
+ @return the column positions, and the energy (last element)
+
+ */
+ Array<Real> solve() const;
+
+
+ /**
+ add a idealspacing to the problem.
+
+ One pair of columns can have no, one or more idealspacings,
+ since they can be "summed" if the columns to which #i# refers are
+ not in this problem, the spacing is ignored.
+ */
+ void add_ideal(const Idealspacing *i);
+
+
+ /** add a col to the problem. columns have to be added left to right. The column contains
+ info on it's minimum width.
+ */
+ void add_column(const PCol *, bool fixed=false, Real fixpos=0.0);
+
+
+
+ bool check_constraints(Vector v) const;
+
+ Vector try_initial_solution() const;
+ void OK() const;
+ void print() const;
+ void print_ideal(const Idealspacing*)const;
+};
+
+
+#endif
--- /dev/null
+/*
+ local-key-item.hh -- part of LilyPond
+
+ (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef LOCALKEYITEM_HH
+#define LOCALKEYITEM_HH
+#include "item.hh"
+#include "varray.hh"
+
+struct Local_acc {
+ int name , acc, octave;
+ static int compare(Local_acc&, Local_acc&);
+};
+
+struct Local_key_item : Item {
+NAME_MEMBERS(Local_key_item);
+ Array<Local_acc> accs;
+ Array<Item*> support_items_;
+ int c0_position;
+
+ /* *************** */
+
+ Local_key_item(int c0position);
+ void add(Item*);
+ void add(int oct, int pitch, int acc);
+ void add(Melodic_req*);
+ void do_pre_processing();
+ Molecule* brew_molecule_p()const;
+};
+#endif // LOCALKEYITEM_HH
+
--- /dev/null
+/*
+ local-key-reg.hh -- declare Local_key_register
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+
+#ifndef LOCALKEYREG_HH
+#define LOCALKEYREG_HH
+#include "register.hh"
+#include "key.hh"
+
+struct Local_key_register : Request_register {
+ Local_key local_key_;
+ Local_key_item* key_item_p_;
+ const Key *key_c_l_;
+ /* *************** */
+ virtual void process_requests();
+ virtual void acknowledge_element(Staff_elem_info);
+ virtual void pre_move_processing();
+ Local_key_register();
+ NAME_MEMBERS(Local_key_register);
+};
+
+#endif // LOCALKEYREG_HH
--- /dev/null
+/*
+ lilypond, (c) 1996,97 Han-Wen Nienhuys
+*/
+#ifndef LOOKUPSYMS_HH
+#define LOOKUPSYMS_HH
+
+#include "symbol.hh"
+#include "fproto.hh"
+#include "scalar.hh"
+
+/// intuitive interface to symbol table
+struct Lookup {
+ Symtables *symtables_;
+ String texsetting;
+ /* *************** */
+ void add(String, Symtable*);
+ void print()const;
+ Real internote();
+
+ Symbol linestaff(int n, Real w);
+ Symbol fill(Box b);
+ Symbol beam_element(int,int,Real=0);
+
+ /// round slope to closest TeXslope
+ Symbol beam(Real&,Real);
+
+ /**
+ pos == 3 : 3 lines above staff (extending below note)
+
+ pos == -3: below staff
+ */
+ Symbol streepjes(int pos);
+
+ Symbol meter(Array<Scalar>);
+ Symbol stem(Real y1_pos, Real y2_pos);
+ Symbol rule_symbol(Real height, Real width);
+ Symbol accidental(int);
+ Symbol ball(int);
+ Symbol flag(int);
+ Symbol rest(int);
+ Symbol clef(String);
+ Symbol bar(String);
+ Symbol dots(int);
+ Symbol slur(int dy, Real &dx, int dir);
+ Symbol half_slur(int dy, Real &dx, int dir, int xpart);
+ Symbol half_slur_middlepart(Real &dx, int dir);
+ Symbol big_slur(int dy, Real &dx, int dir);
+ Symbol text(String style, String text, int align = 1);
+ Symbol script(String idx);
+ Symbol hairpin(Real & width, bool decresc);
+
+ Lookup();
+ Lookup(Lookup const &);
+ ~Lookup();
+};
+
+#endif
--- /dev/null
+#ifndef MAIN_HH
+#define MAIN_HH
+#include "proto.hh"
+
+void debug_init();
+void set_debug(bool);
+void do_scores();
+void add_score(Input_score * s);
+void set_default_output(String s);
+Input_score* current_iscore_l();
+String find_file(String);
+const char *get_version();
+extern String infile_str_g;
+extern Source* source_l_g;
+extern bool only_midi;
+
+extern String default_out_fn;
+
+#endif
--- /dev/null
+/*
+ meter-reg.hh -- declare Meter_register
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+
+#ifndef METERREG_HH
+#define METERREG_HH
+#include "register.hh"
+
+/**
+ generate meters.
+ */
+class Meter_register : public Request_register {
+public:
+ Meter_change_req * meter_req_l_;
+ Meter * meter_p_;
+
+ virtual bool try_request(Request *req_l);
+ virtual void process_requests();
+ virtual void pre_move_processing();
+ virtual void post_move_processing();
+ Meter_register();
+ NAME_MEMBERS(Meter_register);
+};
+#endif // METERREG_HH
--- /dev/null
+/*
+ meter.hh -- declare Meter
+
+ (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef METER_HH
+#define METER_HH
+#include "item.hh"
+#include "varray.hh"
+#include "scalar.hh"
+
+struct Meter: Item {
+ Array<Scalar> args;
+ /* *************** */
+NAME_MEMBERS(Meter);
+
+ Meter(Array<Scalar> args) ;
+ Molecule*brew_molecule_p() const;
+};
+#endif // METER_HH
+
--- /dev/null
+/*
+ midioutput.hh -- declare Midi_output
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+
+#ifndef MIDIOUTPUT_HH
+#define MIDIOUTPUT_HH
+#include "pscore.hh"
+
+struct Midi_output {
+ Midi_output(Score* score_l, Midi_def* );
+
+ void do_staff(Staff*st_l, int count);
+ void header();
+ void staffs();
+
+ Score* score_l_;
+ Midi_def* midi_l_;
+ Midi_stream* midi_stream_l_;
+};
+
+#endif // MIDIOUTPUT_HH
+
--- /dev/null
+#ifndef MISC_HH
+#define MISC_HH
+
+#include "proto.hh"
+#include "real.hh"
+#include "moment.hh"
+#include "scalar.hh"
+#include "grouping.hh"
+
+Moment wholes(int dur, int dots);
+double log_2(double x) ;
+int intlog2(int d);
+inline int
+abs(int i){
+ return (i < 0)?-i:i;
+}
+inline int
+sign(int i) {
+ if (i<0) return -1;
+ else if (i) return 1;
+ else return 0;
+}
+
+Interval itemlist_width(const Array<Item*> &its);
+
+#endif
--- /dev/null
+#ifndef MOLECULE_HH
+#define MOLECULE_HH
+
+#include "proto.hh"
+#include "plist.hh"
+#include "boxes.hh"
+#include "symbol.hh"
+
+/// a symbol which can be translated, and freely copied
+struct Atom {
+ Offset off;
+ Symbol sym;
+
+ /* *************** */
+
+ void translate(Offset o) {
+ off += o;
+ }
+
+ /// how big is #this#?
+ Box extent() const;
+ Atom(Symbol s);
+
+ void print() const;
+
+ String TeXstring() const;
+};
+
+
+/** a group of individually translated symbols. You can add molecules
+ to the top, to the right, etc. */
+struct Molecule {
+ IPointerList<Atom*> ats; // change to List<Atom>?
+
+ /* *************** */
+
+ Molecule() { }
+ Molecule(Atom a) { add(a) ; }
+
+ void add_right(const Molecule &m);
+ void add_left(const Molecule &m);
+ void add_top(const Molecule &m);
+ void add_bottom(const Molecule &m);
+ void add(Molecule const &m);
+ void translate(Offset);
+ void add(Atom a) { ats.bottom().add(new Atom(a)); }
+ /// how big is #this#?
+ Box extent() const;
+
+ String TeXstring() const;
+
+ Molecule(const Molecule&s);
+ void print() const;
+private:
+ void operator=(const Molecule&);
+};
+#endif
--- /dev/null
+/*
+ musicalrequests.hh -- declare Musical requests
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+
+#ifndef MUSICALREQUESTS_HH
+#define MUSICALREQUESTS_HH
+
+#include "request.hh"
+
+
+/**
+ A request which is coupled to a #Voice_element# with nonzero duration.
+ Base class only
+ */
+struct Musical_req : virtual Request {
+ virtual Skip_req* skip() { return 0; }
+ REQUESTMETHODS(Musical_req, musical);
+};
+
+
+struct Skip_req : Musical_req {
+ Moment duration_;
+
+ virtual Moment duration() const;
+ REQUESTMETHODS(Skip_req, skip);
+};
+/** a request with a duration.
+ This request is used only a base class.
+ */
+struct Rhythmic_req : virtual Musical_req {
+ int balltype;
+ int dots;
+ Moment plet_factor;
+ /* *************** */
+ static int compare(const Rhythmic_req &, const Rhythmic_req &);
+ virtual Moment duration() const;
+ Rhythmic_req();
+ Rhythmic_req(int,int);
+ REQUESTMETHODS(Rhythmic_req, rhythmic);
+};
+
+struct Spacing_req :virtual Request {
+ Moment next;
+ Real distance;
+ Real strength;
+ /* *************** */
+ Spacing_req();
+ REQUESTMETHODS(Spacing_req, spacing);
+};
+
+struct Blank_req : Spacing_req, Rhythmic_req {
+ REQUESTMETHODS(Spacing_req, spacing);
+
+};
+
+/// Put a text above or below (?) this staff.
+struct Text_req : virtual Musical_req {
+ /// preferred position (above/below)
+ int dir_i_;
+ /// the characteristics of the text
+ Text_def *tdef_p_;
+ /* *************** */
+ Text_req(int d, Text_def*);
+ ~Text_req();
+ Text_req(Text_req const&);
+ static int compare(const Text_req&,const Text_req&);
+ REQUESTMETHODS(Text_req,text);
+};
+
+/** Put a text in lyric_staff
+ @see Lyric_staff
+ */
+struct Lyric_req : public Rhythmic_req, Text_req {
+ Lyric_req(Text_def* t_p);
+ REQUESTMETHODS(Lyric_req, lreq_l);
+};
+
+/// request which has some kind of pitch
+struct Melodic_req :virtual Musical_req
+{
+ /// 0 is c, 6 is b
+ int notename_i_;
+ /// 0 is central c
+ int octave_i_;
+
+ /// 0 natural, 1 sharp, etc
+ int accidental_i_;
+
+ /// force/supress printing of accidental.
+ bool forceacc_b_;
+
+ /// return height from central c (in halflines)
+ int height()const;
+ /// return pitch from central c (in halfnotes)
+ int pitch()const;
+ Melodic_req();
+
+ REQUESTMETHODS(Melodic_req,melodic);
+};
+
+/// Put a note of specified type, height, and with accidental on the staff.
+struct Note_req : Rhythmic_req, virtual Melodic_req {
+
+
+ Rhythmic_req* rhythmic() { return Rhythmic_req::rhythmic(); }
+ REQUESTMETHODS(Note_req, note);
+ };
+
+/**
+Put a rest on the staff. Why a request? It might be a good idea to not typeset the rest, if the paper is too crowded.
+*/
+class Rest_req : public Rhythmic_req {
+public:
+ REQUESTMETHODS(Rest_req,rest);
+};
+
+/**
+ attach a stem to the noteball.
+ Rhythmic_req parent needed to determine if it will fit inside a beam.
+ */
+struct Stem_req : Rhythmic_req {
+ /// preferred direction for the stem
+ int dir_i_;
+ Stem_req(int s, int dots);
+ REQUESTMETHODS(Stem_req,stem);
+};
+
+/**
+ Requests to start or stop something.
+ This type of request typically results in the creation of a #Spanner#
+*/
+struct Span_req : Musical_req {
+ /// should the spanner start or stop, or is it unwanted?
+ enum {
+ NOSPAN, START, STOP
+ } spantype ;
+ static int compare(const Span_req &r1, const Span_req &r2);
+ REQUESTMETHODS(Span_req,span);
+
+ Span_req();
+
+};
+
+/// request for backward plet generation
+struct Plet_req : Request {
+ char type_c_;
+ int dur_i_;
+ int type_i_;
+ Plet_req();
+
+ REQUESTMETHODS(Plet_req,plet);
+};
+/**
+*/
+
+/** Start / stop a beam at this note. if #nplet# is set, the staff will try to put an
+appropriate number over the beam
+ */
+struct Beam_req : Span_req {
+ int nplet;
+
+ /* *************** */
+ REQUESTMETHODS(Beam_req,beam);
+
+ Beam_req();
+};
+
+/// a slur
+struct Slur_req : Span_req {
+ REQUESTMETHODS(Slur_req,slur);
+
+};
+
+
+/**Put a script above or below this ``note''. eg upbow, downbow. Why a
+request? These symbols may conflict with slurs and brackets, so this
+also a request */
+struct Script_req : Musical_req {
+ int dir_i_;
+ Script_def *scriptdef_p_;
+
+ /* *************** */
+ static int compare(const Script_req &, const Script_req &);
+ Script_req(int d, Script_def*);
+ REQUESTMETHODS(Script_req,script);
+ ~Script_req();
+ Script_req(Script_req const&);
+};
+
+
+
+
+#endif // MUSICALREQUESTS_HH
--- /dev/null
+/*
+ notehead.hh -- part of LilyPond
+
+ (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef NOTEHEAD_HH
+#define NOTEHEAD_HH
+#include "item.hh"
+
+/**
+ ball at the end of the stem
+takes care of:
+
+ * help lines
+ * proper placing of dots
+
+ */
+
+struct Notehead : Item {
+ NAME_MEMBERS(Notehead);
+
+ int position;
+ /// -1 = lowest, 0 = inside, 1 = top
+ int extremal;
+ /// needed for the help-lines
+ int staff_size;
+ int dots;
+ int balltype;
+ int x_dir;
+
+ /* *************** */
+
+ void set_rhythmic(Rhythmic_req *);
+
+ /**
+ position of top line (5 linestaff: 8)
+ */
+ Notehead(int staff_size);
+ void do_print()const;
+ static int compare(Notehead * const &a, Notehead *const &b) ;
+ Molecule* brew_molecule_p()const;
+};
+#endif // NOTEHEAD_HH
+
--- /dev/null
+/*
+ notename.hh -- part of LilyPond
+
+ (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef NOTENAME_HH
+#define NOTENAME_HH
+
+#include "string.hh"
+
+struct Notename_tab {
+ String notetab[7*5];
+
+ void set(int l, int s, String nm);
+ void lookup(int &large, int &small, String s);
+};
+
+void set_notename_tab(Notename_tab*n);
+void lookup_notename(int &large, int &small, String s);
+
+
+#endif // NOTENAME_HH
+
--- /dev/null
+/*
+ offset.hh -- part of LilyPond
+
+ (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef OFFSET_HH
+#define OFFSET_HH
+#include "real.hh"
+
+/// 2d vector
+struct Offset {
+ Real x,y;
+
+ Offset operator+(Offset o)const {
+ Offset r(*this);
+ r+=o;
+ return r;
+ }
+
+ Offset operator+=(Offset o) {
+ x+=o.x;
+ y+=o.y;
+ return *this;
+ }
+ Offset(Real ix , Real iy) {
+ x=ix;
+ y=iy;
+ }
+ Offset() {
+ x=0.0;
+ y=0.0;
+ }
+};
+
+#endif // OFFSET_HH
+
+
--- /dev/null
+#ifndef PSTAFF_HH
+#define PSTAFF_HH
+
+#include "proto.hh"
+#include "plist.hh"
+#include "item.hh"
+#include "symbol.hh"
+
+/// items grouped horizontally
+struct PStaff {
+ PScore * pscore_l_;
+
+
+ PointerList<const Spanner*> spans;
+ PointerList<Item*> its;
+
+ /* *************** */
+ void add(Item*i);
+ PStaff(PScore*);
+
+private:
+ PStaff(PStaff const&);
+};
+
+#endif
--- /dev/null
+/*
+ paper-def.hh -- declare
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+
+#ifndef Paper_def_HH
+#define Paper_def_HH
+#include "proto.hh"
+#include "real.hh"
+#include "string.hh"
+#include "moment.hh"
+
+
+/** symbols, dimensions and constants
+
+ This struct takes care of all kinds of symbols, dimensions and
+ constants. Most of them are related to the point-size of the fonts,
+ so therefore, the lookup table for symbols is also in here.
+
+ see TODO
+ */
+struct Paper_def {
+ Lookup *lookup_p_;
+ String outfile;
+
+ Real linewidth;
+
+ /// how much space does a whole note take (ideally?)
+ Real whole_width;
+
+ /// ideal = geometric_ ^ log2(duration)
+ Real geometric_;
+
+ /* *************** */
+ void reinit();
+ Paper_def(Lookup*);
+ void set(Lookup*);
+ ~Paper_def();
+ Paper_def(Paper_def const&);
+ Real interline()const;
+ Real internote()const;
+ Real rule_thickness()const;
+ Real standard_height()const;
+ Real note_width() const;
+ void print() const;
+ Real duration_to_dist(Moment);
+};
+
+#endif // Paper_def_HH
+
--- /dev/null
+/*
+ parseconstruct.hh -- part of LilyPond
+
+ (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef PARSECONSTRUCT_HH
+#define PARSECONSTRUCT_HH
+
+#include "proto.hh"
+
+extern char const* defined_ch_c_l;
+extern char const* req_defined_ch_c_l;
+void set_default_duration(int *);
+void last_duration(int n);
+void set_duration_mode(String s);
+void get_default_duration(int *);
+void set_default_octave(String);
+void set_plet(int,int);
+Voice_element * get_note_element(String,int * ,int *);
+Voice_element* get_rest_element(String,int *);
+Voice_element* get_word_element(Text_def*, int*);
+void add_requests( Voice_element*v, Array<Request*>&req);
+Request* get_request(char);
+void set_text_style(String);
+Script_def* get_scriptdef(char);
+Text_def*get_text(String s);
+Request* get_plet_request( char c, int dur_i, int type_i );
+Request*get_script_req(int d , Script_def*def);
+Request*get_text_req(int d , Text_def*def);
+Request* get_stemdir_req(int);
+
+
+
+
+Request*get_grouping_req(Array<int> i_arr);
+
+#endif // PARSECONSTRUCT_HH
+
--- /dev/null
+typedef union {
+ Request * request;
+ Real real;
+ Identifier *id;
+ Voice *voice;
+ Voice_element *el;
+ String *string;
+ const char *consstr;
+ Paper_def *paper;
+ Midi_def* midi;
+ Input_music *music;
+ Music_general_chord *chord;
+ Music_voice *mvoice;
+ int i;
+ char c;
+ int ii[10];
+ Moment *moment;
+
+ Array<String> * strvec;
+ Array<int> *intvec;
+ Array<Melodic_req*> *melreqvec;
+ Input_staff *staff;
+ Input_score *score;
+ Symtables * symtables;
+ Symtable * symtable;
+ Symbol * symbol;
+ Lookup*lookup;
+ Interval *interval;
+ Box *box;
+ Notename_tab *notename_tab;
+ Script_def * script;
+ Text_def * textdef;
+} YYSTYPE;
+#define VOICE 258
+#define STAFF 259
+#define SCORE 260
+#define TITLE 261
+#define BAR 262
+#define OUTPUT 263
+#define MULTIVOICE 264
+#define CM_T 265
+#define IN_T 266
+#define PT_T 267
+#define MM_T 268
+#define PAPER 269
+#define WIDTH 270
+#define METER 271
+#define UNITSPACE 272
+#define SKIP 273
+#define COMMANDS 274
+#define COMMAND 275
+#define GEOMETRIC 276
+#define START_T 277
+#define DURATIONCOMMAND 278
+#define OCTAVECOMMAND 279
+#define KEY 280
+#define CLEF 281
+#define TABLE 282
+#define VOICES 283
+#define STEM 284
+#define PARTIAL 285
+#define MUSIC 286
+#define GROUPING 287
+#define CADENZA 288
+#define END 289
+#define SYMBOLTABLES 290
+#define TEXID 291
+#define NOTENAMES 292
+#define SCRIPT 293
+#define TEXTSTYLE 294
+#define PLET 295
+#define GOTO 296
+#define MIDI 297
+#define TEMPO 298
+#define IDENTIFIER 299
+#define PITCHMOD 300
+#define DURATION 301
+#define RESTNAME 302
+#define NOTENAME 303
+#define REAL 304
+#define STRING 305
+#define DOTS 306
+#define INT 307
+
+
+extern YYSTYPE yylval;
--- /dev/null
+#ifndef COLS_HH
+#define COLS_HH
+
+#include "glob.hh"
+#include "boxes.hh"
+#include "plist.hh"
+#include "item.hh"
+
+
+/**
+ stuff grouped vertically.
+ This is a class to address items vertically. It contains the data for:
+ \begin{itemize}
+ \item
+ unbroken score
+ \item
+ broken score
+ \item
+ the linespacing problem
+ \end{itemize}
+ */
+
+struct PCol {
+ PointerList<const Item*> its;
+ PointerList<const Spanner*> stoppers, starters;
+
+
+
+ /** prebreak is put before end of line.
+ if broken here, then (*this) column is discarded, and prebreak
+ is put at end of line, owned by Col
+ */
+ PCol *prebreak_p_;
+
+ /// postbreak at beginning of the new line
+ PCol *postbreak_p_;
+
+ /** if this column is pre or postbreak, then this field points to
+ the parent. */
+ PCol *daddy_l_;
+
+ /// if lines are broken then this column is in #line#
+ const Line_of_score *line_l_;
+
+ /// if lines are broken then this column x-coord #hpos#
+ Real hpos;
+
+ PScore * pscore_l_;
+
+ /* *************** */
+ /// which one (left =0)
+ int rank() const;
+
+ /// does this column have items
+ bool used_b() const;
+
+ void add(Item *i);
+
+ /// Can this be broken? true eg. for bars.
+ bool breakable_b()const;
+
+ Interval width() const;
+ ~PCol();
+ PCol(PCol * parent);
+
+ /**
+ which col comes first?.
+ signed compare on columns.
+
+ @return < 0 if c1 < c2.
+ */static int compare(const PCol &c1, const PCol &c2);
+
+
+ void OK() const;
+ void set_breakable();
+ void print()const;
+private:
+ PCol(PCol const&){}
+};
+
+
+#include "compare.hh"
+instantiate_compare(PCol &, PCol::compare);
+
+
+#endif
--- /dev/null
+// the breaking problem for a score.
+
+#ifndef PSCORE_HH
+#define PSCORE_HH
+
+#include "colhpos.hh"
+#include "varray.hh"
+#include "pcol.hh"
+#include "pstaff.hh"
+
+
+/** all stuff which goes onto paper. notes, signs, symbols in a score can be grouped in two ways:
+ horizontally (staffwise), and vertically (columns). #PScore#
+ contains the items, the columns and the staffs.
+ */
+
+struct PScore {
+ Paper_def *paper_l_;
+
+ /// the columns, ordered left to right
+ IPointerList<PCol *> cols;
+
+ /// the idealspacings, no particular order
+ IPointerList<Idealspacing*> suz;
+
+ /// the staffs ordered top to bottom
+ IPointerList<PStaff*> staffs;
+
+ /// all symbols in score. No particular order.
+ IPointerList<Item*> its;
+
+ /// if broken, the different lines
+ IPointerList<Line_of_score*> lines;
+
+ /// crescs etc; no particular order
+ IPointerList<Spanner *> spanners;
+
+ /// broken spanners
+ IPointerList<Spanner*> broken_spans;
+
+ /* *************** */
+ /* CONSTRUCTION */
+
+ PScore(Paper_def*);
+ /// add a line to the broken stuff. Positions given in #config#
+ void set_breaking(Array<Col_hpositions>);
+
+ void add(PStaff *);
+
+
+ /** add an item.
+ add the item in specified containers. If breakstatus is set
+ properly, add it to the {pre,post}break of the pcol.
+ */
+ void typeset_item(Item *item_p, PCol *pcol_l,PStaff*pstaf_l,int breakstatus=1);
+
+ /// add a Spanner
+ void typeset_spanner(Spanner*, PStaff*);
+
+ /// add to bottom of pcols
+ void add(PCol*);
+ void add_broken(Spanner*);
+
+ /* INSPECTION */
+ Array<Item*> select_items(PStaff*, PCol*);
+
+ /**
+ @return argument as a cursor of the list
+ */
+ PCursor<PCol *> find_col(const PCol *)const;
+
+ /* MAIN ROUTINES */
+ void process();
+
+ /// last deed of this struct
+ void output(Tex_stream &ts);
+
+ /* UTILITY ROUTINES */
+
+ /// get the spacing between c1 and c2, create one if necessary.
+ Idealspacing* get_spacing(PCol *c1, PCol *c2);
+
+ /// connect c1 and c2
+ void do_connect(PCol *c1, PCol *c2, Real distance_f, Real strength_f);
+
+ /// connect c1 and c2 and any children of c1 and c2
+ void connect(PCol* c1, PCol *c2, Real distance_f,Real strength_f= 1.0);
+
+ /* STANDARD ROUTINES */
+ void OK()const;
+ void print() const;
+private:
+ /// before calc_breaking
+ void preprocess();
+
+ /// calculate where the lines are to be broken, and use results
+ void calc_breaking();
+
+ /// after calc_breaking
+ void postprocess();
+
+ /// delete unused columns
+ void clean_cols();
+};
+
+#endif
--- /dev/null
+#ifndef PSTAFF_HH
+#define PSTAFF_HH
+
+#include "proto.hh"
+#include "plist.hh"
+#include "item.hh"
+#include "symbol.hh"
+
+/// items grouped horizontally
+struct PStaff {
+ PScore * pscore_l_;
+
+
+ PointerList<const Spanner*> spans;
+ PointerList<Item*> its;
+
+ /* *************** */
+ void add(Item*i);
+ PStaff(PScore*);
+
+private:
+ PStaff(PStaff const&);
+};
+
+#endif
--- /dev/null
+/*
+ qlp.hh -- declare Ineq_constrained_qp, Mixed_qp
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#ifndef QLP_HH
+#define QLP_HH
+
+#include "matrix.hh"
+
+/// inequality constrained quadratic program
+class Ineq_constrained_qp {
+ friend class Active_constraints;
+
+ Array<Vector> cons;
+ Array<Real> consrhs;
+public:
+ Matrix quad;
+ Vector lin;
+ Real const_term;
+
+
+ /**
+ use a KKT method to assert optimality of sol
+ */
+ void assert_solution(Vector sol) const;
+ /// solve the problem using a projected gradient method
+ Vector solve(Vector start) const;
+
+ /**
+ @return the number of variables in the problem
+ */
+ int dim() const{
+ return lin.dim();
+ }
+
+ /**
+ add a constraint
+
+
+ c*vars >= r
+
+ PRE
+ c.dim() == dim();
+
+ */
+ void add_inequality_cons(Vector c, double r);
+
+ /** set up matrices to go with the problem. */
+ Ineq_constrained_qp(int novars);
+
+ /**
+ evaluate the quadratic function for input #v#
+ */
+ Real eval(Vector v);
+
+ void eliminate_var(int idx, Real value);
+ void OK()const;
+ void print() const;
+
+};
+
+
+/**
+ Quadratic programming with mixed linear constraints.
+ problem definition of a quadratic optimisation problem with linear
+ inequality and equality constraints
+
+
+ x^T QUAD x /2 + b^T x
+*/
+class Mixed_qp :public Ineq_constrained_qp {
+ Array<int> eq_cons;
+ Array<Real> eq_consrhs;
+public:
+ Mixed_qp(int n);
+ void OK() const;
+ void print() const;
+
+ Vector solve(Vector start) const;
+ void add_fixed_var(int i , Real value);
+
+
+ /**
+ add a constraint,
+
+ c*vars == r
+
+ PRE
+ c.dim()==dim();
+ */
+ void add_equality_cons(Vector c, double r);
+};
+#endif
--- /dev/null
+/*
+ qlpsolve.hh -- declare Active_constraints, Inactive_iter
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+
+#ifndef QLPSOLVE_HH
+#define QLPSOLVE_HH
+#include "qlp.hh"
+#include "matrix.hh"
+
+
+/**
+ This class represents the set of active (binding) constraints
+ which can be active while the QLP algorithm is in a feasible
+ point. The active constraints are numbered.
+ If the constraints are of the form
+
+ A^T*x >= b
+
+ then the binding constraints are those where the >= is equality.
+
+ */
+
+class Active_constraints {
+ friend class Inactive_iter;
+
+
+ Matrix A,H;
+ Array<int> active;
+ Array<int> inactive; // actually this is a set, not an array.
+ const Ineq_constrained_qp *opt;
+
+public:
+ String status()const;
+
+ Vector vec(int k) const { return opt->cons[k]; }
+ Real rhs(int k) const { return opt->consrhs[k]; }
+
+
+ /** drop constraint. drop constraint k from the active set. k is the index of the
+ constraint in #active#
+
+ */
+ void drop (int k);
+
+
+ /** add constraint j.
+ add constraint j to the active set j is the index of the
+ constraint in #inactive#
+ */
+ void add(int j);
+
+ /// exchange in and out.
+ void exchange(int in, int out) { add(in); drop (out); }
+
+
+ Vector find_active_optimum(Vector g);
+
+ /// get lagrange multipliers.
+ Vector get_lagrange(Vector v);
+
+ Active_constraints(Ineq_constrained_qp const *op);
+ /** construct: no constraints active, n vars. Put the equalities
+ into the constraints. */
+
+ /// check invariants
+ void OK();
+};
+
+
+/**
+ loop through the inactive constraints.
+ */
+class Inactive_iter {
+ int j;
+ Active_constraints const* ac;
+public:
+ Inactive_iter(Active_constraints const &c) { ac=&c; j=0; }
+ int idx() const { return j; }
+ void operator ++(int) { j++; }
+ int constraint_id() const { return ac->inactive[j]; }
+ Vector vec() const { return ac->vec(constraint_id()); }
+ Real rhs() const { return ac->rhs(constraint_id()); }
+ bool ok() const { return j < ac->inactive.size(); }
+};
+
+#endif // QLPSOLVE_HH
--- /dev/null
+/*
+ register.hh -- part of LilyPond
+
+ (c) 1996,1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#ifndef REGISTER_HH
+#define REGISTER_HH
+
+#include "proto.hh"
+#include "varray.hh"
+#include "request.hh"
+#include "staff-elem-info.hh"
+
+/**
+ a struct which processes requests, and creates the #Staff_elem#s.
+ It may use derived classes. Hungarian postfix: register
+ */
+class Request_register {
+ friend class Register_group_register;
+ /**
+ You cannot copy a Request_register
+ */
+ Request_register(const Request_register&){}
+protected:
+
+ /// utility
+ virtual Paper_def * paper() const;
+
+ /**
+ try to fit the request in this register
+
+ @return
+ false: not noted, not taken.
+
+ true: request swallowed. Don't try to put the request elsewhere.
+
+
+ Default: always return false
+ */
+ virtual bool try_request(Request *req_l);
+
+ /// make items/spanners with the requests you got
+ virtual void process_requests(){}
+
+ /** typeset any items/spanners. Default: do nothing
+ */
+ virtual void pre_move_processing(){}
+ /** reset any appropriate data. Default: do nothing
+ */
+ virtual void post_move_processing(){}
+
+ /**
+ Is this request eligible to be processed? Default: return false.
+ */
+ virtual bool acceptable_request_b(Request*) const;
+
+ /**
+ typeset a "command" item. Default: pass on to daddy.
+ If the column is not breakable, #pre_p# and #post_p# are junked
+ */
+ virtual void typeset_breakable_item(Item * pre_p ,
+ Item * nobreak_p, Item * post_p);
+ /**
+ Invoke walker method to typeset element. Default: pass on to daddy.
+ */
+ virtual void typeset_element(Staff_elem*elem_p);
+
+ /**
+ take note of item/spanner
+ put item in spanner. Adjust local key; etc.
+
+ Default: ignore the info
+ */
+ virtual void acknowledge_element(Staff_elem_info) {}
+ /**
+ Announce element. Default: pass on to daddy. Utility
+ */
+ virtual void announce_element(Staff_elem_info);
+ /**
+ Set features of the register(s). Default: ignore features.
+ */
+ virtual void set_feature(Features){}
+ /**
+ Does this equal or contain a certain register?
+ */
+ virtual bool contains_b(Request_register*reg_l);
+ /**
+ Get information on the staff. Default: ask daddy.
+ */
+ virtual Staff_info get_staff_info();
+
+ virtual void do_print()const;
+public:
+ /** Every Request_register (except for the 'top' which is directly
+ inside the Staff_walker, is a element of a group. */
+ Register_group_register * daddy_reg_l_;
+
+ Request_register();
+ virtual ~Request_register(){}
+ NAME_MEMBERS(Request_register);
+ void print() const;
+};
+
+
+#endif // REGISTER_HH
+
--- /dev/null
+/*
+ registergroup.hh -- declare
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+
+#ifndef REGISTERGROUP_HH
+#define REGISTERGROUP_HH
+
+
+#include "plist.hh"
+#include "staff-elem-info.hh"
+#include "register.hh"
+
+/**
+ Group a number of registers. Usually delegates everything to its contents.
+ Postfix: group
+ */
+class Register_group_register : public Request_register {
+protected:
+ IPointerList<Request_register*> reg_list_;
+ virtual void do_print()const;
+public:
+
+ /**
+ Junk #reg_l#.
+
+ Pre:
+ #reg_l# is in #reg_list_#
+ */
+ virtual void terminate_register(Request_register * reg_l);
+
+ /**
+ Remove #reg_l# from the list, and return it.
+ */
+ Request_register * get_register_p(Request_register*reg_l);
+ virtual void set_feature(Features i);
+ virtual bool acceptable_request_b(Request*);
+ virtual void pre_move_processing();
+ virtual void post_move_processing();
+ virtual void acknowledge_element(Staff_elem_info info);
+ virtual bool try_request(Request*);
+ virtual void process_requests();
+ virtual ~Register_group_register();
+ virtual void add(Request_register* reg_p);
+ virtual bool contains_b(Request_register*);
+};
+
+#endif // REGISTERGROUP_HH
+
+
--- /dev/null
+#if 0
+
+
+
+/**Draw a (Guitar) chord above or below this ``note''.
+Why a request?
+Because everything else is done in requests.
+*/
+struct Chord : Request {
+ // don't know how this looks.
+};
+
+
+/// for absolute dynamics
+enum Loudness {
+ FFF, FF, F, MF, MP, P, PP, PPP
+} ;
+
+
+/**
+Start/stop a bracket at this note. if #nplet# is set, the staff will
+try to put an appropriate number over the bracket
+*/
+struct Bracket_req : Span_req {
+ int nplet; // print a number over the beam.
+};
+
+struct Subtle_req {
+ Moment subtime;
+};
+
+
+/** helper in the hierarchy. Each dynamic is bound to one note ( a
+ crescendo spanning multiple notes is thought to be made of two
+ "dynamics": a start and a stop). Dynamic changes can occur in a
+ smaller time than the length of its note, therefore fore each
+ Dynamic request carries a time, measured from the start of its
+ note.
+
+ This subfield would come in handy, if mpp96 was adapted for midi
+ support.
+
+ Dynamic should have been derived from request, but I don't want to
+ fuss with virtual baseclasses. */
+
+struct Dynamic:Subtle_req {
+
+};
+/// do a crescendo
+struct Cresc_req : Span_req, Dynamic {
+
+};
+
+/// do a decrescendo
+struct Decresc_req : Span_req, Dynamic {
+
+};
+
+/// do a dynamic like "fff" or "mp"
+struct Absdynamic_req : Request, Dynamic {
+ Loudness loudness;
+};
+
+struct Grace_req : Subtle_req {
+
+};
+
+struct Grace_turn_req : Grace_turn {
+
+};
+
+struct Grace_note : Melodic_req {
+
+};
+
+struct Grace_notes {
+
+};
+
+struct Glissando_req : Span_req {
+
+};
+#endif
--- /dev/null
+/*
+ request.hh -- declare Request baseclasses.
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#ifndef REQUEST_HH
+#define REQUEST_HH
+// LilyPond's second egg of columbus!
+
+#include "glob.hh"
+#include "string.hh"
+#include "moment.hh"
+#include "class-name.hh"
+
+/**
+ a voice element wants something printed.
+ Hungarian postfix: req
+ @see lilygut manpage
+ */
+class Request {
+public:
+ Voice_element*elt_l_;
+ char const* defined_ch_c_l_;
+
+ /* *************** */
+ Voice * voice_l();
+ Request();
+ Request(Request const&);
+ virtual ~Request(){}
+
+ NAME_MEMBERS(Request);
+ virtual Request* clone() const { return new Request(*this); }
+ void print()const ;
+
+ virtual Moment duration() const { return 0; }
+
+ /* accessors for children
+ maybe checkout RTTI
+ */
+ virtual Barcheck_req *barcheck() { return 0; }
+ virtual Note_req *note() { return 0;}
+ virtual Script_req *script() { return 0;}
+ virtual Stem_req *stem() { return 0;}
+ virtual Text_req*text() { return 0; }
+ virtual Rest_req *rest() { return 0; }
+ virtual Span_req *span() { return 0; }
+ virtual Beam_req *beam() { return 0 ; }
+ virtual Plet_req* plet() { return 0; }
+ virtual Slur_req *slur() { return 0 ; }
+ virtual Rhythmic_req*rhythmic() { return 0; }
+ virtual Lyric_req* lreq_l() { return 0; }
+ virtual Melodic_req *melodic() { return 0; }
+ virtual Terminate_voice_req *terminate() {return 0;}
+ virtual Group_change_req * groupchange() { return 0;}
+ virtual Group_feature_req * groupfeature() { return 0; }
+ virtual Spacing_req * spacing() { return 0; }
+ virtual Blank_req * blank() { return 0; }
+ virtual Musical_req *musical() { return 0; }
+ virtual Command_req * command() { return 0; }
+protected:
+ virtual void do_print()const ;
+};
+
+#define REQUESTMETHODS(T,accessor) \
+virtual T * accessor() { return this;}\
+NAME_MEMBERS(T);\
+virtual Request *clone() const { return new T(*this); } \
+virtual void do_print() const
+
+#endif
--- /dev/null
+/*
+ rest.hh -- part of LilyPond
+
+ (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef REST_HH
+#define REST_HH
+#include "item.hh"
+
+struct Rest : Item {
+
+ int dots;
+ int balltype;
+
+ /* *************** */
+
+
+ Rest(int dur,int dots);
+ void do_print()const;
+NAME_MEMBERS(Rest);
+ Molecule* brew_molecule_p()const;
+};
+#endif
+
--- /dev/null
+/*
+ sccol.hh -- part of LilyPond
+
+ (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef SCCOL_HH
+#define SCCOL_HH
+#include "proto.hh"
+#include "varray.hh"
+#include "moment.hh"
+
+
+/**
+
+ When typesetting hasn't started on PScore yet, the columns which
+ contain data have a rhythmical position. Score_column is the type
+ with a rhythmical time attached to it. The calculation of
+ idealspacing is done with data in these columns. (notably: the
+ #durations# field)
+
+ */
+
+class Score_column {
+ friend class Score;
+ friend class Score_walker;
+
+ bool musical_b_;
+ Moment when_;
+ void set_breakable();
+public:
+ /// indirection to column
+ PCol * pcol_l_;
+
+ /// length of notes/rests in this column
+ Array<Moment> durations;
+
+ /* *************** */
+
+ Moment when() { return when_; }
+ Score_column(Moment when);
+ static int compare(Score_column & c1, Score_column &c2);
+ void add_duration(Moment );
+ void preprocess();
+ bool breakable_b();
+ bool musical_b() { return musical_b_; }
+ bool used_b();
+ void print() const;
+
+
+};
+
+instantiate_compare(Score_column&, Score_column::compare);
+
+#endif // SCCOL_HH
+
+
+
+
--- /dev/null
+/*
+ score-walker.hh -- declare Score_walker
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+
+#ifndef SCOREWALKER_HH
+#define SCOREWALKER_HH
+#include "pcursor.hh"
+#include "proto.hh"
+#include "varray.hh"
+
+
+/**
+ walk through the score_columns, and while doing so, walk all staffs in a score.
+ */
+class Score_walker : public PCursor<Score_column *>
+{
+ Score* score_l_;
+ /// walkers for the individual staves.
+ Array<Staff_walker *> walker_p_arr_;
+ Array<Staff_walker *> disallow_break_walk_l_arr;
+ int disallow_break_count_;
+ void reinit();
+public:
+ void allow_break(Staff_walker*w);
+ Score_walker(Score*);
+ ~Score_walker();
+ Moment when();
+ void operator++(int);
+ /// process staff walkers.
+ void process();
+};
+#endif // SCOREWALKER_HH
--- /dev/null
+/*
+ score.hh -- declare Score
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+
+#ifndef SCORE_HH
+#define SCORE_HH
+
+#include "varray.hh"
+#include "proto.hh"
+#include "plist.hh"
+#include "moment.hh"
+#include "assoc.hh"
+#include "string.hh"
+
+/// the total music def of one movement
+struct Score {
+ /// paper_, staffs_ and commands_ form the problem definition.
+ Paper_def *paper_p_;
+ Midi_def *midi_p_;
+ IPointerList<Staff*> staffs_;
+
+ /// "runtime" fields for setting up spacing
+ IPointerList<Score_column*> cols_;
+ PScore *pscore_p_;
+
+ const char *defined_ch_c_l_;
+ int errorlevel_i_;
+
+ /* *************************************************************** */
+
+ /// construction
+ Score();
+ ~Score();
+ void add(Staff*);
+
+ /// do everything except outputting to file
+ void process();
+
+ /// output to file
+ void output(String fn);
+
+
+ ///
+ void set(Midi_def* midi_p);
+ ///
+ void set(Paper_def* midi_p);
+
+ // standard
+ void OK() const;
+ void print() const;
+
+ /// find a column.
+ PCursor<Score_column *> find_col(Moment,bool);
+
+ /// when does the last *musical* element finish?
+ Moment last() const;
+
+private:
+ void paper_output();
+ void setup_music();
+ void process_music();
+ /// do midi stuff
+ void midi();
+
+ /// do paper stuff
+ void paper();
+
+ // utils:
+ PCursor<Score_column*> create_cols(Moment);
+
+ Score(Score const&){}
+
+ /**
+ make the pcol_l_ fields of each Score_column point to the correct PCol,
+ remove any unnecessary Score_column's
+ */
+ void do_cols();
+
+ /// remove unused cols
+ void clean_cols();
+
+ /// add #Idealspacings# to #pscore_#
+ void calc_idealspacing();
+};
+#endif
--- /dev/null
+/*
+ scoreline.hh -- part of LilyPond
+
+ (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef SCORELINE_HH
+#define SCORELINE_HH
+#include "proto.hh"
+#include "plist.hh"
+#include "varray.hh"
+
+/// the columns of a score that form one line.
+struct
+Line_of_score {
+ PointerList<PCol *> cols;
+
+ // need to store height of each staff.
+ IPointerList<Line_of_staff*> staffs;
+ PScore * pscore_l_; // needed to generate staffs
+
+ /* *************** */
+ void process() ;
+ Line_of_score(Array<PCol *> sv, PScore *);
+
+ String TeXstring() const;
+
+ // is #c# contained in #*this#?
+ bool element(const PCol *c);
+};
+
+#endif
+
--- /dev/null
+/*
+ script-def.hh -- part of LilyPond
+
+ (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef SCRIPTDEF_HH
+#define SCRIPTDEF_HH
+#include "string.hh"
+struct Script_def{
+ int stemdir;
+ int staffdir;
+
+ bool invertsym;
+ String symidx;
+
+ /* *************** */
+ int compare(Script_def const &);
+ void print() const;
+ Script_def(String, int, int ,bool);
+};
+
+
+#endif // SCRIPTDEF_HH
+
--- /dev/null
+/*
+ script-reg.hh -- part of LilyPond
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+
+#ifndef SCRIPTREG_HH
+#define SCRIPTREG_HH
+
+#include "register.hh"
+
+
+struct Script_register : Request_register {
+ Script * script_p_;
+ Script_req * script_req_l_;
+ int dir_i_;
+ /* *************** */
+ void set_feature(Features dir_i_);
+ Script_register();
+ virtual bool try_request(Request*);
+ virtual void process_requests();
+ virtual void acknowledge_element(Staff_elem_info);
+ virtual void pre_move_processing();
+ virtual void post_move_processing();
+ NAME_MEMBERS(Script_register);
+};
+
+#endif // SCRIPTREG_HH
--- /dev/null
+/*
+ script.hh -- part of LilyPond
+
+ (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef SCRIPT_HH
+#define SCRIPT_HH
+
+#include "script-def.hh"
+#include "item.hh"
+
+struct Script : Item {
+ int dir;
+ int symdir;
+ int pos;
+ int staffsize;
+ Script_def *specs_l_;
+ Stem *stem_l_;
+ Array<Item *> support;
+
+ /* *************** */
+ NAME_MEMBERS(Script);
+ Molecule *brew_molecule_p()const;
+ virtual void do_post_processing();
+ virtual void do_pre_processing();
+ Script(Script_req*, int staffsize);
+ void set_support(Item*);
+ void set_stem(Stem*);
+ Interval support_height()const;
+ virtual Interval width() const;
+private:
+ void set_symdir();
+ void set_default_dir();
+ void set_default_index();
+ Symbol symbol()const;
+};
+
+
+#endif // SCRIPT_HH
+
--- /dev/null
+/*
+ slur-reg.hh -- declare Slur_register
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+
+#ifndef SLURREG_HH
+#define SLURREG_HH
+
+#include "register.hh"
+
+struct Slur_register : Request_register {
+ Array<Slur_req*> requests_arr_;
+ Array<Slur_req*> new_slur_req_l_arr_;
+ Array<Slur *> slur_l_stack_;
+ Array<Slur*> end_slur_l_arr_;
+
+ int dir_i_;
+
+ /* *************** */
+ ~Slur_register();
+ Slur_register();
+ virtual bool try_request(Request*);
+ virtual void process_requests();
+ virtual void acknowledge_element(Staff_elem_info);
+ virtual void pre_move_processing();
+ virtual void post_move_processing();
+ virtual void set_feature(Features);
+ NAME_MEMBERS(Slur_register);
+};
+
+#endif // SLURREG_HH
--- /dev/null
+/*
+ slur.hh -- part of LilyPond
+
+ (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef SLUR_HH
+#define SLUR_HH
+
+#include "directional-spanner.hh"
+#include "fproto.hh"
+#include "varray.hh"
+
+struct Slur : Directional_spanner {
+
+ Array<Notehead*> encompass;
+
+ bool open_left, open_right;
+
+ /* *************** */
+ Offset center() const;
+ Slur();
+ void do_post_processing();
+ void do_pre_processing();
+ void add(Notehead*);
+ void set_default_dir();
+
+ Spanner* do_break_at( PCol*, PCol*) const;
+ void process();
+private:
+ Molecule*brew_molecule_p()const;
+ NAME_MEMBERS(Slur);
+};
+
+#endif // SLUR_HH
+
+
--- /dev/null
+/*
+ spanner.hh -- part of LilyPond
+
+ (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef SPANNER_HH
+#define SPANNER_HH
+
+#include "proto.hh"
+#include "staff-elem.hh"
+
+
+/** a symbol which is attached between two columns. A spanner is a symbol which spans across several columns, so its
+ final appearance can only be calculated after the breaking problem
+ is solved.
+
+ Examples
+
+ - (de)crescendo
+ - slur
+ - beam
+ - bracket
+
+
+ Spanner should know about the items which it should consider:
+ e.g. slurs should be steep enough to "enclose" all those items. This
+ is absolutely necessary for beams, since they have to adjust the
+ length of stems of notes they encompass.
+
+ */
+struct Spanner:Staff_elem {
+ PCol *left, *right;
+
+
+ /* *************** */
+
+ Spanner();
+ virtual Interval width()const;
+ void do_print()const;
+
+ Spanner *broken_at(PCol *c1, PCol *c2) const;
+ virtual Spanner* spanner() { return this; }
+protected:
+
+ /**
+ clone a piece of this spanner.
+ PRE
+ c1 >= start, c2 <= stop
+ */
+ virtual Spanner *do_break_at( PCol *c1, PCol *c2) const=0;
+ NAME_MEMBERS(Spanner);
+};
+#endif
--- /dev/null
+/*
+ staff-column.hh -- declare Staff_column
+
+ (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef STAFFCOLUMN_HH
+#define STAFFCOLUMN_HH
+#include "proto.hh"
+#include "varray.hh"
+#include "moment.hh"
+
+/// store simultaneous requests
+class Staff_column {
+
+ Staff_column(Staff_column const&);
+
+public:
+ Array<Request*> creationreq_l_arr_;
+ Array<Request*> musicalreq_l_arr_;
+ Array<Request*> commandreq_l_arr_;
+ Staff * staff_l_;
+
+ /// fields to collect timing data vertically.
+ Array<Timing_req*> timing_req_l_arr_;
+ Score_column *musical_column_l_, *command_column_l_;
+
+ /* *************** */
+
+ Staff_column();
+
+ Moment when() const;
+ void set_cols(Score_column *c1, Score_column *c2);
+ void add(Voice_element*ve);
+ void OK() const;
+ ~Staff_column();
+ void typeset_breakable_items(Array<Item *> &pre_p_arr,
+ Array<Item *> &nobreak_p_arr,
+ Array<Item *> &post_p_arr);
+ void typeset_musical_item(Item *i);
+protected:
+ void setup_one_request(Request*);
+};
+
+
+
+#endif // STAFFCOLUMN_HH
+
--- /dev/null
+/*
+ staff-elem-info.hh -- declare Staff_elem_info
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+
+#ifndef STAFFELEMINFO_HH
+#define STAFFELEMINFO_HH
+
+#include "proto.hh"
+#include "varray.hh"
+/// data container.
+struct Staff_elem_info {
+ Staff_elem * elem_p_;
+ Request*req_l_;
+ const Voice * voice_l_;
+ Array<Request_register*> origin_reg_l_arr_;
+
+
+ /* *** */
+ Staff_elem_info(Staff_elem*, Request*);
+ Staff_elem_info();
+};
+
+struct Staff_info {
+ int *c0_position_i_;
+ Staff_walker *walk_l_;
+ const Time_description *time_c_l_;
+ const Rhythmic_grouping *rhythmic_c_l_;
+};
+
+
+struct Features {
+ bool initialiser_b_;
+ int direction_i_;
+
+ Features();
+ static Features dir(int);
+};
+#endif // STAFFELEMINFO_HH
--- /dev/null
+/*
+ staff-elem.hh -- part of LilyPond
+
+ (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef STAFFELEM_HH
+#define STAFFELEM_HH
+#include "varray.hh"
+#include "proto.hh"
+#include "offset.hh"
+#include "molecule.hh"
+#include "class-name.hh"
+
+
+/** Both Spanner and Item are Staff_elem's. Most Staff_elem's depend
+ on other Staff_elem's, eg, Beam needs to know and set direction of
+ Stem. So the Beam has to be calculated *before* Stem. This is
+ accomplished with the dependencies field of struct Staff_elem.
+
+ */
+struct Staff_elem {
+ enum Status {
+ ORPHAN, // not yet added to pstaff
+ VIRGIN, // added to pstaff
+ PRECALCING,
+ PRECALCED, // calcs before spacing done
+ POSTCALCING,
+ POSTCALCED, // after spacing calcs done
+ OUTPUT, // molecule has been output
+ } status;
+
+ /// the pstaff it is in
+ PStaff *pstaff_l_;
+
+ /* *************** */
+ Staff_elem(Staff_elem const&);
+ String TeXstring () const ;
+ virtual void print() const;
+ virtual Interval width() const;
+ virtual Interval height() const;
+ Paper_def *paper() const;
+ virtual ~Staff_elem();
+ Staff_elem();
+ NAME_MEMBERS(Staff_elem);
+ void translate(Offset);
+ void add_processing();
+ void pre_processing();
+ void post_processing();
+ void molecule_processing();
+
+ virtual Spanner* spanner() { return 0; }
+ virtual Item * item() { return 0; }
+ void add_dependency(Staff_elem* );
+ void substitute_dependency(Staff_elem* old, Staff_elem * newdep);
+
+protected:
+
+ /// do printing of derived info.
+ virtual void do_print() const=0;
+ /// generate the molecule
+ virtual Molecule* brew_molecule_p()const=0;
+ ///executed directly after the item is added to the PScore
+ virtual void do_add_processing();
+ /// do calculations before determining horizontal spacing
+ virtual void do_pre_processing();
+
+ /// do calculations after determining horizontal spacing
+ virtual void do_post_processing();
+
+ Array<Staff_elem*> dependants;
+
+private:
+ /// member: the symbols
+ Molecule *output; // should scrap, and use temp var?
+
+
+ /**
+ This is needed, because #output# may still be
+ NULL.
+ */
+ Offset offset_;
+ Array<Staff_elem*> dependencies;
+};
+
+
+#endif // STAFFELEM_HH
+
--- /dev/null
+/*
+ staff-walker.hh -- declare Staff_walker
+
+ (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef STAFFWALKER_HH
+#define STAFFWALKER_HH
+
+#include "proto.hh"
+#include "time-description.hh"
+#include "pcursor.hh"
+
+/**
+ manage run-time info when walking staffcolumns such as: key,
+ meter, pending beams & slurs
+ */
+struct Staff_walker : public PCursor<Staff_column*> {
+ Staff * staff_l_;
+ PScore * pscore_l_;
+ Score_walker *score_walk_l_;
+ Time_description time_;
+ Rhythmic_grouping *default_grouping;
+
+ /* *************** */
+
+ Moment when() const;
+ virtual ~Staff_walker();
+ Staff_walker(Staff*, PScore*);
+ void process() ;
+
+ void operator++(int);
+ void allow_break();
+
+protected:
+ /// every time before ++ is called
+ virtual void do_pre_move(){}
+ /// every time after ++ is called
+ virtual void do_post_move(){}
+ virtual void process_requests()=0;
+private:
+ void process_timing_reqs();
+ Staff_walker(Staff_walker const&);
+};
+
+#endif // STAFFWALKER_HH
+
--- /dev/null
+/*
+ staff.hh -- declare Staff
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#ifndef STAFF_HH
+#define STAFF_HH
+
+#include "plist.hh"
+#include "proto.hh"
+#include "moment.hh"
+
+/// base class for a collection of voices.
+class Staff {
+ Staff(const Staff&src);
+
+ /// synchronous horizontal stuff
+ IPointerList<Voice*> voice_list_;
+ Staff_column *get_col(Moment, PCursor<Staff_column*> * last= 0);
+
+public:
+
+ /// runtime field
+ IPointerList<Staff_column*> cols_;
+
+ Score *score_l_;
+ PScore *pscore_l_;
+ PStaff *pstaff_l_;
+
+ /* *************************************************************** */
+
+ void add(const PointerList<Voice*> &s);
+
+ void add_voice(Voice *v);
+ Paper_def*paper()const;
+
+ void setup_staffcols();
+
+ void OK() const;
+ void print() const;
+
+ /// when does the last *musical* element finish?
+ Moment last() const;
+
+// /// extract midi info
+// Midi_track* midi_track_p();
+
+ /// remove unused cols
+ void clean_cols() ;
+ Staff();
+
+ virtual void set_output(PScore * destination)=0;
+ virtual Staff_walker *get_walker_p()=0;
+ virtual ~Staff() { }
+protected:
+
+};
+#endif
--- /dev/null
+/*
+ staffelem.hh -- part of LilyPond
+
+ (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef STAFFELEM_HH
+#define STAFFELEM_HH
+#include "varray.hh"
+#include "proto.hh"
+#include "offset.hh"
+#include "molecule.hh"
+
+/** Both Spanner and Item are Staff_elem's. Most Staff_elem's depend
+ on other Staff_elem's, eg, Beam needs to know and set direction of
+ Stem. So the Beam has to be calculated *before* Stem. This is
+ accomplished with the dependencies field of struct Staff_elem.
+
+ */
+struct Staff_elem {
+ enum Status {
+ ORPHAN, // not yet added to pstaff
+ VIRGIN, // added to pstaff
+ PRECALCING,
+ PRECALCED, // calcs before spacing done
+ POSTCALCING,
+ POSTCALCED, // after spacing calcs done
+ OUTPUT, // molecule has been output
+ } status;
+
+ /// the pstaff it is in
+ PStaff *pstaff_l_;
+
+ /* *************** */
+ Staff_elem(Staff_elem const&);
+ String TeXstring () const ;
+ virtual void print() const;
+ virtual Interval width() const;
+ virtual Interval height() const;
+ Paperdef *paper() const;
+ virtual ~Staff_elem();
+ Staff_elem();
+
+ void translate(Offset);
+ void add_processing();
+ void pre_processing();
+ void post_processing();
+ void molecule_processing();
+ virtual const char *name() const; // to find out derived classes.
+ virtual Spanner* spanner() { return 0; }
+ virtual Item * item() { return 0; }
+ void add_depedency(Staff_elem* );
+ void substitute_dependency(Staff_elem* old, Staff_elem * newdep);
+protected:
+
+ /// do printing of derived info.
+ virtual void do_print() const=0;
+ /// generate the molecule
+ virtual Molecule* brew_molecule_p()const=0;
+ ///executed directly after the item is added to the PScore
+ virtual void do_add_processing();
+ /// do calculations before determining horizontal spacing
+ virtual void do_pre_processing();
+
+ /// do calculations after determining horizontal spacing
+ virtual void do_post_processing();
+
+ Array<Staff_elem*> dependants;
+
+private:
+ /// member: the symbols
+ Molecule *output; // should scrap, and use temp var?
+
+
+ /**
+ This is needed, because #output# may still be
+ NULL.
+ */
+ Offset offset_;
+ Array<Staff_elem*> dependencies;
+};
+#define NAME_METHOD(c) const char *c::name()const{ return #c; } struct c
+#endif // STAFFELEM_HH
+
--- /dev/null
+/*
+ staffeleminfo.hh -- declare Staff_elem_info
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+
+#ifndef STAFFELEMINFO_HH
+#define STAFFELEMINFO_HH
+
+#include "proto.hh"
+
+/// data container.
+struct Staff_elem_info {
+ Staff_elem * elem_p_;
+ Request*req_l_;
+ const Voice * voice_l_;
+ Voice_group_registers * group_regs_l_;
+ Request_register * origin_reg_l_;
+
+ /* *** */
+ Staff_elem_info(Staff_elem*, Request*, Request_register*);
+ Staff_elem_info();
+};
+
+#endif // STAFFELEMINFO_HH
--- /dev/null
+/*
+ staffline.hh -- horizontal structures for broken scores.
+
+ (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef STAFFLINE_HH
+#define STAFFLINE_HH
+
+#include "proto.hh"
+#include "real.hh"
+#include "plist.hh"
+#include "varray.hh"
+#include "glob.hh"
+#include "pstaff.hh"
+
+/// one broken line of staff.
+struct Line_of_staff {
+
+ Line_of_score * line_of_score_l_;
+ PStaff *pstaff_l_;
+
+ /* *************** */
+
+ String TeXstring() const;
+ Line_of_staff(Line_of_score*, PStaff *);
+ Interval height() const;
+ void process();
+};
+
+#endif
--- /dev/null
+/*
+ staffsym.hh -- declare Staff_symbol
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+
+#ifndef STAFFSYM_HH
+#define STAFFSYM_HH
+#include "spanner.hh"
+/**
+ This spanner draws the lines of a pstaff.
+ The bottom line is position 0.
+ */
+class Staff_symbol : public Spanner
+{
+public:
+ /// this many lines.
+ int no_lines_i_;
+
+ NAME_MEMBERS(Staff_symbol);
+ Staff_symbol(int lines);
+ virtual Molecule* brew_molecule_p() const;
+ void set_extent(PCol* p1, PCol* p2);
+ virtual void do_print()const;
+ virtual Spanner *do_break_at( PCol *c1, PCol *c2) const;
+};
+#endif // STAFFSYM_HH
--- /dev/null
+/*
+ stem-beam-reg.hh -- part of LilyPond
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+
+#ifndef STEMBEAMREG_HH
+#define STEMBEAMREG_HH
+#include "register.hh"
+
+struct Stem_beam_register : Request_register {
+ Stem * stem_p_;
+ Beam * beam_p_;
+ Beam_req * beam_req_l_;
+ Stem_req * stem_req_l_;
+ Beam_req * start_req_l_;
+ bool end_beam_b_;
+ Rhythmic_grouping *current_grouping;
+ int default_dir_i_;
+
+ /* *************** */
+ Stem_beam_register();
+ ~Stem_beam_register();
+ virtual void set_feature(Features dir_i_);
+ virtual bool try_request(Request*);
+ virtual void process_requests();
+ virtual void acknowledge_element(Staff_elem_info);
+ virtual void pre_move_processing();
+ virtual void post_move_processing();
+ NAME_MEMBERS(Stem_beam_register);
+};
+#endif // STEMBEAMREG_HH
--- /dev/null
+/*
+ stem.hh -- declare Stem
+
+ (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef STEM_HH
+#define STEM_HH
+#include "item.hh"
+#include "varray.hh"
+#include "moment.hh"
+
+
+/**the rule attached to the ball.
+ takes care of:
+
+ \begin{itemize}
+ \item the rule
+ \item the flag
+ \item up/down position.
+ \end{itemize}
+ */
+
+struct Stem : Item {
+ /// heads that the stem encompasses (positions)
+ int minnote, maxnote;
+
+ /// false if in beam
+ bool print_flag;
+
+ int beams_left;
+ int beams_right;
+
+ /// needed for determining direction/length
+ int staff_center;
+
+
+ /**extent of the stem (positions).
+ fractional, since Beam has to adapt them.
+ */
+
+ Real bot, top;
+ Real stemlen;
+
+ /// flagtype? 4 none, 8 8th flag, 0 = beam.
+ int flag;
+
+
+ /**
+ geen gedonder, jij gaat onder.
+ -1 stem points down, +1: stem points up
+ */
+
+ int dir;
+ Real stem_xoffset;
+
+ Array<Notehead*> heads;
+
+ /* *************** */
+ Stem(int center); //, Moment duration);
+
+ /// ensure that this Stem also encompasses the Notehead #n#
+ void add(Notehead*n);
+
+ NAME_MEMBERS(Stem);
+
+ Real hindex()const;
+ void do_print() const;
+ void set_stemend(Real);
+ int get_default_dir();
+ void set_default_dir();
+ void set_default_stemlen();
+ void set_default_extents();
+ void set_noteheads();
+ void do_pre_processing();
+
+ Interval width() const;
+
+ Molecule* brew_molecule_p() const;
+};
+#endif
--- /dev/null
+#ifndef SYMBOL_HH
+#define SYMBOL_HH
+
+#include "string.hh"
+#include "boxes.hh"
+#include "proto.hh"
+
+struct Symbol {
+ String tex;
+ Box dim;
+
+ Symbol (String, Box);
+ Symbol();
+ String str()const; // for printing.
+};
+
+#endif
--- /dev/null
+/*
+ lilypond, (c) 1996,97 Han-Wen Nienhuys
+*/
+#ifndef SYMTABLE_HH
+#define SYMTABLE_HH
+#include "assoc.hh"
+#include "string.hh"
+#include "symbol.hh"
+
+struct Symtable : public Assoc<String, Symbol> {
+ Symbol lookup(String)const;
+ void print()const;
+};
+
+
+struct Symtables : private Assoc<String, Symtable*> {
+
+ Symtable* operator()(String s);
+ ~Symtables();
+ Symtables();
+ Symtables(Symtables const&);
+ Assoc<String, Symtable*>::add;
+ void print()const;
+};
+
+
+#endif
+
--- /dev/null
+#ifndef TSTREAM__HH
+#define TSTREAM__HH
+
+#include <iostream.h>
+#include "string.hh"
+
+
+/** TeX output.
+ Use this class for writing to a TeX file.
+ It counts braces to prevent nesting errors, and
+ it will add a comment sign before each newline.
+ */
+struct Tex_stream {
+ bool outputting_comment;
+ ostream *os;
+ int nest_level;
+
+ /// open a file for writing
+ Tex_stream(String filename);
+ void header();
+ /// delegate conversion to string class.
+ Tex_stream &operator<<(String);
+
+ /// close the file
+ ~Tex_stream();
+private:
+ Tex_stream(Tex_stream const&);
+};
+#endif
--- /dev/null
+#ifndef TEX_HH
+#define TEX_HH
+
+#include "string.hh"
+#include "boxes.hh"
+#include "scalar.hh"
+
+/** parameter substitution in TeXstrings.
+ this function provides a simple macro mechanism:
+
+ if source == "tex%bla%", then
+ substitute_args(source, {"X","Y"}) == "texXblaY"
+ */
+String
+substitute_args(String source, Array<String> args);
+
+/// parameter substitution in TeXstrings
+String
+substitute_args(String source, Array<Scalar> args);
+
+/// #h# is in points
+String vstrut(Real h);
+
+
+#endif
--- /dev/null
+/*
+ text-def.hh -- part of LilyPond
+
+ (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef TEXTDEF_HH
+#define TEXTDEF_HH
+
+#include "string.hh"
+#include "proto.hh"
+
+struct Text_def {
+ int align_i_;
+ String text_str_;
+ String style_str_;
+ char const* defined_ch_c_l_;
+
+
+ /* ****************/
+ virtual ~Text_def() {};
+ bool compare(const Text_def&);
+ Text_def();
+ virtual void print() const;
+ virtual Atom create_atom(Paper_def*) const;
+};
+
+#endif // TEXTDEF_HH
+
--- /dev/null
+/*
+ text.hh -- part of LilyPond
+
+ (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef TEXT_ITEM_HH
+#define TEXT_ITEM_HH
+
+#include "text-def.hh"
+#include "item.hh"
+
+struct Text_item : Item {
+ int pos_i_;
+ int staffsize_i_;
+ int dir_i_;
+ Text_def* tdef_l_;
+
+ /* ***************/
+ NAME_MEMBERS(Text_item);
+ virtual void set_default_index();
+ Molecule* brew_molecule_p() const;
+ void do_pre_processing();
+
+ Text_item(Text_req*,int);
+};
+
+
+#endif // TEXT_HH
+
--- /dev/null
+/*
+ text-reg.hh -- part of LilyPond
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+
+#ifndef TEXTREG_HH
+#define TEXTREG_HH
+#include "register.hh"
+
+struct Text_register : Request_register{
+ Text_item * text_p_;
+ Text_req * text_req_l_;
+ int dir_i_;
+ /* *************** */
+ virtual void set_feature(Features );
+ Text_register();
+ virtual bool try_request(Request*);
+ virtual void process_requests();
+ virtual void pre_move_processing();
+ virtual void post_move_processing();
+ NAME_MEMBERS(Text_register);
+};
+
+#endif // TEXTREG_HH
--- /dev/null
+/*
+ textspanner.hh -- part of LilyPond
+
+ (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef TEXTSPANNER_HH
+#define TEXTSPANNER_HH
+
+#include "string.hh"
+#include "directional-spanner.hh"
+#include "text-def.hh"
+
+/** a spanner which puts texts on top of other spanners. Use for
+ triplets, eentweetjes, ottava, etc. */
+struct Text_spanner : Spanner {
+ Text_def spec;
+ Offset text_off_;
+ Directional_spanner*support;
+
+ /* *************** */
+
+ NAME_MEMBERS(Text_spanner);
+ virtual void do_pre_processing();
+ virtual void do_post_processing();
+ virtual Interval height() const ;
+ virtual Molecule* brew_molecule_p()const;
+ virtual void do_print() const;
+ virtual Spanner* do_break_at(PCol*,PCol*)const;
+ Text_spanner();
+ void set_support(Directional_spanner*);
+};
+#endif // TEXTSPANNER_HH
+
--- /dev/null
+/*
+ moment.hh -- part of LilyPond
+
+ (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef tdes_HH
+#define tdes_HH
+
+#include "moment.hh"
+
+/// full info on where we are
+struct Time_description {
+ Moment when_;
+
+ /// if true, no bars needed, no reduction of whole_in_measure
+ bool cadenza_b_;
+
+ /// current measure info
+ Moment whole_per_measure_;
+
+ /// where am i
+ Moment whole_in_measure_;
+
+ /// how long is one beat?
+ Moment one_beat_;
+
+ /// idem
+ int bars_i_;
+
+ /* *************** */
+ void set_cadenza(bool);
+ void OK() const;
+ Time_description();
+ void add(Moment dt);
+ String str()const;
+ void print() const;
+ void setpartial(Moment p);
+ Moment barleft();
+ void set_meter(int,int);
+ static int compare (Time_description&, Time_description&);
+};
+
+#include "compare.hh"
+
+
+instantiate_compare(Time_description&,Time_description::compare);
+
+#endif // Time_description_HH
+
--- /dev/null
+/*
+ voice-element.hh -- declare Voice_element
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+
+#ifndef VOICE_ELEMENT_HH
+#define VOICE_ELEMENT_HH
+
+#include "proto.hh"
+#include "plist.hh"
+#include "moment.hh"
+
+/** one horizontal bit. Voice_element is nothing but a container for
+ *the requests, */
+struct Voice_element {
+ Moment duration;
+ char const* defined_ch_c_l_;
+ const Voice *voice_l_;
+ IPointerList<Request*> reqs;
+
+ /* *************** */
+
+ Voice_element();
+ Voice_element(Voice_element const & src );
+
+ void add(Request*);
+ bool find_plet_start_bo(char c, Moment& moment_r);
+ void print ()const;
+ void set_default_group(String id);
+ void set_plet_backwards(Moment& now_moment_r, Moment until_moment, int num_i, int den_i);
+};
+
+#endif // VOICE-ELEMENT_HH
--- /dev/null
+/*
+ voice-group-regs.hh -- declare Voice_group_registers
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+
+#ifndef VOICEGROUPREGS_HH
+#define VOICEGROUPREGS_HH
+
+#include "registergroup.hh"
+
+struct Voice_group_registers : Register_group_register {
+ String group_id_str_;
+ Array<Voice_registers*> voice_regs_l_;
+
+ /* *************** */
+
+ NAME_MEMBERS(Voice_group_registers);
+ static bool static_acceptable_request_b(Request*);
+ virtual void terminate_register(Request_register*);
+ virtual void do_print() const;
+ virtual void add(Request_register*);
+ Voice_group_registers(String id);
+ virtual bool try_request(Request*);
+};
+#endif // VOICEGROUPREGS_HH
--- /dev/null
+/*
+ voice-regs.hh -- declare Voice_registers
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+
+#ifndef VOICEREGS_HH
+#define VOICEREGS_HH
+
+#include "registergroup.hh"
+
+class Voice_registers : public Register_group_register {
+
+
+public:
+ Voice *voice_l_;
+ /* *************** */
+
+ NAME_MEMBERS(Voice_registers);
+ virtual bool acceptable_request_b(Request*);
+ virtual void acknowledge_element(Staff_elem_info info);
+ virtual bool try_request(Request*);
+ Voice_registers(Voice*);
+ virtual void do_print() const;
+};
+
+
+#endif // VOICEREGS_HH
--- /dev/null
+#ifndef VOICE_HH
+#define VOICE_HH
+
+#include "proto.hh"
+#include "plist.hh"
+#include "moment.hh"
+
+/** class for horizontal stuff.
+
+ Voice is a ordered row of Voice_elements. It is strictly
+ horizontal: you cannot have two rhythmic elements running parallel
+ in a Voice. For proper processing, each Voice should have
+ Group_change_req as a first element.
+
+ */
+
+struct Voice {
+ IPointerList<Voice_element *> elts;
+ Moment start;
+
+ /* *************** */
+ Voice();
+ Voice(Voice const&);
+
+ Moment when(const Voice_element*)const;
+ Moment last() const;
+
+ void add(Voice_element*);
+ bool find_plet_start_bo(char c, Moment& moment_r);
+ void print() const;
+ void set_default_group(String id);
+ void set_plet_backwards(Moment& now_moment_r, Moment until_moment, int num_i, int den_i);
+};
+
+#endif
--- /dev/null
+/*
+ walkregs.hh -- declare Walker_registers
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+
+#ifndef WALKREGS_HH
+#define WALKREGS_HH
+
+
+#include "registergroup.hh"
+
+/**
+ Top level registers: the interface to Complex_walker.
+
+ [sigh. Sometimes I wish C++ could do better late binding.]
+ */
+struct Walker_registers : Register_group_register {
+ Array<Item*> prebreak_item_p_arr_;
+ Array<Item*> nobreak_item_p_arr_;
+ Array<Item*> postbreak_item_p_arr_;
+ Array<Staff_elem_info> announce_info_arr_;
+ Array<Voice_group_registers*> group_l_arr_;
+ Complex_walker * walk_l_;
+
+ /* *************** */
+ void change_group(Group_change_req * greq_l,
+ Voice_registers *voice_regs_l,
+ Voice_group_registers * old_group);
+ Voice_group_registers * get_group(String id);
+ void typeset_musical_item(Staff_elem * elem_p);
+ Walker_registers(Complex_walker*);
+ void do_announces();
+ void terminate_register(Request_register * reg);
+ virtual bool try_request(Request * r);
+ virtual Staff_info get_staff_info();
+
+ virtual void announce_element(Staff_elem_info);
+ virtual void acknowledge_element(Staff_elem_info);
+ virtual void typeset_breakable_item(Item * pre_p , Item * nobreak_p, Item * post_p);
+ virtual void typeset_element(Staff_elem*elem_p);
+ virtual void pre_move_processing();
+ virtual void post_move_processing();
+ virtual Paper_def * paper() const;
+};
+
+#endif // WALKREGS_HH
--- /dev/null
+#include "debug.hh"
+#include "input-music.hh"
+#include "voice.hh"
+#include "musicalrequest.hh"
+#include "voice-element.hh"
+
+void
+Input_music::check_plet(Voice_element* velt_l)
+{
+ for (iter_top(velt_l->reqs,i); i.ok(); i++)
+ if ( i->plet() ) {
+ Moment start_moment = 0;
+ if ( !find_plet_start_bo( i->plet()->type_c_, start_moment ) ) {
+ error( "begin of plet not found", i->defined_ch_c_l_ );
+ break;
+ }
+ Moment moment = 0;
+ set_plet_backwards( moment, start_moment, i->plet()->dur_i_, i->plet()->type_i_ );
+ i.del();
+ break;
+ }
+}
+
+void
+Simple_music::add(Voice_element*v)
+{
+ voice_.add(v);
+}
+
+Moment
+Simple_music::length()const
+{
+ return voice_.last();
+}
+void
+Simple_music::translate_time(Moment t)
+{
+ voice_.start += t;
+}
+
+Voice_list
+Simple_music::convert()const
+{
+ Voice_list l;
+ l.bottom().add(new Voice(voice_));
+ return l;
+}
+
+
+void
+Simple_music::print() const
+{
+ mtor << "Simple_music {";
+ voice_.print();
+ mtor << "}\n";
+}
+bool
+Simple_music::find_plet_start_bo(char c, Moment& moment_r)
+{
+ return voice_.find_plet_start_bo(c, moment_r);
+}
+void
+Simple_music::set_plet_backwards(Moment& now_moment_r, Moment until_moment, int num_i, int den_i)
+{
+ voice_.set_plet_backwards(now_moment_r, until_moment, num_i, den_i);
+}
+
+/* *************** */
+
+void
+Complex_music::add(Input_music*v)
+{
+ elts.bottom().add(v);
+}
+
+void
+Complex_music::print() const
+{
+ for (iter_top(elts,i); i.ok(); i++)
+ i->print();
+}
+
+void
+Complex_music::concatenate(Complex_music*h)
+{
+ for (iter_top(h->elts,i); i.ok(); i++)
+ add(i->clone());
+}
+
+Complex_music::Complex_music()
+{
+}
+
+Complex_music::Complex_music(Complex_music const&s)
+{
+ for (iter_top(s.elts,i); i.ok(); i++)
+ add(i->clone());
+}
+void
+Complex_music::set_default_group(String g)
+{
+ for (iter_top(elts,i); i.ok(); i++)
+ i->set_default_group(g);
+}
+bool
+Complex_music::find_plet_start_bo(char c, Moment& moment_r)
+{
+ for (iter_bot(elts,i); i.ok(); i--) {
+ if ( i->find_plet_start_bo(c, moment_r) )
+ return true;
+ }
+ return false;
+}
+void
+Complex_music::set_plet_backwards(Moment& now_moment_r, Moment until_moment, int num_i, int den_i)
+{
+ for (iter_bot(elts,i); i.ok(); i--) {
+ i->set_plet_backwards(now_moment_r, until_moment, num_i, den_i);
+ }
+}
+/* *************************************************************** */
+
+void
+Music_voice::print() const
+{
+ mtor << "Music_voice {";
+ Complex_music::print();
+ mtor << "}\n";
+}
+
+void
+Music_voice::add_elt(Voice_element*v)
+{
+ PCursor<Input_music*> c(elts.bottom());
+ if (!c.ok() || !c->simple()) {
+ Simple_music*vs = new Simple_music;
+
+ c.add(vs);
+ }
+
+ c = elts.bottom();
+ Simple_music *s = c->simple();
+ s->add(v);
+
+ check_plet(v);
+}
+
+Moment
+Music_voice::length()const
+{
+ Moment l = 0;
+
+ for (iter_top(elts,i); i.ok(); i++)
+ l += i->length();
+ return l;
+}
+
+
+Voice_list
+Music_voice::convert()const
+{
+ Voice_list l;
+ Moment here = 0;
+
+ for (iter_top(elts,i); i.ok(); i++) {
+ Moment len = i->length();
+ Voice_list k(i->convert());
+ k.translate_time(here);
+ l.concatenate(k);
+ here +=len;
+ }
+ return l;
+}
+
+void
+Music_voice::translate_time(Moment t)
+{
+ elts.bottom()->translate_time(t);
+}
+
+
+
+/* *************** */
+
+void
+Music_general_chord::add_elt(Voice_element*v)
+{
+ Simple_music*vs = new Simple_music;
+ vs->add(v);
+ elts.bottom().add(vs);
+
+ check_plet(v);
+}
+
+void
+Music_general_chord::print() const
+{
+ mtor << "Music_general_chord {";
+ Complex_music::print();
+ mtor << "}\n";
+}
+
+void
+Music_general_chord::translate_time(Moment t)
+{
+ for (iter_top(elts,i); i.ok(); i++)
+ i->translate_time(t);
+}
+
+Moment
+Music_general_chord::length()const
+{
+ Moment l =0;
+
+ for (iter_top(elts,i); i.ok(); i++)
+ l = l >? i->length();
+ return l;
+}
+
+Voice_list
+Music_general_chord::convert()const
+{
+ Voice_list l;
+ for (iter_top(elts,i); i.ok(); i++) {
+ Voice_list k(i->convert());
+ l.concatenate(k);
+ }
+ return l;
+}
+
+/* *************** */
+
+void
+Multi_voice_chord::set_default_group(String g)
+{
+ int j=0;
+ for (iter_top(elts, i); i.ok(); i++) {
+ i->set_default_group(g + String(j));
+ j++;
+ }
+}
+
+
+/* *************** */
+
+void
+Voice_list::translate_time(Moment x)
+{
+ for (iter_top(*this,i); i.ok(); i++)
+ i->start += x;
+}
+
--- /dev/null
+/*
+ input-score.cc -- implement Input_score
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include "debug.hh"
+#include "input-score.hh"
+#include "input-staff.hh"
+#include "input-music.hh"
+#include "score.hh"
+#include "paper-def.hh"
+#include "midi-def.hh"
+#include "staff.hh"
+
+
+void
+Input_score::add(Input_staff*s)
+{
+ staffs_.bottom().add(s);
+}
+
+void
+Input_score::set(Paper_def*p)
+{
+ delete paper_p_;
+ paper_p_ = p;
+}
+
+void
+Input_score::set(Midi_def* midi_p)
+{
+ delete midi_p_;
+ midi_p_ = midi_p;
+}
+
+Input_score::Input_score(Input_score const&s)
+{
+ paper_p_ = (s.paper_p_)? new Paper_def(*s.paper_p_) :0;
+ midi_p_ = (s.midi_p_)? new Midi_def(*s.midi_p_) : 0;
+ defined_ch_c_l_ = s.defined_ch_c_l_;
+ errorlevel_i_ = s.errorlevel_i_;
+ score_wide_music_p_ = (s.score_wide_music_p_) ?
+ s.score_wide_music_p_->clone():0;
+}
+
+Score*
+Input_score::parse()
+{
+ Score *s_p = new Score;
+ s_p->defined_ch_c_l_= defined_ch_c_l_;
+ s_p->errorlevel_i_ = errorlevel_i_;
+ if (midi_p_)
+ s_p->set(new Midi_def(*midi_p_));
+ if (paper_p_)
+ s_p->set( new Paper_def(*paper_p_));
+
+ for (iter_top(staffs_,i); i.ok(); i++) {
+ Staff* staf_p=i->parse(s_p, score_wide_music_p_);
+ s_p->add(staf_p);
+ }
+
+ return s_p;
+}
+
+void
+Input_score::set(Input_music *m_p)
+{
+ delete score_wide_music_p_;
+ score_wide_music_p_ =m_p;
+}
+
+
+Input_score::~Input_score()
+{
+ delete paper_p_;
+ delete score_wide_music_p_;
+ delete midi_p_;
+}
+
+Input_score::Input_score()
+{
+ score_wide_music_p_ =0;
+ defined_ch_c_l_=0;
+ paper_p_= 0;
+ midi_p_ = 0;
+ errorlevel_i_ = 0;
+}
+
+void
+Input_score::print()const
+{
+#ifndef NPRINT
+ mtor << "Input_score {\n";
+ for (iter_top(staffs_,i); i.ok(); i++) {
+ i->print();
+ }
+ mtor << "}\n";
+#endif
+}
--- /dev/null
+/*
+ input-staff.cc -- implement Input_staff
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include "debug.hh"
+#include "score.hh"
+#include "input-music.hh"
+#include "input-staff.hh"
+#include "staff.hh"
+#include "complex-staff.hh"
+#include "lyric-staff.hh"
+
+#include "lexer.hh"
+
+
+Input_staff::Input_staff(String s)
+{
+ score_wide_music_p_ =0;
+ type= s;
+ defined_ch_c_l_ = 0;
+}
+
+void
+Input_staff::add(Input_music*m)
+{
+ music_.bottom().add(m);
+}
+
+Staff*
+Input_staff::parse(Score*score_l, Input_music *default_score_wide)
+{
+ Staff *p=0;
+ if (type == "melodic")
+ p = new Complex_staff;
+ else if (type == "lyric")
+ p = new Lyric_staff;
+ else {
+ error( "Unknown staff-type `" + type +"\'", defined_ch_c_l_ );
+ exit( 1 );
+ }
+
+ p->score_l_ = score_l;
+
+ for (iter_top(music_,i); i.ok(); i++) {
+ Voice_list vl = i->convert();
+ p->add(vl);
+ }
+ Voice_list vl = (score_wide_music_p_) ? score_wide_music_p_->convert()
+ : default_score_wide->convert();
+ p->add(vl);
+ return p;
+}
+
+Input_staff::Input_staff(Input_staff const&s)
+{
+ for (iter_top(s.music_,i); i.ok(); i++)
+ add(i->clone());
+ defined_ch_c_l_ = s.defined_ch_c_l_;
+ type = s.type;
+ score_wide_music_p_ = (s.score_wide_music_p_) ?
+ s.score_wide_music_p_->clone() : 0;
+}
+
+void
+Input_staff::print() const
+{
+#ifndef NPRINT
+ mtor << "Input_staff {\n";
+ for (iter_top(music_,i); i.ok(); i++)
+ i->print();
+ mtor << "}\n";
+#endif
+}
+void
+Input_staff::set_score_wide(Input_music *m_p)
+{
+ delete score_wide_music_p_;
+ score_wide_music_p_ = m_p;
+}
+
+Input_staff::~Input_staff()
+{
+ delete score_wide_music_p_;
+}
--- /dev/null
+#include "debug.hh"
+#include "item.hh"
+
+
+
+Item::Item()
+{
+ pcol_l_ = 0;
+}
+
+void
+Item::do_print() const
+{
+#ifndef NPRINT
+ mtor << "(unknown)";
+#endif
+}
+
--- /dev/null
+#include "key-item.hh"
+#include "key.hh"
+#include "debug.hh"
+#include "molecule.hh"
+#include "paper-def.hh"
+#include "lookup.hh"
+//#include "clef-reg.hh"
+#include "key-reg.hh"
+
+const int FLAT_TOP_PITCH=2; /* fes,ges,as and bes typeset in lower octave */
+const int SHARP_TOP_PITCH=4; /* ais and bis typeset in lower octave */
+
+
+
+Key_item::Key_item(int c)
+{
+ set_c_position(c);
+}
+
+void
+Key_item::read(const Key_register& key_reg_r)
+{
+ const Array<int> &idx_arr =key_reg_r.accidental_idx_arr_;
+ for (int i = 0 ; i< idx_arr.size(); i++) {
+ int note = idx_arr[i];
+ int acc = key_reg_r.key_.acc(note);
+
+ add(note, acc);
+ }
+}
+
+void
+Key_item::set_c_position(int c0)
+{
+ int octaves =(abs(c0) / 7) +1 ;
+ c_position=(c0 + 7*octaves)%7;
+}
+
+
+void
+Key_item::add(int p, int a)
+{
+ if ((a<0 && p>FLAT_TOP_PITCH) ||
+ (a>0 && p>SHARP_TOP_PITCH)) {
+ p -= 7; /* Typeset below c_position */
+ }
+ pitch.push(p);
+ acc.push(a);
+}
+
+
+Molecule*
+Key_item::brew_molecule_p()const
+{
+ Molecule*output = new Molecule;
+ Real inter = paper()->internote();
+
+ for (int i =0; i < pitch.size(); i++) {
+ Symbol s= paper()->lookup_p_->accidental(acc[i]);
+ Atom a(s);
+ a.translate(Offset(0,(c_position + pitch[i]) * inter));
+ Molecule m(a);
+ output->add_right(m);
+ }
+ Molecule m(paper()->lookup_p_->fill(Box(
+ Interval(0, paper()->note_width()),
+ Interval(0,0))));
+ output->add_right(m);
+ return output;
+}
--- /dev/null
+/*
+ key-reg.cc -- implement Key_register
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+
+ todo: key undo
+
+ */
+#include "time-description.hh"
+#include "key-reg.hh"
+#include "key-item.hh"
+#include "commandrequest.hh"
+#include "staff-column.hh"
+#include "local-key-reg.hh"
+#include "musicalrequest.hh"
+
+Key_register::Key_register()
+{
+ post_move_processing();
+}
+
+bool
+Key_register::try_request(Request * req_l)
+{
+ Command_req* creq_l= req_l->command();
+ if (!creq_l|| !creq_l->keychange())
+ return false;
+
+ assert(!keyreq_l_); // todo
+ keyreq_l_ = creq_l->keychange();
+ read_req(keyreq_l_);
+ return true;
+}
+
+void
+Key_register::acknowledge_element(Staff_elem_info info)
+{
+ Command_req * r_l = info.req_l_->command() ;
+ if (r_l && r_l->clefchange() && !kit_p_) {
+ int c0_i= *get_staff_info().c0_position_i_;
+ kit_p_ = new Key_item(c0_i);
+ kit_p_->read(*this);
+ announce_element(Staff_elem_info(kit_p_, keyreq_l_));
+ }
+}
+
+void
+Key_register::process_requests()
+{
+ const Time_description *time_l = get_staff_info().time_c_l_;
+
+ if (!keyreq_l_ &&
+ (!time_l->whole_in_measure_|| !time_l->when_)) {
+ default_key_b_ = true;
+ }
+
+ if ( default_key_b_ || keyreq_l_) {
+ int c0_i= *get_staff_info().c0_position_i_;
+ kit_p_ = new Key_item(c0_i);
+ kit_p_->read(*this);
+ announce_element(Staff_elem_info(kit_p_, keyreq_l_));
+ }
+}
+
+void
+Key_register::pre_move_processing()
+{
+ if (kit_p_) {
+ if (default_key_b_)
+ typeset_breakable_item(0,0,kit_p_);
+ else
+ typeset_breakable_item(
+ new Key_item(*kit_p_), kit_p_, new Key_item(*kit_p_));
+ kit_p_ = 0;
+ }
+}
+
+
+
+void
+Key_register::read_req(Key_change_req * r)
+{
+ accidental_idx_arr_.set_size(0);
+ for (int i = 0; i < r->melodic_p_arr_.size(); i ++) {
+ int n_i=r->melodic_p_arr_[i]->notename_i_;
+ key_.set(n_i, r->melodic_p_arr_[i]->accidental_i_);
+ accidental_idx_arr_.push(n_i);
+ }
+}
+
+void
+Key_register::post_move_processing()
+{
+ keyreq_l_ = 0;
+ default_key_b_ = false;
+ kit_p_ = 0;
+}
--- /dev/null
+#include "key.hh"
+
+const int OCTAVES=14; // ugh..
+const int ZEROOCTAVE=7;
+
+Key::Key()
+{
+ accidental_i_arr_.set_size(7);
+ for (int i= 0; i < 7 ; i++)
+ accidental_i_arr_[i] = 0;
+}
+
+Local_key::Local_key()
+{
+ octaves.set_size(OCTAVES);
+}
+
+Key&
+Local_key::oct(int i)
+{
+ return octaves[i+ZEROOCTAVE];
+}
+
+void
+Key::set(int i, int a)
+{
+ assert(a > -3 && a < 3);
+ accidental_i_arr_[i]=a;
+}
+
+
+void
+Local_key::reset(Key k)
+{
+ for (int i= 0; i < OCTAVES ; i++)
+ octaves[i] = k;
+}
+
--- /dev/null
+/*
+ keyword.cc -- keywords and identifiers
+ */
+
+#include <stdlib.h>
+
+#include "glob.hh"
+#include "lexer.hh"
+//#include "mudobs.hh"
+//#include "gram.hh"
+
+/* for the keyword table */
+struct Keyword_ent
+{
+ const char *name;
+ int tokcode;
+};
+
+struct Keyword_table
+{
+ Keyword_ent *table;
+ int maxkey;
+ Keyword_table(Keyword_ent *);
+ int lookup(const char *s) const;
+};
+
+
+/* for qsort */
+int
+ tabcmp(const void * p1, const void * p2)
+{
+ return strcmp(((const Keyword_ent *) p1)->name,
+ ((const Keyword_ent *) p2)->name);
+}
+
+Keyword_table::Keyword_table(Keyword_ent *tab)
+{
+ table = tab;
+
+ /* count keywords */
+ for (maxkey = 0; table[maxkey].name; maxkey++);
+
+ /* sort them */
+ qsort(table, maxkey, sizeof(Keyword_ent), tabcmp);
+}
+
+/*
+ lookup with binsearch, return tokencode.
+*/
+int
+Keyword_table::lookup(const char *s)const
+{
+ int lo,
+ hi,
+ cmp,
+ result;
+ lo = 0;
+ hi = maxkey;
+
+ /* binary search */
+ do
+ {
+ cmp = (lo + hi) / 2;
+
+ result = strcmp(s, table[cmp].name);
+
+ if (result < 0)
+ hi = cmp;
+ else
+ lo = cmp;
+ }
+ while (hi - lo > 1);
+ if (!strcmp(s, table[lo].name))
+ {
+ return table[lo].tokcode;
+ } else
+ return -1; /* not found */
+}
+
--- /dev/null
+#include "leastsquares.hh"
+void
+Least_squares::OK() const
+{
+ assert( input.size() > 1 );
+ Real dx = 0.0;
+ for (int i=1; i < input.size(); i++)
+ dx += abs (input[i-1].x - input[i].x);
+
+ assert(dx);
+}
+void
+Least_squares::minimise(Real &coef, Real &offset)
+{
+ OK();
+ Real sx = 0.0;
+ Real sy = 0.0;
+ Real sqx =0.0;
+ Real sxy = 0.0;
+
+ for (int i=0; i < input.size();i++) {
+ Real x=input[i].x;
+ Real y = input[i].y;
+ sx += x;
+ sy += y;
+ sqx += sqr(x);
+ sxy += x*y;
+ }
+ int N = input.size();
+
+
+ coef = (N * sxy - sx*sy )/(N*sqx - sqr(sx));
+ offset = (sy - coef * sx)/N;
+
+}
--- /dev/null
+%{ // -*-Fundamental-*-
+
+#include <stdio.h>
+
+#include "string.hh"
+#include "string-convert.hh"
+#include "notename.hh"
+#include "lexer.hh"
+#include "varray.hh"
+#include "parser.hh"
+#include "debug.hh"
+#include "input-score.hh"
+#include "parseconstruct.hh"
+#include "main.hh"
+
+%}
+
+%option c++
+%option noyywrap
+%option nodefault
+%option yylineno
+%option debug
+%option yyclass="My_flex_lexer"
+%option stack
+
+%x notes
+%x incl
+%x quote
+%x lyrics
+
+
+
+A [a-zA-Z]
+AA {A}|_
+N [0-9]
+AN {AA}|{N}
+PUNCT [?!,.:;]
+ACCENT [\\'"^]
+NATIONAL [\241-\377]
+TEX {AA}|-|{PUNCT}|{ACCENT}|{NATIONAL}
+
+WORD {A}{AN}*
+ALPHAWORD {A}+
+INT -?{N}+
+REAL {INT}?(\.{N}*)?
+
+OPTSIGN !?
+PITCHMOD ['`]*{OPTSIGN}
+RESTNAME r|s|p
+NOTECOMMAND \\{WORD}
+NOTENAME [a-z]+
+UNOTENAME [A-Z][a-z]*
+DOTS \.+
+LYRICS {TEX}+
+COMMENT [%#].*\n
+
+%%
+
+\$ {
+ yy_push_state(notes);
+}
+
+\@ {
+ yy_push_state(lyrics);
+}
+
+<notes>{RESTNAME} {
+ const char *s = YYText();
+ yylval.string = new String (s);
+ mtor << "rest:"<< yylval.string;
+ return RESTNAME;
+}
+<notes>{UNOTENAME} {
+ int *p=yylval.ii;
+ return ret_notename(p, YYText(), -1);
+}
+
+<notes>{NOTENAME} {
+ int *p=yylval.ii;
+ return ret_notename(p, YYText(), 0);
+}
+
+<notes>{NOTECOMMAND} {
+ String c = YYText() +1;
+ mtor << "\\word: " << YYText()+1<<eol;
+ int l = lookup_keyword(c);
+ if (l != -1)
+ return l;
+ Identifier * id = lookup_identifier(c);
+ if (id) {
+ yylval.id = id;
+ return IDENTIFIER;
+ }
+ String *sp = new String( c);
+ yylval.string=sp;
+ return STRING;
+}
+
+<notes>{PITCHMOD} {
+ const char *s = YYText();
+ mtor << "pitchmod:"<< YYText()<<eol;
+ yylval.string = new String (s);
+ return PITCHMOD;
+}
+<notes>{DOTS} {
+ yylval.i = strlen(YYText());
+ return DOTS;
+}
+<notes>{INT} {
+ yylval.i = String_convert::dec2_i( String( YYText() ) );
+ return INT;
+}
+<notes>{COMMENT} {
+}
+<notes>[ \t\n]+ {
+
+}
+<notes>\$ {
+ yy_pop_state();
+}
+<notes>\"[^"]*\" {
+ String s (YYText()+1);
+ s = s.left_str(s.length_i()-1);
+ yylval.string = new String(s);
+ return STRING;
+}
+<notes>. {
+ return yylval.c = YYText()[0];
+}
+
+\" {
+ yy_push_state(quote);
+}
+<quote>[^"]* {
+ yylval.string = new String (YYText());
+}
+<quote>\" {
+ mtor << "quoted string\n";
+ yy_pop_state();
+ return STRING;
+}
+
+<lyrics>{DOTS} {
+ yylval.i = strlen(YYText());
+ return DOTS;
+}
+<lyrics>{INT} {
+ yylval.i = String_convert::dec2_i( String( YYText() ) );
+ return INT;
+}
+<lyrics>{NOTECOMMAND} {
+ String c = YYText() +1;
+ mtor << "\\word: " << YYText()+1<<eol;
+ int l = lookup_keyword(c);
+ if (l != -1)
+ return l;
+
+/* let's try passing tex's typesetting macros like \ss \alpha \c */
+ String* str_p = new String(YYText());//huh?
+ return STRING;
+
+/* and skip identifiers...
+ Identifier * id = lookup_identifier(c);
+ if (id) {
+ yylval.id = id;
+ return IDENTIFIER;
+ }
+ String *sp = new String( c);
+
+ yylval.string=sp;
+ return STRING;
+*/
+}
+<lyrics>\"[^"]*\" {
+ String s (YYText()+1);
+ s = s.left_str(s.length_i()-1);
+ yylval.string = new String(s);
+ return STRING;
+}
+<lyrics>{LYRICS} {
+ String s (YYText());
+ int i = 0;
+ 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 + 1) = 'c';
+ s = s.left_str(i+2) + " " + s.right_str(s.length_i()-i-2);
+ }
+ yylval.string = new String(s);
+ return STRING;
+}
+<lyrics>\| {
+ return YYText()[0];
+}
+<lyrics>{COMMENT} {
+
+}
+<lyrics>[{}] {
+ return YYText()[0];
+}
+<lyrics>[()\[\]|/.^>_-] {
+ return yylval.c = YYText()[0];
+}
+<lyrics>[ \t\n]+ {
+}
+<lyrics>@ {
+ yy_pop_state();
+}
+
+<<EOF>> {
+ mtor << "<<EOF>>";
+
+ if (! close_input())
+ yyterminate(); // can't move this, since it actually rets a YY_NULL
+}
+
+
+include {
+ yy_push_state(incl);
+}
+<incl>[ \t]* { /* eat the whitespace */ }
+<incl>\"[^"]*\"+ { /* got the include file name */
+ String s (YYText()+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();
+}
+
+
+{WORD} {
+ mtor << "word: " << YYText()<<eol;
+ String c = YYText();
+ int l = lookup_keyword(c);
+ if (l != -1)
+ return l;
+ Identifier * id = lookup_identifier(c);
+ if (id) {
+ yylval.id = id;
+ return IDENTIFIER;
+ }
+ String *sp = new String( c);
+ mtor << "new id: " << *sp << eol;
+ yylval.string=sp;
+ return STRING;
+}
+
+{REAL} {
+ Real r;
+ int cnv=sscanf (YYText(), "%lf", &r);
+ assert(cnv == 1);
+ mtor << "REAL" << r<<'\n';
+ yylval.real = r;
+ return REAL;
+}
+
+[{}] {
+
+ mtor << "parens\n";
+ return YYText()[0];
+}
+[*:=] {
+ char c = YYText()[0];
+ mtor << "misc char" <<c<<"\n";
+ return c;
+}
+[ \t\n]+ {
+
+}
+
+{COMMENT} {
+ //ignore
+}
+. {
+ error( String( "illegal character: " ) + String( YYText()[0] ), here_ch_c_l() );
+ return YYText()[0];
+}
+
+%%
+
--- /dev/null
+/*
+ lexerinit.cc -- implement some stuff
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include <iostream.h>
+#include <strstream.h>
+#include "proto.hh"
+#include "plist.hh"
+#include "lexer.hh"
+#include "debug.hh"
+#include "main.hh"
+#include "source-file.hh"
+#include "source.hh"
+
+My_flex_lexer *lexer=0;
+
+int
+yylex() {
+ return lexer->yylex();
+}
+
+bool
+busy_parsing()
+{
+ return lexer;
+}
--- /dev/null
+#include <math.h>
+#include "linespace.hh"
+#include "pcol.hh"
+#include "debug.hh"
+#include "qlp.hh"
+#include "unionfind.hh"
+#include "idealspacing.hh"
+
+const Real COLFUDGE=1e-3;
+
+
+bool
+Spacing_problem::contains(const PCol *w)
+{
+ for (int i=0; i< cols.size(); i++)
+ if (cols[i].pcol_ == w)
+ return true;
+ return false;
+}
+
+int
+Spacing_problem::col_id(const PCol *w)const
+{
+ for (int i=0; i< cols.size(); i++)
+ if (cols[i].pcol_ == w)
+ return i;
+ assert(false);
+ return -1;
+}
+
+void
+Spacing_problem::OK() const
+{
+#ifndef NDEBUG
+ Union_find connected(cols.size());
+ Array<int> fixed;
+ for (int i=0; i < ideals.size(); i++) {
+ assert(ideals[i]->hooke > 0);
+ int l = col_id(ideals[i]->left);
+ int r = col_id(ideals[i]->right);
+ connected.connect(l,r);
+ }
+ for (int i = 0; i < cols.size(); i++)
+ if (cols[i].fixed())
+ fixed.push(i);
+ for (int i = 0; i < cols.size(); i++) {
+ bool c=false;
+ for (int j =0; j<fixed.size(); j++)
+ c |= connected.equiv(fixed[j],i);
+ if (!c)
+ WARN << "You have unconnected columns. \n"
+ "Check if bars and music fit each other\n"
+ "(crashing :-)\n";
+ assert(c);
+ }
+#endif
+}
+
+bool
+Spacing_problem::check_constraints(Vector v) const
+{
+ int dim=v.dim();
+ for (int i=0; i < dim; i++) {
+
+ if (cols[i].fixed()&&
+ abs(cols[i].fixed_position() - v(i)) > COLFUDGE)
+ return false;
+
+ if (!i)
+ continue;
+
+ Real mindist=cols[i-1].minright()
+ +cols[i].minleft();
+
+ // ugh... compares
+ Real dif =v(i) - v(i-1)- mindist;
+ bool b = (dif > - COLFUDGE);
+
+
+ if (!b)
+ return false;
+
+ }
+ return true;
+}
+
+bool
+Spacing_problem::check_feasible() const
+{
+ Vector sol(try_initial_solution());
+ return check_constraints(sol);
+}
+
+// generate a solution which obeys the min distances and fixed positions
+Vector
+Spacing_problem::try_initial_solution() const
+{
+ int dim=cols.size();
+ Vector initsol(dim);
+ for (int i=0; i < dim; i++) {
+ if (cols[i].fixed()) {
+ initsol(i)=cols[i].fixed_position();
+ } else {
+ Real mindist=cols[i-1].minright()
+ +cols[i].minleft();
+ assert(mindist >= 0.0);
+ initsol(i)=initsol(i-1)+mindist;
+
+ //nog niet
+ //if (i>0)
+ // assert(initsol(i) > initsol(i-1));
+ }
+ }
+
+ return initsol;
+}
+Vector
+Spacing_problem::find_initial_solution() const
+{
+ Vector v(try_initial_solution());
+ assert(check_constraints(v));
+ return v;
+}
+
+// generate the matrices
+void
+Spacing_problem::make_matrices(Matrix &quad, Vector &lin, Real &c) const
+{
+ quad.fill(0);
+ lin.fill(0);
+ c = 0;
+ for (int j=0; j < ideals.size(); j++){
+ Idealspacing const*i=ideals[j];
+ int l = col_id(i->left);
+ int r = col_id(i->right);
+
+ quad(r,r) += i->hooke;
+ quad(r,l) -= i->hooke;
+ quad(l,r) -= i->hooke;
+ quad(l,l) += i->hooke;
+
+ lin(r) -= i->space*i->hooke;
+ lin(l) += i->space*i->hooke;
+
+ c += sqr(i->space);
+ }
+}
+
+// put the constraints into the LP problem
+void
+Spacing_problem::make_constraints(Mixed_qp& lp) const
+{
+ int dim=cols.size();
+ for (int j=0; j < dim; j++) {
+ Colinfo *c=&(cols[j]);
+ if (c->fixed()) {
+ lp.add_fixed_var(j,c->fixed_position());
+ }
+ if (j > 0){
+ Vector c1(dim);
+
+ c1(j)=1.0 ;
+ c1(j-1)=-1.0 ;
+ lp.add_inequality_cons(c1, cols[j-1].minright() +
+ cols[j].minleft());
+ }
+ }
+}
+
+Array<Real>
+Spacing_problem::solve() const
+{
+ print();
+ OK();
+ assert(check_feasible());
+
+ /* optimalisatiefunctie */
+ Mixed_qp lp(cols.size());
+ make_matrices(lp.quad,lp.lin, lp.const_term);
+ make_constraints(lp);
+ Vector start=find_initial_solution();
+ Vector sol(lp.solve(start));
+ if (!check_constraints(sol)) {
+ WARN << "solution doesn't satisfy constraints.\n" ;
+ }
+
+
+ Array<Real> posns(sol);
+ posns.push(lp.eval(sol));
+ return posns;
+}
+
+/*
+ add one column to the problem.
+*/
+void
+Spacing_problem::add_column(const PCol *col, bool fixed, Real fixpos)
+{
+ Colinfo c(col,(fixed)? &fixpos : 0);
+ cols.push(c);
+}
+
+void
+Spacing_problem::add_ideal(const Idealspacing *i)
+{
+ const PCol *l =i->left;
+ const PCol *r= i->right;
+
+ if (!contains(l) || !contains(r)) {
+ return;
+ }
+ ideals.push(i);
+}
+
+void
+Spacing_problem::print_ideal(const Idealspacing*id)const
+{
+#ifndef NPRINT
+ int l = col_id(id->left);
+ int r = col_id(id->right);
+
+ mtor << "between " << l <<","<<r<<":" ;
+ id->print();
+#endif
+}
+
+void
+Spacing_problem::print() const
+{
+#ifndef NPRINT
+ for (int i=0; i < cols.size(); i++) {
+ mtor << "col " << i<<' ';
+ cols[i].print();
+ }
+ for (int i=0; i < ideals.size(); i++) {
+ print_ideal(ideals[i]);
+ }
+#endif
+
+}
+
+/* **************** */
+
+void
+Colinfo::print() const
+{
+#ifndef NPRINT
+ mtor << "column { ";
+ if (fixed())
+ mtor << "fixed at " << fixed_position()<<", ";
+ assert(pcol_);
+ mtor << "[" << minleft() << ", " << minright() << "]";
+ mtor <<"}\n";
+#endif
+}
+
+Colinfo::Colinfo(Colinfo const&c)
+{
+ fixpos = (c.fixpos)?new Real(*c.fixpos):0;
+ pcol_ = c.pcol_;
+ width = c.width;
+}
+
+Colinfo::Colinfo(const PCol*col_p, const Real*fixed_r_p )
+{
+ fixpos = (fixed_r_p)? new Real(*fixed_r_p) : 0;
+ pcol_ = col_p;
+ width = pcol_->width();
+}
+
+Colinfo::~Colinfo()
+{
+ delete fixpos;
+}
+
+Colinfo::Colinfo()
+{
+ pcol_=0;
+ fixpos = 0;
+}
+void
+Colinfo::operator=(Colinfo const&c )
+{
+ delete fixpos;
+ fixpos = (c.fixpos)?new Real(*c.fixpos):0;
+ pcol_ = c.pcol_;
+ width = c.width;
+}
--- /dev/null
+#include "local-key-item.hh"
+#include "molecule.hh"
+#include "scalar.hh"
+#include "lookup.hh"
+#include "paper-def.hh"
+#include "musicalrequest.hh"
+#include "notehead.hh"
+#include "misc.hh"
+
+
+
+Local_key_item::Local_key_item(int i)
+{
+ c0_position = i;
+}
+
+void
+Local_key_item::add(Item*head_l)
+{
+ support_items_.push(head_l);
+ add_dependency(head_l);
+}
+
+void
+Local_key_item::add(Melodic_req*m_l)
+{
+ add(m_l->octave_i_, m_l->notename_i_, m_l->accidental_i_);
+}
+void
+Local_key_item::add (int o, int p , int a)
+{
+ Local_acc l;
+ l.octave = o;
+ l.name = p;
+ l.acc = a;
+ accs.push(l);
+}
+
+void
+Local_key_item::do_pre_processing()
+{
+ accs.sort(Local_acc::compare);
+}
+
+Molecule*
+Local_key_item::brew_molecule_p()const
+{
+ Molecule* output = new Molecule;
+ Molecule*octmol = 0;
+ int lastoct = -100;
+ for (int i = 0; i < accs.size(); i++) {
+ // do one octave
+ if (accs[i].octave != lastoct) {
+ if (octmol){
+ Real dy =lastoct*7*paper()->internote();
+ octmol->translate(Offset(0, dy));
+ output->add(*octmol);
+ delete octmol;
+ }
+ octmol= new Molecule;
+ }
+ lastoct = accs[i].octave;
+ Symbol s =paper()->lookup_p_->accidental(accs[i].acc);
+ Atom a(s);
+ Real dy = (accs[i].name + c0_position) * paper()->internote();
+ a.translate(Offset(0,dy));
+
+ octmol->add_right(a);
+ }
+
+ if (octmol){
+ Real dy =lastoct*7*paper()->internote();
+ octmol->translate(Offset(0, dy));
+ output->add(*octmol);
+ delete octmol;
+ }
+
+ Interval head_width=itemlist_width(support_items_);
+ output->translate(Offset(-output->extent().x.right + head_width.left ,0));
+
+ return output;
+}
+
+int
+Local_acc::compare(Local_acc&a, Local_acc&b)
+{
+ if (a.octave - b.octave)
+ return a.octave - b.octave;
+ if (a.name - b.name)
+ return a.name - b.name;
+
+ assert(false);
+};
--- /dev/null
+/*
+ local-key-reg.cc -- implement Local_key_register
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include "musicalrequest.hh"
+#include "commandrequest.hh"
+#include "local-key-reg.hh"
+#include "local-key-item.hh"
+#include "complex-walker.hh"
+#include "key-reg.hh"
+#include "debug.hh"
+#include "key-item.hh"
+
+Local_key_register::Local_key_register()
+{
+ key_item_p_ = 0;
+ key_c_l_ = 0;
+}
+
+void
+Local_key_register::pre_move_processing()
+{
+ if (key_item_p_) {
+ typeset_element(key_item_p_);
+ key_item_p_ = 0;
+ }
+}
+void
+Local_key_register::acknowledge_element(Staff_elem_info info)
+{
+ if (info.req_l_->melodic()) {
+ Melodic_req * melodic_l_ = info.req_l_->melodic();
+
+ if( melodic_l_->forceacc_b_ ||
+ local_key_.oct(melodic_l_->octave_i_).acc(melodic_l_->notename_i_)
+ != melodic_l_->accidental_i_) {
+ Item * support_l_ = info.elem_p_->item();
+
+
+ if (!key_item_p_) {
+ key_item_p_ = new Local_key_item(*get_staff_info().c0_position_i_);
+ }
+
+ key_item_p_->add(melodic_l_);
+ key_item_p_->add(support_l_);
+ local_key_.oct(melodic_l_->octave_i_)
+ .set(melodic_l_->notename_i_, melodic_l_->accidental_i_);
+ }
+ } else if (info.elem_p_->name()==Key_item::static_name()) {
+ Key_register * key_reg_l =
+ (Key_register*)info.origin_reg_l_arr_[0];
+ key_c_l_ = &key_reg_l->key_;
+ local_key_.reset(*key_c_l_);
+ }
+}
+
+void
+Local_key_register::process_requests()
+{
+ const Time_description * time_c_l_ = get_staff_info().time_c_l_;
+ if (! time_c_l_->whole_in_measure_){
+ if (key_c_l_)
+ local_key_.reset(*key_c_l_);
+ else if( time_c_l_->when_ >Moment(0))
+ warning ("Help me! can't figure current key", 0);
+ }
+}
--- /dev/null
+/*
+ lookup.cc -- implement simple Lookup methods.
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include "lookup.hh"
+#include "debug.hh"
+#include "symtable.hh"
+#include "dimen.hh"
+#include "tex.hh"
+#include "scalar.hh"
+
+Lookup::Lookup()
+{
+ texsetting = "\\unknowntexsetting";
+ symtables_ = new Symtables;
+}
+
+Lookup::Lookup(Lookup const &s)
+{
+ texsetting = s.texsetting;
+ symtables_ = new Symtables(*s.symtables_);
+}
+Lookup::~Lookup()
+{
+ delete symtables_;
+}
+
+void
+Lookup::add(String s, Symtable*p)
+{
+ symtables_->add(s, p);
+}
+
+void
+Lookup::print()const
+{
+ mtor << "Lookup: " << texsetting << " {\n";
+ symtables_->print();
+ mtor << "}\n";
+}
+
+Symbol
+Lookup::text(String style, String text, int dir)
+{
+ Array<String> a;
+
+ a.push(text);
+ Symbol tsym = (*symtables_)("style")->lookup(style);
+ a[0] = substitute_args(tsym.tex,a);
+
+ Symbol s = (*symtables_)("align")->lookup(dir);
+ s.tex = substitute_args(s.tex,a);
+ s.dim.y = tsym.dim.y;
+ return s;
+}
+
+
+Real
+Lookup::internote()
+{
+ return ball(4).dim.y.length()/2;
+}
+
+Symbol
+Lookup::ball(int j)
+{
+ if (j > 4)
+ j = 4;
+
+ Symtable * st = (*symtables_)("balls");
+ return st->lookup(String(j));
+}
+
+Symbol
+Lookup::rest(int j)
+{
+ return (*symtables_)("rests")->lookup(String(j));
+}
+
+Symbol
+Lookup::fill(Box b)
+{
+ Symbol s( (*symtables_)("param")->lookup("fill"));
+ s.dim = b;
+ return s;
+}
+
+Symbol
+Lookup::accidental(int j)
+{
+ return (*symtables_)("accidentals")->lookup(String(j));
+}
+
+
+Symbol
+Lookup::bar(String s)
+{
+ return (*symtables_)("bars")->lookup(s);
+}
+
+Symbol
+Lookup::script(String s)
+{
+ return (*symtables_)("scripts")->lookup(s);
+}
+
+Symbol
+Lookup::clef(String s)
+{
+ return (*symtables_)("clefs")->lookup(s);
+}
+
+Symbol
+Lookup::dots(int j)
+{
+ if (j>3)
+ error("max 3 dots"); // todo
+ return (*symtables_)("dots")->lookup(j);
+}
+
+Symbol
+Lookup::flag(int j)
+{
+ return (*symtables_)("flags")->lookup(j);
+}
+
+Symbol
+Lookup::streepjes(int i)
+{
+ assert(i);
+
+ int arg;
+ String idx;
+
+ if (i < 0) {
+ idx = "botlines";
+ arg = -i;
+ } else {
+ arg = i;
+ idx = "toplines";
+ }
+ Symbol ret = (*symtables_)("streepjes")->lookup(idx);
+
+ Array<String> a;
+ a.push(arg);
+ ret.tex = substitute_args(ret.tex, a);
+
+ return ret;
+}
+
+Symbol
+Lookup::hairpin(Real &wid, bool decresc)
+{
+ int idx = int(rint(wid / 6 PT));
+ if(!idx) idx ++;
+ wid = idx*6 PT;
+ String idxstr = (decresc)? "decrescendosym" : "crescendosym";
+ Symbol ret=(*symtables_)("param")->lookup(idxstr);
+
+ Array<String> a;
+ a.push(idx);
+ ret.tex = substitute_args(ret.tex, a);
+ ret.dim.x = Interval(0,wid);
+ return ret;
+}
+
+Symbol
+Lookup::linestaff(int lines, Real wid)
+{
+ Symbol s;
+ s.dim.x = Interval(0,wid);
+ Real dy = (lines >0) ? (lines-1)*internote()*2 : 0;
+ s.dim.y = Interval(0,dy);
+
+ Array<String> a;
+ a.push(lines);
+ a.push(print_dimen(wid));
+
+ s.tex = (*symtables_)("param")->lookup("linestaf").tex;
+ s.tex = substitute_args(s.tex, a);
+
+ return s;
+}
+
+
+Symbol
+Lookup::meter(Array<Scalar> a)
+{
+ Symbol s;
+ s.dim.x = Interval( 0 PT, 10 PT);
+ s.dim.y = Interval(0, 20 PT); // todo
+ String src = (*symtables_)("param")->lookup("meter").tex;
+ s.tex = substitute_args(src,a);
+ return s;
+}
+
+
+Symbol
+Lookup::stem(Real y1,Real y2)
+{
+ if (y1 > y2) {
+ Real t = y1;
+ y1 = y2;
+ y2 = t;
+ }
+ Symbol s;
+
+ s.dim.x = Interval(0,0);
+ s.dim.y = Interval(y1,y2);
+
+ Array<String> a;
+ a.push(print_dimen(y1));
+ a.push(print_dimen(y2));
+
+ String src = (*symtables_)("param")->lookup("stem").tex;
+ s.tex = substitute_args(src,a);
+ return s;
+}
--- /dev/null
+#include "musicalrequest.hh"
+#include "paper-def.hh"
+#include "lyric-item.hh"
+#include "stem.hh"
+#include "molecule.hh"
+#include "lookup.hh"
+#include "text-def.hh"
+#include "source-file.hh"
+#include "source.hh"
+#include "debug.hh"
+#include "main.hh"
+
+Lyric_item::Lyric_item(Lyric_req* lreq_l, int voice_count_i)
+ : Text_item(lreq_l,0)
+{
+ pos_i_ = -voice_count_i * 4 ; // 4 fontsize dependant. TODO
+ dir_i_ = -1;
+}
+
+void
+Lyric_item::do_pre_processing()
+{
+
+ // test context-error
+ if ( tdef_l_->text_str_.index_i( "Gates" ) >=0)// :-)
+ warning( "foul word", tdef_l_->defined_ch_c_l_ );
+}
--- /dev/null
+#include "musicalrequest.hh"
+#include "voice.hh"
+#include "staff-walker.hh"
+#include "debug.hh"
+#include "staff.hh"
+#include "lyric-staff.hh"
+#include "lyric-walker.hh"
+#include "pscore.hh"
+
+void
+Lyric_staff::set_output(PScore*pscore_l)
+{
+ pstaff_l_ = new PStaff(pscore_l);
+ pscore_l_ = pscore_l;
+ pscore_l_->add(pstaff_l_);
+}
+
+Staff_walker*
+Lyric_staff::get_walker_p()
+{
+ return new Lyric_walker(this);
+}
--- /dev/null
+#include <iostream.h>
+#include <assert.h>
+#include "proto.hh"
+#include "plist.hh"
+#include "lgetopt.hh"
+#include "misc.hh"
+#include "string.hh"
+#include "main.hh"
+#include "path.hh"
+#include "config.hh"
+#include "source-file.hh"
+#include "source.hh"
+
+Source source;
+Source* source_l_g = &source;
+String infile_str_g;
+bool only_midi = false;
+extern void parse_file(String,String);
+
+
+void
+destill_inname( String &name_str_r);
+Long_option_init theopts[] = {
+ 1, "output", 'o',
+ 0, "warranty", 'w',
+ 0, "help", 'h',
+ 0, "debug", 'd',
+ 1, "init", 'i',
+ 1, "include", 'I',
+ 0, "midi", 'M',
+ 0,0,0
+};
+
+void
+help()
+{
+ cout <<
+ "--help, -h This help\n"
+ "--warranty, -w show warranty & copyright\n"
+ "--output, -o set default output\n"
+ "--debug, -d enable debug output\n"
+ "--init, -i set init file\n"
+ "--include, -I add to file search path.\n"
+ "--midi, -M midi output only\n"
+ ;
+
+}
+
+void
+notice()
+{
+ cout <<
+ "\n"
+ "LilyPond, a music typesetter.\n"
+ "Copyright (C) 1996,97 by\n"
+ " Han-Wen Nienhuys <hanwen@stack.nl>\n"
+ "Contributors\n"
+ " Jan Nieuwenhuizen <jan@digicash.com>\n"
+ " Mats Bengtsson <matsb@s3.kth.se>\n"
+ "\n"
+ " This program is free software; you can redistribute it and/or\n"
+ "modify it under the terms of the GNU General Public License version 2\n"
+ "as published by the Free Software Foundation.\n"
+ "\n"
+ " This program is distributed in the hope that it will be useful,\n"
+ "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
+ "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
+ "General Public License for more details.\n"
+ "\n"
+ " You should have received a copy (refer to the file COPYING) of the\n"
+ "GNU General Public License along with this program; if not, write to\n"
+ "the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,\n"
+ "USA.\n";
+}
+
+static File_path * path =0;
+struct Main_init {
+ Main_init() {
+ path = new File_path(LIBDIR);
+ path->push(String(LIBDIR)+"init/");
+ debug_init();
+ }
+ ~Main_init() {
+ delete path;
+ }
+} main_init;
+
+int
+main (int argc, char **argv)
+{
+ Getopt_long oparser(argc, argv,theopts);
+ cout << get_version();
+ String init_str("symbol.ini");
+
+ while (Long_option_init * opt = oparser()) {
+ switch ( opt->shortname){
+ case 'o':
+ set_default_output(oparser.optarg);
+ break;
+ case 'w':
+ notice();
+ exit(0);
+ break;
+ case 'I':
+ path->push(oparser.optarg);
+ break;
+ case 'i':
+ init_str = oparser.optarg;
+ break;
+ case 'h':
+ help();
+ exit(0);
+ break;
+ case 'd':
+ set_debug(true);
+ break;
+ case 'M':
+ only_midi = true;
+ break;
+ default:
+ assert(false);
+ break;
+ }
+ }
+
+ int p=0;
+ char *arg ;
+ while ( (arg= oparser.get_next_arg()) ) {
+ String f(arg);
+ destill_inname(f);
+ infile_str_g = f;
+ parse_file(init_str,f);
+ do_scores();
+ p++;
+ }
+ if (!p) {
+ parse_file(init_str, "");
+ do_scores();
+ }
+
+ return 0;
+}
+
+String
+find_file(String f)
+{
+ return path->find(f);
+}
+
+/// make input file name: add default extension. "" is stdin.
+void
+destill_inname( String &name_str_r)
+{
+ if ( name_str_r.length_i() )
+ {
+ if( name_str_r[ 0 ] != '-' )
+ {
+ String a,b,c,d;
+ split_path(name_str_r,a,b,c,d);
+
+ // add extension if not present.
+ if (d == "")
+ d = ".ly";
+ name_str_r = a+b+c+d;
+ }
+ } else name_str_r = "";
+}
+
--- /dev/null
+/*
+ meter-reg.cc -- implement Meter_register
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include "meter-reg.hh"
+#include "meter.hh"
+#include "commandrequest.hh"
+
+Meter_register::Meter_register()
+
+{
+ post_move_processing();
+}
+
+bool
+Meter_register::try_request(Request*r_l)
+{
+ Command_req* creq_l= r_l->command();
+ if (!creq_l || !creq_l->meterchange())
+ return false;
+
+ assert(!meter_req_l_);
+ meter_req_l_ = r_l->command()->meterchange();
+
+ return true;
+}
+
+void
+Meter_register::process_requests()
+{
+ if (meter_req_l_ ) {
+ Array<Scalar> args;
+ args.push(meter_req_l_->beats_i_);
+ args.push(meter_req_l_->one_beat_i_);
+
+ meter_p_ = new Meter(args);
+ }
+
+ if (meter_p_)
+ announce_element(Staff_elem_info(meter_p_, meter_req_l_) );
+}
+
+void
+Meter_register::pre_move_processing()
+{
+ if (meter_p_) {
+ Meter * post_p =new Meter(*meter_p_);
+ Meter * pre_p =new Meter(*meter_p_);
+
+ typeset_breakable_item(pre_p, meter_p_, post_p);
+ meter_p_ =0;
+ }
+}
+
+void
+Meter_register::post_move_processing()
+{
+ meter_req_l_ = 0;
+ meter_p_ =0;
+}
--- /dev/null
+#include "scalar.hh"
+#include "molecule.hh"
+#include "meter.hh"
+#include "paper-def.hh"
+#include "lookup.hh"
+
+Meter::Meter(Array<Scalar>a)
+ :args(a)
+{
+}
+
+Molecule*
+Meter::brew_molecule_p()const
+{
+ Symbol s = paper()->lookup_p_->meter(args);
+ return new Molecule(Atom(s));
+}
+
--- /dev/null
+#include <math.h>
+
+#include "item.hh"
+#include "misc.hh"
+#include "glob.hh"
+#include "moment.hh"
+
+
+// depreciated, see struct Duration*
+Moment
+wholes(int dur, int dots)
+{
+ if (!dur)
+ return 0;
+
+ Moment f = Rational(1)/Moment(dur);
+ Moment delta = f;
+
+ while (dots--) {
+ delta /= 2.0;
+ f += delta;
+ }
+ return f;
+}
+int
+intlog2(int d) {
+ int i=0;
+ while (!(d&1)) {
+ d/= 2;
+ i++;
+ }
+ assert(!(d/2));
+ return i;
+}
+
+double
+log_2(double x) {
+ return log(x) /log(2.0);
+}
+
+Interval
+itemlist_width(const Array<Item*> &its)
+{
+ Interval iv ;
+ iv.set_empty();
+
+ for (int j =0; j < its.size(); j++){
+ iv.unite (its[j]->width());
+
+ }
+ return iv;
+}
+
--- /dev/null
+#include "varray.hh"
+#include "interval.hh"
+#include "dimen.hh"
+#include "string.hh"
+#include "molecule.hh"
+#include "symbol.hh"
+#include "debug.hh"
+#include "tex.hh"
+
+void
+Atom::print() const
+{
+ mtor << "texstring: " <<sym.tex<<"\n";
+}
+
+Box
+Atom::extent() const
+{
+ Box b( sym.dim);
+ b.translate(off);
+ return b;
+}
+
+Atom::Atom(Symbol s)
+{
+ sym=s;
+}
+
+
+String
+Atom::TeXstring() const
+{
+ // whugh.. Hard coded...
+ String s("\\placebox{%}{%}{%}");
+ Array<String> a;
+ a.push(print_dimen(off.y));
+ a.push(print_dimen(off.x));
+ a.push(sym.tex);
+ return substitute_args(s, a);
+}
+
+/* *************** */
+
+String
+Molecule::TeXstring() const
+{
+ String s;
+ for(iter_top(ats,c); c.ok(); c++)
+ s+=c->TeXstring();
+ return s;
+}
+
+Box
+Molecule::extent() const
+{
+ Box b;
+ for(iter_top(ats,c); c.ok(); c++)
+ b.unite(c->extent());
+ return b;
+}
+
+void
+Molecule::translate(Offset o)
+{
+ for (iter_top(ats,c); c.ok(); c++)
+ c->translate(o);
+}
+
+void
+Molecule::add(const Molecule &m)
+{
+ for (iter_top(m.ats,c); c.ok(); c++) {
+ add(**c);
+ }
+}
+
+void
+Molecule::add_right(const Molecule &m)
+{
+ if (!ats.size()) {
+ add(m);
+ return;
+ }
+ Real xof=extent().x.right - m.extent().x.left;
+ Molecule toadd(m);
+ toadd.translate(Offset(xof, 0.0));
+ add(toadd);
+}
+
+void
+Molecule::add_left(const Molecule &m)
+{
+ if (!ats.size()) {
+ add(m);
+ return;
+ }
+ Real xof=extent().x.left - m.extent().x.right;
+ Molecule toadd(m);
+ toadd.translate(Offset(xof, 0.0));
+ add(toadd);
+}
+
+
+void
+Molecule::add_top(const Molecule &m)
+{
+ if (!ats.size()) {
+ add(m);
+ return;
+ }
+ Real yof=extent().y.right - m.extent().y.left;
+ Molecule toadd(m);
+ toadd.translate(Offset(0,yof));
+ add(toadd);
+}
+
+void
+Molecule::add_bottom(const Molecule &m)
+{
+ if (!ats.size()) {
+ add(m);
+ return;
+ }
+ Real yof=extent().y.left- m.extent().y.right;
+ Molecule toadd(m);
+ toadd.translate(Offset(0,yof));
+ add(toadd);
+}
+
+void
+Molecule::operator = (const Molecule&)
+{
+ assert(false);
+}
+
+Molecule::Molecule(const Molecule&s)
+{
+ add(s);
+}
+
+void
+Molecule::print() const
+{
+ for (iter_top(ats,c); c.ok(); c++)
+ c->print();
+}
--- /dev/null
+#include <strstream.h>
+
+#include "interval.hh"
+#include "identparent.hh"
+#include "assoc-iter.hh"
+#include "lexer.hh"
+#include "input-file.hh"
+#include "parser.hh"
+#include "keyword.hh"
+#include "assoc.hh"
+#include "lexer.hh"
+#include "debug.hh"
+#include "notename.hh"
+#include "source-file.hh"
+#include "parseconstruct.hh"
+
+static Keyword_ent the_key_tab[]={
+ "bar", BAR,
+ "cadenza", CADENZA,
+ "clef", CLEF,
+ "cm", CM_T,
+ "command", COMMAND,
+ "commands", COMMANDS,
+ "duration", DURATIONCOMMAND,
+ "geometric", GEOMETRIC,
+ "goto", GOTO,
+ "in", IN_T,
+ "key", KEY,
+ "meter", METER,
+ "midi", MIDI,
+ "mm", MM_T,
+ "multivoice", MULTIVOICE,
+ "octave", OCTAVECOMMAND,
+ "output", OUTPUT,
+ "partial", PARTIAL,
+ "paper", PAPER,
+ "plet", PLET,
+ "pt", PT_T,
+ "score", SCORE,
+ "script", SCRIPT,
+ "skip", SKIP,
+ "staff", STAFF,
+ "start", START_T,
+ "stem", STEM,
+ "table", TABLE,
+ "symboltables", SYMBOLTABLES,
+ "notenames", NOTENAMES,
+ "tempo", TEMPO,
+ "texid", TEXID,
+ "textstyle", TEXTSTYLE,
+ "unitspace", UNITSPACE,
+ "voice", VOICE,
+ "voices", VOICES,
+ "width", WIDTH,
+ "music", MUSIC,
+ "grouping", GROUPING,
+ 0,0
+};
+
+int
+My_flex_lexer::ret_notename(int *p, String text, int octave_mod)
+{
+ text = text.lower_str();
+ char const* ch_c_l = here_ch_c_l();
+ if ( ch_c_l ) {
+ ch_c_l--;
+ while ( ( *ch_c_l == ' ' )
+ || ( *ch_c_l == '\t' ) || ( *ch_c_l == '\n' ) )
+ ch_c_l--;
+ ch_c_l++;
+ }
+
+ lookup_notename(p[0], p[1], text);
+ p[2] = octave_mod;
+ mtor << "notename: "<< text <<eol;
+ if (p[0] < 0) {
+
+ errorlevel_i_ |= 1;
+ error( String( "notename does not exist: " ) + YYText(), ch_c_l );
+ p[0] = p[1] = 0;
+ }
+ return NOTENAME;
+}
+
+My_flex_lexer::My_flex_lexer()
+{
+ keytable = new Keyword_table(the_key_tab);
+ the_id_tab = new Assoc<String, Identifier*>;
+ defaulttab = 0;
+ errorlevel_i_ = 0;
+}
+
+int
+My_flex_lexer::lookup_keyword(String s)
+{
+ return keytable->lookup(s);
+}
+
+Identifier*
+My_flex_lexer::lookup_identifier(String s)
+{
+ if (!the_id_tab->elt_query(s))
+ return 0;
+
+ return (*the_id_tab)[s];
+}
+
+char const*
+My_flex_lexer::here_ch_c_l()
+{
+ return include_stack.top()->sourcefile_l_->ch_c_l() + yyin->tellg();
+}
+
+void
+My_flex_lexer::add_identifier(Identifier*i)
+{
+ delete lookup_identifier(i->name);
+ (*the_id_tab)[i->name] = i;
+}
+
+My_flex_lexer::~My_flex_lexer()
+{
+ delete keytable;
+ delete defaulttab;
+ for (Assoc_iter<String,Identifier*> ai(*the_id_tab); ai.ok(); ai++) {
+ mtor << "deleting: " << ai.key()<<'\n';
+ delete ai.val();
+ }
+ delete the_id_tab;
+}
+void
+My_flex_lexer::print_declarations()const
+{
+ for (Assoc_iter<String,Identifier*> ai(*the_id_tab); ai.ok(); ai++) {
+ ai.val()->print();
+ }
+}
+
+String
+My_flex_lexer::spot()const
+{
+ return include_stack.top()->name + ": " + String( lineno() );
+}
+
+void
+My_flex_lexer::LexerError(const char *s)
+{
+ if (lexer->include_stack.empty()) {
+ *mlog << "error at EOF" << s << '\n';
+ } else {
+ char const* ch_c_l = here_ch_c_l();
+ if ( ch_c_l ) {
+ ch_c_l--;
+ while ( ( *ch_c_l == ' ' ) || ( *ch_c_l == '\t' ) || ( *ch_c_l == '\n' ) )
+ ch_c_l--;
+ ch_c_l++;
+ }
+ errorlevel_i_ |= 1;
+ error( s, ch_c_l );
+ }
+}
+
+// set the new input to s, remember old file.
+void
+My_flex_lexer::new_input(String s)
+{
+ if (!include_stack.empty()) {
+ include_stack.top()->line = lineno();
+ // should this be saved at all?
+ include_stack.top()->defined_ch_c_l_ = defined_ch_c_l;
+ }
+
+ Input_file *newin = new Input_file(s);
+ include_stack.push(newin);
+ switch_streams(newin->is);
+
+ yylineno = 1;
+}
+
+// pop the inputstack.
+bool
+My_flex_lexer::close_input()
+{
+ Input_file *old = include_stack.pop();
+ bool ok = true;
+ if (include_stack.empty()) {
+ ok = false;
+ } else {
+ Input_file *i = include_stack.top();
+ switch_streams(i->is);
+ yylineno = i->line;
+ defined_ch_c_l = i->defined_ch_c_l_;
+ }
+ delete old;
+ return ok;
+}
--- /dev/null
+/*
+ could use cleanup
+ */
+#include <ctype.h>
+#include "lexer.hh"
+#include "string.hh"
+#include "real.hh"
+#include "debug.hh"
+#include "musicalrequest.hh"
+#include "commandrequest.hh"
+#include "voice.hh"
+#include "notename.hh"
+#include "identparent.hh"
+#include "varray.hh"
+#include "text-def.hh"
+#include "parseconstruct.hh"
+#include "input-music.hh"
+#include "voice-element.hh"
+
+int default_duration = 4, default_dots=0, default_octave=0;
+int default_plet_type = 1, default_plet_dur = 1;
+String textstyle="roman"; // in lexer?
+
+bool last_duration_mode = false;
+
+void
+set_duration_mode(String s)
+{
+ s = s.upper_str();
+ last_duration_mode = (s== "LAST");
+}
+
+void
+last_duration(int n)
+{
+ if (last_duration_mode)
+ default_duration = n;
+}
+
+/* triplet is '2/3' */
+void
+set_plet(int num,int den)
+{
+ assert(num >0&& den>0);
+ default_plet_dur = num;
+ default_plet_type = den;
+}
+
+Text_def*
+get_text(String s) return t;
+{
+ t= new Text_def;
+ t->text_str_= s;
+ t->style_str_ = textstyle;
+ t->defined_ch_c_l_ = defined_ch_c_l;
+ return t;
+}
+
+void
+set_text_style(String s)
+{
+ textstyle = s;
+}
+
+void
+parse_octave (const char *a, int &j, int &oct)
+{
+ while (1)
+ {
+ if (a[j] == '\'')
+ oct ++;
+ else if (a[j] == '`')
+ oct --;
+ else
+ break;
+ j++;
+ }
+}
+
+void
+parse_pitch( const char *a, Melodic_req* mel_l)
+{
+ int j=0;
+
+ // octave
+ mel_l->octave_i_ = default_octave;
+ parse_octave(a,j,mel_l->octave_i_);
+
+ // accidental
+ mel_l->forceacc_b_ = false;
+
+ if (a[j] == '!'){
+ mel_l->forceacc_b_ = true;
+ j++;
+ }
+}
+
+Voice_element *
+get_note_element(String pitch, int * notename, int * duration )
+{
+ Voice_element*v = new Voice_element;
+ v->defined_ch_c_l_ = defined_ch_c_l;
+
+
+ int dur = duration[0];
+ int dots = duration[1];
+
+ if (dur >= 2) {
+ Stem_req * stem_req_p = new Stem_req(dur,dots);
+ stem_req_p->plet_factor = Moment(default_plet_dur, default_plet_type);
+ stem_req_p->defined_ch_c_l_ = defined_ch_c_l;
+ v->add(stem_req_p);
+ }
+
+ if ( !defined_ch_c_l )
+ defined_ch_c_l = lexer->here_ch_c_l();
+
+ Note_req * rq = new Note_req;
+ rq->notename_i_ =notename[0];
+ rq->accidental_i_ = notename[1];
+ parse_pitch(pitch, rq);
+ rq->octave_i_ += notename[2];
+
+ rq->balltype = dur;
+ rq->dots = dots;
+ rq->plet_factor = Moment(default_plet_dur, default_plet_type);
+ rq->defined_ch_c_l_ = defined_ch_c_l;
+
+ v->add(rq);
+
+ return v;
+}
+
+Voice_element*
+get_word_element(Text_def* tdef_p, int* duration)
+{
+ Voice_element* velt_p = new Voice_element;
+ velt_p->defined_ch_c_l_ = defined_ch_c_l;
+
+ int dur = duration[0];
+ int dots=duration[1];
+
+ tdef_p->defined_ch_c_l_ = defined_ch_c_l;
+
+ Lyric_req* lreq_p = new Lyric_req(tdef_p);
+
+ lreq_p->balltype = dur;
+ lreq_p->dots = dots;
+ lreq_p->plet_factor = Moment(default_plet_dur, default_plet_type);
+ lreq_p->print();
+ lreq_p->defined_ch_c_l_ = defined_ch_c_l;
+
+ velt_p->add(lreq_p);
+
+ return velt_p;
+}
+
+Voice_element *
+get_rest_element(String, int * duration )
+{
+ Voice_element* velt_p = new Voice_element;
+ velt_p->defined_ch_c_l_ = defined_ch_c_l;
+
+ Rest_req * rest_req_p = new Rest_req;
+ rest_req_p->plet_factor = Moment(default_plet_dur, default_plet_type);
+ rest_req_p->balltype = duration[0];
+ rest_req_p->dots = duration[1];
+ rest_req_p->print();
+ rest_req_p->defined_ch_c_l_ = defined_ch_c_l;
+
+ velt_p->add(rest_req_p);
+
+ return velt_p;
+}
+
+void
+get_default_duration(int *p)
+{
+ *p++ = default_duration;
+ *p = default_dots;
+}
+
+void
+set_default_duration(int *p)
+{
+ default_duration = *p++;
+ default_dots = *p++;
+}
+
+
+void
+set_default_octave(String d)
+{
+ int i=0;
+ default_octave=0;
+ parse_octave(d, i, default_octave);
+}
+
+Request*
+get_plet_request( char c, int dur_i, int type_i )
+{
+ Plet_req* plet_req_p = new Plet_req;
+ plet_req_p->dur_i_ = dur_i;
+ plet_req_p->type_i_ = type_i;
+ plet_req_p->type_c_ = c;
+ return plet_req_p;
+}
+
+Request*
+get_request(char c)
+{
+ Request* req_p=0;
+ switch (c) {
+ case '|':
+ req_p = new Barcheck_req;
+ break;
+
+ case '[':
+ case ']':
+ {
+ Beam_req*b = new Beam_req;
+ if (default_plet_type != 1)
+ b->nplet = default_plet_type;
+ req_p = b;
+ }
+ break;
+
+
+ case ')':
+ case '(':
+ req_p = new Slur_req;
+ break;
+ default:
+ assert(false);
+ break;
+ }
+
+ switch (c) {
+ case '(':
+ case '[':
+ req_p->span()->spantype = Span_req::START;
+ break;
+ case ')':
+ case ']':
+ req_p->span()->spantype = Span_req::STOP;
+ break;
+
+ default:
+ break;
+ }
+
+ req_p->defined_ch_c_l_ = req_defined_ch_c_l;
+ return req_p;
+}
+
+void
+add_requests(Voice_element *v, Array<Request*> &req)
+{
+ for (int i = 0; i < req.size(); i++) {
+ v->add(req[i]);
+ }
+ req.set_size(0);
+}
+
+Script_def*
+get_scriptdef(char c)
+{
+ String s;
+ switch (c) {
+ case '^' : s = "marcato";
+ break;
+ case '+' : s = "stopped";
+ break;
+ case '-' : s = "tenuto";
+ break;
+ case '|': s = "staccatissimo";
+ break;
+ case 'o' : s = "";
+ break;
+ case '>' : s = "accent";
+ break;
+ case 'v' : s = "";
+ break;
+ case '.' : s = "staccato";
+ break;
+ }
+ return lexer->lookup_identifier(s)->script(1);
+}
+
+Request*
+get_script_req(int d , Script_def*def)
+{
+ Script_req* script_req_p = new Script_req(d, def);
+ return script_req_p;
+}
+
+Request*
+get_text_req(int d , Text_def*def)
+{
+ Text_req* text_req_p = new Text_req(d, def);
+ return text_req_p;
+}
+
+Request*
+get_stemdir_req(int d)
+{
+ Group_feature_req * gfreq_p = new Group_feature_req;
+ gfreq_p->stemdir_i_ =d;
+ return gfreq_p;
+}
+
+Request*
+get_grouping_req(Array<int> i_arr)
+{
+ Measure_grouping_req * mr_p = new Measure_grouping_req;
+ for (int i=0; i <i_arr.size(); ) {
+ mr_p->beat_i_arr_.push(i_arr[i++]);
+ mr_p->elt_length_arr_.push(Moment(1, i_arr[i++]));
+ }
+ return mr_p;
+}
--- /dev/null
+#include "misc.hh"
+#include "notehead.hh"
+#include "dimen.hh"
+#include "debug.hh"
+#include "paper-def.hh"
+#include "lookup.hh"
+#include "molecule.hh"
+#include "musicalrequest.hh"
+
+
+
+Notehead::Notehead(int ss)
+{
+ x_dir = 0;
+ staff_size=ss;
+ position = 0;
+ balltype = 0;
+ dots = 0;
+ extremal = 0;
+}
+
+void
+Notehead::set_rhythmic(Rhythmic_req*r_req_l)
+{
+ balltype = r_req_l->balltype;
+ dots = r_req_l->dots;
+}
+
+void
+Notehead::do_print()const
+{
+#ifndef NPRINT
+ mtor << "balltype "<< balltype << ", position = "<< position
+ << "dots " << dots;
+#endif
+}
+
+
+int
+Notehead::compare(Notehead *const &a, Notehead * const &b)
+{
+ return a->position - b->position;
+}
+
+Molecule*
+Notehead::brew_molecule_p() const return out;
+{
+ Paper_def *p = paper();
+
+ Real dy = p->internote();
+ Symbol s = p->lookup_p_->ball(balltype);
+
+ out = new Molecule(Atom(s));
+ if (dots) {
+ Symbol d = p->lookup_p_->dots(dots);
+ Molecule dm;
+ dm.add(Atom(d));
+ if (!(position %2))
+ dm.translate(Offset(0,dy));
+ out->add_right(dm);
+ }
+ out->translate(Offset(x_dir * p->note_width(),0));
+ bool streepjes = (position<-1)||(position > staff_size+1);
+ if (streepjes) {
+ int dir = sign(position);
+ int s =(position<-1) ? -((-position)/2): (position-staff_size)/2;
+ Symbol str = p->lookup_p_->streepjes(s);
+ Molecule sm;
+ sm.add(Atom(str));
+ if (position % 2)
+ sm.translate(Offset(0,-dy* dir));
+ out->add(sm);
+ }
+
+ out->translate(Offset(0,dy*position));
+}
+
--- /dev/null
+#include "glob.hh"
+#include "string.hh"
+#include "notename.hh"
+#include "lexer.hh"
+#include "identifier.hh"
+
+
+
+void
+Notename_tab::lookup(int &large, int &small, String s)
+{
+ large = -1;
+ small = 0;
+
+ for (int i =0; i < 7*5; i++)
+ if (s == notetab[i])
+ {
+ large = i /5;
+ small = i %5 - 2;
+ return;
+ }
+}
+
+
+void
+Notename_tab::set(int l, int s, String n)
+{
+ assert(l < 8 && s <= 2 && s >= -2 && l >=0);
+ notetab[l * 5 + s +2] = n;
+}
+/* *************** */
+void
+My_flex_lexer::set(Notename_tab *n)
+{
+ delete defaulttab;
+ defaulttab = n;
+}
+
+void
+My_flex_lexer::lookup_notename(int &large, int &small, String s)
+{
+ if (!defaulttab)
+ set(lookup_identifier("default_table")->
+ notename_tab(true));
+
+ defaulttab->lookup(large, small, s);
+}
--- /dev/null
+#include <math.h>
+#include "misc.hh"
+#include "paper-def.hh"
+#include "debug.hh"
+#include "lookup.hh"
+#include "dimen.hh"
+
+
+
+// golden ratio
+const Real PHI = (1+sqrt(5))/2;
+
+// see Roelofs, p. 57
+Real
+Paper_def::duration_to_dist(Moment d)
+{
+ if (!d)
+ return 0;
+
+ return whole_width * pow(geometric_, log_2(d));
+}
+
+Real
+Paper_def::rule_thickness()const
+{
+ return 0.4 PT;
+}
+
+Paper_def::Paper_def(Lookup *l)
+{
+ lookup_p_ = l;
+ linewidth = 15 *CM_TO_PT; // in cm for now
+ whole_width = 8 * note_width();
+ geometric_ = sqrt(2);
+ outfile = "lelie.out";
+}
+
+Paper_def::~Paper_def()
+{
+ delete lookup_p_;
+}
+Paper_def::Paper_def(Paper_def const&s)
+{
+ lookup_p_ = new Lookup(*s.lookup_p_);
+ geometric_ = s.geometric_;
+ whole_width = s.whole_width;
+ outfile = s.outfile;
+ linewidth = s.linewidth;
+}
+
+void
+Paper_def::set(Lookup*l)
+{
+ assert(l != lookup_p_);
+ delete lookup_p_;
+ lookup_p_ = l;
+}
+
+Real
+Paper_def::interline() const
+{
+ return lookup_p_->ball(4).dim.y.length();
+}
+
+Real
+Paper_def::internote() const
+{
+ return lookup_p_->internote();
+}
+Real
+Paper_def::note_width()const
+{
+ return lookup_p_->ball(4).dim.x.length( );
+}
+Real
+Paper_def::standard_height() const
+{
+ return 20 PT;
+}
+
+void
+Paper_def::print() const
+{
+#ifndef NPRINT
+ mtor << "Paper {width: " << print_dimen(linewidth);
+ mtor << "whole: " << print_dimen(whole_width);
+ mtor << "out: " <<outfile;
+ lookup_p_->print();
+ mtor << "}\n";
+#endif
+}
--- /dev/null
+%{ // -*-Fundamental-*-
+#include <iostream.h>
+
+#include "lookup.hh"
+#include "misc.hh"
+#include "lexer.hh"
+#include "paper-def.hh"
+#include "midi-def.hh"
+#include "input-score.hh"
+#include "main.hh"
+#include "keyword.hh"
+#include "debug.hh"
+#include "parseconstruct.hh"
+#include "dimen.hh"
+#include "identifier.hh"
+#include "commandrequest.hh"
+#include "musicalrequest.hh"
+#include "voice-element.hh"
+
+#ifndef NDEBUG
+#define YYDEBUG 1
+#endif
+
+Array<Request*> pre_reqs, post_reqs;
+Array<const char *> define_spots;
+Paper_def*default_paper();
+char const* defined_ch_c_l;
+char const* req_defined_ch_c_l;
+int fatal_error_i = 0;
+
+%}
+
+
+%union {
+ Request * request;
+ Real real;
+ Identifier *id;
+ Voice *voice;
+ Voice_element *el;
+ String *string;
+ const char *consstr;
+ Paper_def *paper;
+ Midi_def* midi;
+ Input_music *music;
+ Music_general_chord *chord;
+ Music_voice *mvoice;
+ int i;
+ char c;
+ int ii[10];
+ Moment *moment;
+
+ Array<String> * strvec;
+ Array<int> *intvec;
+ Array<Melodic_req*> *melreqvec;
+ Input_staff *staff;
+ Input_score *score;
+ Symtables * symtables;
+ Symtable * symtable;
+ Symbol * symbol;
+ Lookup*lookup;
+ Interval *interval;
+ Box *box;
+ Notename_tab *notename_tab;
+ Script_def * script;
+ Text_def * textdef;
+}
+
+%token VOICE STAFF SCORE TITLE BAR OUTPUT MULTIVOICE
+%token CM_T IN_T PT_T MM_T PAPER WIDTH METER UNITSPACE SKIP COMMANDS COMMAND
+%token GEOMETRIC START_T DURATIONCOMMAND OCTAVECOMMAND
+%token KEY CLEF TABLE VOICES STEM
+%token PARTIAL MUSIC GROUPING CADENZA
+%token END SYMBOLTABLES TEXID TABLE NOTENAMES SCRIPT TEXTSTYLE PLET
+%token GOTO
+%token MIDI TEMPO
+
+%token <id> IDENTIFIER
+%token <string> PITCHMOD DURATION RESTNAME
+%token <ii> NOTENAME
+%token <real> REAL
+%token <string> STRING
+
+%token <i> DOTS INT
+%type <real> unit
+%type <melreqvec> pitch_list
+%type <c> open_request_parens close_request_parens close_plet_parens
+%type <id> declaration
+%type <string> declarable_identifier
+%type <paper> paper_block paper_body
+%type <midi> midi_block midi_body
+%type <real> dim real
+%type <ii> default_duration explicit_duration notemode_duration mudela_duration
+%type <ii> notename
+%type <moment> duration_length
+%type <el> voice_elt full_element lyrics_elt command_elt
+
+%type <score> score_block score_body
+%type <staff> staff_block staff_init staff_body
+%type <i> int
+%type <intvec> intastint_list
+%type <request> post_request pre_request command_req
+%type <string> pitchmod
+%type <music> music
+%type <chord> music_chord music_chord_body
+
+%type <mvoice> music_voice_body music_voice
+
+%type <interval> dinterval
+%type <box> box
+%type <symtable> symtable symtable_body
+%type <lookup> symtables symtables_body
+%type <symbol> symboldef
+%type <notename_tab> notename_tab notename_tab_body
+%type <i> script_dir
+%type <script> script_definition script_body mudela_script
+%type <request> script_req textscript_req
+%type <textdef> mudela_text
+
+
+%%
+
+mudela: /* empty */
+ | mudela score_block {
+ add_score($2);
+ }
+ | mudela add_declaration { }
+ | mudela mudela_command {}
+ ;
+
+mudela_command:
+ notename_tab { lexer->set($1); }
+ ;
+
+/*
+ DECLARATIONS
+*/
+add_declaration: declaration {
+ lexer->add_identifier($1);
+ }
+ ;
+
+declarable_identifier:
+ STRING { $$ = $1; }
+ | IDENTIFIER { $$ = new String($1->name); }
+ ;
+
+declaration:
+ declarable_identifier '=' staff_block {
+ $$ = new Staff_id(*$1, $3);
+ delete $1;
+ }
+ | declarable_identifier '=' music_voice {
+ $$ = new M_voice_id(*$1, $3);
+ delete $1;
+ }
+ | declarable_identifier '=' script_definition {
+ $$ = new Script_id(*$1, $3);
+ delete $1;
+ }
+ | declarable_identifier '=' music_chord {
+ $$ = new M_chord_id(*$1, $3);
+ delete $1;
+ }
+ | declarable_identifier '=' symtables {
+ $$ = new Lookup_id(*$1, $3);
+ delete $1;
+ }
+ | declarable_identifier '=' notename_tab {
+ $$ = new Notetab_id(*$1, $3);
+ delete $1;
+ }
+ | declarable_identifier '=' real {
+ $$ = new Real_id(*$1, new Real($3));
+ delete $1;
+ }
+ | declarable_identifier error '}' {
+
+ }
+ ;
+
+notename_tab:
+ NOTENAMES '{' notename_tab_body '}' { $$ = $3; }
+ ;
+
+notename_tab_body: {
+ $$ = new Notename_tab;
+ }
+ | IDENTIFIER {
+ $$ = $1->notename_tab(true);
+ }
+ | notename_tab_body STRING int int {
+ $$->set($3, $4, *$2);
+ delete $2;
+ }
+ ;
+
+/*
+ SCORE
+*/
+score_block:
+ SCORE { define_spots.push(lexer->here_ch_c_l()); }
+ /*cont*/ '{' score_body '}' {
+ $$ = $4;
+ $$->defined_ch_c_l_ = define_spots.pop();
+ if (!$$->paper_p_ && ! $$->midi_p_)
+ $$->paper_p_ = default_paper();
+
+ /* handle error levels. */
+ $$->errorlevel_i_ = lexer->errorlevel_i_;
+ lexer->errorlevel_i_ = 0;
+ }
+ ;
+
+score_body: {
+ $$ = new Input_score;
+ }
+ | score_body staff_block { $$->add($2); }
+ | score_body COMMANDS '{' music_voice_body '}' {
+ $$->set($4);
+ }
+ | score_body paper_block { $$->set($2); }
+ | score_body midi_block { $$->set($2); }
+ | score_body error {
+
+ }
+ ;
+
+intastint_list:
+ /* */ { $$ =new Array<int>; }
+ | intastint_list int '*' int {
+ $$->push($2); $$->push($4);
+ }
+ ;
+
+
+/*
+ PAPER
+*/
+paper_block:
+ PAPER
+
+ '{' paper_body '}' { $$ = $3; }
+ ;
+
+paper_body:
+ /* empty */ {
+ $$ = default_paper();
+ }
+ | paper_body WIDTH dim { $$->linewidth = $3;}
+ | paper_body OUTPUT STRING { $$->outfile = *$3;
+ delete $3;
+ }
+ | paper_body symtables { $$->set($2); }
+ | paper_body UNITSPACE dim { $$->whole_width = $3; }
+ | paper_body GEOMETRIC REAL { $$->geometric_ = $3; }
+ | paper_body error {
+
+ }
+ ;
+
+/*
+ MIDI
+*/
+midi_block:
+ MIDI
+
+ '{' midi_body '}' { $$ = $3; }
+ ;
+
+midi_body: {
+ $$ = new Midi_def;
+ }
+ | midi_body OUTPUT STRING {
+ $$->outfile_str_ = *$3;
+ delete $3;
+ }
+ | midi_body TEMPO mudela_duration ':' int {
+ $$->set_tempo( wholes( $3[0], $3[1] ), $5 );
+ }
+ | midi_body error {
+
+ }
+ ;
+
+/*
+ STAFFs
+*/
+staff_block:
+ STAFF { define_spots.push(lexer->here_ch_c_l()); }
+/*cont*/ '{' staff_body '}' {
+ $$ = $4;
+ $$-> defined_ch_c_l_ = define_spots.pop();
+ }
+ ;
+
+
+
+staff_init:
+ IDENTIFIER { $$ = $1->staff(true); }
+ | STRING {
+ $$ = new Input_staff(*$1);
+ delete $1;
+ }
+ ;
+
+staff_body:
+ staff_init
+ | staff_body COMMANDS '{' music_voice_body '}' {
+ $$->set_score_wide($4);
+ }
+ | staff_body music {
+ $2->set_default_group( "staff_music" + String($$->music_.size()));
+ $$->add($2);
+ }
+ | staff_body error {
+ }
+ ;
+
+/*
+ MUSIC
+*/
+music:
+ music_voice { $$ = $1; }
+ | music_chord { $$ = $1; }
+ ;
+
+music_voice: MUSIC '{' music_voice_body '}' { $$ = $3; }
+ ;
+
+music_voice_body:
+ /* */ {
+ $$ = new Music_voice;
+ }
+ | music_voice_body IDENTIFIER {
+ $$->concatenate($2->mvoice(true));
+ }
+ | music_voice_body full_element {
+ $$->add_elt($2);
+ }
+ | music_voice_body voice_command {
+ }
+ | music_voice_body music {
+ $$->add($2);
+ }
+ | music_voice_body error {
+ }
+ ;
+
+music_chord: '{' music_chord_body '}' { $$ = $2; }
+ ;
+
+music_chord_body:
+ /* */ {
+ $$ = new Voice_group_chord;
+ }
+ | MULTIVOICE {
+ $$ = new Multi_voice_chord;
+ }
+ | music_chord_body IDENTIFIER {
+ $$->concatenate($2->mchord(true));
+ }
+ | music_chord_body music {
+ $$->add($2);
+ }
+ | music_chord_body full_element {
+ $$ ->add_elt($2);
+ }
+ | music_chord_body error {
+ }
+ ;
+
+
+/*
+ VOICE ELEMENTS
+*/
+full_element: pre_requests voice_elt post_requests {
+ add_requests($2, pre_reqs);
+ add_requests($2, post_reqs);
+ $$ = $2;
+ }
+ | pre_requests lyrics_elt post_requests {
+ add_requests($2, pre_reqs);
+ add_requests($2, post_reqs);
+ $$ = $2;
+ }
+ | command_elt
+ ;
+
+command_elt:
+/* empty */ {
+ $$ = new Voice_element;
+ $$-> defined_ch_c_l_ = lexer->here_ch_c_l();
+ }
+/* cont: */
+ command_req {
+ $2-> defined_ch_c_l_ = $$->defined_ch_c_l_;
+ $$->add($2);
+
+ }
+ ;
+
+command_req:
+ '|' {
+ $$ = new Barcheck_req;
+ }
+ | BAR STRING {
+ $$ = new Bar_req(*$2);
+ delete $2;
+ }
+ | METER '{' int '*' int '}' {
+ Meter_change_req *m = new Meter_change_req;
+ m->set($3,$5);
+ $$ = m;
+ }
+ | SKIP '{' duration_length '}' {
+ Skip_req * skip_p = new Skip_req;
+ skip_p->duration_ = *$3;
+ delete $3;
+ $$ = skip_p;
+ }
+ | CADENZA '{' int '}' {
+ $$ = new Cadenza_req($3);
+ }
+ | PARTIAL '{' duration_length '}' {
+ $$ = new Partial_measure_req(*$3);
+ delete $3;
+ }
+ | STEM '{' int '}' {
+ $$ = get_stemdir_req($3);
+ }
+ | CLEF STRING {
+ $$ = new Clef_change_req(*$2);
+ delete $2;
+ }
+ | KEY '{' pitch_list '}' {
+ Key_change_req *key_p= new Key_change_req;
+ key_p->melodic_p_arr_ = *$3;
+ $$ = key_p;
+ delete $3;
+ }
+ | GROUPING '{' intastint_list '}' {
+ $$ = get_grouping_req(*$3); delete $3;
+ }
+ ;
+
+post_requests:
+ {
+ assert(post_reqs.empty());
+ }
+ | post_requests post_request {
+ $2->defined_ch_c_l_ = lexer->here_ch_c_l();
+ post_reqs.push($2);
+ }
+ | post_requests close_plet_parens INT '/' INT {
+ post_reqs.push( get_request($2) );
+ req_defined_ch_c_l = lexer->here_ch_c_l();
+ post_reqs.push( get_plet_request( $2, $3, $5 ) );
+ }
+ ;
+
+post_request:
+ close_request_parens {
+ $$ = get_request($1);
+ }
+ | script_req
+ | textscript_req
+ ;
+
+close_plet_parens:
+ ']' {
+ req_defined_ch_c_l = lexer->here_ch_c_l();
+ $$ = ']';
+ }
+ ;
+
+close_request_parens:
+ '(' {
+ $$='(';
+ }
+ | ']' {
+ $$ = ']';
+ }
+ ;
+
+open_request_parens:
+ ')' {
+ $$=')';
+ }
+ | '[' {
+ $$='[';
+ }
+ ;
+
+script_definition:
+ SCRIPT '{' script_body '}' { $$ = $3; }
+ ;
+
+script_body:
+ STRING int int int {
+ $$ = new Script_def(*$1,$2, $3,$4);
+ delete $1;
+ }
+ ;
+
+textscript_req:
+ script_dir mudela_text { $$ = get_text_req($1,$2); }
+ ;
+
+mudela_text:
+ STRING {
+ defined_ch_c_l = lexer->here_ch_c_l();
+ $$ = get_text(*$1);
+ delete $1;
+ }
+ ;
+
+script_req:
+ script_dir mudela_script {
+ $$ = get_script_req($1, $2);
+ }
+ ;
+
+mudela_script:
+ IDENTIFIER { $$ = $1->script(true); }
+ | script_definition { $$ = $1; }
+ | '^' { $$ = get_scriptdef('^'); }
+ | '+' { $$ = get_scriptdef('+'); }
+ | '-' { $$ = get_scriptdef('-'); }
+ | '|' { $$ = get_scriptdef('|'); }
+ | 'o' { $$ = get_scriptdef('o'); }
+ | '>' { $$ = get_scriptdef('>'); }
+ | '.' { $$ = get_scriptdef('.'); }
+ | DOTS {
+ if ( $1 > 1 )
+ warning( "too many staccato dots", lexer->here_ch_c_l() );
+ $$ = get_scriptdef('.');
+ }
+ | error {
+ $$ = get_scriptdef('.');
+ yyerrok;
+ }
+ ;
+
+script_dir:
+ '_' { $$ = -1; }
+ |'^' { $$ = 1; }
+ |'-' { $$ = 0; }
+ ;
+
+pre_requests:
+ | pre_requests pre_request {
+ pre_reqs.push($2);
+ $2->defined_ch_c_l_ = lexer->here_ch_c_l();
+ }
+ ;
+
+pre_request:
+ open_request_parens {
+ defined_ch_c_l = lexer->here_ch_c_l();
+ $$ = get_request($1);
+ }
+ ;
+
+voice_command:
+ PLET '{' INT '/' INT '}' {
+ set_plet($3,$5);
+ }
+ | DURATIONCOMMAND '{' STRING '}' {
+ set_duration_mode(*$3);
+ delete $3;
+ }
+ | DURATIONCOMMAND '{' notemode_duration '}' {
+ set_default_duration($3);
+ }
+ | OCTAVECOMMAND '{' pitchmod '}' {
+ set_default_octave(*$3);
+ delete $3;
+ }
+ | TEXTSTYLE STRING {
+ set_text_style(*$2);
+ delete $2;
+ }
+ ;
+
+duration_length:
+ mudela_duration {
+ $$ = new Moment(wholes($1[0], $1[1]));
+ }
+ |int '*' mudela_duration {
+ $$ = new Moment(Rational($1) * wholes($3[0], $3[1]));
+ }
+ ;
+
+notemode_duration:
+ explicit_duration
+ | default_duration
+ ;
+
+mudela_duration:
+ int {
+ $$[0] = $1;
+ $$[1] = 0;
+ }
+ | int DOTS {
+ $$[0] = $1;
+ $$[1] = $2;
+ }
+ ;
+
+
+explicit_duration:
+ INT {
+ last_duration($1);
+ $$[0] = $1;
+ $$[1] = 0;
+ }
+ | INT DOTS {
+ last_duration($1);
+ $$[0] = $1;
+ $$[1] = $2;
+ }
+ | DOTS {
+ 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:
+ {
+ get_default_duration($$);
+ }
+ ;
+
+pitchmod: {
+ defined_ch_c_l = lexer->here_ch_c_l();
+ $$ = new String;
+ }
+ | PITCHMOD {
+ defined_ch_c_l = lexer->here_ch_c_l();
+ $$ = $1;
+ }
+ ;
+
+notename:
+ NOTENAME
+ ;
+
+voice_elt:
+ pitchmod notename notemode_duration {
+ $$ = get_note_element(*$1, $2, $3);
+ delete $1;
+ }
+ | RESTNAME notemode_duration {
+ $$ = get_rest_element(*$1, $2);
+ delete $1;
+
+ }
+ ;
+
+lyrics_elt:
+ mudela_text notemode_duration {
+ $$ = get_word_element($1, $2);
+ };
+
+/*
+ UTILITIES
+ */
+pitch_list: {
+ $$ = new Array<Melodic_req*>;
+ }
+ | pitch_list NOTENAME {
+ Melodic_req *m_p = new Melodic_req;
+ m_p->notename_i_ = $2[0];
+ m_p->accidental_i_ = $2[1];
+ $$->push(m_p);
+ }
+ ;
+
+int:
+ real {
+ $$ = int($1);
+ if ( distance($1,Real(int($$)) ) > 1e-8)
+ error( "integer expected", lexer->here_ch_c_l() );
+ }
+ ;
+
+real:
+ INT {
+ $$ = Real($1);
+ }
+ | REAL {
+ $$ = $1;
+ }
+ | IDENTIFIER {
+ $$ = * $1->real(0);
+ }
+ ;
+
+
+
+dim:
+ real unit { $$ = $1*$2; }
+ ;
+
+
+unit: CM_T { $$ = 1 CM; }
+ |IN_T { $$ = 1 INCH; }
+ |MM_T { $$ = 1 MM; }
+ |PT_T { $$ = 1 PT; }
+ ;
+
+/*
+ symbol tables
+*/
+symtables:
+ SYMBOLTABLES '{' symtables_body '}' { $$ = $3; }
+ ;
+
+symtables_body:
+ {
+ $$ = new Lookup;
+ }
+ | IDENTIFIER {
+ $$ = new Lookup(*$1->lookup(true));
+ }
+ | symtables_body TEXID STRING {
+ $$->texsetting = *$3;
+ delete $3;
+ }
+ | symtables_body STRING '=' symtable {
+ $$->add(*$2, $4);
+ delete $2;
+ }
+ ;
+
+symtable:
+ TABLE '{' symtable_body '}' { $$ = $3; }
+ ;
+
+symtable_body:
+ { $$ = new Symtable; }
+ | symtable_body STRING symboldef {
+ $$->add(*$2, *$3);
+ delete $2;
+ delete $3;
+ }
+ ;
+
+symboldef:
+ STRING box {
+ $$ = new Symbol(*$1, *$2);
+ delete $1;
+ delete $2;
+ }
+ | STRING {
+ Box b;
+ $$ = new Symbol(*$1, b);
+ delete $1;
+ }
+ ;
+
+box:
+ dinterval dinterval {
+ $$ = new Box(*$1, *$2);
+ delete $1;
+ delete $2;
+ }
+ ;
+
+dinterval: dim dim {
+ $$ = new Interval($1, $2);
+ }
+ ;
+
+%%
+
+void
+yyerror(const char *s)
+{
+ lexer->LexerError(s);
+
+ if ( fatal_error_i )
+ exit( fatal_error_i );
+}
+
+void
+parse_file(String init, String s)
+{
+ *mlog << "Parsing ... ";
+ lexer = new My_flex_lexer;
+
+#ifdef YYDEBUG
+ yydebug = !monitor->silence("InitParser") && check_debug;
+ lexer->set_debug( !monitor->silence("InitLexer") && check_debug);
+#endif
+
+ lexer->new_input(init);
+ yyparse();
+
+#ifdef YYDEBUG
+ yydebug = !monitor->silence("Parser") && check_debug;
+ lexer->set_debug( !monitor->silence("Lexer") && check_debug);
+#endif
+
+ lexer->new_input(s);
+ yyparse();
+ delete lexer;
+ lexer = 0;
+
+ if(!define_spots.empty())
+ warning("Braces don't match.",0);
+}
+
+Paper_def*
+default_paper()
+{
+ return new Paper_def(
+ lexer->lookup_identifier("default_table")->lookup(true));
+}
+
+
--- /dev/null
+#include "pcol.hh"
+#include "pscore.hh"
+#include "pstaff.hh"
+#include "debug.hh"
+
+Interval
+PCol::width() const
+{
+ Interval w;
+
+ for (iter_top(its,i); i.ok(); i++)
+ w.unite(i->width());
+ if (w.empty())
+ w.unite(Interval(0,0));
+ return w;
+}
+
+int
+PCol::rank() const
+{
+ if(!pscore_l_)
+ return -1;
+ PCursor<PCol*> me=pscore_l_->find_col( (PCol*)this);
+ if (!me.ok())
+ return -1;
+ PCursor<PCol*> bot(pscore_l_->cols.top());
+ return me - bot;
+}
+
+void
+PCol::print() const
+{
+#ifndef NPRINT
+ mtor << "PCol {";
+
+ if (rank() >= 0)
+ mtor << "rank: " << rank() << '\n';
+
+ mtor << "# symbols: " << its.size() ;
+ if (breakable_b()){
+ mtor << "\npre,post: ";
+ prebreak_p_->print();
+ postbreak_p_->print();
+ } else if (daddy_l_) {
+ mtor<<'\n' << ((this == daddy_l_->prebreak_p_) ?
+ "prebreak" : "postbreak");
+ mtor << '\n';
+ }
+ mtor << "extent: " << width().str() << "\n";
+ mtor << "}\n";
+#endif
+}
+
+int
+PCol::compare(const PCol &c1, const PCol &c2)
+{
+ PScore*ps_l = c1.pscore_l_;
+ PCursor<PCol*> ac(ps_l->find_col(&c1));
+ PCursor<PCol*> bc(ps_l->find_col(&c2));
+ assert(ac.ok() && bc.ok());
+ return ac - bc;
+}
+
+void
+PCol::OK() const
+{
+#ifndef NDEBUG
+ if (prebreak_p_ || postbreak_p_ ) {
+ assert(prebreak_p_&&postbreak_p_);
+ assert(prebreak_p_->daddy_l_ == this);
+ assert(postbreak_p_->daddy_l_ == this);
+ }
+#endif
+}
+
+void
+PCol::set_breakable()
+{
+ if (breakable_b())
+ return;
+
+ prebreak_p_ = new PCol(this);
+ postbreak_p_ = new PCol(this);
+ prebreak_p_->pscore_l_ = pscore_l_;
+ postbreak_p_->pscore_l_ = pscore_l_;
+}
+
+bool
+PCol::breakable_b() const
+{
+ return prebreak_p_||postbreak_p_;
+}
+
+PCol::PCol(PCol *parent)
+{
+ daddy_l_ = parent;
+ prebreak_p_=0;
+ postbreak_p_=0;
+ line_l_=0;
+ hpos = -1.0;
+ pscore_l_ = 0;
+}
+
+PCol::~PCol()
+{
+ delete prebreak_p_;
+ delete postbreak_p_;
+}
+
+void
+PCol::add( Item *i)
+{
+ its.bottom().add(i);
+ i->pcol_l_ = this;
+}
+
+bool
+PCol::used_b()const
+{
+ return breakable_b() || its.size();
+}
--- /dev/null
+#include "idealspacing.hh"
+#include "debug.hh"
+#include "lookup.hh"
+#include "spanner.hh"
+#include "paper-def.hh"
+#include "molecule.hh"
+#include "dimen.hh"
+#include "scoreline.hh"
+#include "pscore.hh"
+#include "tex-stream.hh"
+#include "item.hh"
+#include "break.hh"
+
+Idealspacing*
+PScore::get_spacing(PCol*l, PCol*r)
+{
+ assert(l!=r);
+
+ Idealspacing*i_p =new Idealspacing(l,r);
+ suz.bottom().add(i_p);
+
+ return i_p;
+}
+
+
+void
+PScore::clean_cols()
+{
+ for (iter_top(cols,c); c.ok(); )
+ if (!c->used_b()) {
+ delete c.remove_p();
+ } else
+ c++;
+}
+
+
+void
+PScore::add(PStaff *s)
+{
+ assert(s->pscore_l_ == this);
+ staffs.bottom().add(s);
+}
+
+
+void
+PScore::do_connect(PCol *c1, PCol *c2, Real d, Real h)
+{
+ if (!c1 || !c2 )
+ return;
+ Idealspacing*s_l=get_spacing(c1,c2);
+
+
+ s_l->hooke = h;
+ s_l->space =d;
+}
+
+void
+PScore::connect(PCol* c1, PCol *c2, Real d, Real h)
+{
+ do_connect(c1,c2,d,h);
+ do_connect(c1->postbreak_p_, c2,d,h);
+ do_connect(c1, c2->prebreak_p_,d,h);
+ do_connect(c1->postbreak_p_, c2->prebreak_p_,d,h);
+}
+
+void
+PScore::typeset_item(Item *i, PCol *c, PStaff *s, int breakstat)
+{
+ assert(c && i && s);
+
+ if (breakstat == 0) {
+ typeset_item(i, c->prebreak_p_, s);
+ return;
+ }
+
+ if (breakstat == 2) {
+ typeset_item(i, c->postbreak_p_, s);
+ return;
+ }
+
+
+ its.bottom().add(i);
+ s->add(i);
+ c->add(i);
+
+ /* first do this, because i->width() may follow the 0-pointer */
+ i->add_processing();
+}
+
+void
+PScore::typeset_spanner(Spanner*span_p, PStaff*ps)
+{
+ span_p->pstaff_l_ = ps;
+ spanners.bottom().add(span_p);
+ ps->spans.bottom().add(span_p);
+
+ // do not init start/stop fields. These are for broken spans only.
+ span_p->add_processing();
+}
+
+
+void
+PScore::add(PCol *p)
+{
+ p->pscore_l_ = this;
+ if (p->breakable_b()){
+ p->prebreak_p_->pscore_l_ = this;
+ p->postbreak_p_->pscore_l_ = this;
+ }
+ cols.bottom().add(p);
+}
+
+PScore::PScore( Paper_def*p)
+{
+ paper_l_ = p;
+}
+
+void
+PScore::output(Tex_stream &ts)
+{
+ int l=1;
+
+ ts << "\n "<< paper_l_->lookup_p_->texsetting << "%(Tex id)\n";
+ for (iter_top(lines,lic); lic.ok(); lic++) {
+ ts << "% line of score no. " << l++ <<"\n";
+ ts << lic->TeXstring();
+ if ((lic+1).ok())
+ ts << "\\interscoreline\n";
+ }
+}
+
+
+Array<Item*>
+PScore::select_items(PStaff*ps, PCol*pc)
+{
+ Array<Item*> ret;
+ assert(ps && pc);
+ for (iter_top(pc->its,i); i.ok(); i++){
+ if (i->pstaff_l_ == ps)
+ ret.push((Item*)(const Item*)i);
+ }
+ return ret;
+}
+
+void
+PScore::OK()const
+{
+#ifdef NDEBUG
+ for (iter_top(cols,cc); cc.ok(); cc++)
+ cc->OK();
+ for (iter_top(suz,i); i.ok(); i++)
+ i->OK();
+#endif
+}
+
+void
+PScore::print() const
+{
+#ifndef NPRINT
+ mtor << "PScore { ";
+ paper_l_->print();
+ mtor << "\ncolumns: ";
+ for (iter_top(cols,cc); cc.ok(); cc++)
+ cc->print();
+
+ mtor << "\nideals: ";
+ for (iter_top(suz,i); i.ok(); i++)
+ i->print();
+ mtor << "}\n";
+#endif
+}
+
+void
+PScore::preprocess()
+{
+ for (iter_top(spanners,i); i.ok(); i++) {
+ i->pre_processing();
+ }
+ for (iter_top(its,i); i.ok(); i++){
+ i->pre_processing();
+ }
+}
+
+void
+PScore::postprocess()
+{
+ for (iter_top(broken_spans,i); i.ok(); i++) { // could chase spans as well.
+ i->post_processing();
+ }
+ for (iter_top(its,i); i.ok(); i++){
+ i->post_processing();
+ }
+
+ for (iter_top(broken_spans,i); i.ok(); i++) {
+ i->molecule_processing();
+ }
+ for (iter_top(its,i); i.ok(); i++){
+ i->molecule_processing();
+ }
+
+ for (iter_top(lines,i); i.ok(); i++)
+ i->process();
+
+}
+
+PCursor<PCol *>
+PScore::find_col(const PCol *c)const
+{
+ const PCol*what = c;
+ if (what->daddy_l_ )
+ what = what->daddy_l_;
+
+ return cols.find((PCol*)what);
+}
+
+void
+PScore::add_broken(Spanner*s)
+{
+ assert(s->left->line_l_ == s->right->line_l_);
+ broken_spans.bottom().add(s);
+ s->left->starters.bottom().add (s);
+ s->right->stoppers.bottom().add (s);
+}
+
+void
+PScore::set_breaking(Array<Col_hpositions> breaking)
+{
+ for (int j=0; j < breaking.size(); j++) {
+ Array<PCol*> &curline(breaking[j].cols);
+ Array<Real> &config(breaking[j].config);
+
+ Line_of_score *s_p = new Line_of_score(curline,this);
+ lines.bottom().add(s_p);
+ for (int i=0; i < curline.size(); i++){
+ curline[i]->hpos = config[i];
+ }
+ }
+}
+
+void
+PScore::calc_breaking()
+{
+ Word_wrap w(*this);
+ set_breaking(w.solve());
+}
+
+void
+PScore::process()
+{
+ clean_cols();
+ *mlog << "Preprocessing ... " <<flush;
+ preprocess();
+ *mlog << "\nCalculating column positions ... " <<flush;
+ calc_breaking();
+ *mlog << "\nPostprocessing ..." << endl;
+ postprocess();
+}
--- /dev/null
+#include "pstaff.hh"
+#include "molecule.hh"
+
+PStaff::PStaff(PScore*ps)
+{
+ pscore_l_=ps;
+}
+
+void
+PStaff::add(Item *i)
+{
+ its.bottom().add(i);
+ i->pstaff_l_ = this;
+}
--- /dev/null
+#include "debug.hh"
+#include "const.hh"
+#include "qlp.hh"
+#include "choleski.hh"
+
+void
+Mixed_qp::add_equality_cons(Vector , double )
+{
+ assert(false);
+}
+
+void
+Mixed_qp::add_fixed_var(int i, Real r)
+{
+ eq_cons.push(i);
+ eq_consrhs.push(r);
+}
+
+void
+Ineq_constrained_qp::add_inequality_cons(Vector c, double r)
+{
+ cons.push(c);
+ consrhs.push(r);
+}
+
+Ineq_constrained_qp::Ineq_constrained_qp(int novars):
+ quad(novars),
+ lin(novars),
+ const_term (0.0)
+{
+}
+
+void
+Ineq_constrained_qp::OK() const
+{
+#ifndef NDEBUG
+ assert(cons.size() == consrhs.size());
+ Matrix Qdif= quad - quad.transposed();
+ assert(Qdif.norm()/quad.norm() < EPS);
+#endif
+}
+
+
+Real
+Ineq_constrained_qp::eval (Vector v)
+{
+ return v * quad * v + lin * v + const_term;
+}
+
+/**
+ eliminate appropriate variables, until we have a Ineq_constrained_qp
+ then solve that.
+
+ PRE
+ cons should be ascending
+ */
+Vector
+Mixed_qp::solve(Vector start) const
+{
+ print();
+ Ineq_constrained_qp pure(*this);
+
+ for (int i= eq_cons.size()-1; i>=0; i--) {
+ pure.eliminate_var(eq_cons[i], eq_consrhs[i]);
+ start.del(eq_cons[i]);
+ }
+ Vector sol = pure.solve(start);
+ for (int i= 0; i < eq_cons.size(); i++) {
+ sol.insert( eq_consrhs[i],eq_cons[i]);
+ }
+ return sol;
+}
+
+/*
+ assume x(idx) == value, and adjust constraints, lin and quad accordingly
+
+ TODO: add const_term
+ */
+void
+Ineq_constrained_qp::eliminate_var(int idx, Real value)
+{
+ Vector row(quad.row(idx));
+ row*= value;
+
+ quad.delete_row(idx);
+
+ quad.delete_column(idx);
+
+ lin.del(idx);
+ row.del(idx);
+ lin +=row ;
+
+ for (int i=0; i < cons.size(); i++) {
+ consrhs[i] -= cons[i](idx) *value;
+ cons[i].del(idx);
+ }
+}
+
+
+
+void
+Ineq_constrained_qp::assert_solution(Vector sol) const
+{
+ Array<int> binding;
+ for (int i=0; i < cons.size(); i++) {
+ Real R=cons[i] * sol- consrhs[i];
+ assert(R> -EPS);
+ if (R < EPS)
+ binding.push(i);
+ }
+ // KKT check...
+ // todo
+}
+
+void
+Ineq_constrained_qp::print() const
+{
+#ifndef NPRINT
+ mtor << "Quad " << quad;
+ mtor << "lin " << lin <<"\n"
+ << "const " << const_term<<"\n";
+ for (int i=0; i < cons.size(); i++) {
+ mtor << "constraint["<<i<<"]: " << cons[i] << " >= " << consrhs[i];
+ mtor << "\n";
+ }
+#endif
+}
+
+/* *************** */
+
+Mixed_qp::Mixed_qp(int n)
+ : Ineq_constrained_qp(n)
+{
+}
+
+void
+Mixed_qp::OK() const
+{
+#ifndef NDEBUG
+ Ineq_constrained_qp::OK();
+ assert(eq_consrhs.size() == eq_cons.size());
+#endif
+}
+
+void
+Mixed_qp::print() const
+{
+#ifndef NPRINT
+ Ineq_constrained_qp::print();
+ for (int i=0; i < eq_cons.size(); i++) {
+ mtor << "eq cons "<<i<<": x["<<eq_cons[i]<<"] == " << eq_consrhs[i]<<"\n";
+ }
+#endif
+}
+
--- /dev/null
+#include "qlpsolve.hh"
+#include "const.hh"
+#include "debug.hh"
+#include "choleski.hh"
+
+const Real TOL=1e-2; // roughly 1/10 mm
+
+String
+Active_constraints::status() const
+{
+ String s("Active|Inactive [");
+ for (int i=0; i< active.size(); i++) {
+ s += String(active[i]) + " ";
+ }
+
+ s+="| ";
+ for (int i=0; i< inactive.size(); i++) {
+ s += String(inactive[i]) + " ";
+ }
+ s+="]";
+
+ return s;
+}
+
+void
+Active_constraints::OK()
+{
+ #ifndef NDEBUG
+ H.OK();
+ A.OK();
+ assert(active.size() +inactive.size() == opt->cons.size());
+ assert(H.dim() == opt->dim());
+ assert(active.size() == A.rows());
+ Array<int> allcons;
+
+ for (int i=0; i < opt->cons.size(); i++)
+ allcons.push(0);
+ for (int i=0; i < active.size(); i++) {
+ int j = active[i];
+ allcons[j]++;
+ }
+ for (int i=0; i < inactive.size(); i++) {
+ int j = inactive[i];
+ allcons[j]++;
+ }
+ for (int i=0; i < allcons.size(); i++)
+ assert(allcons[i] == 1);
+#endif
+}
+
+Vector
+Active_constraints::get_lagrange(Vector gradient)
+{
+ Vector l(A*gradient);
+
+ return l;
+}
+
+void
+Active_constraints::add(int k)
+{
+ // add indices
+ int cidx=inactive[k];
+ active.push(cidx);
+
+ inactive.swap(k,inactive.size()-1);
+ inactive.pop();
+
+ Vector a( opt->cons[cidx] );
+ // update of matrices
+ Vector Ha = H*a;
+ Real aHa = a*Ha;
+ Vector addrow(Ha.dim());
+ if (abs(aHa) > EPS) {
+ /*
+ a != 0, so if Ha = O(EPS), then
+ Ha * aH / aHa = O(EPS^2/EPS)
+
+ if H*a == 0, the constraints are dependent.
+ */
+ H -= Matrix(Ha/aHa , Ha);
+
+
+ /*
+ sorry, don't know how to justify this. ..
+ */
+ addrow=Ha;
+ addrow/= aHa;
+ A -= Matrix(A*a, addrow);
+ A.insert_row(addrow,A.rows());
+ }else
+ WARN << "degenerate constraints";
+}
+
+void
+Active_constraints::drop(int k)
+{
+ int q=active.size()-1;
+
+ // drop indices
+ inactive.push(active[k]);
+ active.swap(k,q);
+ A.swap_rows(k,q);
+ active.pop();
+
+ Vector a(A.row(q));
+ if (a.norm() > EPS) {
+ /*
+
+ */
+ Real q = a*opt->quad*a;
+ H += Matrix(a,a/q);
+ A -= A*opt->quad*Matrix(a,a/q);
+ }else
+ WARN << "degenerate constraints";
+ #ifndef NDEBUG
+ Vector rem_row(A.row(q));
+ assert(rem_row.norm() < EPS);
+ #endif
+
+ A.delete_row(q);
+}
+
+
+Active_constraints::Active_constraints(Ineq_constrained_qp const *op)
+ : A(0,op->dim()),
+ H(op->dim()),
+ opt(op)
+{
+ for (int i=0; i < op->cons.size(); i++)
+ inactive.push(i);
+ Choleski_decomposition chol(op->quad);
+ H=chol.inverse();
+}
+
+/** Find the optimum which is in the planes generated by the active
+ constraints.
+ */
+Vector
+Active_constraints::find_active_optimum(Vector g)
+{
+ return H*g;
+}
+
+/* *************************************************************** */
+
+int
+min_elt_index(Vector v)
+{
+ Real m=INFTY; int idx=-1;
+ for (int i = 0; i < v.dim(); i++){
+ if (v(i) < m) {
+ idx = i;
+ m = v(i);
+ }
+ assert(v(i) <= INFTY);
+ }
+ return idx;
+}
+
+
+/**the numerical solving. Mordecai Avriel, Nonlinear Programming: analysis and methods (1976)
+ Prentice Hall.
+
+ Section 13.3
+
+ This is a "projected gradient" algorithm. Starting from a point x
+ the next point is found in a direction determined by projecting
+ the gradient onto the active constraints. (well, not really the
+ gradient. The optimal solution obeying the active constraints is
+ tried. This is why H = Q^-1 in initialisation) )
+
+
+ */
+Vector
+Ineq_constrained_qp::solve(Vector start) const
+{
+ Active_constraints act(this);
+
+
+ act.OK();
+
+
+ Vector x(start);
+ Vector gradient=quad*x+lin;
+// Real fvalue = x*quad*x/2 + lin*x + const_term;
+// it's no use.
+
+ Vector last_gradient(gradient);
+ int iterations=0;
+
+ while (iterations++ < MAXITER) {
+ Vector direction= - act.find_active_optimum(gradient);
+
+ mtor << "gradient "<< gradient<< "\ndirection " << direction<<"\n";
+
+ if (direction.norm() > EPS) {
+ mtor << act.status() << '\n';
+
+ Real minalf = INFTY;
+
+ Inactive_iter minidx(act);
+
+
+ /*
+ we know the optimum on this "hyperplane". Check if we
+ bump into the edges of the simplex
+ */
+
+ for (Inactive_iter ia(act); ia.ok(); ia++) {
+
+ if (ia.vec() * direction >= 0)
+ continue;
+ Real alfa= - (ia.vec()*x - ia.rhs())/
+ (ia.vec()*direction);
+
+ if (minalf > alfa) {
+ minidx = ia;
+ minalf = alfa;
+ }
+ }
+ Real unbounded_alfa = 1.0;
+ Real optimal_step = min(minalf, unbounded_alfa);
+
+ Vector deltax=direction * optimal_step;
+ x += deltax;
+ gradient += optimal_step * (quad * deltax);
+
+ mtor << "step = " << optimal_step<< " (|dx| = " <<
+ deltax.norm() << ")\n";
+
+ if (minalf < unbounded_alfa) {
+ /* bumped into an edge. try again, in smaller space. */
+ act.add(minidx.idx());
+ mtor << "adding cons "<< minidx.idx()<<'\n';
+ continue;
+ }
+ /*ASSERT: we are at optimal solution for this "plane"*/
+
+
+ }
+
+ Vector lagrange_mult=act.get_lagrange(gradient);
+ int m= min_elt_index(lagrange_mult);
+
+ if (m>=0 && lagrange_mult(m) > 0) {
+ break; // optimal sol.
+ } else if (m<0) {
+ assert(gradient.norm() < EPS) ;
+
+ break;
+ }
+
+ mtor << "dropping cons " << m<<'\n';
+ act.drop(m);
+ }
+ if (iterations >= MAXITER)
+ WARN<<"didn't converge!\n";
+
+ mtor << ": found " << x<<" in " << iterations <<" iterations\n";
+ assert_solution(x);
+ return x;
+}
+
+
--- /dev/null
+/*
+ register.cc -- implement Request_register
+
+ Sourcefile of LilyPond musictypesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include "voice.hh"
+#include "musicalrequest.hh"
+#include "register.hh"
+#include "notehead.hh"
+#include "complex-walker.hh"
+#include "local-key-item.hh"
+#include "complex-staff.hh"
+#include "registergroup.hh"
+#include "debug.hh"
+
+
+bool
+Request_register::try_request(Request*)
+{
+ return false;
+}
+
+Request_register::Request_register()
+{
+ daddy_reg_l_ = 0;
+}
+
+void
+Request_register::announce_element(Staff_elem_info i)
+{
+ i.origin_reg_l_arr_.push(this);
+ daddy_reg_l_->announce_element(i);
+}
+
+void
+Request_register::typeset_element(Staff_elem*p)
+{
+ daddy_reg_l_->typeset_element(p);
+}
+
+Paper_def*
+Request_register::paper()const
+{
+ return daddy_reg_l_->paper();
+}
+
+void
+Request_register::typeset_breakable_item(Item * pre_p , Item * nobreak_p,
+ Item * post_p)
+{
+ daddy_reg_l_->typeset_breakable_item(pre_p, nobreak_p, post_p);
+}
+
+bool
+Request_register::acceptable_request_b(Request*)const
+{
+ return false;
+}
+
+bool
+Request_register::contains_b(Request_register *reg_l)
+{
+ return this == reg_l;
+}
+
+Staff_info
+Request_register::get_staff_info() return inf;
+{
+ inf = daddy_reg_l_->get_staff_info();
+}
+
+void
+Request_register::print() const
+{
+#ifndef NPRINT
+ mtor << name() << " {";
+ do_print();
+ mtor << "}\n";
+#endif
+}
+
+void
+Request_register::do_print()const
+{
+}
--- /dev/null
+/*
+ registergroup.cc -- implement Register_group_register
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include "proto.hh"
+#include "plist.hh"
+#include "registergroup.hh"
+#include "register.hh"
+
+bool
+Register_group_register::acceptable_request_b(Request* r)
+{
+ for (iter_top(reg_list_, i); i.ok(); i++) {
+ if (i->acceptable_request_b(r))
+ return true;
+ }
+ return false;
+}
+
+void
+Register_group_register::set_feature(Features d)
+{
+ for (iter_top(reg_list_, i); i.ok(); i++) {
+ i->set_feature(d);
+ }
+}
+
+void
+Register_group_register::pre_move_processing()
+{
+ for (iter_top(reg_list_, i); i.ok(); i++)
+ i->pre_move_processing();
+}
+
+void
+Register_group_register::process_requests()
+{
+ for (iter_top(reg_list_, i); i.ok(); i++)
+ i->process_requests();
+}
+
+void
+Register_group_register::post_move_processing()
+{
+ for (iter_top(reg_list_, i); i.ok(); i++)
+ i->post_move_processing();
+}
+
+void
+Register_group_register::acknowledge_element(Staff_elem_info info)
+{
+ if (!contains_b(info.origin_reg_l_arr_[0]))
+ return;
+
+ for (iter_top(reg_list_, i); i.ok(); i++)
+ i->acknowledge_element(info);
+}
+
+bool
+Register_group_register::contains_b(Request_register* reg_l)
+{
+ bool parent_b = Request_register::contains_b(reg_l);
+
+ if (parent_b)
+ return true;
+ for (iter_top(reg_list_, j); j.ok(); j++)
+ if (j->contains_b(reg_l))
+ return true;
+ return false;
+}
+
+
+
+bool
+Register_group_register::try_request(Request*req_l)
+{
+ for (iter_top(reg_list_, i); i.ok(); i++)
+ if (i->try_request(req_l))
+ return true;
+ return false;
+}
+
+void
+Register_group_register::add(Request_register *reg_p)
+{
+ reg_list_.bottom().add(reg_p);
+ reg_p->daddy_reg_l_ = this;
+}
+
+
+Register_group_register::~Register_group_register()
+{
+
+}
+
+Request_register *
+Register_group_register::get_register_p(Request_register*reg_l)
+{
+ iterator(reg_list_) reg_cur= reg_list_.find(reg_l);
+ assert(reg_cur.ok());
+ return reg_cur.remove_p();
+}
+
+void
+Register_group_register::terminate_register(Request_register*r_l)
+{
+ delete get_register_p(r_l);
+}
+
+void
+Register_group_register::do_print()const
+{
+#ifndef NPRINT
+ for (iter_top(reg_list_, i); i.ok(); i++)
+ i->print();
+#endif
+}
--- /dev/null
+/*
+ request.cc -- implement all musical requests.
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include "musicalrequest.hh"
+#include "misc.hh"
+#include "debug.hh"
+#include "script-def.hh"
+#include "text-def.hh"
+#include "voice.hh"
+#include "voice-element.hh"
+
+void
+Stem_req::do_print() const
+{
+ Rhythmic_req::do_print();
+ mtor << "dir : " << dir_i_;
+}
+
+Stem_req::Stem_req(int s, int d)
+ : Rhythmic_req(s,d)
+{
+ dir_i_ = 0;
+}
+
+/* ************** */
+void Musical_req::do_print()const{}
+void Request::do_print() const{}
+
+/* *************** */
+
+void
+Request::print() const
+{
+ mtor << name() << " {";
+ do_print();
+ mtor << "}\n";
+}
+
+
+
+void
+Span_req::do_print() const
+{
+#ifndef NPRINT
+ mtor << spantype ;
+#endif
+}
+
+Request::Request()
+{
+ elt_l_ = 0;
+ defined_ch_c_l_ = 0;
+}
+Request::Request(Request const&src)
+{
+ elt_l_ = 0;
+ defined_ch_c_l_ = src.defined_ch_c_l_;
+}
+/* *************** */
+Spacing_req::Spacing_req()
+{
+ next = 0;
+ distance = 0;
+ strength = 0;
+}
+void
+Spacing_req::do_print()const
+{
+ mtor << "next " << next << "dist " << distance << "strength\n";
+}
+
+void
+Blank_req::do_print()const
+{
+ Spacing_req::do_print();
+}
+/* *************** */
+Melodic_req::Melodic_req()
+{
+ notename_i_ = 0;
+ octave_i_ = 0;
+ accidental_i_ = 0;
+ forceacc_b_ = false;
+}
+
+void
+Melodic_req::do_print() const
+{
+ mtor << "notename: " << notename_i_ << " acc: " <<accidental_i_<<" oct: "<< octave_i_;
+}
+
+int
+Melodic_req::height() const
+{
+ return notename_i_ + octave_i_*7;
+}
+
+/*
+ should be settable from input to allow "viola"-mode
+ */
+static Byte pitch_byte_a[ 7 ] = { 0, 2, 4, 5, 7, 9, 11 };
+
+int
+Melodic_req::pitch() const
+{
+ return pitch_byte_a[ notename_i_ % 7 ] + accidental_i_ + octave_i_ * 12;
+}
+
+Plet_req::Plet_req()
+{
+ type_c_ = ']';
+ dur_i_ = 1;
+ type_i_ = 1;
+}
+
+void
+Plet_req::do_print() const
+{
+ mtor << "plet: " << type_c_ << ": " << dur_i_ << "/" << type_i_;
+}
+
+/* *************** */
+int
+Rhythmic_req::compare(const Rhythmic_req &r1, const Rhythmic_req &r2)
+{
+ return sign(r1.duration() - r2.duration());
+}
+Rhythmic_req::Rhythmic_req(int b, int d)
+{
+ plet_factor = 1;
+ balltype = b;
+ dots = d;
+}
+
+Rhythmic_req::Rhythmic_req()
+{
+ plet_factor = 1;
+ balltype = 1;
+ dots = 0;
+}
+
+void
+Rhythmic_req::do_print() const
+{
+ mtor << "ball: " << balltype ;
+ int d =dots;
+ while (d--)
+ mtor << '.';
+
+ mtor<<", plet factor"<<plet_factor<<"\n";
+}
+
+
+Moment
+Rhythmic_req::duration() const {
+ return wholes(balltype,dots)*plet_factor;
+}
+/* *************** */
+
+Lyric_req::Lyric_req(Text_def* def_p)
+ :Text_req(0, def_p)
+{
+ def_p->align_i_ = 0; // centre
+ dir_i_ = -1; // lyrics below (invisible) staff
+}
+
+void
+Lyric_req::do_print() const
+{
+ Rhythmic_req::do_print();
+ Text_req::do_print();
+}
+/* *************** */
+void
+Note_req::do_print() const
+{
+ Melodic_req::do_print();
+ Rhythmic_req::do_print();
+}
+/* *************** */
+void
+Rest_req::do_print() const
+{
+ Rhythmic_req::do_print();
+}
+
+/* *************** */
+Beam_req::Beam_req()
+{
+ nplet = 0;
+}
+
+void Beam_req::do_print()const{}
+/* *************** */
+void Slur_req::do_print()const{}
+/* *************** */
+int
+Span_req:: compare(const Span_req &r1, const Span_req &r2)
+{
+ return r1.spantype - r2.spantype;
+}
+
+Span_req::Span_req()
+{
+ spantype = NOSPAN;
+}
+
+/* *************** */
+Script_req::Script_req(int d , Script_def*def)
+{
+ dir_i_ = d;
+ scriptdef_p_ = def;
+}
+
+int
+Script_req::compare(const Script_req &d1, const Script_req &d2)
+{
+ return d1.dir_i_ == d2.dir_i_ &&
+ d1.scriptdef_p_->compare(*d2.scriptdef_p_);
+}
+
+Script_req::Script_req(Script_req const &s)
+ : Request( s )
+{
+ dir_i_ = s.dir_i_;
+ scriptdef_p_ = new Script_def(*s.scriptdef_p_);
+}
+
+void
+Script_req::do_print() const
+{
+ mtor << " dir " << dir_i_ ;
+ scriptdef_p_->print();
+}
+
+
+Script_req::~Script_req()
+{
+ delete scriptdef_p_;
+}
+/* *************** */
+int
+Text_req:: compare(const Text_req &r1, const Text_req &r2)
+{
+ bool b1 = (r1.dir_i_ == r2.dir_i_);
+ bool b2 = (r1.tdef_p_ ->compare(*r2.tdef_p_));
+ return b1 && b2;
+}
+Text_req::~Text_req()
+{
+ delete tdef_p_;
+ tdef_p_ = 0;
+}
+
+Text_req::Text_req(Text_req const& src)
+{
+ tdef_p_ = new Text_def(*src.tdef_p_);
+ dir_i_ = src.dir_i_;
+}
+
+Text_req::Text_req(int dir_i, Text_def* tdef_p)
+{
+ dir_i_ = dir_i;
+ tdef_p_ = tdef_p;
+}
+
+void
+Text_req::do_print() const
+{
+ mtor << " dir " << dir_i_ ;
+ tdef_p_->print();
+}
+
+/* *************** */
+
+Moment
+Skip_req::duration() const
+{
+ return duration_;
+}
+
+void
+Skip_req::do_print() const
+{
+ mtor << "duration: " << duration();
+}
+
+Voice *
+Request::voice_l()
+{
+ if (!elt_l_)
+ return 0;
+ else
+ return (Voice*)elt_l_->voice_l_;
+}
--- /dev/null
+#include "rest.hh"
+#include "dimen.hh"
+#include "debug.hh"
+#include "paper-def.hh"
+#include "lookup.hh"
+#include "molecule.hh"
+
+
+Rest::Rest(int t, int d)
+{
+ balltype = t;
+ dots = d;
+}
+
+
+void
+Rest::do_print()const
+{
+#ifndef NPRINT
+ mtor << "Rest "<<balltype<< "dots " << dots;
+ Item::print();
+#endif
+}
+
+Molecule*
+Rest::brew_molecule_p()const
+{
+ Paper_def *p =paper();
+
+ Symbol s;
+ s = p->lookup_p_->rest(balltype);
+
+ Molecule *m = new Molecule(Atom(s));
+ if (dots) {
+ Symbol d =p->lookup_p_->dots(dots);
+ Molecule dm;
+ dm.add(Atom(d));
+ m->add_right(dm);
+ }
+ return m;
+}
+
--- /dev/null
+/*
+ score-column.cc -- implement Score_column
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include "debug.hh"
+#include "pcol.hh"
+#include "score-column.hh"
+
+int
+Score_column::compare(Score_column & c1, Score_column &c2)
+{
+ return sign(c1.when_ - c2.when_);
+}
+
+void
+Score_column::set_breakable()
+{
+ pcol_l_->set_breakable();
+}
+
+Score_column::Score_column(Moment w)
+{
+ when_ = w;
+ pcol_l_ = new PCol(0);
+ musical_b_ = false;
+}
+
+bool
+Score_column::used_b() {
+ return pcol_l_->used_b();
+}
+
+void
+Score_column::print() const
+{
+#ifndef NPRINT
+ mtor << "Score_column { mus "<< musical_b_ <<" at " << when_<<'\n';
+ mtor << "durations: [";
+ for (int i=0; i < durations.size(); i++)
+ mtor << durations[i] << " ";
+ mtor << "]\n";
+ pcol_l_->print();
+ mtor << "}\n";
+#endif
+}
+
+int
+Moment_compare(Moment &a , Moment& b)
+{
+ return sign(a-b);
+}
+
+void
+Score_column::preprocess()
+{
+ durations.sort(Moment_compare);
+}
+void
+Score_column::add_duration(Moment d)
+{
+ assert(d);
+ for (int i = 0; i< durations.size(); i++) {
+ if (d == durations[i])
+ return ;
+ }
+ durations.push(d);
+}
+
+bool
+Score_column::breakable_b()
+{
+ return pcol_l_->breakable_b();
+}
--- /dev/null
+/*
+ score-walker.cc -- implement Score_walker
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+#include "proto.hh"
+#include "plist.hh"
+#include "debug.hh"
+#include "score-walker.hh"
+#include "score.hh"
+#include "staff-walker.hh"
+#include "staff.hh"
+#include "score-column.hh"
+
+Score_walker::Score_walker(Score *s)
+ :PCursor<Score_column *> (s->cols_)
+{
+ score_l_ = s;
+ for (iter_top(s->staffs_,i); i.ok(); i++) {
+ Staff_walker* w_p=i->get_walker_p();
+ w_p->score_walk_l_ =this;
+ walker_p_arr_.push(w_p);
+ }
+
+ if(ok()) {
+ s->find_col(0, false)->set_breakable();
+ s->find_col(s->last(), false)->set_breakable();
+ }
+ reinit();
+}
+
+
+void
+Score_walker::reinit()
+{
+ disallow_break_walk_l_arr = walker_p_arr_;
+ disallow_break_count_ = disallow_break_walk_l_arr.size();
+}
+
+
+/** Advance the cursor, and all Staff_walkers contained in this. Reset
+ runtime fields */
+void
+Score_walker::operator ++(int )
+{
+ Moment last = ptr()->when();
+
+ PCursor<Score_column *>::operator++(0);
+ if (ok() && ptr()->when() == last)
+ PCursor<Score_column *>::operator++(0);
+ reinit();
+ if (!ok())
+ return;
+ for (int i=0; i< walker_p_arr_.size(); i++) {
+ if (walker_p_arr_[i]->ok() &&
+ walker_p_arr_[i]->when() < when()) {
+
+ walker_p_arr_[i]->operator++(0);
+ }
+ }
+}
+
+/** Allow the command_column to be breakable for one staff. If all
+ staffs allow, then allow a break here. */
+void
+Score_walker::allow_break(Staff_walker*w)
+{
+ for (int i=0; i < disallow_break_walk_l_arr.size(); i++) {
+ if (w == disallow_break_walk_l_arr[i]) {
+ disallow_break_count_ --;
+ disallow_break_walk_l_arr[i] =0;
+
+ if (!disallow_break_count_) {
+ PCursor<Score_column*> col_cursor = *this;
+ if (ptr()->musical_b())
+ col_cursor --;
+ col_cursor->set_breakable();
+ }
+ }
+ }
+}
+
+Moment
+Score_walker::when()
+{
+ return ptr()->when();
+}
+
+void
+Score_walker::process()
+{
+ for (int i=0; i < walker_p_arr_.size(); i++) {
+ Staff_walker *w = walker_p_arr_[i];
+ if ( w->ok() && w->when() == when() ) {
+ walker_p_arr_[i]->process();
+ }
+ }
+ if (when().denominator() == 1) {
+ *mlog << "." <<flush;
+ }
+}
+
+Score_walker::~Score_walker()
+{
+ for (int i=0; i < walker_p_arr_.size(); i++)
+ delete walker_p_arr_[i];
+ assert( !score_l_->find_col(score_l_->last(), true)->used_b());
+}
+
+
--- /dev/null
+/*
+ score.cc -- implement Score
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+#include "tex-stream.hh"
+#include "score.hh"
+#include "score-column.hh"
+#include "pscore.hh"
+#include "staff.hh"
+#include "debug.hh"
+#include "paper-def.hh"
+#include "main.hh"
+#include "source.hh"
+#include "source-file.hh"
+#include "score-walker.hh"
+#include "midi-output.hh"
+#include "midi-def.hh"
+
+extern String default_out_fn;
+
+void
+Score::setup_music()
+{
+ *mlog << "\nSetting up music ..." << flush;
+ if (last() == Moment(0)) {
+ errorlevel_i_ |= 1;
+ error("Need to have music in a score.", defined_ch_c_l_);
+ }
+
+ for (iter_top(staffs_,i); i.ok(); i++) {
+ i->setup_staffcols();
+ i->OK();
+ }
+}
+
+void
+Score::process_music()
+{
+ *mlog << "Processing music ..." << flush;
+ for (Score_walker w(this); w.ok(); w++) {
+ w.process();
+ }
+}
+
+void
+Score::process()
+{
+ setup_music();
+
+ paper();
+ midi();
+}
+
+void
+Score::paper()
+{
+ if (!paper_p_)
+ return;
+
+ pscore_p_ = new PScore(paper_p_);
+
+ find_col(0, false)->set_breakable(); // ugh
+ find_col(last(), false)->set_breakable();
+ do_cols();
+
+ for (iter_top(staffs_,i); i.ok(); i++)
+ i->set_output(pscore_p_);
+
+
+ process_music();
+ clean_cols(); // can't move clean_cols() farther up.
+ print();
+ calc_idealspacing();
+
+ // debugging
+ OK();
+ *mlog << endl;
+ pscore_p_->process();
+
+ // output
+ paper_output();
+
+}
+
+/**
+ Remove empty cols, preprocess other columns.
+ */
+void
+Score::clean_cols()
+{
+ for (iter_top(staffs_,i); i.ok(); i++)
+ i->clean_cols();
+
+ for (iter_top(cols_,c); c.ok(); ) {
+ if (!c->pcol_l_->used_b()) {
+ delete c.remove_p();
+ } else {
+ c->preprocess();
+ c++;
+ }
+ }
+}
+
+/**
+ Create columns at time #w#.
+ this sux. We should have Score_column create the appropriate PCol.
+ Unfortunately, PCols don't know about their position.
+
+ @return cursor pointing to the nonmusical (first) column
+ */
+PCursor<Score_column*>
+Score::create_cols(Moment w)
+{
+ Score_column* c1 = new Score_column(w);
+ Score_column* c2 = new Score_column(w);
+
+ c1->musical_b_ = false;
+ c2->musical_b_ = true;
+
+ iter_top(cols_,i);
+
+ for (; i.ok(); i++) {
+ assert(i->when() != w);
+ if (i->when() > w)
+ break;
+ }
+
+ if (!i.ok()) {
+ cols_.bottom().add(c1);
+ cols_.bottom().add(c2);
+ i = cols_.bottom();
+ i --;
+ } else {
+ i.insert(c1);
+ i.insert(c2);
+ i -= 2;
+ }
+ return i;
+}
+
+PCursor<Score_column*>
+Score::find_col(Moment w, bool mus)
+{
+ iter_top( cols_,i);
+
+ for (; i.ok(); i++) {
+ if (i->when() == w && i->musical_b_ == mus)
+ return i;
+ if (i->when() > w)
+ break;
+ }
+ i = create_cols(w);
+ if (mus)
+ i++;
+ return i;
+}
+
+void
+Score::do_cols()
+{
+ iter_top(cols_,i);
+ for (; i.ok(); i++) {
+ pscore_p_->add(i->pcol_l_);
+ }
+}
+
+Moment
+Score::last() const
+{
+ Moment l = 0;
+ for (iter_top(staffs_,i); i.ok(); i++) {
+ l = l>? i->last();
+ }
+ return l;
+}
+
+void
+Score::set(Paper_def *pap_p)
+{
+ delete paper_p_;
+ paper_p_ = pap_p;
+}
+
+void
+Score::set(Midi_def* midi_p)
+{
+ delete midi_p_;
+ midi_p_ = midi_p;
+}
+
+void
+Score::OK() const
+{
+#ifndef NDEBUG
+ for (iter_top(staffs_,i); i.ok(); i++) {
+ i->OK();
+ assert(i->score_l_ == this);
+ }
+ staffs_.OK();
+ cols_.OK();
+ for (iter_top(cols_,cc); cc.ok() && (cc+1).ok(); cc++) {
+ assert(cc->when() <= (cc+1)->when());
+ }
+#endif
+}
+
+
+void
+Score::print() const
+{
+#ifndef NPRINT
+ mtor << "score {\n";
+ for (iter_top(staffs_,i); i.ok(); i++) {
+ i->print();
+ }
+ for (iter_top(cols_,i); i.ok(); i++) {
+ i->print();
+ }
+ if (pscore_p_)
+ pscore_p_->print();
+ if (midi_p_)
+ midi_p_->print();
+
+ mtor << "}\n";
+#endif
+}
+
+Score::Score()
+{
+ pscore_p_=0;
+ paper_p_ = 0;
+ midi_p_ = 0;
+ errorlevel_i_ = 0;
+ defined_ch_c_l_ = 0;
+}
+
+Score::~Score()
+{
+ delete pscore_p_;
+ delete paper_p_;
+ delete midi_p_;
+}
+
+void
+Score::paper_output()
+{
+ OK();
+ if (paper_p_->outfile=="")
+ paper_p_->outfile = default_out_fn + ".out";
+
+ if ( errorlevel_i_ ) {
+ *mlog << "lilypond: warning: no output to: " << paper_p_->outfile
+ << " (errorlevel=" << errorlevel_i_ << ")" << endl;
+ return;
+ }
+
+ *mlog << "TeX output to " << paper_p_->outfile << " ...\n";
+
+ Tex_stream the_output(paper_p_->outfile);
+
+ the_output << "% outputting Score, defined at: " <<
+ source_l_g->
+ sourcefile_l (defined_ch_c_l_)->file_line_no_str(defined_ch_c_l_) << "\n";
+ pscore_p_->output(the_output);
+}
+
+void
+Score::midi()
+{
+ if (!midi_p_)
+ return;
+
+ if (midi_p_->outfile_str_ == "")
+ midi_p_->outfile_str_ = default_out_fn + ".midi";
+
+ *mlog << "midi output to " << midi_p_->outfile_str_ << " ...\n";
+ Midi_output(this, midi_p_);
+}
+
+void
+Score::add(Staff*s)
+{
+ s->score_l_ = this;
+ staffs_.bottom().add(s);
+}
--- /dev/null
+#include "scoreline.hh"
+#include "staffline.hh"
+#include "dimen.hh"
+#include "spanner.hh"
+#include "symbol.hh"
+#include "paper-def.hh"
+#include "pcol.hh"
+#include "pscore.hh"
+
+
+String
+Line_of_score::TeXstring() const
+{
+ String s("\\vbox{%<- line of score\n");
+ for (iter_top(staffs,sc); sc.ok(); sc++){
+ s += sc->TeXstring();
+ if ((sc+1).ok())
+ s+= "\\interstaffline\n";
+ }
+ s += "}";
+ return s;
+}
+
+
+Line_of_score::Line_of_score(Array<PCol *> sv,
+ PScore *ps)
+{
+ pscore_l_ = ps;
+ for (int i=0; i< sv.size(); i++) {
+ PCol *p=(PCol *) sv[i];
+ cols.bottom().add(p);
+ p->line_l_=this;
+ }
+
+ for (iter_top(pscore_l_->staffs,sc); sc.ok(); sc++)
+ staffs.bottom().add(new Line_of_staff(this, sc));
+}
+/* construct a line with the named columns. Make the line field
+ in each column point to this
+
+ #sv# isn't really const!!
+ */
+
+
+void
+Line_of_score::process()
+{
+ for (iter_top(staffs,i); i.ok(); i++)
+ i->process();
+}
+
--- /dev/null
+#include "main.hh"
+#include "input-score.hh"
+#include "score.hh"
+#include "string.hh"
+#include "paper-def.hh"
+#include "debug.hh"
+
+static Array<Input_score*> score_array_global;
+String default_out_fn = "lelie";
+
+void
+do_scores()
+{
+ for (int i=0; i < score_array_global.size(); i++) {
+ Input_score* &is_p = score_array_global[i];
+ if (is_p->errorlevel_i_) {
+ warning("Score contains errors. Will not process it. ",
+ is_p->defined_ch_c_l_);
+ delete is_p;
+ continue;
+ }
+
+ if (only_midi) {
+ delete is_p->paper_p_;
+ is_p->paper_p_ = 0;
+ }
+
+ Score * s_p = is_p->parse();
+ delete is_p;
+ s_p->print ();
+ s_p->process();
+ delete s_p;
+ }
+ score_array_global.set_size(0);
+}
+
+void
+add_score(Input_score * s)
+{
+ score_array_global.push(s);
+}
+
+void
+set_default_output(String s)
+{
+ default_out_fn = s;
+}
+
--- /dev/null
+#include "debug.hh"
+#include "script-def.hh"
+
+Script_def::Script_def(String idx, int stem, int staff ,bool invert)
+{
+ symidx = idx ;
+ stemdir =stem;
+ staffdir = staff;
+ invertsym = invert;
+}
+void
+Script_def::print() const
+{
+ mtor << "Script_def{ idx: " << symidx
+ << " direction, stem: " << stemdir << " staff : " << staffdir << "}\n";
+}
+int
+Script_def::compare(Script_def const & c)
+{
+ return !(symidx == c.symidx &&
+ stemdir == c.stemdir&&
+ staffdir == c.staffdir&&
+ invertsym == c.invertsym);
+}
--- /dev/null
+/*
+ script-reg.cc -- implement Script_register
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include "script-reg.hh"
+#include "script.hh"
+#include "musicalrequest.hh"
+#include "complex-walker.hh"
+#include "stem.hh"
+
+Script_register::Script_register()
+{
+ script_p_ = 0;
+ post_move_processing();
+}
+
+bool
+Script_register::try_request(Request *r_l)
+{
+ if (!r_l->script())
+ return false ;
+
+ if (script_req_l_
+ && Script_req::compare(*script_req_l_, *r_l->script()))
+
+ return false;
+
+ script_req_l_ = r_l->script();
+
+ return true;
+}
+
+void
+Script_register::process_requests()
+{
+ if (script_req_l_) {
+ script_p_ = new Script(script_req_l_, 10);
+ announce_element(
+ Staff_elem_info(script_p_, script_req_l_));
+ }
+}
+
+void
+Script_register::acknowledge_element(Staff_elem_info info)
+{
+ if (!script_p_)
+ return;
+ if (info.elem_p_->name() == Stem::static_name())
+ script_p_->set_stem((Stem*)info.elem_p_);
+ else if (info.req_l_->rhythmic())
+ script_p_->set_support(info.elem_p_->item());
+}
+
+void
+Script_register::pre_move_processing()
+{
+ if (script_p_){
+ script_p_->dir = dir_i_;
+ typeset_element(script_p_);
+ script_p_ = 0;
+ }
+}
+void
+Script_register::post_move_processing()
+{
+ script_req_l_ = 0;
+}
+
+void
+Script_register::set_feature(Features i)
+{
+ if (i.direction_i_|| i.initialiser_b_)
+ dir_i_ = i.direction_i_;
+}
--- /dev/null
+#include "musicalrequest.hh"
+#include "paper-def.hh"
+#include "script.hh"
+#include "stem.hh"
+#include "molecule.hh"
+#include "lookup.hh"
+
+
+
+void
+Script::set_stem(Stem*st_l)
+{
+ stem_l_ = st_l;
+ add_dependency(st_l);
+}
+
+void
+Script::set_support(Item*i)
+{
+ support.push(i);
+ add_dependency(i);
+}
+
+Script::Script(Script_req* rq, int staflen)
+{
+ staffsize =staflen;
+ specs_l_ = rq->scriptdef_p_;
+ stem_l_ = 0;
+ pos = 0;
+ symdir=1;
+ dir =rq->dir_i_;
+}
+
+void
+Script::set_symdir()
+{
+ if (specs_l_->invertsym)
+ symdir = (dir < 0) ? -1:1;
+}
+
+void
+Script::set_default_dir()
+{
+ if (specs_l_->stemdir) {
+ if (!stem_l_)
+ dir = 1;
+ else
+ dir = stem_l_->dir * specs_l_->stemdir;
+ }
+}
+
+Interval
+Script::support_height() const return r;
+{
+ for (int i=0; i < support.size(); i++)
+ r.unite(support[i]->height());
+}
+
+void
+Script::set_default_index()
+{
+ Real inter_f= paper()->internote();
+ Interval dy = symbol().dim.y;
+
+ int d = specs_l_->staffdir;
+ Real y ;
+ if (!d) {
+ Interval v= support_height();
+ y = v[dir] -dy[-dir] + 2*dir*inter_f;
+ } else {
+ y = (d > 0) ? staffsize + 2: -2; // ug
+ y *=inter_f;
+ Interval v= support_height();
+
+ if (d > 0) {
+ y = y >? v.max();
+ } else if (d < 0) {
+ y = y <? v.min();
+ }
+ }
+
+ if (stem_l_) {
+ Interval v= stem_l_->height();
+
+ if (d > 0 || (!d && dir > 0)) {
+ y = y >? v.max();
+ }else if (d < 0 || (!d && dir < 0)) {
+ y = y <? v.min();
+ }
+ }
+
+ pos = int(rint(Real(y)/inter_f));
+}
+
+Interval
+Script::width() const
+{
+ return symbol().dim.x;
+}
+
+Symbol
+Script::symbol()const
+{
+ String preidx_str = (symdir < 0) ?"-" :"";
+ return paper()->lookup_p_->script(preidx_str + specs_l_->symidx);
+}
+
+void
+Script::do_pre_processing()
+{
+ set_default_dir();
+ set_symdir();
+}
+
+void
+Script::do_post_processing()
+{
+ set_default_index();
+}
+
+Molecule*
+Script::brew_molecule_p() const
+{
+ Real dy = paper()->internote();
+
+ Molecule*out = new Molecule(Atom(symbol()));
+ out->translate(Offset(0,dy * pos));
+ return out;
+}
--- /dev/null
+/*
+ slur-reg.cc -- implement Slur_register
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include "proto.hh"
+#include "plist.hh"
+#include "musicalrequest.hh"
+#include "complex-walker.hh"
+#include "slur-reg.hh"
+#include "slur.hh"
+#include "debug.hh"
+#include "notehead.hh"
+
+void
+Slur_register::set_feature(Features i)
+{
+ dir_i_ = i.direction_i_;
+}
+
+Slur_register::Slur_register()
+{
+ set_feature(Features::dir(0));
+}
+
+bool
+Slur_register::try_request(Request *req_l)
+{
+ if(!req_l->slur())
+ return false;
+
+ new_slur_req_l_arr_.push(req_l->slur());
+ return true;
+}
+
+void
+Slur_register::acknowledge_element(Staff_elem_info info)
+{
+ if (info.elem_p_->name() == Notehead::static_name()) {
+ Notehead *head_p =(Notehead*) info.elem_p_ ;// ugh
+ for (int i = 0; i < slur_l_stack_.size(); i++)
+ slur_l_stack_[i]->add(head_p );
+ for (int i = 0; i < end_slur_l_arr_.size(); i++)
+ end_slur_l_arr_[i]->add(head_p);
+ }
+}
+/*
+ abracadabra
+ */
+void
+Slur_register::process_requests()
+{
+ Array<Slur*> start_slur_l_arr_;
+ for (int i=0; i< new_slur_req_l_arr_.size(); i++) {
+ Slur_req* slur_req_l = new_slur_req_l_arr_[i];
+ // end slur: move the slur to other array
+ if (slur_req_l->spantype == Span_req::STOP) {
+ if (slur_l_stack_.empty())
+ warning("can't find slur to end",
+ slur_req_l->defined_ch_c_l_);
+ else {
+ end_slur_l_arr_.push(slur_l_stack_.pop());
+ requests_arr_.pop();
+ }
+ } else if (slur_req_l->spantype == Span_req::START) {
+ // push a new slur onto stack.
+ //(use temp. array to wait for all slur STOPs)
+ Slur * s_p =new Slur;
+ requests_arr_.push(slur_req_l);
+ start_slur_l_arr_.push(s_p);
+ announce_element(Staff_elem_info(s_p, slur_req_l));
+ }
+ }
+ for (int i=0; i < start_slur_l_arr_.size(); i++)
+ slur_l_stack_.push(start_slur_l_arr_[i]);
+}
+
+void
+Slur_register::pre_move_processing()
+{
+ for (int i = 0; i < end_slur_l_arr_.size(); i++) {
+ if (dir_i_)
+ end_slur_l_arr_[i]->dir_i_ = dir_i_;
+ typeset_element(end_slur_l_arr_[i]);
+ }
+ end_slur_l_arr_.set_size(0);
+}
+
+void
+Slur_register::post_move_processing()
+{
+ new_slur_req_l_arr_.set_size(0);
+}
+Slur_register::~Slur_register()
+{
+ for (int i=0; i < requests_arr_.size(); i++) {
+ warning("unterminated slur", requests_arr_[i]->defined_ch_c_l_);
+ }
+}
--- /dev/null
+/*
+
+ TODO:
+ think about crossing stems.
+ */
+#include "slur.hh"
+#include "scalar.hh"
+#include "lookup.hh"
+#include "paper-def.hh"
+#include "notehead.hh"
+#include "pcol.hh"
+#include "molecule.hh"
+#include "debug.hh"
+#include "boxes.hh"
+
+
+
+Slur::Slur()
+{
+ open_right=open_left=false;
+}
+
+Offset
+Slur::center() const
+{
+ int pos1 = encompass.top()->position;
+ int pos2 = encompass[0]->position;
+
+ int dy = pos1-pos2;
+
+ Real w = width().length();
+
+ return Offset(w/2,dy * paper()->internote());
+}
+
+void
+Slur::add(Notehead*n)
+{
+ encompass.push(n);
+ add_dependency(n);
+}
+
+void
+Slur::set_default_dir()
+{
+ int sumpos=0;
+ for (int i=0; i < encompass.size(); i ++) {
+ sumpos += encompass[i]->position;
+ }
+
+ /* should consult stems */
+ Real meanpos = sumpos/Real(encompass.size());
+ if (meanpos < 5) // todo
+ dir_i_ = -1;
+ else
+ dir_i_ = 1;
+}
+
+void
+Slur::do_pre_processing()
+{
+ right = encompass.top()->pcol_l_;
+ left = encompass[0]->pcol_l_;
+}
+
+Spanner*
+Slur::do_break_at(PCol*l, PCol*r) const
+{
+ assert(l->line_l_ == r->line_l_);
+ Slur*ret = new Slur(*this);
+
+ ret->encompass.set_size(0);
+ for (int i =0; i < encompass.size(); i++) {
+ if (encompass[i]->pcol_l_->line_l_==l->line_l_)
+ ret->encompass.push(encompass[i]);
+ }
+ if (right != r)
+ ret->open_right = true;
+ if (left != l)
+ ret->open_left = true;
+
+
+ return ret;
+}
+
+void
+Slur::do_post_processing()
+{
+ if (!dir_i_)
+ set_default_dir();
+}
+
+Molecule*
+Slur::brew_molecule_p() const
+{
+ Molecule*output = new Molecule;
+
+ int minp=1000, maxp=-1000; // todo
+ for (int i=0; i<encompass.size(); i++) {
+ minp = encompass[i]->position <? minp;
+ maxp = encompass[i]->position >? maxp;
+ }
+ assert(encompass.size()>0); // todo
+
+ Notehead *lnote_p =encompass[0];
+ Notehead *rnote_p =encompass.top();
+ int lpos_i = lnote_p->position;
+ int rpos_i = rnote_p->position;
+ Offset left_off(lnote_p->x_dir, lpos_i + 2*dir_i_);
+ Offset right_off(lnote_p->x_dir, rpos_i + 2*dir_i_);
+ if (!lnote_p->extremal)
+ left_off += Offset(0.5, -dir_i_);
+ if (!rnote_p->extremal)
+ right_off+= Offset(-0.5, -dir_i_);
+
+ int dy = int(right_off.y - left_off.y);
+
+ Real nw_f = paper()->note_width();
+ Real nh_f = paper()->internote();
+ Real w = width().length();
+
+ w+= (right_off.x - left_off.x) * nw_f ;
+ Real round_w = w; // slur lookup rounds the slurwidth .
+
+ Symbol sl = paper()->lookup_p_->slur(dy , round_w, dir_i_);
+
+ Real error = w-round_w;
+
+ Atom a(sl);
+ a.translate(Offset((left_off.x + 0.5 )*nw_f + error/2,
+ left_off.y * nh_f));
+ output->add(a);
+ return output;
+}
+
--- /dev/null
+#include "debug.hh"
+#include "spanner.hh"
+#include "pcol.hh"
+
+
+
+void
+Spanner::do_print()const
+{
+ mtor << " (unknown) ";
+}
+
+Spanner*
+Spanner::broken_at(PCol*c1, PCol *c2)const
+{
+ Spanner *span_p = do_break_at(c1,c2);
+
+ for (int i=0; i < dependants.size(); i++) {
+ dependants[i]->substitute_dependency((Staff_elem*)this, span_p);
+ }
+
+ span_p->left = c1;
+ span_p->right = c2;
+
+ return span_p;
+}
+
+Spanner::Spanner()
+{
+ left = right = 0;
+}
+
+
+Interval
+Spanner::width()const
+{
+ Real r = right->hpos;
+ Real l = left->hpos;
+ assert(*left < *right);
+ assert(r>=l);
+
+ return Interval(0, r-l);
+}
--- /dev/null
+/*
+ staff-column.cc -- implement Staff_column
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+#include "proto.hh"
+#include "plist.hh"
+#include "staff.hh"
+#include "voice.hh"
+#include "time-description.hh"
+#include "score-column.hh"
+#include "staff-column.hh"
+#include "commandrequest.hh"
+#include "musicalrequest.hh"
+#include "interval.hh"
+#include "pscore.hh"
+#include "item.hh"
+#include "pcol.hh"
+#include "voice-element.hh"
+
+void
+Staff_column::OK() const
+{
+#ifndef NDEBUG
+ assert (command_column_l_->when() == musical_column_l_->when());
+#endif
+}
+
+Moment
+Staff_column::when() const
+{
+ return (command_column_l_)?
+ command_column_l_->when():
+ musical_column_l_->when();
+}
+
+void
+Staff_column::add(Voice_element*ve)
+{
+ for (iter_top(ve->reqs,j); j.ok(); j++) {
+ if (j->command()) {
+ Command_req * c_l = j->command();
+ if (c_l->timing()) {
+ timing_req_l_arr_.push(j->command()->timing());
+ }
+ if (c_l->groupchange())
+ creationreq_l_arr_.push(c_l);
+ else if (!c_l->barcheck() && !c_l->partial() &&
+ !c_l->measuregrouping())
+ setup_one_request(j); // no need to bother children
+ } else {
+ if (j->rhythmic()) {
+ musical_column_l_->add_duration(j->rhythmic()->duration());
+ }
+ if (!j->musical()->skip())
+ setup_one_request(j);
+ }
+ }
+}
+
+Staff_column::Staff_column()
+{
+ musical_column_l_ = 0;
+ command_column_l_ = 0;
+ staff_l_ = 0;
+}
+
+
+
+
+Staff_column::~Staff_column()
+{
+}
+
+void
+Staff_column::set_cols(Score_column*c1, Score_column*c2)
+{
+ command_column_l_ = c1;
+ musical_column_l_ = c2;
+}
+
+void
+Staff_column::setup_one_request(Request * j)
+{
+ if (j->command()) // ugh
+ commandreq_l_arr_.push(j);
+ else if (j->musical())
+ musicalreq_l_arr_.push(j);
+}
+
+void
+Staff_column::typeset_musical_item(Item*i)
+{
+ assert(i);
+ Score_column * scorecolumn_l = musical_column_l_;
+ musical_column_l_->pcol_l_->pscore_l_->typeset_item(i, scorecolumn_l->pcol_l_,
+ staff_l_->pstaff_l_);
+}
+
+/**
+ align items in #item_l_arr#,
+
+ @return the width of the items after aligning.
+ */
+Interval
+align_items(Array<Item*> item_l_arr)
+{
+ Interval wid(0,0);
+ for (int i =0; i < item_l_arr.size(); i++) {
+ Interval item_width= item_l_arr[i]->width();
+ Real dx =wid.right - item_width.left;
+ item_width += dx;
+ item_l_arr[i]->translate(Offset(dx ,0));
+ wid.unite(item_width);
+ }
+ return wid;
+}
+
+void
+translate_items(Real x, Array<Item*> item_l_arr)
+{
+ for (int i =0; i < item_l_arr.size(); i++)
+ item_l_arr[i]->translate(Offset(x, 0));
+}
+/*
+ UGR
+ This still sux
+ */
+void
+Staff_column::typeset_breakable_items(Array<Item *> &pre_p_arr,
+ Array<Item *> &nobreak_p_arr,
+ Array<Item *> &post_p_arr)
+{
+ PCol * c= command_column_l_->pcol_l_;
+ PScore *ps_l=command_column_l_->pcol_l_->pscore_l_;
+
+ if (!c->breakable_b()) {
+ for (int i =0; i < pre_p_arr.size(); i++)
+ delete pre_p_arr[i];
+ pre_p_arr.set_size(0);
+ for (int i =0; i < post_p_arr.size(); i++)
+ delete post_p_arr[i];
+ post_p_arr.set_size(0);
+ }
+
+
+ for (int i =0; i < pre_p_arr.size(); i++) {
+ ps_l->typeset_item(pre_p_arr[i], c, staff_l_->pstaff_l_,0);
+ }
+ for (int i =0; i < nobreak_p_arr.size(); i++) {
+ ps_l->typeset_item(nobreak_p_arr[i], c, staff_l_->pstaff_l_,1);
+ }
+ for (int i =0; i < post_p_arr.size(); i++) {
+ ps_l->typeset_item(post_p_arr[i], c, staff_l_->pstaff_l_,2);
+ }
+
+ Interval pre_wid= align_items(pre_p_arr);
+ translate_items( -pre_wid.right, pre_p_arr);
+ align_items(nobreak_p_arr);
+ Interval post_wid =align_items(post_p_arr);
+ translate_items (-post_wid.left , post_p_arr);
+
+ pre_p_arr.set_size(0);
+ post_p_arr.set_size(0);
+ nobreak_p_arr.set_size(0);
+}
--- /dev/null
+/*
+ staff-elem-info.cc -- implement Staff_elem_info
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include "staff-elem-info.hh"
+#include "request.hh"
+
+Staff_elem_info::Staff_elem_info(Staff_elem*s_l, Request*r_l)
+{
+ elem_p_ = s_l;
+ voice_l_ = (r_l)?r_l->voice_l():0;
+ req_l_ = r_l;
+}
+
+Staff_elem_info::Staff_elem_info()
+{
+ elem_p_ = 0;
+ voice_l_ = 0;
+
+ req_l_ = 0;
+}
+
+Features::Features()
+{
+ direction_i_ = 0;
+ initialiser_b_ = false;
+}
+
+Features
+Features::dir(int d) return f;
+{
+ f.initialiser_b_ = true;
+ f.direction_i_ = d;
+}
--- /dev/null
+#include "pscore.hh"
+#include "symbol.hh"
+#include "pstaff.hh"
+#include "molecule.hh"
+#include "staff-elem.hh"
+#include "debug.hh"
+
+String
+Staff_elem::TeXstring() const
+{
+ Molecule m(*output);
+ m.translate(offset_); // ugh?
+ return m.TeXstring();
+}
+
+Staff_elem::Staff_elem(Staff_elem const&s)
+ : dependants(s.dependants),
+ dependencies(s.dependencies)
+{
+ status = s.status;
+ assert(!s.output);
+ output = 0;
+ pstaff_l_ = s.pstaff_l_;
+ offset_ = Offset(0,0);
+}
+/**
+ TODO:
+ If deleted, then remove dependants depency!
+ */
+Staff_elem::~Staff_elem()
+{
+ delete output;
+}
+
+void
+Staff_elem::translate(Offset O)
+{
+ offset_ += O;
+}
+Interval
+Staff_elem::width() const
+{
+ Interval r;
+
+ if (!output){
+ Molecule*m = brew_molecule_p();
+ r = m->extent().x;
+ delete m;
+ } else
+ r = output->extent().x;
+
+ if (!r.empty()) // float exception on DEC Alpha
+ r+=offset_.x;
+
+ return r;
+}
+Interval
+Staff_elem::height() const
+{
+ Interval r;
+
+ if (!output){
+ Molecule*m = brew_molecule_p();
+ r = m->extent().y;
+ delete m;
+ } else
+ r = output->extent().y;
+
+ if (!r.empty())
+ r+=offset_.y;
+
+
+ return r;
+}
+
+void
+Staff_elem::print()const
+{
+#ifndef NPRINT
+ mtor << name() << "{\n";
+ do_print();
+ if (output)
+ output->print();
+
+ mtor << "}\n";
+#endif
+}
+
+
+
+Staff_elem::Staff_elem()
+{
+ pstaff_l_=0;
+ offset_ = Offset(0,0);
+ output = 0;
+ status = ORPHAN;
+}
+
+
+Paper_def*
+Staff_elem::paper() const
+{
+ assert(pstaff_l_);
+ return pstaff_l_->pscore_l_->paper_l_;
+}
+
+void
+Staff_elem::add_processing()
+{
+ if (status >= VIRGIN)
+ return;
+ status = VIRGIN;
+ do_add_processing();
+}
+
+void
+Staff_elem::pre_processing()
+{
+ if (status >= PRECALCED )
+ return;
+ assert(status != PRECALCING); // cyclic dependency
+ status = PRECALCING;
+
+ for (int i=0; i < dependencies.size(); i++)
+ if (dependencies[i])
+ dependencies[i]->pre_processing();
+
+
+ do_pre_processing();
+ status = PRECALCED;
+}
+void
+Staff_elem::post_processing()
+{
+ if (status >= POSTCALCED)
+ return;
+ assert(status != POSTCALCING);// cyclic dependency
+ status=POSTCALCING;
+
+ for (int i=0; i < dependencies.size(); i++)
+ if (dependencies[i])
+ dependencies[i]->post_processing();
+ do_post_processing();
+ status=POSTCALCED;
+}
+
+void
+Staff_elem::molecule_processing()
+{
+ if (status >= OUTPUT)
+ return;
+ status = OUTPUT; // do it only once.
+ for (int i=0; i < dependencies.size(); i++)
+ if (dependencies[i])
+ dependencies[i]->molecule_processing();
+
+ output= brew_molecule_p();
+}
+
+void
+Staff_elem::do_post_processing()
+{
+}
+
+void
+Staff_elem::do_pre_processing()
+{
+}
+
+void
+Staff_elem::do_add_processing()
+{
+}
+
+void
+Staff_elem::substitute_dependency(Staff_elem * old, Staff_elem * newdep)
+{
+ bool hebbes_b=false;
+ for (int i=0; i < dependencies.size(); i++) {
+ if (dependencies[i] == old){
+ dependencies[i] = newdep;
+ hebbes_b = true;
+ } else if (dependencies[i] == newdep) {
+ hebbes_b = true;
+ }
+ }
+ if (!hebbes_b)
+ dependencies.push(newdep);
+}
+
+void
+Staff_elem::add_dependency(Staff_elem * p)
+{
+ for (int i=0; i < dependencies.size(); i ++)
+ if (dependencies[i] == p)
+ return;
+
+ dependencies.push(p);
+ p->dependants.push(p);
+}
--- /dev/null
+/*
+ staff-walker.cc -- implement Staff_walker
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include "proto.hh"
+#include "plist.hh"
+#include "grouping.hh"
+#include "staff.hh"
+#include "musicalrequest.hh"
+#include "staff-walker.hh"
+#include "staff-column.hh"
+#include "score-column.hh"
+#include "debug.hh"
+#include "time-description.hh"
+#include "commandrequest.hh"
+#include "grouping.hh"
+#include "score-walker.hh"
+
+Staff_walker::~Staff_walker()
+{
+ do_pre_move();
+}
+
+Staff_walker::Staff_walker(Staff_walker const &s)
+ :PCursor<Staff_column*> (s)
+{
+ assert(false);
+}
+
+Staff_walker::Staff_walker(Staff * s, PScore*ps )
+ : PCursor<Staff_column*> (s->cols_)
+{
+ staff_l_ = s;
+ pscore_l_ = ps;
+
+ // should be in tdes. TODO
+ default_grouping = new Rhythmic_grouping(MInterval(0, 1), 4);
+ score_walk_l_ = 0;
+}
+
+Moment
+Staff_walker::when() const
+{
+ return ptr()->when();
+}
+
+
+void
+Staff_walker::process_timing_reqs()
+{
+ for (int i=0; i < ptr()->timing_req_l_arr_.size(); i++) {
+ Timing_req * tr_l = ptr()->timing_req_l_arr_[i];
+ if (tr_l->meterchange()) {
+ int b_i=tr_l->meterchange()->beats_i_;
+ int o_i = tr_l->meterchange()->one_beat_i_;
+ time_.set_meter(b_i, o_i);
+
+ *default_grouping = Rhythmic_grouping(
+ MInterval(0,Moment(b_i, o_i)), b_i);
+ }
+ }
+
+ for (int i=0; i < ptr()->timing_req_l_arr_.size(); i++) {
+ Timing_req * tr_l = ptr()->timing_req_l_arr_[i];
+ if (tr_l->partial()) {
+ time_.setpartial(tr_l->partial()->duration_);
+ } else if (tr_l->barcheck() && time_.whole_in_measure_) {
+ warning( "Barcheck failed", tr_l->defined_ch_c_l_ );
+ } else if (tr_l->cadenza()) {
+ time_.set_cadenza(tr_l->cadenza()->on_b_);
+ } else if (tr_l->measuregrouping()) {
+ *default_grouping = parse_grouping(
+ tr_l->measuregrouping()->beat_i_arr_,
+ tr_l->measuregrouping()->elt_length_arr_);
+ }
+ }
+ time_.OK();
+}
+
+void
+Staff_walker::operator++(int i)
+{
+ Moment last = when();
+
+ do_pre_move();
+ PCursor<Staff_column*>::operator++(i);
+ if (ok() ) {
+ Moment delta_t = when() - last;
+ assert(delta_t >Moment(0));
+ time_.add( delta_t );
+ }
+ do_post_move();
+}
+
+void
+Staff_walker::process()
+{
+ process_timing_reqs();
+ process_requests();
+}
+
+void
+Staff_walker::allow_break()
+{
+ score_walk_l_->allow_break(this);
+}
+
--- /dev/null
+#include "proto.hh"
+#include "plist.hh"
+#include "staff.hh"
+#include "score.hh"
+#include "voice.hh"
+#include "staff-walker.hh"
+#include "staff-column.hh"
+#include "score-column.hh"
+#include "voice-element.hh"
+#include "debug.hh"
+#include "musicalrequest.hh"
+#include "commandrequest.hh" // todo
+#include "midi-stream.hh"
+
+void
+Staff::add(PointerList<Voice*> const &l)
+{
+ for (iter_top(l,i); i.ok(); i++)
+ voice_list_.bottom().add(i);
+}
+
+Paper_def *
+Staff::paper() const
+{
+ return score_l_->paper_p_;
+}
+
+void
+Staff::clean_cols()
+{
+ iter_top(cols_,i);
+ for(; i.ok(); ){
+ if (!i->musical_column_l_->used_b())
+ i->musical_column_l_ = 0;
+ if (!i->command_column_l_->used_b())
+ i->command_column_l_ =0;
+
+ if (!i->command_column_l_&& !i->musical_column_l_)
+ delete i.remove_p();
+ else
+ i++;
+ }
+}
+
+Staff_column *
+Staff::get_col(Moment w, PCursor<Staff_column*> *last)
+{
+ iter_top(cols_,i);
+ if (last && last->ok() && (*last)->when() <= w)
+ i = *last;
+
+ for (; i.ok(); i++) {
+ if (i->when() == w) {
+ if (last)
+ *last = i;
+ return i;
+ } else if (i->when() > w)
+ break;
+ }
+
+
+ PCursor<Score_column*> scorecolumns(score_l_->find_col(w, false));
+ Staff_column* staffcolumn_p = new Staff_column;
+ staffcolumn_p->staff_l_ = this;
+ Score_column* comcol_l = scorecolumns++;
+ staffcolumn_p->set_cols(comcol_l, scorecolumns);
+
+ if (!i.ok()) {
+ cols_.bottom().add( staffcolumn_p);
+ i = cols_.bottom();
+ } else {
+ i.insert(staffcolumn_p);
+ i--;
+ }
+ if (last)
+ *last = i;
+ return i;
+}
+
+/**
+ put all stuff grouped vertically in the Staff_cols.
+ Do the preprarations for walking the cols. not virtual
+ */
+void
+Staff::setup_staffcols()
+{
+ for (iter_top(voice_list_,i); i.ok(); i++) {
+ PCursor<Staff_column*> last(cols_);
+ Moment now = i->start;
+ for (iter_top(i->elts,j); j.ok(); j++) {
+
+ Staff_column *s_l= get_col(now, &last);
+ assert(now == s_l->when());
+ s_l->add(j);
+ now += j->duration;
+ }
+
+ }
+ OK();
+}
+
+void
+Staff::OK() const
+{
+#ifndef NDEBUG
+ cols_.OK();
+ voice_list_.OK();
+ iter_top(cols_, i);
+ iter_top(cols_, j);
+ i++;
+ for (; i.ok(); j++,i++) {
+ assert(j->when () < i->when() );
+ }
+ assert(score_l_);
+#endif
+}
+
+
+Moment
+Staff::last() const
+{
+ Moment l = 0;
+ for (iter_top(voice_list_,i); i.ok(); i++) {
+ l = l >? i->last();
+ }
+ return l;
+}
+
+void
+Staff::print() const
+{
+#ifndef NPRINT
+ mtor << "Staff {\n";
+ for (iter_top(voice_list_,i); i.ok(); i++) {
+ i->print();
+ }
+ mtor <<"}\n";
+#endif
+}
+
+Staff::Staff()
+{
+ score_l_ =0;
+ pscore_l_ =0;
+ pstaff_l_ =0;
+}
--- /dev/null
+#include "staffline.hh"
+#include "scoreline.hh"
+#include "dimen.hh"
+#include "spanner.hh"
+#include "symbol.hh"
+#include "paper-def.hh"
+#include "molecule.hh"
+#include "pcol.hh"
+#include "pscore.hh"
+
+static String
+make_vbox(Interval i)
+{
+ Real r = (i.empty()) ? 0.0 : i.length();
+ String s("\\vbox to ");
+ s += print_dimen(r);
+ s += "{\\vskip "+print_dimen(i.right)+" ";
+ return s;
+}
+
+
+String
+Line_of_staff::TeXstring() const
+{
+ String s("%line_of_staff\n");
+
+ s+=make_vbox(height());
+ // the staff itself: eg lines, accolades
+ s += "\\hbox{";
+ {
+ iter_top(line_of_score_l_->cols,cc);
+ Real lastpos=cc->hpos;
+
+ // all items in the current line & staff.
+ for (; cc.ok(); cc++) {
+ Real delta=cc->hpos - lastpos;
+ lastpos = cc->hpos;
+
+ // moveover
+ if (delta)
+ s +=String( "\\kern ") + print_dimen(delta);
+
+ // now output the items.
+ for (iter_top(cc->its,i); i.ok(); i++) {
+ if (i->pstaff_l_ == pstaff_l_)
+ s += i->TeXstring();
+ }
+ // spanners.
+ for (iter_top(cc->starters,i); i.ok(); i++)
+ if (i->pstaff_l_ == pstaff_l_)
+ s += i->TeXstring();
+ }
+ }
+ s+="\\hss}\\vss}";
+ return s;
+}
+
+Line_of_staff::Line_of_staff(Line_of_score * sc, PStaff*st)
+{
+ line_of_score_l_=sc;
+ pstaff_l_=st;
+
+ PCol *linestart = sc->cols.top();
+ PCol *linestop = sc->cols.bottom();
+
+ for (iter_top(pstaff_l_->spans,i); i.ok(); i++) {
+ PCol *brokenstart = &max(*linestart, *i->left);
+ PCol *brokenstop = &min(*linestop, *i->right);
+ if ( *brokenstart < *brokenstop) {
+ Spanner*span_p =i->broken_at(brokenstart,brokenstop);
+ line_of_score_l_->pscore_l_-> // higghl
+ add_broken(span_p);
+ }
+ }
+}
+
+
+Interval
+Line_of_staff::height() const
+{
+ Interval y(0,0);
+
+ iter_top(line_of_score_l_->cols,cc);
+
+ // all items in the current line & staff.
+ for (; cc.ok(); cc++) {
+ for (iter_top(cc->its,i); i.ok(); i++) {
+ if (i->pstaff_l_ == pstaff_l_)
+ y.unite(i->height());
+
+ }
+ // spanners.
+ for (iter_top(cc->starters,i); i.ok(); i++)
+ if (i->pstaff_l_ == pstaff_l_) {
+ y.unite(i->height());
+ }
+ }
+
+ return y;
+}
+
+void
+Line_of_staff::process()
+{
+#if 0
+ if (!pstaff_l_->stafsym_p_)
+ pstaff_l_->brew_molecule_p(line_of_score_l_->pscore_l_->
+ paper_l_->linewidth);
+#endif
+}
--- /dev/null
+/*
+ staffsym.cc -- implement Staff_symbol
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+#include "staffsym.hh"
+#include "lookup.hh"
+#include "paper-def.hh"
+#include "debug.hh"
+
+
+
+Staff_symbol::Staff_symbol(int l)
+{
+ no_lines_i_ = l;
+}
+
+void
+Staff_symbol::do_print()const
+{
+ mtor << "lines: " << no_lines_i_;
+}
+
+Molecule*
+Staff_symbol::brew_molecule_p() const
+{
+ Atom a = paper()->lookup_p_->linestaff(no_lines_i_, width().length());
+ return new Molecule(a);
+}
+
+Spanner*
+Staff_symbol::do_break_at(PCol*p1, PCol*p2)const
+{
+ Staff_symbol *span_p=new Staff_symbol(*this);
+ return span_p;
+}
+
+void
+Staff_symbol::set_extent(PCol*p1, PCol*p2)
+{
+ assert(p1&&p2);
+ left = p1;
+ right = p2;
+}
--- /dev/null
+/*
+ stem-beam-reg.cc -- part of LilyPond
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include "musicalrequest.hh"
+#include "stem-beam-reg.hh"
+#include "beam.hh"
+#include "stem.hh"
+#include "grouping.hh"
+#include "text-spanner.hh"
+#include "complex-walker.hh"
+#include "complex-staff.hh"
+#include "debug.hh"
+#include "grouping.hh"
+#include "notehead.hh"
+
+Stem_beam_register::Stem_beam_register()
+{
+ post_move_processing();
+ current_grouping = 0;
+ beam_p_ = 0;
+ set_feature(Features::dir(0));
+ start_req_l_ = 0;
+}
+
+bool
+Stem_beam_register::try_request(Request*req_l)
+{
+ if ( req_l->beam() ) {
+ if (bool(beam_p_ ) == bool(req_l->beam()->spantype == Span_req::START))
+ return false;
+
+ if (beam_req_l_ && Beam_req::compare(*beam_req_l_ , *req_l->beam()))
+ return false;
+
+ beam_req_l_ = req_l->beam();
+ return true;
+ }
+
+ if ( req_l->stem() ) {
+ if (current_grouping && !current_grouping->child_fit_query(
+ get_staff_info().time_c_l_->whole_in_measure_))
+ return false;
+
+ if (stem_req_l_ && Stem_req::compare(*stem_req_l_, *req_l->stem()))
+ return false;
+
+ stem_req_l_ = req_l->stem();
+ return true;
+ }
+ return false;
+}
+
+void
+Stem_beam_register::process_requests()
+{
+ if (beam_req_l_) {
+ if (beam_req_l_->spantype == Span_req::STOP) {
+ end_beam_b_ = true;
+ start_req_l_ = 0;
+ } else {
+ beam_p_ = new Beam;
+ start_req_l_ = beam_req_l_;
+
+ current_grouping = new Rhythmic_grouping;
+ if (beam_req_l_->nplet) {
+ Text_spanner* t = new Text_spanner();
+ t->set_support(beam_p_);
+ t->spec.align_i_ = 0;
+ t->spec.text_str_ = beam_req_l_->nplet;
+ t->spec.style_str_="italic";
+ typeset_element(t);
+ }
+
+ }
+ }
+
+ if (stem_req_l_) {
+ stem_p_ = new Stem(4);
+ if (current_grouping)
+ current_grouping->add_child(
+ get_staff_info().time_c_l_->whole_in_measure_,
+ stem_req_l_->duration());
+
+ stem_p_->flag = stem_req_l_->balltype;
+
+ if (beam_p_) {
+ if (stem_req_l_->balltype<= 4)
+ warning( "stem doesn't fit in Beam",
+ stem_req_l_->defined_ch_c_l_);
+ else
+ beam_p_->add(stem_p_);
+ stem_p_->print_flag = false;
+ } else {
+ stem_p_->print_flag = true;
+ }
+
+ announce_element(Staff_elem_info(stem_p_, stem_req_l_));
+ }
+}
+
+void
+Stem_beam_register::acknowledge_element(Staff_elem_info info)
+{
+ if (!stem_p_)
+ return;
+
+ if (info.elem_p_->name() == Notehead::static_name() &&
+ stem_req_l_->duration() == info.req_l_->rhythmic()->duration())
+
+ stem_p_->add((Notehead*)info.elem_p_);
+}
+
+void
+Stem_beam_register::pre_move_processing()
+{
+ if (stem_p_) {
+ if (default_dir_i_)
+ stem_p_->dir = default_dir_i_;
+
+ typeset_element(stem_p_);
+ stem_p_ = 0;
+ }
+ if (beam_p_ && end_beam_b_) {
+ const Rhythmic_grouping * rg_c_l = get_staff_info().rhythmic_c_l_;
+ rg_c_l->extend(current_grouping->interval());
+ beam_p_->set_grouping(*rg_c_l, *current_grouping);
+ typeset_element(beam_p_);
+ delete current_grouping;
+ current_grouping = 0;
+ beam_p_ = 0;
+ }
+ end_beam_b_ = false;
+}
+void
+Stem_beam_register::post_move_processing()
+{
+ stem_p_ = 0;
+ beam_req_l_ = 0;
+ stem_req_l_ = 0;
+ end_beam_b_ = false;
+}
+
+Stem_beam_register::~Stem_beam_register()
+{
+ if (beam_p_)
+ warning("unterminated beam", start_req_l_->defined_ch_c_l_);
+}
+
+void
+Stem_beam_register::set_feature(Features i)
+{
+ default_dir_i_ = i.direction_i_;
+}
--- /dev/null
+#include "stem.hh"
+#include "dimen.hh"
+#include "debug.hh"
+#include "paper-def.hh"
+#include "notehead.hh"
+#include "lookup.hh"
+#include "molecule.hh"
+#include "pcol.hh"
+#include "misc.hh"
+
+const int STEMLEN=7;
+
+
+Stem::Stem(int c) //, Moment len)
+{
+ beams_left = 0;
+ beams_right = 0;
+ minnote = 1000; // invalid values
+ maxnote = -1000;
+ bot = top = 0;
+ flag = 4;
+ dir =0;
+ staff_center=c;
+ stemlen=0;
+ print_flag=true;
+ stem_xoffset=0;
+}
+
+void
+Stem::do_print() const
+{
+#ifndef NPRINT
+ mtor << "flag "<< flag << " print_flag " << print_flag
+ << "min,max [" << minnote << ", " << maxnote << "]";
+#endif
+}
+void
+Stem::set_stemend(Real se)
+{
+
+ // todo: margins
+ if (! ((dir > 0 && se >= maxnote) || (se <= minnote && dir <0)) )
+ warning("Weird stem size; check for narrow beams",0);
+
+ top = (dir < 0) ? maxnote : se;
+ bot = (dir < 0) ? se : minnote;
+ flag = dir*abs(flag);
+}
+
+void
+Stem::add(Notehead *n)
+{
+ assert(status < PRECALCED);
+
+ if (n->balltype == 1)
+ return;
+ int p = n->position;
+ if (p < minnote)
+ minnote = p;
+ if (p > maxnote)
+ maxnote = p;
+ heads.push(n);
+ n->add_dependency(this);
+}
+
+
+int
+Stem::get_default_dir()
+{
+ if (dir)
+ return dir;
+ Real mean = (minnote+maxnote)/2;
+ return (mean > staff_center) ? -1: 1;
+}
+
+void
+Stem::set_default_dir()
+{
+ dir = get_default_dir();
+}
+
+void
+Stem::set_default_stemlen()
+{
+ if (!dir)
+ set_default_dir();
+
+ int stafftop = 2*staff_center;
+ stemlen = STEMLEN + (maxnote - minnote);
+
+ // uhh... how about non 5-line staffs?
+ if (maxnote < -2 && dir == 1){
+ int t = staff_center - staff_center/2;
+ stemlen = t - minnote +2;
+ } else if (minnote > stafftop + 2 && dir == -1) {
+ int t = staff_center + staff_center/2;
+ stemlen = maxnote -t +2;
+ }
+
+ assert(stemlen);
+}
+
+
+void
+Stem::set_default_extents()
+{
+ if (minnote > maxnote) {
+ warning("Empty stem. Ugh!", 0);
+ minnote = -10;
+ maxnote = 20;
+ }
+
+ if (!stemlen)
+ set_default_stemlen();
+
+ set_stemend((dir< 0) ? maxnote-stemlen: minnote +stemlen);
+ if (dir > 0){
+ stem_xoffset = paper()->note_width()-paper()->rule_thickness();
+ } else
+ stem_xoffset = 0;
+}
+
+void
+Stem::set_noteheads()
+{
+ if(!heads.size())
+ return;
+ heads.sort(Notehead::compare);
+ heads[0]->extremal = -1;
+ heads.top()->extremal = 1;
+ int parity=1;
+ int lastpos = heads[0]->position;
+ for (int i=1; i < heads.size(); i ++) {
+ int dy =abs(lastpos- heads[i]->position);
+
+ if (dy <= 1) {
+ if (parity)
+ heads[i]->x_dir = (stem_xoffset>0) ? 1:-1;
+ parity = !parity;
+ } else
+ parity = 0;
+ lastpos = heads[i]->position;
+ }
+}
+
+void
+Stem::do_pre_processing()
+{
+ if (bot == top)
+ set_default_extents();
+ set_noteheads();
+}
+
+
+Interval
+Stem::width()const
+{
+ if (!print_flag || abs(flag) <= 4)
+ return Interval(0,0); // TODO!
+ Paper_def*p= paper();
+ Interval r(p->lookup_p_->flag(flag).dim.x);
+ r+= stem_xoffset;
+ return r;
+}
+
+Molecule*
+Stem::brew_molecule_p()const return out;
+{
+ assert(bot!=top);
+
+
+ Paper_def *p =paper();
+
+ Real dy = p->internote();
+ Symbol ss =p->lookup_p_->stem(bot*dy,top*dy);
+
+
+ out = new Molecule(Atom(ss));
+
+ if (print_flag&&abs(flag) > 4){
+ Symbol fl = p->lookup_p_->flag(flag);
+ Molecule m(fl);
+ if (flag < -4){
+ out->add_bottom(m);
+ } else if (flag > 4) {
+ out->add_top(m);
+ } else
+ assert(false);
+ }
+
+ out->translate(Offset(stem_xoffset,0));
+}
+
+Real
+Stem::hindex()const
+{
+ return pcol_l_->hpos + stem_xoffset; // hmm. + offset_.x;
+}
+
+
--- /dev/null
+#include "symbol.hh"
+#include "varray.hh"
+
+
+Symbol::Symbol()
+ : dim(Interval(0,0),Interval(0,0))
+{
+ tex = "\\unknown";
+}
+Symbol::Symbol(String s, Box b)
+ : dim(b)
+{
+ tex = s;
+}
+
+
+String
+Symbol::str()const return s;
+{
+ s = "symbol(\'"+tex+"\', (" + dim.x.str() + ", " + dim.y.str() + "))";
+}
--- /dev/null
+#include "misc.hh"
+#include "dimen.hh"
+#include "debug.hh"
+#include "real.hh"
+#include "symbol.hh"
+#include "assoc.hh"
+#include "assoc-iter.hh"
+#include "symtable.hh"
+
+Symtables::Symtables()
+{
+}
+
+Symtables::Symtables(Symtables const &s)
+{
+ for (Assoc_iter<String, Symtable*> i(s); i.ok(); i++) {
+ add(i.key(), new Symtable(*i.val()));
+ }
+}
+
+Symtables::~Symtables()
+{
+ for (Assoc_iter<String, Symtable*> i(*this); i.ok(); i++) {
+ delete i.val();
+ }
+}
+
+Symbol
+Symtable::lookup(String s) const
+{
+ if (elt_query(s))
+ return (*this)[s];
+ else {
+ error( "Unknown symbol `" +s+"'\n");
+ }
+ Symbol sy; // unreachable
+ return sy;
+}
+
+Symtable*
+Symtables::operator()(String s)
+{
+ return Assoc<String, Symtable*>::operator[](s);
+}
+void
+Symtables::print() const
+{
+ for (Assoc_iter<String, Symtable*> i(*this); i.ok(); i++) {
+ mtor << "table \'" << i.key() << "\' {\n";
+ i.val()->print();
+ mtor << "}\n";
+ }
+}
+void
+Symtable::print() const
+{
+ for (Assoc_iter<String, Symbol> i(*this); i.ok(); i++) {
+ mtor << "\'" << i.key() << "\'->" << i.val().str() << "\n";
+ }
+}
+
--- /dev/null
+#include "proto.hh"
+#include "idealspacing.hh"
+#include "plist.hh"
+#include "pcol.hh"
+#include "item.hh"
+#include "musicalrequest.hh"
+#include "spanner.hh"
+#include "scoreline.hh"
+#include "staffline.hh"
+
+#include "pcursor.tcc"
+#include "plist.tcc"
+
+
+#define IPLC_instantiate(a) IPL_instantiate(a); PL_instantiate(const a)
+
+
+IPLC_instantiate(Line_of_score);
+IPLC_instantiate(Line_of_staff);
+IPLC_instantiate(Item);
+IPLC_instantiate(Spanner);
+IPLC_instantiate(PStaff);
+IPLC_instantiate(Idealspacing);
+IPLC_instantiate(PCol);
+
--- /dev/null
+/*
+ template2.cc -- instantiate some list templates.
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include "symbol.hh"
+#include "voice.hh"
+#include "voice-element.hh"
+#include "musicalrequest.hh"
+#include "staff.hh"
+#include "score-column.hh"
+#include "staff-column.hh"
+#include "spanner.hh"
+#include "plist.tcc"
+#include "pcursor.tcc"
+
+IPL_instantiate(Request);
+IPL_instantiate(Score_column);
+IPL_instantiate(Staff_column);
+IPL_instantiate(Staff);
+IPL_instantiate(Voice_element);
+IPL_instantiate(Voice);
+
+
--- /dev/null
+#include "request.hh"
+#include "input-score.hh"
+#include "input-staff.hh"
+#include "input-music.hh"
+#include "molecule.hh"
+#include "source-file.hh"
+#include "voice-element.hh"
+#include "plist.tcc"
+#include "pcursor.tcc"
+
+IPL_instantiate(Atom);
+IPL_instantiate(Atom);
+IPL_instantiate(Input_staff);
+IPL_instantiate(Input_music);
+IPL_instantiate(Source_file);
--- /dev/null
+/*
+ template4.cc -- instantiate PointerList baseclass.
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include "proto.hh"
+#include "list.tcc"
+#include "cursor.tcc"
+
+L_instantiate(void *);
--- /dev/null
+#include "proto.hh"
+#include "string.hh"
+#include "moment.hh"
+#include "real.hh"
+
+#include "interval.tcc"
+
+Interval__instantiate(Real);
+Interval__instantiate(Rational);
--- /dev/null
+#include "proto.hh"
+#include "plist.tcc"
+#include "register.hh"
+#include "voice-group-regs.hh"
+#include "voice-regs.hh"
+
+
+IPL_instantiate(Voice_registers);
+IPL_instantiate(Voice_group_registers);
+IPL_instantiate(Request_register);
--- /dev/null
+/*
+
+ Code to generate beams for TeX
+
+ */
+
+#include <math.h>
+#include "symbol.hh"
+#include "molecule.hh"
+#include "tex.hh"
+#include "symtable.hh"
+#include "dimen.hh"
+#include "debug.hh"
+#include "lookup.hh"
+
+Symbol
+Lookup::beam_element(int sidx, int widx, Real slope)
+{
+ Symbol bs=(*symtables_)("beamslopes")->lookup("slope");
+
+ Array<String> args;
+ args.push(sidx);
+ args.push(widx);
+ bs.tex = substitute_args(bs.tex,args);
+ int w = 2 << widx;
+ Real width = w PT;
+ bs.dim.x = Interval(0,width);
+ bs.dim.y = Interval(0,width*slope);
+ return bs;
+}
+
+// ugh.. hard wired tex-code.
+static int
+slope_index(Real &s)
+{
+ if (abs(s) > 0.5) {
+ WARN << "beam steeper than 0.5 (" << s << ")\n";
+ s = sign(s) * 0.5;
+ }
+
+ int i = int(rint(s * 20.0));
+
+ s = i/20.0;
+ if (s>0)
+ return 6*i +122;
+ else
+ return -6 * i+ 186;
+}
+
+Symbol
+Lookup::rule_symbol(Real height, Real width)
+{
+ Symbol bs=(*symtables_)("beamslopes")->lookup("horizontal");
+ Array<String> args;
+ args.push(print_dimen(height));
+ args.push(print_dimen(width));
+ bs.tex = substitute_args(bs.tex,args);
+ bs.dim.x = Interval(0,width);
+ bs.dim.y = Interval(0,height);
+ return bs;
+}
+
+Symbol
+Lookup::beam(Real &slope, Real width)
+{
+ int sidx = slope_index(slope);
+ if (!slope)
+ return rule_symbol(2 PT, width);
+ if (width < 2 PT) {
+ WARN<<"Beam too narrow. (" << print_dimen(width) <<")\n";
+ width = 2 PT;
+ }
+ Real elemwidth = 64 PT;
+ int widx = 5;
+
+ Molecule m;
+
+ while (elemwidth > width) {
+ widx --;
+ elemwidth /= 2.0;
+ }
+ Real overlap = elemwidth/4;
+ Real last_x = width - elemwidth;
+ Real x = overlap;
+ Atom elem(beam_element(sidx, widx, slope));
+ Atom a(elem);
+ m.add(a);
+ while (x < last_x) {
+ a=elem;
+ a.translate(Offset(x-overlap, (x-overlap)*slope));
+ m.add(a);
+ x += elemwidth - overlap;
+ }
+ a=elem;
+ a.translate(Offset(last_x, (last_x) * slope));
+ m.add(a);
+
+ Symbol ret;
+ ret.tex = m.TeXstring();
+ ret.dim.y = Interval(0,width*slope);
+ ret.dim.x = Interval(0,width);
+
+ return ret;
+}
+
+
--- /dev/null
+#include <math.h>
+#include "misc.hh"
+#include "lookup.hh"
+#include "molecule.hh"
+#include "dimen.hh"
+#include "debug.hh"
+
+static
+char direction_char(int y_sign)
+{
+ char c='#';
+ switch(y_sign){
+ case -1:
+ c = 'd';
+ break;
+ case 0:
+ c = 'h';
+ break;
+ case 1:
+ c = 'u';
+ break;
+ default:
+ assert(false);
+ }
+ return c;
+}
+
+Symbol
+Lookup::half_slur_middlepart(Real &dx, int dir)
+{
+ if (dx >= 400 PT) {// todo
+ WARN<<"halfslur too large" <<print_dimen(dx)<< "shrinking (ugh)\n";
+ dx = 400 PT;
+ }
+ int widx = int(floor(dx / 4.0));
+ dx = widx * 4.0;
+ if (widx) widx --;
+ else {
+ WARN << "slur too narrow\n";
+ }
+
+ Symbol s;
+
+ s.dim.y = Interval(min(0,0), max(0,0)); // todo
+ s.dim.x = Interval(0,dx);
+
+ String f = String("\\hslurchar");
+ f += direction_char(0);
+
+ int idx = widx;
+ if (dir < 0)
+ idx += 128;
+
+
+ f+=String( "{" ) + String( idx ) + "}";
+ s.tex = f;
+ Atom a(s);
+ a.translate(Offset(dx/2,0));
+ s.tex = a.TeXstring();
+
+ return s;
+}
+Symbol
+Lookup::half_slur(int dy, Real &dx, int dir, int xpart)
+{
+ Real orig_dx = dx;
+ if (!xpart)
+ return half_slur_middlepart(dx, dir);
+
+ int widx;
+
+ if (dx >= 96 PT) {
+ WARN << "Slur half too wide." << print_dimen(orig_dx) << " shrinking (ugh)\n";
+ dx = 96 PT;
+ }
+
+ widx = int(rint(dx/12.0));
+ dx = widx*12.0;
+ if (widx)
+ widx --;
+ else {
+ WARN << "slur too narrow " << print_dimen(orig_dx)<<"\n";
+ }
+
+ Symbol s;
+ s.dim.x = Interval(0,dx);
+ s.dim.y = Interval(min(0,dy), max(0,dy));
+
+
+ String f = String("\\hslurchar");
+
+ f+= direction_char(dir);
+
+ int hidx = dy;
+ if (hidx <0)
+ hidx = -hidx;
+ hidx --;
+ int idx =-1;
+
+
+ idx = widx * 16 + hidx;
+ if (xpart < 0)
+ idx += 128;
+
+ f+=String( "{" ) + String( idx ) + "}";
+
+
+ s.tex = f;
+
+ return s;
+}
+
+Symbol
+Lookup::slur (int dy , Real &dx, int dir)
+{
+ assert(dx >=0 && abs(dir) <= 1);
+ int y_sign = sign(dy);
+
+ bool large = dy > 16;
+
+ if (y_sign) {
+ large |= dx>= 4*16 PT;
+ } else
+ large |= dx>= 4*54 PT;
+
+ if (large) {
+ return big_slur(dy, dx, dir);
+ }
+ Real orig_dx = dx;
+ int widx = int(floor(dx/4.0)); // slurs better too small..
+ dx = 4.0 * widx;
+ if (widx)
+ widx --;
+ else {
+ WARN << "slur too narrow: " << print_dimen(orig_dx) << "\n";
+ }
+
+ int hidx = dy;
+ if (hidx <0)
+ hidx = -hidx;
+ hidx --;
+ if (hidx > 16) {
+ WARN<<"slur to steep: " << dy << " shrinking (ugh)\n";
+ }
+
+ Symbol s;
+ s.dim.x = Interval(0,dx);
+ s.dim.y = Interval(min(0,dy), max(0,dy));
+
+ String f = String("\\slurchar") + String( direction_char(y_sign) );
+
+ int idx=-1;
+ if (y_sign) {
+ idx = hidx * 16 + widx;
+ if (dir < 0)
+ idx += 128;
+ } else {
+ if (dx >= 4*54 PT) {
+ WARN << "slur too wide: " << print_dimen(dx) <<
+ " shrinking (ugh)\n";
+ dx = 4*54 PT;
+ }
+ idx = widx;
+ if (dir < 0)
+ idx += 54;
+ }
+
+ f+=String( "{" ) + String( idx ) + "}";
+ s.tex = f;
+
+ Atom a(s);
+ a.translate(Offset(dx/2,0));
+ s.dim = a.extent();
+ s.tex = a.TeXstring();
+ return s;
+}
+
+Symbol
+Lookup::big_slur(int dy , Real &dx, int dir)
+{
+ assert(dx >= 24 PT);
+ Real slur_extra =abs(dy) /2.0 + 2;
+ int l_dy = int(Real (dy)/2 + slur_extra*dir);
+ int r_dy = dy - l_dy;
+
+ Real left_wid = dx/4.0;
+ Real right_wid = left_wid;
+
+ Atom l = half_slur(l_dy, left_wid, dir, -1);
+ Atom r = half_slur(r_dy, right_wid, dir, 1);
+ Real mid_wid = dx - left_wid - right_wid;
+
+ Atom m = half_slur(0, mid_wid, dir, 0);
+
+ Molecule mol;
+ mol.add(l);
+ Atom a(m);
+ a.translate(Offset(0,slur_extra * internote()));
+ mol.add_right(m);
+ mol.add_right(r);
+ mol.translate(Offset(0, l_dy * internote()));
+ Symbol s;
+ s.tex = mol.TeXstring();
+ s.dim = mol.extent();
+ return s;
+}
+
+
--- /dev/null
+/*
+ tex-stream.cc -- implement Tex_stream
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include <fstream.h>
+#include <time.h>
+
+#include "tex.hh"
+#include "main.hh"
+#include "tex-stream.hh"
+#include "debug.hh"
+
+Tex_stream::Tex_stream(String filename)
+{
+ os = new ofstream(filename);
+ if (!*os)
+ error("can't open `" + filename+"\'");
+ nest_level = 0;
+ outputting_comment=false;
+ header();
+}
+void
+Tex_stream::header()
+{
+ *os << "% Creator: " << get_version();
+ *os << "% Automatically generated, at ";
+ time_t t(time(0));
+ *os << ctime(&t);
+ *os << "% from musical definition: " + infile_str_g + "\n";
+}
+Tex_stream::~Tex_stream()
+{
+ delete os;
+ assert(nest_level == 0);
+}
+
+// print string. don't forget indent.
+Tex_stream &
+Tex_stream::operator<<(String s)
+{
+
+ for (const char *cp = s; *cp; cp++) {
+ if (outputting_comment) {
+ *os << *cp;
+ if (*cp == '\n') {
+ outputting_comment=false;
+
+ }
+ continue;
+ }
+ switch(*cp)
+ {
+ case '%':
+ outputting_comment = true;
+ *os << *cp;
+ break;
+ case '{':
+ nest_level++;
+ *os << *cp;
+ break;
+ case '}':
+ nest_level--;
+ *os << *cp;
+
+ if (nest_level < 0) {
+ delete os; // we want to see the remains.
+ assert(nest_level>=0);
+ }
+ /* FALLTHROUGH */
+
+ case '\n':
+ *os << "%\n";
+ *os << String(' ', nest_level);
+ break;
+ default:
+ *os << *cp;
+ break;
+ }
+ }
+ return *this;
+}
+
+
+/* *************************************************************** */
--- /dev/null
+#include "dimen.hh"
+#include "tex.hh"
+#include "symbol.hh"
+#include "const.hh"
+#include "varray.hh"
+
+String
+vstrut(Real h)
+{
+ return String("\\vrule height ") + print_dimen(h) + "depth 0pt width 0pt";
+}
+
+
+static void
+substitute_arg(String& r, String arg)
+{
+ int p = r.index_i('%');
+ if (p < 0)
+ return ;
+
+ r = r.left_str(p) + arg + r.right_str(r.length_i() - p -1);
+}
+
+
+String
+substitute_args(String source, Array<String> args)
+{
+ String retval (source);
+ for (int i = 0 ; i < args.size(); i++)
+ substitute_arg(retval, args[i]);
+ while (retval.index_i('%') >= 0)
+ substitute_arg(retval, "");
+ return retval;
+}
+
+String
+substitute_args(String source, Array<Scalar> args)
+{
+ Array<String> sv;
+ for (int i = 0 ; i < args.size(); i++)
+ sv.push(args[i]);
+
+ return substitute_args(source, sv);
+}
--- /dev/null
+#include "debug.hh"
+#include "lookup.hh"
+#include "paper-def.hh"
+#include "molecule.hh"
+#include "text-def.hh"
+
+Text_def::Text_def()
+{
+ align_i_ = 1; // right
+ style_str_ = "roman";
+ defined_ch_c_l_ = 0;
+}
+bool
+Text_def::compare(const Text_def&def)
+{
+ return align_i_ == def.align_i_ && text_str_ == def.text_str_
+ && style_str_ == def.style_str_;
+}
+
+Atom
+Text_def::create_atom(Paper_def*p) const
+{
+ return p->lookup_p_->text(style_str_, text_str_, -align_i_);
+}
+
+void
+Text_def::print() const
+{
+ mtor << "Text `" << text_str_ << "\', style " <<
+ style_str_ << "align " << align_i_ << '\n';
+}
--- /dev/null
+/*
+ textitem.cc -- implement Text_item
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+
+ #include "musicalrequest.hh"
+#include "paper-def.hh"
+#include "text-item.hh"
+#include "stem.hh"
+#include "molecule.hh"
+#include "lookup.hh"
+
+
+
+Text_item::Text_item(Text_req* treq_l, int staffsize_i)
+{
+ staffsize_i_ = staffsize_i;
+ dir_i_ = treq_l->dir_i_;
+ if (!dir_i_)
+ dir_i_ = -1;
+ tdef_l_ = treq_l->tdef_p_;
+}
+
+void
+Text_item::set_default_index()
+{
+ pos_i_ = (dir_i_ > 0) ? staffsize_i_ + 2: -4;
+}
+
+void
+Text_item::do_pre_processing()
+{
+ set_default_index();
+}
+
+
+Molecule*
+Text_item::brew_molecule_p() const
+{
+ Molecule* mol_p = new Molecule(tdef_l_->create_atom(paper()));
+ mol_p->translate(Offset(0, pos_i_ * paper()->internote()));
+
+ if(dir_i_<0)
+ mol_p->translate(Offset(0, -mol_p->extent().y.length() ));
+
+ return mol_p;
+}
--- /dev/null
+/*
+ text-reg.cc -- implement Text_register
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include "musicalrequest.hh"
+#include "text-reg.hh"
+#include "text-item.hh"
+
+Text_register::Text_register()
+{
+ text_p_ = 0;
+ set_feature(Features::dir(0));
+ post_move_processing();
+}
+
+bool
+Text_register::try_request(Request*req_l)
+{
+ if (!req_l->text())
+ return false;
+ if (text_req_l_ &&
+ Text_req::compare(*req_l->text(), *text_req_l_))
+
+ return false;
+
+ text_req_l_ = req_l->text();
+ return true;
+}
+
+void
+Text_register::process_requests()
+{
+
+ if (text_req_l_) {
+ text_p_ = new Text_item(text_req_l_, 10); // UGH
+ announce_element(Staff_elem_info(text_p_, text_req_l_));
+ }
+}
+void
+Text_register::pre_move_processing()
+{
+ if (text_p_) {
+ text_p_->dir_i_ = dir_i_;
+ typeset_element(text_p_);
+ text_p_ = 0;
+ }
+}
+void
+Text_register::set_feature(Features i)
+{
+ dir_i_ = i.direction_i_;
+}
+void
+Text_register::post_move_processing()
+{
+ text_req_l_ = 0;
+}
--- /dev/null
+#include "molecule.hh"
+#include "boxes.hh"
+#include "text-spanner.hh"
+#include "text-def.hh"
+#include "debug.hh"
+#include "paper-def.hh"
+
+
+
+void
+Text_spanner::set_support(Directional_spanner*d)
+{
+ support = d;
+ add_dependency(d);
+}
+
+Text_spanner::Text_spanner()
+{
+ support = 0;
+}
+
+void
+Text_spanner::do_print() const
+{
+ spec.print();
+}
+
+void
+Text_spanner::do_post_processing()
+{
+ switch(spec.align_i_) {
+ case 0:
+ text_off_ = support->center() +
+ Offset(0,support->dir_i_ * paper()->internote() * 4); // todo
+ break;
+ default:
+ assert(false);
+ break;
+ }
+}
+
+Molecule*
+Text_spanner::brew_molecule_p() const
+{
+ Atom tsym (spec.create_atom(paper()));
+ tsym.translate(text_off_);
+
+ Molecule*output = new Molecule;
+ output->add( tsym );
+ return output;
+}
+
+void
+Text_spanner::do_pre_processing()
+{
+ right = support->right;
+ left = support->left;
+ assert(left && right);
+}
+
+Interval
+Text_spanner::height()const
+{
+ return brew_molecule_p()->extent().y;
+}
+
+Spanner*
+Text_spanner::do_break_at(PCol*c1, PCol*c2)const
+{
+ return new Text_spanner(*this); // todo
+}
--- /dev/null
+/*
+ time-description.cc -- implement Time_description
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include "time-description.hh"
+#include "debug.hh"
+
+String
+Time_description::str()const
+{
+ String s( "Time_description { ");
+ if (cadenza_b_)
+ s+=String( " (cadenza) ");
+ s+= "at ";
+ s+=when_;
+ s+="\nmeter " + String(whole_per_measure_/one_beat_) +":" +
+ String(Rational(Rational(1)/one_beat_));
+ s+= "\nposition "+String( bars_i_) + ":"+ whole_in_measure_ +"\n}\n";
+ return s;
+}
+
+void
+Time_description::print() const
+{
+#ifndef NPRINT
+ mtor << str();
+#endif
+}
+void
+Time_description::OK() const
+{
+#ifndef NDEBUG
+ if (!cadenza_b_)
+ assert(whole_in_measure_ < whole_per_measure_);
+ assert(Moment(0) <= whole_in_measure_);
+ assert(one_beat_);
+#endif
+}
+
+void
+Time_description::set_cadenza(bool b)
+{
+ if (cadenza_b_ && !b) {
+ if (whole_in_measure_) {
+ bars_i_ ++;
+ whole_in_measure_ = 0;
+ }
+ }
+ cadenza_b_ = b ;
+}
+
+Time_description::Time_description()
+{
+ whole_per_measure_ = 1;
+ whole_in_measure_ =0;
+ one_beat_ = Moment(1,4);
+ when_ = 0;
+ bars_i_ = 0;
+ cadenza_b_ = false;
+}
+
+void
+Time_description::add(Moment dt)
+{
+ assert(dt >= Rational(0));
+ when_ += dt;
+ whole_in_measure_ += dt;
+
+ while ( !cadenza_b_ && whole_in_measure_ >= whole_per_measure_ ) {
+ whole_in_measure_ -= whole_per_measure_;
+ bars_i_ ++;
+ }
+}
+
+void
+Time_description::set_meter(int l, int o)
+{
+ assert(o);
+ one_beat_ = Rational(1)/Moment(o);
+ whole_per_measure_ = Moment(l) * one_beat_;
+ if(whole_in_measure_)
+ error_t("Meterchange should be at start of measure", *this);
+}
+
+void
+Time_description::setpartial(Moment p)
+{
+ if (when_)
+ error_t ("Partial measure only allowed at beginning.", *this);
+ if (p<Rational(0)||p > whole_per_measure_)
+ error_t ("Partial measure has incorrect size", *this);
+ whole_in_measure_ = whole_per_measure_ - p;
+}
+
+Moment
+Time_description::barleft()
+{
+ assert(!cadenza_b_);
+ return whole_per_measure_-whole_in_measure_;
+}
+
+int
+Time_description::compare(Time_description &t1, Time_description&t2)
+{
+ int i = sign(t1.when_-t2.when_);
+
+ if (!i) {
+ assert(t1.bars_i_==t2.bars_i_);
+ assert(t1.one_beat_ == t2.one_beat_);
+ assert(t1.whole_in_measure_ == t2.whole_in_measure_);
+ assert(t1.whole_per_measure_ == t2.whole_per_measure_);
+ }
+
+ return i;
+}
--- /dev/null
+#include "version.hh"
+#include "fversion.hh"
+
+static char *s = "LilyPond " VERSIONSTR "/FlowerLib " FVERSIONSTR
+". Compile: " __DATE__ ", " __TIME__ " (" COMPILER ")\n";
+
+const char *
+get_version()
+{
+ return s;
+}
--- /dev/null
+/*
+ voiceelt.cc -- implement Voice_element
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include "proto.hh"
+#include "plist.hh"
+#include "debug.hh"
+#include "voice.hh"
+#include "voice-element.hh"
+#include "musicalrequest.hh"
+#include "commandrequest.hh"
+
+
+void
+Voice_element::print() const
+{
+#ifndef NPRINT
+ mtor << "voice_element { dur :"<< duration <<"\n";
+ for (iter_top(reqs,rc); rc.ok(); rc++) {
+ rc->print();
+ }
+ mtor << "}\n";
+#endif
+}
+
+void
+Voice_element::add(Request*r)
+{
+ if (r->duration()) {
+ assert (!duration || duration == r->duration());
+ duration = r->duration();
+ }
+
+ r->elt_l_ = this;
+ reqs.bottom().add(r);
+}
+
+
+Voice_element::Voice_element()
+{
+ voice_l_ = 0;
+ duration = 0;
+ defined_ch_c_l_ = 0;
+}
+
+Voice_element::Voice_element(Voice_element const&src)
+{
+ defined_ch_c_l_ = src.defined_ch_c_l_;
+
+ voice_l_=0;
+ for (iter_top(src.reqs, i); i.ok(); i++)
+ add(i->clone());
+
+}
+bool
+Voice_element::find_plet_start_bo(char c, Moment& moment_r)
+{
+ assert( c == ']' );
+ moment_r += duration;
+ for ( PCursor<Request*> req_l_pcur( reqs.top() ); req_l_pcur.ok(); req_l_pcur++ ) {
+ if (req_l_pcur->beam() && req_l_pcur->beam()->spantype == Span_req::START )
+ return true;
+ }
+ return false;
+}
+
+void
+Voice_element::set_default_group(String s)
+{
+ for (iter_top(reqs, i); i.ok(); i++)
+ if (i->groupchange())
+ return ;
+ Group_change_req *greq = new Group_change_req;
+ greq->newgroup_str_ = s;
+ add(greq);
+}
+
+void
+Voice_element::set_plet_backwards(Moment& now_moment_r,
+ Moment until_moment, int num_i, int den_i)
+{
+ now_moment_r += duration;
+ if ( now_moment_r > until_moment )
+ return;
+ for ( PCursor<Request*> req_l_pcur( reqs.top() ); req_l_pcur.ok(); req_l_pcur++ ) {
+ if (req_l_pcur->beam() && req_l_pcur->beam()->spantype == Span_req::START )
+ req_l_pcur->beam()->nplet = den_i;
+ if (req_l_pcur->rhythmic())
+ req_l_pcur->rhythmic()->plet_factor = Moment(num_i, den_i);
+ if (req_l_pcur->stem())
+ req_l_pcur->stem()->plet_factor = Moment(num_i, den_i);
+ }
+}
--- /dev/null
+/*
+ voicegroup.cc -- implement Voice_group_registers
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include "proto.hh"
+#include "plist.hh"
+#include "musicalrequest.hh"
+#include "voice-regs.hh"
+#include "voice-group-regs.hh"
+#include "register.hh"
+#include "text-reg.hh"
+#include "stem-beam-reg.hh"
+#include "script-reg.hh"
+#include "complex-walker.hh"
+#include "commandrequest.hh"
+#include "debug.hh"
+
+static int temp_id_count;
+
+Voice_group_registers::Voice_group_registers(String id)
+{
+ add(new Text_register);
+ add(new Stem_beam_register);
+ add(new Script_register);
+
+ if (id=="") // UGH
+ id = __FUNCTION__ + String(temp_id_count++);
+ group_id_str_ = id;
+}
+
+bool
+Voice_group_registers::try_request(Request*r_l)
+{
+ for (int i=0; i < voice_regs_l_.size(); i++) {
+ if (voice_regs_l_[i]->voice_l_ == r_l->voice_l())
+ goto gotcha;
+ }
+ return false;
+gotcha:
+ if (r_l->groupfeature()) {
+ set_feature(Features::dir(r_l->groupfeature()->stemdir_i_));
+ return true;
+ }
+ return Register_group_register::try_request(r_l);
+}
+
+
+bool
+Voice_group_registers::static_acceptable_request_b(Request*r)
+{
+ return (r->stem() || r->beam() || r->text() || r->script() ||
+ r->groupfeature());
+}
+
+void
+Voice_group_registers::terminate_register(Request_register*r_l)
+{
+ if (r_l->name() == Voice_registers::static_name()) {
+ for (int i=0; i <voice_regs_l_.size(); i++) {
+ if (r_l == voice_regs_l_[i])
+ voice_regs_l_.del(i);
+ Register_group_register::terminate_register(r_l);
+ return;
+ }
+ }
+ assert(false);
+}
+void
+Voice_group_registers::do_print() const
+{
+#ifndef NPRINT
+ mtor << "ID: " << group_id_str_<<"\n";
+ Register_group_register::do_print();
+#endif
+}
+void
+Voice_group_registers::add(Request_register*r_l)
+{
+ Register_group_register::add(r_l);
+ if (r_l->name() == Voice_registers::static_name())
+ voice_regs_l_.push( (Voice_registers*)r_l );
+}
--- /dev/null
+/*
+ voice-regs.cc -- implement Voice_registers
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+#include "proto.hh"
+#include "plist.hh"
+#include "commandrequest.hh"
+#include "musicalrequest.hh"
+#include "voice-regs.hh"
+#include "register.hh"
+#include "slur-reg.hh"
+#include "headreg.hh"
+#include "walk-regs.hh"
+#include "debug.hh"
+
+Voice_registers::Voice_registers(Voice *v_p)
+{
+ voice_l_ = v_p;
+ add(new Notehead_register);
+ add(new Slur_register);
+}
+
+void
+Voice_registers::acknowledge_element(Staff_elem_info i)
+{
+ if (i.voice_l_ != voice_l_)
+ return;
+ Register_group_register::acknowledge_element(i);
+}
+
+bool
+Voice_registers::try_request(Request*r_l)
+{
+ if (r_l->voice_l() !=voice_l_)
+ return false;
+
+ Command_req *c=r_l->command();
+ if (c&&c->terminate()) {
+ daddy_reg_l_->terminate_register(this);
+ return true; // scary. We're deleted now..
+ } else if (c&&c->groupchange()) {
+
+ ((Walker_registers*)daddy_reg_l_->daddy_reg_l_)-> // scary.
+ change_group(c->groupchange(), this,
+ (Voice_group_registers*)daddy_reg_l_); // UGR!
+ return true;
+ }
+
+ return Register_group_register::try_request(r_l);
+}
+
+bool
+Voice_registers::acceptable_request_b(Request*r)
+{
+// return (r->rest() || r->note() || r->slur() || r->groupchange());
+ return r->groupchange()
+ || Register_group_register::acceptable_request_b(r);
+}
+void
+Voice_registers::do_print() const
+{
+ mtor << "Voice= " << voice_l_<<'\n';
+ Register_group_register::do_print();
+}
--- /dev/null
+/*
+ voice.cc -- implement Voice
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include "proto.hh"
+#include "plist.hh"
+#include "debug.hh"
+#include "voice.hh"
+#include "musicalrequest.hh"
+#include "commandrequest.hh"
+#include "midi-item.hh"
+#include "midi-stream.hh"
+#include "voice-element.hh"
+
+void
+Voice::set_default_group(String s)
+{
+ elts.top()->set_default_group(s);
+}
+
+bool
+Voice::find_plet_start_bo(char c, Moment& moment_r)
+{
+ for (iter_bot(elts, i); i.ok(); i--)
+ if ( i->find_plet_start_bo(c, moment_r) )
+ return true;
+ return false;
+}
+
+void
+Voice::set_plet_backwards(Moment& now_moment_r, Moment until_moment,
+ int num_i, int den_i)
+{
+ for (iter_bot(elts, i); i.ok(); i--)
+ if ( now_moment_r <= until_moment )
+ i->set_plet_backwards(now_moment_r, until_moment, num_i, den_i);
+ else
+ return;
+}
+
+Voice::Voice(Voice const&src)
+{
+ for (iter_top(src.elts, i); i.ok(); i++)
+ add(new Voice_element(**i));
+
+ start = src.start;
+}
+
+Voice::Voice()
+{
+ start = 0;
+}
+
+void
+Voice::add(Voice_element*v)
+{
+ v->voice_l_ = this;
+ elts.bottom().add(v);
+}
+
+void
+Voice::print() const
+{
+#ifndef NPRINT
+ mtor << "Voice { start: "<< start<<eol;
+ for (iter_top(elts,i); i.ok(); i++)
+ i->print();
+ mtor << "}\n";
+#endif
+}
+
+Moment
+Voice::last() const
+{
+ Moment l =0;
+ if (elts.size())
+ l = start;
+
+ for (iter_top(elts,i); i.ok(); i++)
+ l += i->duration;
+ return l;
+}
+
--- /dev/null
+/*
+ walkregs.cc -- implement Walker_registers
+
+ source file of the LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include "debug.hh"
+#include "clef-reg.hh"
+#include "local-key-reg.hh"
+#include "key-reg.hh"
+#include "meter-reg.hh"
+#include "bar-reg.hh"
+#include "bar.hh"
+#include "walk-regs.hh"
+#include "staff-elem.hh"
+#include "staff.hh"
+#include "complex-walker.hh"
+#include "staff-column.hh"
+#include "voice-group-regs.hh"
+#include "voice-regs.hh"
+#include "commandrequest.hh"
+
+
+Walker_registers::Walker_registers(Complex_walker *w)
+{
+ walk_l_ = w;
+ add( new Bar_register);
+ add( new Clef_register);
+ add( new Key_register);
+ add( new Meter_register);
+ add( new Local_key_register);
+}
+
+void
+Walker_registers::announce_element(Staff_elem_info info)
+{
+ if (info.elem_p_->name() == Bar::static_name()) {
+ walk_l_->allow_break();
+ }
+ announce_info_arr_.push(info);
+}
+
+void
+Walker_registers::acknowledge_element(Staff_elem_info )
+{
+ assert(false);
+}
+
+void
+Walker_registers::do_announces()
+{
+ Request dummy_req;
+ for (int i = 0; i < announce_info_arr_.size(); i++){
+ Staff_elem_info info = announce_info_arr_[i];
+
+ if (!info.req_l_)
+ info.req_l_ = &dummy_req;
+ Register_group_register::acknowledge_element(info);
+ }
+ announce_info_arr_.set_size(0);
+}
+
+void
+Walker_registers::typeset_element(Staff_elem *elem_p)
+{
+ typeset_musical_item(elem_p);
+}
+
+void
+Walker_registers::typeset_musical_item(Staff_elem * elem_p)
+{
+ walk_l_->typeset_element(elem_p);
+}
+
+void
+Walker_registers::typeset_breakable_item(Item * pre_p , Item * nobreak_p,
+ Item * post_p)
+{
+ if (pre_p)
+ prebreak_item_p_arr_.push(pre_p);
+ if (nobreak_p)
+ nobreak_item_p_arr_.push(nobreak_p);
+ if (post_p)
+ postbreak_item_p_arr_.push(post_p);
+}
+
+void
+Walker_registers::pre_move_processing()
+{
+ // this generates all items.
+ Register_group_register::pre_move_processing();
+ walk_l_->ptr()->typeset_breakable_items(prebreak_item_p_arr_,
+ nobreak_item_p_arr_,
+ postbreak_item_p_arr_);
+}
+void
+Walker_registers::post_move_processing()
+{
+ Register_group_register::post_move_processing();
+}
+
+void
+Walker_registers::change_group(Group_change_req * greq_l,
+ Voice_registers *voice_regs_l,
+ Voice_group_registers * old_group)
+{
+ Voice_registers *regs_p = (old_group)
+ ? (Voice_registers*) old_group->get_register_p(voice_regs_l)
+ : new Voice_registers(greq_l->voice_l());
+ Voice_group_registers * new_group_l = get_group(greq_l->newgroup_str_);
+ new_group_l->add(regs_p);
+
+ mtor << "processed change request";
+ print();
+}
+
+Voice_group_registers *
+Walker_registers::get_group(String id)
+{
+ for (int i=0; i < group_l_arr_.size(); i++) {
+ if (group_l_arr_[i]->group_id_str_ == id)
+ return group_l_arr_[i];
+ }
+ Voice_group_registers *group_p = new Voice_group_registers(id);
+ group_l_arr_.push(group_p);
+ add(group_p);
+ return group_p;
+}
+
+void
+Walker_registers::terminate_register(Request_register * reg)
+{
+ for (int i=0; i < group_l_arr_.size(); i++) {
+ if (group_l_arr_[i] == reg) {
+ group_l_arr_.del(i);
+ Register_group_register::terminate_register(reg);
+ return;
+ }
+ }
+ assert(false);
+}
+
+bool
+Walker_registers::try_request(Request * r)
+{
+ bool b = Register_group_register::try_request(r);
+ if (!b) {
+ Command_req * cr_l = r->command() ;
+
+ if (cr_l && cr_l->groupchange()) {
+ change_group(cr_l->groupchange(), 0, 0);
+ } else
+ warning("junking request: " + String(r->name()),
+ r->defined_ch_c_l_);
+ }
+ return b;
+}
+
+
+Staff_info
+Walker_registers::get_staff_info() return inf;
+{
+ inf.c0_position_i_ = &walk_l_->c0_position_i_;
+ inf.walk_l_ = walk_l_;
+ inf.time_c_l_ = &walk_l_->time_;
+ inf.rhythmic_c_l_ = walk_l_->default_grouping;
+}
+Paper_def*
+Walker_registers::paper()const
+{
+ return walk_l_->staff_l_->paper();
+}
--- /dev/null
+#include "proto.hh"
+#include "plist.hh"
+#include "debug.hh"
+#include "lexer.hh"
+#include "moment.hh"
+#include "time-description.hh"
+#include "source-file.hh"
+#include "source.hh"
+#include "main.hh"
+
+ostream &warnout (cerr);
+ostream *mlog(&cerr);
+/*
+void
+warning(String s)
+{
+ WARN << s;
+}
+*/
+
+void
+error(String s)
+{
+ if (busy_parsing())
+ yyerror(s);
+ else
+ cerr << "error: " << s << "\n";
+
+ exit(1);
+}
+
+void
+error_t(const String& s, const Moment& r)
+{
+ String t_mom = String(trunc(r)) + String(r - Moment(trunc(r)));
+ String e=s+ " (t = " + t_mom + ")";
+ error(e);
+}
+
+void
+error_t(const String& s, Time_description const &t_tdes)
+{
+ String e=s+ " (at t=" + String(t_tdes.bars_i_) + ": " + String(t_tdes.whole_in_measure_) + ")\n";
+ error(e);
+}
+
+void
+message( String message_str, char const* context_ch_c_l )
+{
+ String str = "lilypond: ";
+ Source_file* sourcefile_l = source_l_g->sourcefile_l( context_ch_c_l );
+ if ( sourcefile_l ) {
+ str += sourcefile_l->file_line_no_str(context_ch_c_l) + String(": ");
+ }
+ str += message_str;
+ if ( sourcefile_l ) {
+ str += ":\n";
+ str += sourcefile_l->error_str( context_ch_c_l );
+ }
+ if ( busy_parsing() )
+ cerr << endl;
+ cerr << str << endl;
+}
+
+void
+warning( String message_str, char const* context_ch_c_l )
+{
+ message( "warning: " + message_str, context_ch_c_l );
+}
+
+void
+error( String message_str, char const* context_ch_c_l )
+{
+ message( message_str, context_ch_c_l );
+ // since when exits error again?
+ // i-d say: error: errorlevel |= 1; -> no output upon error
+ // warning: recovery -> output (possibly wrong)
+ if ( lexer )
+ lexer->errorlevel_i_ |= 1;
+// exit( 1 );
+}
--- /dev/null
+#include "break.hh"
+#include "pscore.hh"
+#include "debug.hh"
+
+/** el stupido. This should be done more accurately:
+
+ It would be nice to have a Dynamic Programming type of algorithm
+ similar to TeX's
+
+ */
+Array<Col_hpositions>
+Word_wrap::solve()
+{
+ problem_OK();
+ iter_top(pscore_.cols,curcol);
+ Array<Col_hpositions> breaking;
+ Line_of_cols breakpoints(find_breaks());
+ assert(breakpoints.size()>=2);
+
+ int break_idx_i=0;
+ while ( break_idx_i < breakpoints.size() -1) {
+ Col_hpositions minimum;
+ Col_hpositions current;
+
+ // do another line
+ PCol *post = breakpoints[break_idx_i]->postbreak_p_;
+ current.add( post);
+ curcol++; // skip the breakable.
+ break_idx_i++;
+
+ while (break_idx_i < breakpoints.size()) {
+
+ // add another measure.
+ while (breakpoints[break_idx_i] != curcol.ptr()){
+ current.add(curcol);
+ curcol++;
+ }
+ current.add(breakpoints[break_idx_i]->prebreak_p_ );
+
+ // try to solve
+ if (!feasible(current.cols)) {
+ if (!minimum.cols.size())
+ error("sorry, this measure is too long, breakpoint: "
+ + String(break_idx_i) );
+ current.energy = INFTY; // make sure we go back
+ } else {
+ current = solve_line(current.cols);
+ current.print();
+ }
+
+ // update minimum, or backup.
+ if (current.energy < minimum.energy) {
+ minimum = current;
+ } else { // we're one col too far.
+ break_idx_i--;
+ while (curcol.ptr() != breakpoints[break_idx_i])
+ curcol --;
+ break; // do the next line.
+ }
+
+
+ // add nobreak version of breakable column
+ current.cols.top()=breakpoints[break_idx_i];
+ curcol ++;
+ break_idx_i++;
+ }
+
+ *mlog << "[" <<break_idx_i<<"]"<<flush;
+ breaking.push(minimum);
+ }
+
+ return breaking;
+}
+
+Word_wrap::Word_wrap(PScore&ps)
+ : Break_algorithm(ps)
+{
+}
+++ /dev/null
-%%
-%% include file for LilyPond
-
-\def\mdef#1#2{\def#1{\mchar{#2}}}
-\def\mchar#1{\musicfnt\char#1}
-\def\rationalmultiply#1*#2/#3{\multiply #1 by #2 \divide #1 by #3}
-\def\maccentraise#1#2{\dimen0=\noteheight
- \rationalmultiply\dimen0*#2%
- \raise\dimen0\hbox{#1}}
-\def\maccentdef#1#2#3{\def#1{\maccentraise{\mchar{#2}}{#3}}}
-\def\vcenter#1{\vbox to 0pt{\vss #1\vss}}
-
-\def\topalign#1{\vbox to 0pt{#1\vss}}
-\def\botalign#1{\vbox to 0pt{\vss #1}}
-
-\def\centeralign#1{\hbox to 0pt{\hss#1\hss}}
-\def\leftalign#1{\hbox to 0pt{#1\hss}}
-\def\rightalign#1{\hbox to 0pt{\hss#1}}
-
-
-%% musix defs
-\parindent=0pt
-\newdimen\smallspace
-\newdimen\interlinedist
- \newcount\n
- \newdimen\balkhoog
- \newdimen\notewidth
- \newdimen\noteheight
- \newdimen\notewidthhalf
- \newdimen\notewidthdouble
- \newdimen\staffrulethickness
- \newdimen\interstaffrule
-\newdimen\balkhalf
-\def\musixtwentydefs{
- \font\textfont=cmr10
- \font\meterfont=cmbx12
- \font\slurufont=xslu20
- \font\slurdfont=xsld20
- \font\slurhfont=xslz20
- \font\hslurufont=xslhu20
- \font\hslurdfont=xslhd20
- \font\hslurhfont=xslhz20
- \font\musicfnt=musix20
- \font\italicfont=cmti10
- \font\dynfont=cmbxti10 scaled \magstep1
- \balkhoog=20pt
- \notewidth=6pt
- \noteheight=5pt
- \staffrulethickness=0.4pt
- \musixcalc
-}
-
-
-\def\musixsixteendefs{
- \font\textfont=cmr8
- \font\meterfont=cmbx12
- \font\italicfont=cmti8
- \font\slurufont=xslu16
- \font\slurdfont=xsld16
- \font\slurhfont=xslz20 % sigh
- \font\hslurufont=xslhu16
- \font\hslurdfont=xslhd16
- \font\hslurhfont=xslhz20
- \font\musicfnt=musix16
- \font\dynfont=cmbxti10
- \balkhoog=16pt
- \staffrulethickness=0.4pt
- \notewidth=5pt
- \noteheight=4pt
- \musixcalc
-}
-
-\def\musixcalc{
- \interlinedist=\fontdimen5\musicfnt
- \smallspace=.3\interlinedist
- \interstaffrule=\balkhoog
- \advance\interstaffrule by-\staffrulethickness
- \divide\interstaffrule by 4
- \advance\interstaffrule by -\staffrulethickness
- \notewidthhalf=\notewidth
- \notewidthdouble=\notewidth
- \rationalmultiply \notewidthhalf*1/2
- \multiply \notewidthdouble by 2
- \balkhalf=\balkhoog
- \rationalmultiply\balkhalf*1/2
-}
-% \def\dyn{\italicfont}
-\def\dyn{\dynfont}
-\def\dynf{f\kern-.1ex}
-\def\dynm{f\kern-.15ex}
-\def\dynp{p\kern-.15ex}
-\def\ppp{\dynfont\dynp\dynp p}
-\def\pp{\dynfont\dynp p}
-\def\p{\dynfont p}
-\def\mp{\dynfont\dynm p}
-\def\mf{\dynfont\dynm f}
-\def\f{\dynfont f}
-\def\ff{\dynfont\dynf f}
-\def\fff{\dynfont\dynf\dynf f}
-
-\def\slurcharh#1{{\slurhfont\char#1}}
-\def\slurcharu#1{{\slurufont\char#1}}
-\def\slurchard#1{{\slurdfont\char#1}}
-\def\hslurcharh#1{{\hslurhfont\char#1}}
-\def\hslurcharu#1{{\hslurufont\char#1}}
-\def\hslurchard#1{{\hslurdfont\char#1}}
-
-\mdef\quartball{'007}
-\mdef\halfball{'010}
-\mdef\wholeball{'011}
-\mdef\halfrest{'074}
-\mdef\wholerest{'075}
-\mdef\quartrest{62}
-\mdef\eighthrest{63}
-\mdef\sixteenthrest{64}
-\mdef\thirtysecondrest{65}
-\mdef\sharp{52}
-\mdef\flat{50}
-\mdef\natural{54}
-\mdef\sharpsharp{53}
-\mdef\flatflat{51}
-
-\mdef\singledot{'00}
-\mdef\doubledot{'01}
-\mdef\tripledot{'02}
-\mdef\mussepline{155}
-
-\mdef\violinclef{71}
-\mdef\bassclef{73}
-\mdef\altoclef{75}
-\mdef\cviolinclef{72}
-\mdef\cbassclef{74}
-\mdef\caltoclef{76}
-
-\mdef\deigthflag{45}
-\mdef\dsixteenthflag{46}
-\mdef\dthirtysecondflag{47}
-
-% pointing up
-\mdef\ueigthflag{40}
-\mdef\usixteenthflag{41}
-\mdef\uthirtysecondflag{42}
-
-\maccentdef\repeatcolon{55}{2/1}
-\def\emptybar{}
-
-\def\thinbar{\vrule height\balkhoog}
-%? what-s wrong with rightalign?
-\def\thickbar{\vrule height\balkhoog width 2\smallspace}
-\def\maatstreep{\thinbar}
-% \def\finishbar{\rightalign{\thinbar\kern\smallspace\thickbar}}
-\def\finishbar{\hss\rightalign{\thinbar\kern\smallspace\thickbar}}
-% \def\repeatstopbar{\rightalign{\repeatcolon\hskip2\smallspace\thinbar\hskip\smallspace\thickbar}}
-\def\repeatstopbar{\hss\rightalign{\repeatcolon\hskip2\smallspace\thinbar\hskip\smallspace\thickbar}}
-% \def\repeatstopbar{\kern-3\smallspace\rightalign{\repeatcolon\kern2\smallspace\thinbar\kern\smallspace\thickbar}\kern3\smallspace}
-\def\repeatstartbar{\hbox{\thickbar\kern\smallspace\thinbar\kern2\smallspace\repeatcolon}}
-\def\repeatstopstart{\hbox{\repeatcolon\kern2\smallspace\thinbar\kern\smallspace\thickbar\kern\smallspace\thickbar\kern\smallspace\thinbar\kern2\smallspace\repeatcolon}}
-\def\doublebar{\hbox{\thinbar\hskip\smallspace\thinbar}}
-
-%compatability
-\def\repeatbar{\repeatstopbar}
-\def\startrepeat{\repeatstartbar}
-\def\repeatbarstartrepeat{\repeatstopstart}
-
-\def\generalmeter#1#2{\botalign{\vbox to\balkhalf{\vss \meterfont#1}%
- \nointerlineskip
- \vbox to \balkhalf{\vss\meterfont #2}}}
-\def\defaultlineseparator{\vbox{\mussepline\vskip -5pt\mussepline}}
-\def\lineseparator{\defaultlineseparator}
-\def\beauty{%
- \par\vskip 10pt plus 30pt minus 10pt\par
- \hskip -5pt\lineseparator
- \par\vskip 10pt plus 30pt minus 10pt\par
-}
-
-\def\interstaffline{%
- \vskip 10pt
-}
-\def\ugly{\nointerlineskip\par
-\vskip 40pt\par\vbox{\leftalign{\vrule width30pt height1pt}}\par\vskip 40pt
-}
-\def\interscoreline{\beauty}
-
-
-\def\lines#1#2{%
- \vbox{\kern-\interstaffrule
- \n=0\nointerlineskip%
- \loop\ifnum\n<#1\advance\n by1%
- \kern\interstaffrule
- \hrule height \staffrulethickness width#2
- \repeat
- }}
-
-\def\toplines#1{ % why space needed here?
- \topalign{\hbox{\kern-\notewidth\lines{#1}{\notewidthdouble}}}}
-\def\botlines#1{ % idem ditto
- \botalign{\hbox{\kern-\notewidth\lines{#1}{\notewidthdouble}}}}
-
-%
-% a staffsymbol with #1 lines, width #2
-% bottom at baseline
-\def\linestafsym#1#2{\leftalign{\botalign{\lines{#1}{#2}}}}
-
-\def\eigthflag{\topalign{\ueigthflag}}
-\def\sixteenthflag{\topalign{\usixteenthflag}}
-\def\thirtysecondflag{\topalign{\uthirtysecondflag}}
-
-\def\cquartrest{\vcenter\quartrest}
-\def\ceighthrest{\vcenter\eighthrest}
-\def\csixteenthrest{\vcenter\sixteenthrest}
-\def\cthirtysecondrest{\vcenter\thirtysecondrest}
-
-\def\lsingledot{\kern-\notewidth\singledot}
-\def\ldoubledot{\kern-\notewidth\doubledot}
-\def\ltripledot{\kern-\notewidth\tripledot}
-
-\maccentdef\sforzato{30}{-3/2}
-\maccentdef\marcato{20}{-1/1}
-\maccentdef\imarcato{21}{1/1}
-\maccentdef\staccato{24}{-1/1}
-\maccentdef\istaccato{25}{1/1}
-\maccentdef\staccatissimo{28}{-1/1}
-\maccentdef\istaccatissimo{29}{1/1}
-\maccentdef\portato{18}{-9/10}
-\maccentdef\iportato{19}{9/10}
-\maccentdef\tenuto{26}{0/1}
-\maccentdef\itenuto{27}{0/1}
-\maccentdef\fermata{80}{-1/1}
-\maccentdef\ifermata{81}{1/1}
-
-
-
-\mdef\spicato{28}
-\mdef\ispicato{29}
-\mdef\upbow{23}
-\mdef\downbow{22}
-\mdef\portato{26}
-
-\def\stem#1#2{\vrule height#2 depth-#1}
-
-\def\placebox#1#2#3{%
- \botalign{\hbox{\raise #1\leftalign{\kern #2{}#3}}}%
-}
-
-
-\def\beamslope#1#2{{\count0=#2\advance\count0 by#1\musicfnt\char\count0}}
-\def\rulesym#1#2{\vrule height #1 width #2}
-\def\crescendosym#1{\count0=84\advance\count0 by #1}
-\def\decrescendosym#1{\count0=116\advance\count0 by #1}
-\def\settext#1{\textfont #1}
-\def\setitalic#1{\italicfont #1}
+++ /dev/null
-% Mats Bengtsson
-\documentclass[a4paper, 10pt]{article}
-
-% Allow for 8-bit characters:
-\usepackage[latin1]{inputenc}
-\usepackage[T1]{fontenc}
-
-\begin{document}
-\input lilyponddefs
-\input titledefs
-
-\def\settext#1{\normalfont #1} % Allow for 8-bit characters
-
-\input lelie.out
-\end{document}
--- /dev/null
+# not currently used
+MAJOR_VERSION = 0
+MINOR_VERSION = 0
+PATCH_LEVEL = 1
+# use to send patches, always empty for released version:
+MY_PATCH_LEVEL = #
+#
--- /dev/null
+#
+# project LilyPond -- the musical typesetter
+# title makefile for m2m
+# file m2m/Makefile
+#
+# Copyright (c) 1997 by
+# Jan Nieuwenhuizen <jan@digicash.com>
+# Han-Wen Nienhuys <hanwen@stack.nl>
+#
+
+# subdir level:
+#
+depth = ..
+#
+
+# identify module:
+#
+NAME = m2m
+MODULE_NAME = m2m
+MAJOR_VERSION = $(TOPLEVEL_MAJOR_VERSION)
+MINOR_VERSION = $(TOPLEVEL_MINOR_VERSION)
+PATCH_LEVEL = $(TOPLEVEL_PATCH_LEVEL)
+# use to send patches, always empty for released version:
+MY_PATCH_LEVEL = $(TOPLEVEL_MY_PATCH_LEVEL)
+# include ./$(depth)/m2m/.version
+build = ./$(depth)/lily/.build
+#
+
+# generic variables:
+#
+include ./$(depth)/make/Variables.make
+#
+
+# descent order into subdirectories:
+#
+SUBDIRS = include
+#
+
+# to be remade each build:
+#
+VERSION_DEPENDENCY = $(lily-version)
+#
+
+# list of c++ header files:
+#
+HHFILES = # $(shell ls include/*.hh)
+#
+
+# list of c++ source files:
+#
+CCFILES = $(shell ls *.cc)
+#
+
+# list of other source files:
+#
+EXTRA_SOURCE_FILES = $(shell ls *.y *.l)
+#
+
+# list of distribution files:
+#
+DISTFILES = Makefile .version $(HHFILES) $(CCFILES) $(EXTRA_SOURCE_FILES)
+#
+
+# list of custom libraries:
+#
+# yes, i know about the -L and -l options,
+# but these libraries get rebuild when needed.
+CUSTOMLIBES = $(LIBLILY) $(LIBFLOWER)
+
+LOADLIBES +=
+#
+
+# main target of this module:
+#
+# MAINTARGET = $(EXECUTABLE)
+# MAINTARGET = $(LIBRARY)
+MAINTARGET = $(bindir)/$(EXECUTABLE)# huh?
+# MAINTARGET = $(libdir)/$(LIBRARY)# huh?
+
+default: $(MAINTARGET)
+#
+
+# generic targets and rules:
+#
+include ./$(depth)/make/Targets.make
+include ./$(depth)/make/Rules.make
+#
+
+# explicit dependencies: (how to do auto?)
+#
+midi-lexer.l: $(outdir)/midi-parser.hh
+midi-main.cc: check-flower-version $(lily-version)
+#
+
+# auto dependencies:
+#
+-include ./$(outdir)/*.dep
+#
+
--- /dev/null
+# lib/include/Makefile
+
+# subdir level:
+#
+depth = ../..
+#
+
+# identify module:
+#
+MODULE_NAME = lilypond
+MAJOR_VERSION = $(TOPLEVEL_MAJOR_VERSION)
+MINOR_VERSION = $(TOPLEVEL_MINOR_VERSION)
+PATCH_LEVEL = $(TOPLEVEL_PATCH_LEVEL)
+# use to send patches, always empty for released version:
+MY_PATCH_LEVEL = $(TOPLEVEL_MY_PATCH_LEVEL)
+build = ./$(depth)/lily/.build
+#
+
+# generic stuff/Makefile
+#
+include ./$(depth)/make/Include.make
+#
+
--- /dev/null
+%{
+// midi-lexer.l
+
+
+#include "m2m.hh"
+#include "midi-parser.hh"
+
+%}
+
+%option c++
+%option noyywrap
+%option nodefault
+%option yylineno
+%option debug
+%option yyclass="My_midi_lexer"
+%option stack
+
+%x data
+%x event
+%x int8
+%x int16
+%x int32
+%x meta_event
+%x track
+
+INT8 [\x00-\xff]
+INT16 {INT8}{INT8}
+INT32 {INT16}{INT16}
+INT7_8UNSET [\x00-\x7f]
+INT7_8SET [\x80-\xff]
+VARINT {INT7_8SET}{0,3}{INT7_8UNSET}
+
+HEADER MThd
+TRACK MTrk
+
+XRUNNING_STATUS [\x30-\x4f]
+RUNNING_STATUS [\x00-\x5f]
+DATA_ENTRY [\x60-\x79]
+ALL_NOTES_OFF [\x7a-\x7f]
+NOTE_OFF [\x80-\x8f]
+NOTE_ON [\x90-\x9f]
+POLYPHONIC_AFTERTOUCH [\xa0-\xaf]
+CONTROLMODE_CHANGE [\xb0-\xbf]
+PROGRAM_CHANGE [\xc0-\xcf]
+CHANNEL_AFTERTOUCH [\xd0-\xdf]
+PITCHWHEEL_RANGE [\xe0-\xef]
+
+SYSEX_EVENT1 [\xf0]
+SYSEX_EVENT2 [\xf7]
+
+META_EVENT [\xff]
+
+SEQUENCE [\x00][\x02]
+YYTEXT [\x01]
+YYCOPYRIGHT [\x02]
+YYTRACK_NAME [\x03]
+YYINSTRUMENT_NAME [\x04]
+YYLYRIC [\x05]
+YYMARKER [\x06]
+YYCUE_POINT [\x07]
+
+END_OF_TRACK [\x2f][\x00]
+TEMPO [\x51][\x03]
+SMPTE_OFFSET [\x54][\x05]
+TIME [\x58][\x04]
+KEY [\x59][\x02]
+SSME [\0x7f][\x03]
+
+%%
+
+{HEADER}/{INT32} { // using /{INT32}; longer match than {INT32}
+ dtor << "lex: header" << endl;
+ yy_push_state( int16 );
+ yy_push_state( int16 );
+ yy_push_state( int16 );
+ yy_push_state( int32 );
+ return HEADER;
+}
+
+{TRACK}/{INT32} { // using /{INT32}; longer match than {INT32}
+ dtor << "lex: track" << endl;
+ yy_push_state( track );
+ yy_push_state( int32 );
+ return TRACK;
+}
+{INT8} {
+ error( String( "top level: illegal byte: " )
+ + String_convert::bin2hex_str( String( *YYText() ) ) );
+ exit( 1 );
+}
+<int32>{INT32} {
+ dtor << "lex: int32" << endl;
+ assert( YYLeng() == 4 );
+ String str( (Byte const*)YYText(), YYLeng() );
+ yylval.i = String_convert::bin2_i( str );
+ yy_pop_state();
+ return INT32;
+}
+<int16>{INT16} {
+ dtor << "lex: int16" << endl;
+ assert( YYLeng() == 2 );
+ String str( (Byte const*)YYText(), YYLeng() );
+ yylval.i = String_convert::bin2_i( str );
+ yy_pop_state();
+ return INT16;
+}
+<int8>{INT8} {
+ dtor << "lex: int8" << endl;
+ assert( YYLeng() == 1 );
+// yylval.byte = *(Byte*)YYText();
+ yylval.i = *(Byte*)YYText();
+ yy_pop_state();
+ return INT8;
+}
+
+<track>{VARINT} {
+ String str( (Byte const*)YYText(), YYLeng() );
+ yylval.i = My_midi_lexer::varint2_i( str );
+ dtor << String( "lex: track: varint(" )
+ + String( yylval.i ) + "): "
+ + String_convert::bin2hex_str( str ) << endl;
+ yy_push_state( event );
+ return VARINT;
+}
+<track>{INT8} {
+ error( String( "track: illegal byte: " )
+ + String_convert::bin2hex_str( String( *YYText() ) ) );
+ exit( 1 );
+}
+<event>{RUNNING_STATUS} {
+// yylval.byte = *(Byte*)YYText();
+ yylval.i = *(Byte*)YYText();
+ dtor << String ( "lex: running status: " ) + String( yylval.i ) << endl;
+ yy_pop_state();
+// yy_push_state( int8 );
+ yy_push_state( int8 );
+ return RUNNING_STATUS;
+}
+<event>{DATA_ENTRY} {
+// yylval.byte = *(Byte*)YYText();
+ yylval.i = *(Byte*)YYText();
+ dtor << String ( "lex: undefined data entry: " ) + String( yylval.i ) << endl;
+ yy_pop_state();
+ yy_push_state( int8 );
+ return DATA_ENTRY;
+}
+<event>{ALL_NOTES_OFF} {
+ dtor << "lex: all note off" << endl;
+// yylval.byte = *(Byte*)YYText();
+ yylval.i = *(Byte*)YYText();
+ dtor << String ( "lex: all notes off: " ) + String( yylval.i ) << endl;
+ yy_pop_state();
+ yy_push_state( int8 );
+ yy_push_state( int8 );
+ return ALL_NOTES_OFF;
+}
+<event>{NOTE_OFF} {
+ dtor << "lex: note off" << endl;
+// yylval.byte = *(Byte*)YYText();
+ yylval.i = *(Byte*)YYText();
+ yy_pop_state();
+ yy_push_state( int8 );
+ yy_push_state( int8 );
+ return NOTE_OFF;
+}
+<event>{NOTE_ON} {
+ dtor << "lex: note on" << endl;
+// yylval.byte = *(Byte*)YYText();
+ yylval.i = *(Byte*)YYText();
+ yy_pop_state();
+ yy_push_state( int8 );
+ yy_push_state( int8 );
+ return NOTE_ON;
+}
+<event>{POLYPHONIC_AFTERTOUCH} {
+ dtor << "lex: polyphonic aftertouch" << endl;
+// yylval.byte = *(Byte*)YYText();
+ yylval.i = *(Byte*)YYText();
+ yy_pop_state();
+ yy_push_state( int8 );
+ yy_push_state( int8 );
+ return POLYPHONIC_AFTERTOUCH;
+}
+<event>{CONTROLMODE_CHANGE} {
+ dtor << "lex: controlmode change" << endl;
+// yylval.byte = *(Byte*)YYText();
+ yylval.i = *(Byte*)YYText();
+ yy_pop_state();
+ yy_push_state( int8 );
+ yy_push_state( int8 );
+ return CONTROLMODE_CHANGE;
+}
+<event>{PROGRAM_CHANGE} {
+ dtor << "lex: program change" << endl;
+// yylval.byte = *(Byte*)YYText();
+ yylval.i = *(Byte*)YYText();
+ yy_pop_state();
+ yy_push_state( int8 );
+ return PROGRAM_CHANGE;
+}
+<event>{CHANNEL_AFTERTOUCH} {
+ dtor << "lex: channel aftertouch" << endl;
+// yylval.byte = *(Byte*)YYText();
+ yylval.i = *(Byte*)YYText();
+ yy_pop_state();
+ yy_push_state( int8 );
+ yy_push_state( int8 );
+ return CHANNEL_AFTERTOUCH;
+}
+<event>{PITCHWHEEL_RANGE} {
+ dtor << "lex: pitchwheel range" << endl;
+// yylval.byte = *(Byte*)YYText();
+ yylval.i = *(Byte*)YYText();
+ yy_pop_state();
+ yy_push_state( int8 );
+ yy_push_state( int8 );
+ return PITCHWHEEL_RANGE;
+}
+<event>{SYSEX_EVENT1} { // len data
+ dtor << "lex: sysex1" << endl;
+ yy_pop_state();
+ yy_push_state( data );
+ return SYSEX_EVENT1;
+}
+<event>{SYSEX_EVENT2} { // len data
+ dtor << "lex: sysex2" << endl;
+ yy_pop_state();
+// yy_push_state( int8 ); //?
+ yy_push_state( data );
+ return SYSEX_EVENT2;
+}
+<event>{META_EVENT} {
+ dtor << "lex: meta" << endl;
+ yy_push_state( meta_event );
+ return META_EVENT;
+}
+<event>{INT8} {
+ error( String( "event: illegal byte: " )
+ + String_convert::bin2hex_str( String( *YYText() ) ) );
+ exit( 1 );
+}
+<meta_event>{SEQUENCE} { // ssss sequence number
+ dtor << "lex: sequence" << endl;
+ yy_pop_state();
+ yy_pop_state();
+ yy_push_state( int16 );
+ return SEQUENCE;
+}
+<meta_event>{YYTEXT} { // len data
+ dtor << "lex: text" << endl;
+// yylval.byte = *(Byte*)YYText();
+ yylval.i = *(Byte*)YYText();
+ yy_pop_state();
+ yy_pop_state();
+ yy_push_state( data );
+ return YYTEXT;
+}
+<meta_event>{YYCOPYRIGHT} {
+ dtor << "lex: copyright" << endl;
+// yylval.byte = *(Byte*)YYText();
+ yylval.i = *(Byte*)YYText();
+ yy_pop_state();
+ yy_pop_state();
+ yy_push_state( data );
+ return YYCOPYRIGHT;
+}
+<meta_event>{YYTRACK_NAME} {
+ dtor << "lex: track name" << endl;
+// yylval.byte = *(Byte*)YYText();
+ yylval.i = *(Byte*)YYText();
+ yy_pop_state();
+ yy_pop_state();
+ yy_push_state( data );
+ return YYTRACK_NAME;
+}
+<meta_event>{YYINSTRUMENT_NAME} {
+ dtor << "lex: instrument name" << endl;
+// yylval.byte = *(Byte*)YYText();
+ yylval.i = *(Byte*)YYText();
+ yy_pop_state();
+ yy_pop_state();
+ yy_push_state( data );
+ return YYINSTRUMENT_NAME;
+}
+<meta_event>{YYLYRIC} {
+ dtor << "lex: lyric" << endl;
+// yylval.byte = *(Byte*)YYText();
+ yylval.i = *(Byte*)YYText();
+ yy_pop_state();
+ yy_pop_state();
+ yy_push_state( data );
+ return YYLYRIC;
+}
+<meta_event>{YYMARKER} {
+ dtor << "lex: marker" << endl;
+// yylval.byte = *(Byte*)YYText();
+ yylval.i = *(Byte*)YYText();
+ yy_pop_state();
+ yy_pop_state();
+ yy_push_state( data );
+ return YYMARKER;
+}
+<meta_event>{YYCUE_POINT} {
+ dtor << "lex: cue point" << endl;
+// yylval.byte = *(Byte*)YYText();
+ yylval.i = *(Byte*)YYText();
+ yy_pop_state();
+ yy_pop_state();
+ yy_push_state( data );
+ return YYCUE_POINT;
+}
+<meta_event>{TEMPO} { // tttttt usec
+ dtor << "lex: tempo" << endl;
+ yy_pop_state();
+ yy_pop_state();
+ yy_push_state( int8 );
+ yy_push_state( int8 );
+ yy_push_state( int8 );
+ return TEMPO;
+}
+<meta_event>{SMPTE_OFFSET} { // hr mn se fr ff
+ dtor << "lex: smpte offset" << endl;
+ yy_pop_state();
+ yy_pop_state();
+ yy_push_state( int8 );
+ yy_push_state( int8 );
+ yy_push_state( int8 );
+ yy_push_state( int8 );
+ yy_push_state( int8 );
+ return SMPTE_OFFSET;
+}
+<meta_event>{TIME} { // nn dd cc bb
+ dtor << "lex: time" << endl;
+ yy_pop_state();
+ yy_pop_state();
+ yy_push_state( int8 );
+ yy_push_state( int8 );
+ yy_push_state( int8 );
+ yy_push_state( int8 );
+ return TIME;
+}
+<meta_event>{KEY} { // sf mi
+ dtor << "lex: key" << endl;
+ yy_pop_state();
+ yy_pop_state();
+ yy_push_state( int8 );
+ yy_push_state( int8 );
+ return KEY;
+}
+<meta_event>{SSME} { // len data
+ dtor << "lex: smme" << endl;
+ yy_pop_state();
+ yy_pop_state();
+ yy_push_state( data );
+ return SSME;
+}
+<meta_event>{END_OF_TRACK} {
+ dtor << "lex: end of track" << endl;
+ yy_pop_state();
+ yy_pop_state();
+ yy_pop_state();
+ return END_OF_TRACK;
+}
+<meta_event>{INT8} {
+ warning( String( "meta_event: unimplemented event: " )
+ + String_convert::bin2hex_str( String( *YYText() ) ),
+ this->here_ch_c_l() );
+ yy_pop_state();
+ yy_pop_state();
+ yy_push_state( int8 );
+ yy_push_state( int8 );
+ return INT8;
+}
+
+<data>{VARINT} {
+ dtor << "lex: data" << endl;
+ String str( (Byte const*)YYText(), YYLeng() );
+ int i = My_midi_lexer::varint2_i( str );
+ String* str_p = new String;
+ while ( i-- )
+ *str_p += (char)yyinput();
+ yylval.str_p = str_p;
+ yy_pop_state();
+ return DATA;
+}
+<data>{INT8} {
+ error( String( "data: illegal byte: " )
+ + String_convert::bin2hex_str( String( *YYText() ) ) );
+ exit( 1 );
+}
+
+<<EOF>> {
+// mtor << "<<EOF>>";
+
+ if ( !close_i() )
+ yyterminate(); // can't move this, since it actually rets a YY_NULL
+}
+
+%%
+
--- /dev/null
+%{
+
+#include "m2m.hh"
+
+#ifndef NDEBUG
+#define YYDEBUG 1
+#endif
+
+%}
+
+%union {
+ Byte byte;
+ char c;
+ int i;
+ String* str_p;
+ Request* request_p;
+ Midi_event* midi_event_p; // Voice_element* ?
+ Midi_score* midi_score_p; // Input_score* ?
+ Midi_track* midi_track_p; // Input_music* ?
+}
+
+%token HEADER TRACK
+%token SYSEX_EVENT1 SYSEX_EVENT2
+%token META_EVENT
+%token SEQUENCE
+%token END_OF_TRACK TEMPO SMPTE_OFFSET TIME KEY SSME
+
+%token<i> INT8 INT16 INT32 INT7_8UNSET INT7_8SET VARINT
+%token<i> RUNNING_STATUS DATA_ENTRY ALL_NOTES_OFF
+%token<i> NOTE_OFF NOTE_ON
+%token<i> POLYPHONIC_AFTERTOUCH CONTROLMODE_CHANGE PROGRAM_CHANGE
+%token<i> CHANNEL_AFTERTOUCH PITCHWHEEL_RANGE
+%token<i> YYTEXT YYCOPYRIGHT YYTRACK_NAME YYINSTRUMENT_NAME YYLYRIC YYMARKER YYCUE_POINT
+%token<str_p> DATA
+
+%type <i> varint
+%type <midi_score_p> header midi_score
+%type <midi_track_p> track
+%type <midi_event_p> event
+%type <midi_event_p> the_event meta_event the_meta_event text_event midi_event sysex_event
+%type <midi_event_p> running_status data_entry all_notes_off
+%type <midi_event_p> note_off note_on
+%type <midi_event_p> polyphonic_aftertouch controlmode_change program_change
+%type <midi_event_p> channel_aftertouch pitchwheel_range
+
+%%
+
+midi: /* empty */
+ | midi midi_score {
+ midi_parser_l_g->add_score( $2 );
+ }
+ ;
+
+midi_score:
+ header {
+ }
+ | midi_score track {
+ $$->add_track( $2 );
+ if ( midi_parser_l_g->copyright_str_.length_i() )
+ $2->copyright_str_ = midi_parser_l_g->copyright_str_;
+ if ( midi_parser_l_g->track_name_str_.length_i() )
+ $2->name_str_ = midi_parser_l_g->track_name_str_;
+ if ( midi_parser_l_g->instrument_str_.length_i() )
+ $2->instrument_str_ = midi_parser_l_g->instrument_str_;
+ midi_parser_l_g->reset();
+ }
+ ;
+
+header:
+ HEADER INT32 INT16 INT16 INT16 {
+ $$ = new Midi_score( $3, $4, $5 );
+ midi_parser_l_g->set_division_4( $5 );
+ }
+ ;
+
+track:
+ TRACK INT32 {
+ $$ = new Midi_track( midi_parser_l_g->track_i_++,
+ // silly, cause not set yet!
+ midi_parser_l_g->copyright_str_,
+ midi_parser_l_g->track_name_str_,
+ midi_parser_l_g->instrument_str_ );
+ }
+ | track event {
+ $$->add_event( midi_parser_l_g->mom(), $2 );
+ }
+ ;
+
+event:
+ varint the_event {
+ $$ = $2;
+ if ( $2 ) {
+ String str = $2->mudela_str( false );
+ if ( str.length_i() )
+ dtor << str << " " << flush;
+ }
+ }
+ ;
+
+varint:
+ VARINT {
+ midi_parser_l_g->forward( $1 );
+ }
+ ;
+
+the_event:
+ meta_event {
+ }
+ | midi_event {
+ }
+ | sysex_event {
+ }
+ ;
+
+meta_event:
+ META_EVENT the_meta_event {
+ $$ = $2;
+ }
+ |
+ META_EVENT INT8 INT8 INT8 {
+ $$ = 0;
+ }
+ ;
+
+the_meta_event:
+ SEQUENCE INT16 {
+ }
+ | text_event DATA {
+ Midi_text::Type type = (Midi_text::Type)$1;
+ $$ = 0;
+ switch ( type )
+ {
+ case Midi_text::COPYRIGHT:
+ midi_parser_l_g->copyright_str_ = *$2;
+ break;
+ case Midi_text::TRACK_NAME:
+ midi_parser_l_g->track_name_str_ = *$2;
+ while ( midi_parser_l_g->track_name_str_.index_i( ' ' ) != -1 )
+ *(midi_parser_l_g->track_name_str_.ch_l() + midi_parser_l_g->track_name_str_.index_i( ' ' ) ) = '_';
+ break;
+ case Midi_text::INSTRUMENT_NAME:
+ midi_parser_l_g->instrument_str_ = *$2;
+ break;
+ default:
+ $$ = new Midi_text( type, *$2 );
+ break;
+ }
+ dtor << *$2 << endl;
+ delete $2;
+ }
+ | END_OF_TRACK {
+ $$ = 0;
+ }
+ | TEMPO INT8 INT8 INT8 {
+ $$ = new Midi_tempo( ( $2 << 16 ) + ( $3 << 8 ) + $4 );
+ dtor << $$->mudela_str( false ) << endl;
+ midi_parser_l_g->set_tempo( ( $2 << 16 ) + ( $3 << 8 ) + $4 );
+ }
+ | SMPTE_OFFSET INT8 INT8 INT8 INT8 INT8 {
+ $$ = 0;
+ }
+ | TIME INT8 INT8 INT8 INT8 {
+ $$ = new Midi_time( $2, $3, $4, $5 );
+ dtor << $$->mudela_str( true ) << endl;
+ midi_parser_l_g->set_time( $2, $3, $4, $5 );
+ }
+ | KEY INT8 INT8 {
+ $$ = new Midi_key( $2, $3 );
+ midi_parser_l_g->set_key( $2, $3 );
+ }
+ | SSME DATA {
+ $$ = new Midi_text( (Midi_text::Type)0, *$2 );
+ delete $2;
+ }
+ ;
+
+text_event:
+ YYTEXT {
+ dtor << "\n% Text: ";
+ }
+ | YYCOPYRIGHT {
+ dtor << "\n% Copyright: ";
+ }
+ | YYTRACK_NAME {
+ dtor << "\n% Track name: ";
+ }
+ | YYINSTRUMENT_NAME {
+ dtor << "\n% Instrument name: ";
+ }
+ | YYLYRIC {
+ dtor << "\n% Lyric: ";
+ }
+ | YYMARKER {
+ dtor << "\n% Marker: ";
+ }
+ | YYCUE_POINT {
+ dtor << "\n% Cue point: ";
+ }
+ ;
+
+midi_event:
+ running_status {
+ }
+ | data_entry {
+ }
+ | all_notes_off {
+ }
+ | note_off {
+ }
+ | note_on {
+ }
+ | polyphonic_aftertouch {
+ }
+ | controlmode_change {
+ }
+ | program_change {
+ }
+ | channel_aftertouch {
+ }
+ | pitchwheel_range {
+ }
+ ;
+
+running_status:
+ RUNNING_STATUS INT8 { //INT8 {
+ $$ = 0;
+ }
+ ;
+
+data_entry:
+ DATA_ENTRY INT8 {
+ $$ = 0;
+ }
+ ;
+
+all_notes_off:
+ ALL_NOTES_OFF INT8 INT8 {
+ $$ = 0;
+ }
+ ;
+
+note_off:
+ NOTE_OFF INT8 INT8 {
+ int i = $1;
+ i = i & ~0x80;
+ $$ = midi_parser_l_g->note_end_midi_event_p( $1 & ~0x80, $2, $3 );
+ }
+ ;
+
+note_on:
+ NOTE_ON INT8 INT8 {
+ int i = $1;
+ i = i & ~0x90;
+ $$ = 0;
+ midi_parser_l_g->note_begin( $1 & ~0x90, $2, $3 );
+ }
+ ;
+
+polyphonic_aftertouch:
+ POLYPHONIC_AFTERTOUCH INT8 INT8 {
+ $$ = 0;
+ }
+ ;
+
+controlmode_change:
+ CONTROLMODE_CHANGE INT8 INT8 {
+ $$ = 0;
+ }
+ ;
+
+program_change:
+ PROGRAM_CHANGE INT8 {
+ $$ = 0;
+ }
+ ;
+
+channel_aftertouch:
+ CHANNEL_AFTERTOUCH INT8 INT8 {
+ $$ = 0;
+ }
+ ;
+
+pitchwheel_range:
+ PITCHWHEEL_RANGE INT8 INT8 {
+ $$ = 0;
+ }
+ ;
+
+sysex_event:
+ SYSEX_EVENT1 DATA {
+ $$ = 0;
+ }
+ | SYSEX_EVENT2 DATA { // INT8 ?
+ $$ = 0;
+ }
+ ;
--- /dev/null
+#
+# project LilyPond -- the musical typesetter
+# title generic red tape for include/Makefile
+# file make/Include.make
+#
+# Copyright (c) 1997 by
+# Jan Nieuwenhuizen <jan@digicash.com>
+# Han-Wen Nienhuys <hanwen@stack.nl>
+
+# identify module:
+#
+NAME = generic-include
+MAJOR_VERSION = $(TOPLEVEL_MAJOR_VERSION)
+MINOR_VERSION = $(TOPLEVEL_MINOR_VERSION)
+PATCH_LEVEL = $(TOPLEVEL_PATCH_LEVEL)
+# use to send patches, always empty for released version:
+MY_PATCH_LEVEL = $(TOPLEVEL_MY_PATCH_LEVEL)
+build = ./$(depth)/lily/.build
+#
+
+# generic variables:
+#
+include ./$(depth)/make/Variables.make
+#
+
+# list of c++ header files:
+#
+HHFILES = $(shell ls *.hh)
+#
+
+# list of c++ inline files:
+#
+INLFILES = $(shell ls *.inl)
+#
+
+# list of c++ template files:
+#
+TCCFILES = $(shell ls *.tcc)
+#
+
+# list of distribution files:
+#
+DISTFILES = Makefile $(HHFILES) $(INLFILES) $(TCCFILES)
+#
+
+# generic targets and rules:
+#
+include ./$(depth)/make/Targets.make
+include ./$(depth)/make/Rules.make
+#
+
--- /dev/null
+#
+# project LilyPond -- the musical typesetter
+# title initial makefile for lilypond
+# file make/Initial.make
+#
+# Copyright (c) 1997 by
+# Jan Nieuwenhuizen <jan@digicash.com>
+# Han-Wen Nienhuys <hanwen@stack.nl>
+#
+
+# subdir level:
+#
+depth = ..
+#
+
+# ugh
+NAME = dummy
+MAJOR_VERSION = $(TOPLEVEL_MAJOR_VERSION)
+MINOR_VERSION = $(TOPLEVEL_MINOR_VERSION)
+PATCH_LEVEL = $(TOPLEVEL_PATCH_LEVEL)
+# use to send patches, always empty for released version:
+MY_PATCH_LEVEL = $(TOPLEVEL_MY_PATCH_LEVEL)
+build = ./$(depth)/lily/.build
+#
+
+# generic variables:
+#
+include ./$(depth)/make/Variables.make
+#
+
+
+# ugh
+# initdefault: $(CCDIR)/parser.cc $(CCDIR)/lexer.cc hdr/version.hh alldeps
+initdefault: check-flower-version $(lily-version) dummydep
+# $(MAKE) -C ./$(depth)/lily $(outdir)/parser.cc
+
+# ugh!
+dummydep:
+ touch ./$(depth)/flower/lib/$(depdir)/dummy.dep
+ touch ./$(depth)/lib/$(depdir)/dummy.dep
+ touch ./$(depth)/lily/$(depdir)/dummy.dep
+ touch ./$(depth)/m2m/$(depdir)/dummy.dep
+
+#$(DEPDIR)/%.dep: $(CCDIR)/%.cc
+# $(DODEP) $(CXX) -E $(CXXFLAGS) $^ > /dev/null
+
+# generic targets and rules:
+#
+include ./$(depth)/make/Targets.make
+include ./$(depth)/make/Rules.make
+#
+
--- /dev/null
+#
+# project LilyPond -- the musical typesetter
+# title zucht
+# file make/Makefile
+#
+# Copyright (c) 1997 by
+# Jan Nieuwenhuizen <jan@digicash.com>
+# Han-Wen Nienhuys <hanwen@stack.nl>
+# ...your sort order here, or how to comment-out a comment
+
+# subdir level:
+#
+depth = ..
+#
+
+# identify module:
+#
+NAME = make
+MAJOR_VERSION = $(TOPLEVEL_MAJOR_VERSION)
+MINOR_VERSION = $(TOPLEVEL_MINOR_VERSION)
+PATCH_LEVEL = $(TOPLEVEL_PATCH_LEVEL)
+# use to send patches, always empty for released version:
+MY_PATCH_LEVEL = $(TOPLEVEL_MY_PATCH_LEVEL)
+build = ./$(depth)/lily/.build
+#
+
+# list of generic make files:
+#
+MAKEFILES = $(shell ls *.make)
+#
+
+# list of distribution files:
+#
+DISTFILES = Makefile $(MAKEFILES)
+#
+
+# generic variables:
+#
+include ./$(depth)/make/Variables.make
+#
+
+# generic targets and rules:
+#
+include ./$(depth)/make/Targets.make
+include ./$(depth)/make/Rules.make
+#
+
--- /dev/null
+#
+# project LilyPond -- the musical typesetter
+# title generic make rules
+# file make/Rules.make
+#
+# Copyright (c) 1997 by
+# Jan Nieuwenhuizen <jan@digicash.com>
+# Han-Wen Nienhuys <hanwen@stack.nl>
+
+.SUFFIXES:
+.SUFFIXES: .cc .o .hh .y .l .pod .txt .1 .dep
+
+# compile rules:
+#
+$(outdir)/%.o: %.cc
+ $(DODEP)\
+ $(CXX) -c $(CXXFLAGS) $(CXX_OUTPUT_OPTION)
+
+$(outdir)/%.cc: %.y
+# $(BISON) -d $<
+ $(BISON) $<
+# mv $(shell basename $@ .cc ).tab.h $(include-lib)/$(shell basename $@ .cc).hh
+# mv $(shell basename $@ .cc ).tab.h $(outdir)/$(shell basename $@ .cc).hh
+ mv $(shell basename $@ .cc ).tab.c $@
+
+$(outdir)/%.hh: %.y
+ $(BISON) -d $<
+ mv $(shell basename $@ .hh ).tab.h $@
+ mv $(shell basename $@ .hh ).tab.c $(outdir)/$(shell basename $@ .hh).cc
+
+$(outdir)/%.cc: %.l
+ $(FLEX) -t $< > $@
+
+$(outdir)/%.text: $(outdir)/%.1
+ groff -man -Tascii $< > $@
+
+$(outdir)/%.1: %.pod
+ pod2man --center="LilyPond documentation" --section="0"\
+ --release="LilyPond $(MAJVER).$(MINVER).$(PATCHLEVEL)" $< > $@
+#
+
+# specific stuff:
+#
+$(LIBFLOWER): check-flower-version
+# $(MAKE) -C ./$(depth)/flower/lib
+ $(MAKE) ./$(outdir)/$(@F) -C $(depth)/flower/lib
+#
+$(LIBLILY): check-flower-version $(lily-version)
+# $(MAKE) -C ./$(depth)/lib
+ $(MAKE) ./$(outdir)/$(@F) -C $(depth)/lib
+#
+
--- /dev/null
+# kept in dist bo stripping stable stuff, still to copy...
+
+# Sources.make
+# sourcefiles to be shipped. Also used for dependencies
+
+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\
+ glob.hh grouping.hh headreg.hh idealspacing.hh\
+ identifier.hh identparent.hh \
+ inputmusic.hh inputscore.hh inputstaff.hh\
+ inputfile.hh\
+ item.hh key.hh keyitem.hh\
+ keyreg.hh\
+ keyword.hh leastsquares.hh lexer.hh linespace.hh \
+ localkeyitem.hh localkeyreg.hh lookup.hh \
+ lyricitem.hh lyricstaff.hh lyricwalker.hh\
+ main.hh meter.hh meterreg.hh\
+ mididef.hh midiitem.hh midioutput.hh midistream.hh\
+ midiwalker.hh\
+ misc.hh\
+ molecule.hh moment.hh musicalrequest.hh\
+ notehead.hh notename.hh offset.hh paperdef.hh\
+ parseconstruct.hh pcol.hh proto.hh\
+ pscore.hh pstaff.hh qlp.hh\
+ qlpsolve.hh register.hh registergroup.hh reqtodo.hh \
+ request.hh rest.hh scorecolumn.hh score.hh\
+ scoreline.hh scorewalker.hh script.hh scriptdef.hh scriptreg.hh \
+ slur.hh slurreg.hh source.hh sourcefile.hh\
+ spanner.hh staff.hh\
+ staffelem.hh staffeleminfo.hh staffline.hh staffsym.hh stembeamreg.hh\
+ staffcolumn.hh stem.hh staffwalker.hh symbol.hh symtable.hh\
+ tex.hh textdef.hh \
+ textitem.hh textreg.hh textspanner.hh timedescription.hh \
+ tstream.hh voice.hh\
+ voiceregs.hh voicegroupregs.hh walkregs.hh
+
+mycc=bar.cc barreg.cc beam.cc \
+ binary-source-file.cc\
+ boxes.cc break.cc calcideal.cc clefreg.cc\
+ clefitem.cc colhpos.cc commandrequest.cc\
+ complexstaff.cc complexwalker.cc \
+ debug.cc dimen.cc\
+ directionalspanner.cc\
+ grouping.cc groupregs.cc headreg.cc\
+ idealspacing.cc identifier.cc\
+ inputmusic.cc inputscore.cc\
+ inputstaff.cc\
+ inputfile.cc\
+ item.cc key.cc keyitem.cc \
+ keyreg.cc keyword.cc\
+ leastsquares.cc lexerinit.cc linespace.cc \
+ localkeyitem.cc localkeyreg.cc lookup.cc\
+ lyricitem.cc lyricstaff.cc lyricwalker.cc\
+ main.cc meter.cc meterreg.cc\
+ mididef.cc midiitem.cc midioutput.cc midistream.cc\
+ midiwalker.cc misc.cc molecule.cc mylexer.cc note.cc\
+ notehead.cc notename.cc\
+ paperdef.cc pcol.cc pscore.cc pstaff.cc qlp.cc qlpsolve.cc\
+ register.cc registergroup.cc request.cc rest.cc\
+ scorecolumn.cc score.cc\
+ scoreline.cc scores.cc scorewalker.cc script.cc\
+ scriptdef.cc scriptreg.cc slur.cc\
+ slurreg.cc source.cc sourcefile.cc\
+ spanner.cc staff.cc\
+ staffelem.cc staffline.cc staffsym.cc\
+ stembeamreg.cc staffcolumn.cc stem.cc\
+ staffeleminfo.cc staffwalker.cc symbol.cc\
+ symtable.cc tex.cc texbeam.cc\
+ texslur.cc textdef.cc textitem.cc textreg.cc textspanner.cc\
+ timedescription.cc tstream.cc voice.cc voiceelt.cc \
+ voiceregs.cc voicegroupregs.cc\
+ walkregs.cc warn.cc windhoos-suck-suck-suck-thank-you-cygnus.cc wordwrap.cc\
+ template1.cc template2.cc template3.cc template4.cc\
+ template5.cc template6.cc version.cc
+
+# a bit of a hack to keep exec size under control.
+stablecc=request.cc bar.cc boxes.cc break.cc \
+ item.cc keyword.cc leastsquares.cc \
+ lookup.cc molecule.cc meter.cc\
+ paperdef.cc parser.cc lexer.cc pstaff.cc qlp.cc qlpsolve.cc\
+ template1.cc template2.cc template3.cc template4.cc\
+ template5.cc template6.cc version.cc tstream.cc tex.cc\
+ voice.cc wordwrap.cc spanner.cc
+
+
+# m2m headers
+#
+mym2mhh=\
+ 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=\
+ duration.cc\
+ lily-stream.cc\
+ midi-event.cc\
+ midi-main.cc\
+ midi-score.cc\
+ midi-template.cc\
+ 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\
+
+#
+
--- /dev/null
+#
+# project LilyPond -- the musical typesetter
+# title generic red tape for stuff/Makefile
+# file make/Stuff.make
+#
+# Copyright (c) 1997 by
+# Jan Nieuwenhuizen <jan@digicash.com>
+# Han-Wen Nienhuys <hanwen@stack.nl>
+# identify module:
+#
+
+NAME = generic-stuff
+MAJOR_VERSION = $(TOPLEVEL_MAJOR_VERSION)
+MINOR_VERSION = $(TOPLEVEL_MINOR_VERSION)
+PATCH_LEVEL = $(TOPLEVEL_PATCH_LEVEL)
+# use to send patches, always empty for released version:
+MY_PATCH_LEVEL = $(TOPLEVEL_MY_PATCH_LEVEL)
+# build = ./$(depth)/lily/.build
+#
+
+# generic variables:
+#
+include ./$(depth)/make/Variables.make
+#
+
+# generic targets and rules:
+#
+include ./$(depth)/make/Targets.make
+include ./$(depth)/make/Rules.make
+#
+
--- /dev/null
+#
+# project LilyPond -- the musical typesetter
+# title generic make rules
+# file make/Rules.make
+#
+# Copyright (c) 1997 by
+# Jan Nieuwenhuizen <jan@digicash.com>
+# Han-Wen Nienhuys <hanwen@stack.nl>
+
+.PHONY : all clean default dist doc doc++ dummy exe help lib tags
+
+# target all:
+#
+all: default
+ for i in $(SUBDIRS); do $(MAKE) -C $$i all; done
+#
+
+# dependency list of executable:
+#
+EXECUTABLE = $(bindir)/$(NAME)
+$(EXECUTABLE): $(OFILES) $(CUSTOMLIBES)
+# $(STRIPDEBUG) $(STABLEOBS)
+# $(LD_COMMAND) -o $@ $^ $(LOADLIBES)
+ $(LD_COMMAND) $(OFILES) $(LOADLIBES)
+ touch $(VERSION_DEPENDENCY)
+ $(INCREASE_BUILD)
+ touch $(build) #waai necessary?
+#
+exe: $(EXECUTABLE)
+#
+
+# dependency list of library:
+#
+LIBRARY = $(libdir)/$(LIB_PREFIX)$(NAME)$(LIB_SUFFIX)
+$(LIBRARY): $(OFILES) $(CUSTOMLIBES)
+ $(AR_COMMAND) $(OFILES)
+ touch $(VERSION_DEPENDENCY)
+ $(INCREASE_BUILD)
+ touch $(build) #waai necessary?
+#
+lib: $(LIBRARY)
+#
+
+clean:
+ rm -f $(allexe) core $(allobs)
+ for i in $(SUBDIRS); do $(MAKE) -C $$i clean; done
+
+distclean: clean
+ rm -rf $(lily-version) $(flower-version) .b $(build) .GENERATE *~ $(allout)
+
+
+# configure:
+#
+config:
+ $(bindir)/configure
+#
+
+# value of $(OSTYPE) on windhoos; "make $OSTYPE" if you use bash :-)
+#
+win32:
+ $(MAKE) -C . CXX=g++
+#
+
+# xcompile to doze:
+#
+doze: dos
+dos:
+ $(MAKE) -C . CXX="gcc-go32 -I/usr/i386-go32/include -I/usr/i386-go32/include/g++ -D_WIN32 -Dcaddr_t=char* -DMAP_SHARED=0"
+#
+
+# target help:
+#
+help:
+ @echo "Usage:"
+ @echo " $(MAKE) ["VARIABLE=value" ...] [target]"
+ @echo
+ @echo "targets:"
+ @echo " all clean config dist distclean doc doc++"
+ @echo " exe help lib moduledist tags"
+ @echo " dos: xcomplile to dos"
+ @echo " win32: native cygnus-win32 compile"
+#
+
+doc:
+ $(MAKE) -C Documentation do-doc
+
+# doc++ documentation of classes
+doc++: $(progdocs)
+ doc++ -kp -d $(DOCDIR) $^
+
+dist:
+ -mkdir $(distdir)
+ $(MAKE) localdist
+ (cd ./$(depth); tar cfz $(DIST_NAME).tar.gz $(DIST_NAME))
+ rm -rf $(distdir)/ # should be trapped
+
+localdist:
+ ln $(DISTFILES) $(distdir)/$(localdir)
+ for i in $(SUBDIRS); do mkdir $(distdir)/$(localdir)/$$i; done
+ for i in $(SUBDIRS); do $(MAKE) localdir=$(localdir)/$$i -C $$i localdist; done
+
+moduledist:
+ -mkdir $(module-distdir)
+ $(MAKE) localmoduledist
+ (cd ./$(depth); tar cfz $(MODULE_DIST_NAME).tar.gz $(MODULE_DIST_NAME))
+ rm -rf $(module-distdir)/ # should be trapped
+
+localmoduledist:
+ ln $(DISTFILES) $(module-distdir)/$(localdir)
+ for i in $(SUBDIRS); do mkdir $(module-distdir)/$(localdir)/$$i; done
+ for i in $(SUBDIRS); do $(MAKE) localdir=$(localdir)/$$i -C $$i localmoduledist; done
+
+all-tags: tags
+ for i in $(SUBDIRS); do $(MAKE) -C $$i all-tags; done
+
+tags:
+ etags -CT $(allcc)
+
+# version stuff:
+#
+check-flower-version:
+ $(MAKE) flower-version -C ./$(depth)/flower
+$(lily-version): ./$(depth)/.version ./$(bindir)/make_version $(build)
+ ./$(bindir)/make_version "$(MAJOR_VERSION)" "$(MINOR_VERSION)" "$(PATCH_LEVEL)" "$(MY_PATCH_LEVEL)" "$(BUILD)" "$(CXX) $(CXXVER)" > $@
+#
+
--- /dev/null
+# THIS IS A TEMPLATE FOR SUB-PROJECT MAKEFILES
+# should we make Include-dir and Stuff-dir templates too?
+
+# project LilyPond -- the musical typesetter
+# title makefile for ...
+# file ../Makefile
+#
+# Copyright (c) 1997 by
+# Jan Nieuwenhuizen <jan@digicash.com>
+# Han-Wen Nienhuys <hanwen@stack.nl>
+#
+
+# subdir level:
+#
+depth = ..
+#
+
+# identify module:
+#
+NAME = ...
+# include ./$(depth)/$(NAME)/.version
+MAJOR_VERSION = 0
+MINOR_VERSION = 0
+PATCH_LEVEL = 0
+# use to send patches, always empty for released version:
+MY_PATCH_LEVEL = # include separator: "-1" or ".a"
+build = ./$(depth)/lily/.build
+#
+
+# generic variables:
+#
+include ./$(depth)/make/Variables.make
+#
+
+# descent order into subdirectories:
+#
+SUBDIRS =
+#
+
+# to be remade each build:
+#
+VERSION_DEPENDENCY = $(lily-version)
+#
+
+# module compile settings: (not generally needed!
+#
+EXTRA_CFLAGS =
+EXTRA_CXXFLAGS =
+EXTRA_LDFLAGS =
+#
+
+# list of c++ header files:
+#
+HHFILES = $(shell ls *.hh)
+#
+
+# list of c++ source files:
+#
+CCFILES = $(shell ls *.cc)
+#
+
+# list of other source files:
+#
+EXTRA_SOURCE_FILES = $(shell ls *.y *.l)
+#
+
+# list of distribution files:
+#
+DISTFILES = $(HHFILES) $(CCFILES) $(EXTRA_SOURCE_FILES)
+#
+
+# list of custom libraries:
+#
+CUSTOMLIBES = \
+
+LOADLIBES +=
+#
+
+# main target of this module:
+#
+MAINTARGET = $(EXECUTABLE)
+# MAINTARGET = $(LIBRARY)
+
+default: $(MAINTARGET)
+#
+
+# generic targets and rules:
+#
+include ./$(depth)/make/Targets.make
+include ./$(depth)/make/Rules.make
+#
+
+# auto dependencies:
+#
+include ./$(outdir)/*.dep
+#
+
--- /dev/null
+#
+# project LilyPond -- the musical typesetter
+# title user changeable settings
+# file make/User.make
+#
+# Copyright (c) 1997 by
+# Jan Nieuwenhuizen <jan@digicash.com>
+# Han-Wen Nienhuys <hanwen@stack.nl>
+
+# this still sux
+# will be split into CFLAGS/EXTRA_CFLAGS etc,
+# so that defineable generically and per module
+
+# you-re using a i386, eh?
+#
+#PROFILEFLAG=-pg
+#
+
+# optimization and debugging:
+#
+# if defined (=not commented-out), debugging flag is ignored!
+OPTIFLAG=-DNDEBUG -DNPRINT -O2
+#
+DEBUGFLAG=-g
+#
+
+# turn off -pipe if linker doesn't support it
+#
+USER_CXXFLAGS=-pipe -Wall -W -Wmissing-prototypes -DSTRING_UTILS_INLINED -O
+#
+
+#
+# -lefence = ElectricFence.
+#
+# ElectricFence is a memory debugger which uses the
+# VM hardware to trap malloc/free errors.
+#
+
+EXTRALIB+= #-lefence
+
--- /dev/null
+#
+# project LilyPond -- the musical typesetter
+# title generic variables
+# file make/Variables.make
+# abstract do not change this file; edit settings in User.make
+#
+# Copyright (c) 1997 by
+# Jan Nieuwenhuizen <jan@digicash.com>
+# Han-Wen Nienhuys <hanwen@stack.nl>
+
+# toplevel version info, might be handy?
+#
+include ./$(depth)/.version
+#
+
+# directory names:
+#
+outdir = out# "objects" won-t do, used for libs and deps as well
+bindir = ./$(depth)/bin
+distdir = ./$(depth)/$(DIST_NAME)
+module-distdir = ./$(depth)/$(MODULE_DIST_NAME)
+depdir = $(outdir)
+libdir = $(outdir)
+flowerout = ./$(depth)/flower/lib/$(outdir)
+libout = ./$(depth)/lib/$(outdir)
+# flower-dir = ./$(depth)/flower
+include-lib = ./$(depth)/lib/include
+include-flower = ./$(depth)/flower/lib/include
+#
+
+# user settings:
+#
+include ./$(depth)/make/User.make
+#
+
+ifdef PROFILEFLAG
+ DEFINES+=$(OPTIFLAG) $(PROFILEFLAG)
+ EXTRA_LIBES+=-pg
+endif
+
+ifndef DEBUGFLAG
+ DEFINES+=$(OPTIFLAG)
+else
+ DEFINES+=$(DEBUGFLAG)
+endif
+
+# build no:
+#
+# need to be defined in local Makefiles:
+# build = ./$(depth)/lily/.build
+BUILD = $(shell cat $(build))
+INCREASE_BUILD = @echo `expr \`cat $(build)\` + 1` > .b; mv .b $(build)
+#
+
+# the version:
+#
+VERSION=$(MAJOR_VERSION).$(MINOR_VERSION).$(PATCH_LEVEL)$(MY_PATCH_LEVEL)
+TOPLEVEL_VERSION=$(TOPLEVEL_MAJOR_VERSION).$(TOPLEVEL_MINOR_VERSION).$(TOPLEVEL_PATCH_LEVEL)$(TOPLEVEL_MY_PATCH_LEVEL)
+#
+
+# compiler version:
+#
+CXXVER=`$(CXX) --version`
+#
+
+# module and top level dist:
+#
+# fix naming, use TOPLEVEL_ prefix _or_ MODULE?
+MODULE_DIST_NAME = $(MODULE_NAME)-$(VERSION)
+DIST_NAME = lilypond-$(TOPLEVEL_VERSION)
+#
+
+# list of object files:
+#
+SOURCE_FILES = $(CCFILES) $(EXTRA_SOURCE_FILES)
+OFILEC = $(SOURCE_FILES:.c=.o)
+OFILECC = $(OFILEC:.cc=.o)
+OFILEL = $(OFILECC:.l=.o)
+OFILEY = $(OFILEL:.y=.o)
+OFILES = $(patsubst %,$(outdir)/%,$(OFILEY))
+#
+
+# clean file lists:
+#
+allexe = $(bindir)/lilypond $(bindir)/m2m
+allobs = $(shell find $(outdir) -name "*.o" )
+allibs = $(shell find $(libdir) -name "*.lib" )
+alldeps = $(shell find $(outdir) -name "*.dep" )
+allout = $(shell find . -name "$(outdir)" )
+#
+
+# version stuff:
+#
+flower-version = $(flowerout)/fversion.hh
+lily-version = $(libout)/version.hh
+#
+
+# custom libraries:
+#
+LIBFLOWER = $(depth)/flower/lib/$(outdir)/$(LIB_PREFIX)flower$(LIB_SUFFIX)
+LIBLILY = $(depth)/lib/$(outdir)/$(LIB_PREFIX)lily$(LIB_SUFFIX)
+#
+
+# compile and link options:
+#
+ARFLAGS = ru
+CFLAGS = $(DEFINES) $(INCLUDES) $(USER_CFLAGS) $(EXTRA_CFLAGS)
+CXXFLAGS = $(CFLAGS) $(USER_CXXFLAGS) $(EXTRA_CXXFLAGS)
+INCLUDES = -Iinclude -I$(outdir) -I$(include-lib) -I$(libout) -I$(include-flower) -I$(flowerout)
+CXX_OUTPUT_OPTION = $< -o $@
+LDFLAGS = $(EXTRA_LDFLAGS)
+LOADLIBES = $(EXTRA_LIBES) $(CUSTOMLIBES) -lg++
+#
+
+# librarian:
+#
+AR = ar
+AR_COMMAND = $(AR) $(ARFLAGS) $@
+#
+
+# compiler:
+#
+# "CC = $(CC)"
+# "CXX = $(CXX)"
+#
+
+# linker:
+#
+LD = $(CXX)
+LD_COMMAND = $(LD) $(LDFLAGS) -o $@
+#
+
+# dependencies:
+#
+depfile = ./$(depdir)/$(subst .o,.dep,$(notdir $@))
+DODEP=rm -f $(depfile); DEPENDENCIES_OUTPUT="$(depfile) $(outdir)/$(notdir $@)"
+#
+
+# utils:
+#
+FLEX = flex
+BISON = bison
+#
+
+# generic target names:
+#
+EXECUTABLE = $(NAME)$(EXE)
+LIB_PREFIX = lib
+LIB_SUFFIX = .a
+LIBRARY = $(LIB_PREFIX)$(NAME)$(LIB_SUFFIX)
+#
+
+STRIPDEBUG=true #replace to do stripping of certain objects
+
+++ /dev/null
-#!/bin/sh
-
-case $# in
-0) echo make_patch old new name
- exit 1;;
-esac
-
-old=$1
-new=$2
-nm=$3-
-
-newarc=../releases/$nm$new.tar.gz
-oldarc=../releases/$nm$old.tar.gz
-
-
-if [ ! -x $nm$new ]
-then
- echo untarring ..
- if [ ! -f $newarc ]
- then
- echo cant find $newarc
- exit
- fi
- tar zfxv $newarc
-fi
-if [ ! -x $nm$old ]
-then
- echo untarring
-
- if [ ! -f $oldarc ]
- then
- echo cant find oldarc
- exit
- fi
- tar zfxv $oldarc
-fi
-
-#(cd $nm$old; touch depend; make clean)
-#(cd $nm$new; touch depend; make clean)
-(cd $nm$new; diff -urP ../$nm$old . > ../patch-$new)
-rm -rf $nm$old $nm$new
+++ /dev/null
-#!/bin/sh
-echo '#ifndef VERSION_HH'
-echo '#define VERSION_HH'
-echo '#define MAJORVERSION ' $1
-echo '#define MINORVERSION ' $2
-echo '#define PATCHLEVEL ' $3
-echo '#define VERSIONSTR "'$1.$2.$3'"'
-echo '#define COMPILER "'$4'"'
-echo '#endif'
+++ /dev/null
-DISTFILES=Makefile
-dist:
- ln $(DISTFILES) $(DDIR)/$(SUBDIR)
-
-clean:
- rm *.o
\ No newline at end of file
+++ /dev/null
-default:
- $(MAKE) -C ..
-
-win32:
- $(MAKE) -C .. Windows_NT
-
-DISTFILES=Makefile $(allcc) $(othersrc)
-dist:
- ln $(DISTFILES) $(DDIR)/$(SUBDIR)
-
-TAGS: $(allcc)
- $(TAGSACTION) $^
-
-clean:
- rm -f $(gencc)
+++ /dev/null
-/*
- bar-reg.cc -- implement Bar_register
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-#include "bar-reg.hh"
-#include "bar.hh"
-#include "commandrequest.hh"
-#include "score-column.hh"
-#include "time-description.hh"
-
-Bar_register::Bar_register()
-{
- post_move_processing();
-}
-
-bool
-Bar_register::try_request(Request*r_l)
-{
- Command_req* c_l = r_l->command();
- if (!c_l|| !c_l->bar())
- return false;
-
- assert(!bar_req_l_);
- bar_req_l_ = c_l->bar();
-
- return true;
-}
-
-void
-Bar_register::process_requests()
-{
- if (bar_req_l_ ) {
- bar_p_ = new Bar(bar_req_l_->type_str_);
- } else if (!get_staff_info().time_c_l_->whole_in_measure_) {
- bar_p_ = new Bar("|");
- }
-
- if (bar_p_){
- announce_element(Staff_elem_info(bar_p_, bar_req_l_) );
- }
-}
-
-void
-Bar_register::split_bar(Bar *& pre, Bar * no, Bar * &post)
-{
- String s= no->type;
- if (s == ":|:") {
- pre = new Bar(":|");
- post = new Bar("|:");
- }else if (s=="|:") {
- post = new Bar(s);
- } else {
- pre = new Bar(*no);
- }
-}
-
-void
-Bar_register::pre_move_processing()
-{
- if (bar_p_) {
- Bar * post_p =0;
- Bar * pre_p =0;
- split_bar(pre_p, bar_p_, post_p);
-
- typeset_breakable_item(pre_p, bar_p_, post_p);
- bar_p_ =0;
- }
-}
-
-void
-Bar_register::post_move_processing()
-{
- bar_req_l_ = 0;
- bar_p_ =0;
-}
+++ /dev/null
-#include "bar.hh"
-#include "string.hh"
-#include "molecule.hh"
-#include "paper-def.hh"
-#include "lookup.hh"
-#include "debug.hh"
-
-
-
-Bar::Bar( String t)
-{
- type = t;
-}
-
-void
-Bar::do_print()const
-{
- mtor << type;
-}
-
-Molecule*
-Bar::brew_molecule_p()const
-{
- Symbol s = paper()->lookup_p_->bar(type);
- Molecule*output = new Molecule(Atom(s));
- return output;
-}
-
+++ /dev/null
-#include "varray.hh"
-
-#include "dimen.hh"
-#include "beam.hh"
-#include "misc.hh"
-#include "debug.hh"
-#include "symbol.hh"
-#include "molecule.hh"
-#include "leastsquares.hh"
-#include "pcol.hh"
-#include "stem.hh"
-#include "paper-def.hh"
-#include "lookup.hh"
-#include "grouping.hh"
-
-
-
-struct Stem_info {
- Real x;
- Real idealy;
- Real miny;
- int no_beams;
-
-
- Stem_info(){}
- Stem_info(const Stem*);
-};
-
-Stem_info::Stem_info(const Stem*s)
-{
- x = s->hindex();
- int dir = s->dir;
- idealy = max(dir*s->top, dir*s->bot);
- miny = max(dir*s->minnote, dir*s-> maxnote);
- assert(miny <= idealy);
-
-}
-
-/* *************** */
-
-Offset
-Beam::center()const
-{
- assert(status >= POSTCALCED);
-
- Real w=(paper()->note_width() + width().length())/2.0;
- return Offset(w, (left_pos + w* slope)*paper()->internote());
-}
-
-
-Beam::Beam()
-{
- slope = 0;
- left_pos = 0.0;
-}
-
-void
-Beam::add(Stem*s)
-{
- stems.bottom().add(s);
- s->add_dependency(this);
- s->print_flag = false;
-}
-
-void
-Beam::set_default_dir()
-{
- int dirs[2];
- dirs[0]=0; dirs[1] =0;
- for (iter_top(stems,i); i.ok(); i++) {
- int d = i->get_default_dir();
- dirs[(d+1)/2] ++;
- }
- dir_i_ = (dirs[0] > dirs[1]) ? -1 : 1;
- for (iter_top(stems,i); i.ok(); i++) {
- i->dir = dir_i_;
- }
-}
-
-/*
- should use minimum energy formulation (cf linespacing)
- */
-void
-Beam::solve_slope()
-{
- Array<Stem_info> sinfo;
- for (iter_top(stems,i); i.ok(); i++) {
- i->set_default_extents();
- Stem_info info(i);
- sinfo.push(info);
- }
- Real leftx = sinfo[0].x;
- Least_squares l;
- for (int i=0; i < sinfo.size(); i++) {
- sinfo[i].x -= leftx;
- l.input.push(Offset(sinfo[i].x, sinfo[i].idealy));
- }
-
- l.minimise(slope, left_pos);
- Real dy = 0.0;
- for (int i=0; i < sinfo.size(); i++) {
- Real y = sinfo[i].x * slope + left_pos;
- Real my = sinfo[i].miny;
-
- if (my - y > dy)
- dy = my -y;
- }
- left_pos += dy;
- left_pos *= dir_i_;
- slope *= dir_i_;
-
- // URG
- Real sl = slope*paper()->internote();
- paper()->lookup_p_->beam(sl, 20 PT);
- slope = sl /paper()->internote();
-}
-
-void
-Beam::set_stemlens()
-{
- iter_top(stems,s);
- Real x0 = s->hindex();
- for (; s.ok() ; s++) {
- Real x = s->hindex()-x0;
- s->set_stemend(left_pos + slope * x);
- }
-}
-
-
-void
-Beam::do_post_processing()
-{
- solve_slope();
- set_stemlens();
-}
-
-void
-Beam::set_grouping(Rhythmic_grouping def, Rhythmic_grouping cur)
-{
- def.OK();
- cur.OK();
- assert(cur.children.size() == stems.size());
-
- cur.split(def);
-
- Array<int> b;
- {
- iter_top(stems,s);
- Array<int> flags;
- for (; s.ok(); s++) {
- int f = intlog2(abs(s->flag))-2;
- assert(f>0);
- flags.push(f);
- }
- int fi =0;
- b= cur.generate_beams(flags, fi);
- b.insert(0,0);
- b.push(0);
- assert(stems.size() == b.size()/2);
- }
-
- iter_top(stems,s);
- for (int i=0; i < b.size() && s.ok(); i+=2, s++) {
- s->beams_left = b[i];
- s->beams_right = b[i+1];
- }
-}
-
-
-// todo.
-Spanner *
-Beam::do_break_at( PCol *, PCol *) const
-{
- Beam *beam_p= new Beam(*this);
-
- return beam_p;
-}
-
-void
-Beam::do_pre_processing()
-{
- left = (*stems.top()) ->pcol_l_;
- right = (*stems.bottom())->pcol_l_;
- assert(stems.size()>1);
- if (!dir_i_)
- set_default_dir();
-
-}
-
-
-Interval
-Beam::width() const
-{
- Beam * me = (Beam*) this; // ugh
- return Interval( (*me->stems.top()) ->hindex(),
- (*me->stems.bottom()) ->hindex() );
-}
-
-/*
- beams to go with one stem.
- */
-Molecule
-Beam::stem_beams(Stem *here, Stem *next, Stem *prev)const
-{
- 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();
- paper()->lookup_p_->beam(sl, 20 PT);
-
- Molecule leftbeams;
- Molecule rightbeams;
-
- /* half beams extending to the left. */
- if (prev) {
- int lhalfs= lhalfs = here->beams_left - prev->beams_right ;
- int lwholebeams= here->beams_left <? prev->beams_right ;
- Real w = (here->hindex() - prev->hindex())/4;
- Symbol dummy;
- Atom a(dummy);
- if (lhalfs) // generates warnings if not
- a = paper()->lookup_p_->beam(sl, w);
- a.translate(Offset (-w, -w * sl));
- for (int j = 0; j < lhalfs; j++) {
- Atom b(a);
- b.translate(Offset(0, -dir_i_ * dy * (lwholebeams+j)));
- leftbeams.add( b );
- }
- }
-
- if (next){
- int rhalfs = here->beams_right - next->beams_left;
- int rwholebeams = here->beams_right <? next->beams_left;
-
- Real w = next->hindex() - here->hindex();
- Atom a = paper()->lookup_p_->beam(sl, w + stemdx);
-
- int j = 0;
- for (; j < rwholebeams; j++) {
- Atom b(a);
- b.translate(Offset(0, -dir_i_ * dy * j));
- rightbeams.add( b );
- }
-
- w /= 4;
- if (rhalfs)
- a = paper()->lookup_p_->beam(sl, w);
-
- for (; j < rwholebeams + rhalfs; j++) {
- Atom b(a);
- b.translate(Offset(0, -dir_i_ * dy * j));
- rightbeams.add(b );
- }
-
- }
- leftbeams.add(rightbeams);
- return leftbeams;
-}
-
-
-Molecule*
-Beam::brew_molecule_p() const return out;
-{
- Real inter=paper()->internote();
- out = new Molecule;
- Real x0 = stems.top()->hindex();
-
- for (iter_top(stems,i); i.ok(); i++) {
- PCursor<Stem*> p(i-1);
- PCursor<Stem*> n(i+1);
- Stem * prev = p.ok() ? p.ptr() : 0;
- Stem * next = n.ok() ? n.ptr() : 0;
-
- Molecule sb = stem_beams(i, next, prev);
- Real x = i->hindex()-x0;
- sb.translate(Offset(x, (x * slope + left_pos)* inter));
- out->add(sb);
- }
- out->translate(Offset(x0 - left->hpos,0));
-}
-
-void
-Beam::do_print()const
-{
-#ifndef NPRINT
- mtor << "slope " <<slope << "left ypos " << left_pos;
- Spanner::print();
-#endif
-}
-
-Beam::~Beam()
-{
-
-}
+++ /dev/null
-/*
- binary-source-file.cc -- implement Binary_source_file
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Jan Nieuwenhuizen
-*/
-
-
-#include <limits.h> // INT_MAX
-#include <assert.h>
-
-#include "proto.hh"
-#include "plist.hh"
-#include "string.hh"
-#include "debug.hh"
-#include "source-file.hh"
-#include "binary-source-file.hh"
-#include "string-convert.hh"
-
-Binary_source_file::Binary_source_file( String& filename_str )
- : Source_file( filename_str )
-{
-}
-
-Binary_source_file::~Binary_source_file()
-{
-}
-
-String
-Binary_source_file::error_str( char const* pos_ch_c_l )
-{
- assert( this );
- if ( !in_b( pos_ch_c_l ) )
- return "";
-
- char const* begin_ch_c_l = pos_ch_c_l - 8 >? ch_c_l();
- char const* end_ch_c_l = pos_ch_c_l + 7 <? ch_c_l() + length_off();
-
- String pre_str( (Byte const*)begin_ch_c_l, pos_ch_c_l - begin_ch_c_l );
- pre_str = String_convert::bin2hex_str( pre_str );
- for ( int i = 2; i < pre_str.length_i(); i += 3 )
- pre_str = pre_str.left_str( i ) + " " + pre_str.mid_str( i + 1, INT_MAX );
- String post_str( (Byte const*)pos_ch_c_l, end_ch_c_l - pos_ch_c_l );
- post_str = String_convert::bin2hex_str( post_str );
- for ( int i = 2; i < post_str.length_i(); i += 3 )
- post_str = post_str.left_str( i ) + " " + post_str.mid_str( i + 1, INT_MAX );
-
- String str = pre_str
- + String( '\n' )
- + String( ' ', pre_str.length_i() + 1 )
- + post_str;
- return str;
-}
-
-int
-Binary_source_file::line_i( char const* pos_ch_c_l )
-{
- if ( !in_b( pos_ch_c_l ) )
- return 0;
-
- return pos_ch_c_l - ch_c_l();
-}
-
+++ /dev/null
-#include "boxes.hh"
-#include "const.hh"
-#include "varray.hh"
-
-
-Box::Box()
-{
-}
-
-Box::Box(Interval ix, Interval iy)
-{
- x = ix;
- y = iy;
-}
-
+++ /dev/null
-/*
- do calculations for breaking problem
- */
-#include "break.hh"
-#include "paper-def.hh"
-#include "linespace.hh"
-#include "debug.hh"
-#include "scoreline.hh"
-#include "pscore.hh"
-
-
-/*
- return all breakable columns
- */
-Line_of_cols
-Break_algorithm::find_breaks() const
-{
- Line_of_cols retval;
- for (iter_top(pscore_.cols,c); c.ok(); c++)
- if (c->breakable_b())
- retval.push(c);
- assert(retval.top() == pscore_.cols.bottom().ptr());
- return retval;
-}
-
-// construct an appropriate Spacing_problem and solve it.
-Col_hpositions
-Break_algorithm::solve_line(Line_of_cols curline) const
-{
- Spacing_problem sp;
-
- sp.add_column(curline[0], true, 0.0);
- for (int i=1; i< curline.size()-1; i++)
- sp.add_column(curline[i]);
- sp.add_column(curline.top(), true, linelength);
-
- // misschien moeven uit Spacing_problem?
- for (iter_top(pscore_.suz,i); i.ok(); i++) {
- sp.add_ideal(i);
- }
- Array<Real> the_sol=sp.solve();
- Col_hpositions col_hpos;
- col_hpos.cols = curline;
- col_hpos.energy = the_sol.pop();
- col_hpos.config = the_sol;
- col_hpos.OK();
- return col_hpos;
-}
-
-Break_algorithm::Break_algorithm(PScore&s)
- :pscore_(s)
-{
- linelength = s.paper_l_->linewidth;
-}
-
-bool
-Break_algorithm::feasible(Line_of_cols curline) const
-{
- Real l =0;
- for (int i=0; i < curline.size(); i++)
- l +=curline[i]->width().length();
- return l < linelength;
-}
-
-void
-Break_algorithm::problem_OK() const
-{
- if (!pscore_.cols.size())
- error("Score does not have any columns");
-#ifndef NDEBUG
- iter_top(pscore_.cols,start);
- PCursor<PCol *> end (pscore_.cols.bottom());
-
- assert(start->breakable_b());
- assert(end->breakable_b());
-#endif
-}
+++ /dev/null
-#include "idealspacing.hh"
-#include "score.hh"
-#include "pscore.hh"
-#include "paper-def.hh"
-#include "score-column.hh"
-#include "dimen.hh"
-
-
-/**
- this needs A LOT of rethinking.
-
- generate springs between columns.
-
- */
-void
-Score::calc_idealspacing()
-{
- iter_top(cols_,i);
-
- for (; i.ok(); i++) {
- assert(i->used_b());
- PCursor<Score_column*> j(i+1);
- if (i->musical_b()) {
- assert(j.ok());
- for (int n=0; n < i->durations.size(); n++) {
- Moment d = i->durations[n];
- Real dist = paper_p_->duration_to_dist(d);
- Real strength = i->durations[0]/i->durations[n];
- assert(strength <= 1.0);
-
- while (j->when() < d + i->when())
- j++;
- Moment delta_desired = j->when() - (d+i->when());
- dist += paper_p_->duration_to_dist(delta_desired);
-
- pscore_p_->connect(i->pcol_l_, j->pcol_l_, dist, strength);
- }
- } else if (j.ok()) {
-
- /* attach i to the next column in use. This exists, since
- the last col is breakable, and therefore in use
- */
-
- Moment d = j->when() - i->when();
- Real dist = (d) ? paper_p_->duration_to_dist(d) : 2 PT; // todo
-
- pscore_p_->connect(i->pcol_l_, j->pcol_l_, dist, (d) ? 1.0:1.0);
- }
- // !j.ok() might hold if we're at the last col.
- }
-}
-
-
+++ /dev/null
-/*
- clef-item.cc -- implement Clef_item
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-#include "clef-item.hh"
-#include "string.hh"
-#include "molecule.hh"
-#include "paper-def.hh"
-#include "lookup.hh"
-#include "clef-reg.hh"
-
-
-
-Clef_item::Clef_item()
-{
- change = true;
- read("violin");
-}
-
-void
-Clef_item::read(String t)
-{
- type = t;
- if (type == "violin")
- y_off = 2;
- if (type == "alto")
- y_off = 4;
- if (type == "tenor")
- y_off = 6;
- if (type == "bass")
- y_off = 6;
-}
-void
-Clef_item::read(Clef_register const &k)
-{
- read(k.clef_type_str_);
-}
-
-Molecule*
-Clef_item::brew_molecule_p()const
-{
- String t = type;
- if (change)
- t += "_change";
- Symbol s = paper()->lookup_p_->clef(t);
- Molecule*output = new Molecule(Atom(s));
- output->translate(Offset(0, paper()->internote() * y_off));
- return output;
-}
-
+++ /dev/null
-/*
- clef.cc -- implement Clef_register
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>,
- Mats Bengtsson <matsb@s3.kth.se>
-*/
-
-#include "clef-reg.hh"
-#include "clef-item.hh"
-#include "debug.hh"
-#include "commandrequest.hh"
-#include "time-description.hh"
-#include "staff-column.hh"
-
-Clef_register::Clef_register()
-{
- clef_p_ = 0;
-
- /* ugly hack to prevent segfault (daddy_reg_l_ == 0 at construction) */
- clef_type_str_ = "";
-}
-
-bool
-Clef_register::set_type(String s)
-{
- clef_type_str_ = s;
- if (clef_type_str_ == "violin") {
- c0_position_i_= -2;
- } else if (clef_type_str_ == "alto") {
- c0_position_i_= 4;
- } else if (clef_type_str_ == "tenor") {
- c0_position_i_= 6;
- } else if (clef_type_str_ == "bass") {
- c0_position_i_= 10;
- }else
- return false;
- *get_staff_info().c0_position_i_ = c0_position_i_;
-
- return true;
-}
-
-void
-Clef_register::read_req(Clef_change_req*c_l)
-{
- if (!set_type(c_l->clef_str_))
- error("unknown clef type ", c_l->defined_ch_c_l_);
-}
-
-bool
-Clef_register::try_request(Request * r_l)
-{
- Command_req* creq_l= r_l->command();
- if (!creq_l || !creq_l->clefchange())
- return false;
-
- clef_req_l_ = creq_l->clefchange();
-
- // do it now! Others have to read c0_pos.
- read_req(creq_l->clefchange());
- return true;
-}
-
-void
-Clef_register::process_requests()
-{
- const Time_description *time_l = get_staff_info().time_c_l_;
- if (!clef_req_l_ && (!time_l->whole_in_measure_|| !time_l->when_)) {
- clef_p_ = new Clef_item;
- clef_p_->change = false;
- } else if (clef_req_l_) {
- clef_p_ = new Clef_item;
- clef_p_->change = true;
- }
- if (clef_p_) {
- clef_p_->read(*this);
- announce_element(Staff_elem_info(clef_p_,
- clef_req_l_));
- }
-}
-
-void
-Clef_register::pre_move_processing()
-{
- if (!clef_p_)
- return;
- if (clef_p_->change) {
- Clef_item* post_p = new Clef_item(*clef_p_);
- post_p->change = false;
- typeset_breakable_item(new Clef_item(*clef_p_),
- clef_p_, post_p);
- } else {
- typeset_breakable_item(0, 0, clef_p_);
- }
- clef_p_ = 0;
-}
-
-void
-Clef_register::post_move_processing()
-{
- clef_req_l_ = 0;
- /* not in ctor, since the reg might not be linked in.*/
- if (clef_type_str_ == "") {
- set_type("violin");
- }
-}
+++ /dev/null
-#include "colhpos.hh"
-#include "real.hh"
-#include "debug.hh"
-#include "const.hh"
-#include "vector.hh"
-
-Col_hpositions::Col_hpositions()
-{
- energy = INFTY;
-}
-
-void
-Col_hpositions::add( PCol*c)
-{
- cols.push(c);
-}
-
-void
-Col_hpositions::print() const
-{
-#ifndef NPRINT
- mtor << "energy : " << energy << '\n';
- mtor << "line of " << config.size() << " cols\n";
- Vector v(config);
- mtor << v;
-#endif
-}
-
-void
-Col_hpositions::OK()const
-{
-#ifndef NDEBUG
- assert(config.size() == cols.size());
-#endif
-}
+++ /dev/null
-/*
- commandrequest.cc -- implement Nonmusical reqs
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-#include "commandrequest.hh"
-#include "debug.hh"
-#include "musicalrequest.hh"
-
-
-void
-Cadenza_req::do_print()const
-{
- mtor << on_b_;
-}
-
-Cadenza_req::Cadenza_req(bool b)
-{
- on_b_ =b;
-}
-/* *************** */
-
-
-int
-Bar_req::compare(const Bar_req &c1)const
-{
- return type_str_ == c1.type_str_;
-}
-
-void
-Bar_req::do_print() const
-{
- mtor << type_str_;
-}
-
-Bar_req::Bar_req(String s)
-{
- type_str_ = s;
-}
-
-Partial_measure_req::Partial_measure_req(Moment m)
-{
- duration_ =m;
-}
-/* *************** */
-Meter_change_req::Meter_change_req()
-{
- beats_i_ = 0;
- one_beat_i_ =0;
-}
-void
-Meter_change_req::set(int b,int o)
-{
- beats_i_=b;
- one_beat_i_=o;
-}
-
-void
-Timing_req::do_print()const{}
-
-void
-Command_req::do_print()const{}
-/* *************** */
-void
-Barcheck_req::do_print() const{}
-
-/* *************** */
-void
-Clef_change_req::do_print() const
-{
- mtor << clef_str_ ;
-}
-
-Clef_change_req::Clef_change_req(String s)
-{
- clef_str_ = s;
-}
-/* *************** */
-void
-Group_feature_req::do_print() const
-{
- mtor << "stemdir " << stemdir_i_;
-}
-
-Group_feature_req::Group_feature_req()
-{
- stemdir_i_ = 0;
-}
-
-void
-Group_change_req::do_print()const
-{
- mtor << "id : " << newgroup_str_;
-}
-/* *************** */
-void
-Terminate_voice_req::do_print()const
-{
-}
-
-/* *************** */
-void
-Partial_measure_req::do_print() const
-{
- mtor << duration_;
-}
-
-void
-Meter_change_req::do_print() const
-{
- mtor << beats_i_ << "*" << one_beat_i_;
-}
-
-/* *************** */
-
-void
-Measure_grouping_req::do_print() const
-{
- for (int i=0; i < elt_length_arr_.size(); i++) {
- mtor << beat_i_arr_[i] <<"*" << elt_length_arr_[i]<<" ";
- }
-}
-/* *************** */
-void
-Key_change_req::do_print() const
-{
- for (int i=0; i < melodic_p_arr_.size(); i++) {
- melodic_p_arr_[i]->print();
- }
-}
-
-Key_change_req::Key_change_req()
-{
-}
-Key_change_req::Key_change_req(Key_change_req const&c)
-{
- for (int i=0; i < c.melodic_p_arr_.size(); i++) {
- melodic_p_arr_.push( c.melodic_p_arr_[i]->clone()->melodic() );
- }
-}
-
-Key_change_req::~Key_change_req()
-{
- for (int i=0; i < melodic_p_arr_.size(); i++)
- delete melodic_p_arr_[i];
-}
+++ /dev/null
-#include "complex-staff.hh"
-#include "complex-walker.hh"
-#include "score.hh"
-#include "pscore.hh"
-#include "staffsym.hh"
-#include "score-column.hh"
-
-const NO_LINES = 5;
-
-/** Aside from putting fields right, this generates the staff symbol.
- */
-void
-Complex_staff::set_output(PScore* pscore_l )
-{
- pstaff_l_ = new PStaff(pscore_l);
- pscore_l_ = pscore_l;
- pscore_l_->add(pstaff_l_);
-
- Staff_symbol *span_p = new Staff_symbol(NO_LINES);
-
- Score_column* col_last
- =score_l_->find_col(score_l_->last(), false);
- Score_column* col_first=
- score_l_->find_col(0, false);
-
- span_p->set_extent(col_first->pcol_l_->postbreak_p_,
- col_last->pcol_l_->prebreak_p_);
-
- pscore_l_->typeset_spanner(span_p, pstaff_l_);
-}
-
-
-Staff_walker *
-Complex_staff::get_walker_p()
-{
- return new Complex_walker(this);
-}
+++ /dev/null
-/*
- complex-walker.cc -- implement Complex_walker
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-#include "musicalrequest.hh"
-#include "staff-column.hh"
-#include "voice.hh"
-#include "pscore.hh"
-#include "complex-staff.hh"
-#include "debug.hh"
-#include "voice-group-regs.hh"
-#include "voice-regs.hh"
-#include "complex-walker.hh"
-//#include "misc.hh"
-#include "commandrequest.hh"
-#include "walkregs.hh"
-
-void
-Complex_walker::do_post_move()
-{
- walk_regs_p_->post_move_processing();
-}
-
-void
-Complex_walker::do_pre_move()
-{
- walk_regs_p_->pre_move_processing();
-}
-
-void
-Complex_walker::do_announces()
-{
- walk_regs_p_->do_announces();
-}
-
-bool
-Complex_walker::try_command_request(Command_req *req_l)
-{
- return walk_regs_p_->try_request(req_l);
-}
-
-void
-Complex_walker::try_request(Request*req)
-{
- walk_regs_p_->try_request(req);
-}
-
-void
-Complex_walker::process_requests()
-{
- Staff_column*c =ptr();
-
- for (int i=0; i < c->creationreq_l_arr_.size(); i++) {
- try_request(c->creationreq_l_arr_[i]);
- }
- for (int i=0; i < c->commandreq_l_arr_.size(); i++) {
- try_request(c->commandreq_l_arr_[i]);
- }
-
- for (int i=0; i < c->musicalreq_l_arr_.size(); i++) {
- try_request(c->musicalreq_l_arr_[i]);
- }
-
- regs_process_requests();
- do_announces();
-}
-
-void
-Complex_walker::regs_process_requests()
-{
- walk_regs_p_->process_requests();
-}
-
-void
-Complex_walker::typeset_element(Staff_elem *elem_p)
-{
- if (!elem_p)
- return;
- if (elem_p->spanner())
- pscore_l_->typeset_spanner(elem_p->spanner(), staff()->pstaff_l_);
- else
- ptr()->typeset_musical_item(elem_p->item());
-}
-
-Complex_walker::Complex_walker(Complex_staff*s)
- : Staff_walker(s, s->pstaff_l_->pscore_l_)
-{
- walk_regs_p_ = new Walker_registers(this);
- do_post_move();
-}
-
-
-Complex_walker::~Complex_walker()
-{
-}
-
-Complex_staff*
-Complex_walker::staff()
-{
- return (Complex_staff*) staff_l_;
-}
-
-
-
+++ /dev/null
-#include <fstream.h>
-#include <signal.h>
-#include <std/new.h>
-#include <stdlib.h>
-#include "debug.hh"
-#include "dstream.hh"
-#include "vector.hh"
-
-Dstream *monitor=0;
-ostream * nulldev =0;
-
-struct _Dinit {
- _Dinit() {
- nulldev = new ofstream("/dev/null");
- monitor = new Dstream(&cout,".dstreamrc");
- }
- ~_Dinit() {
- delete nulldev;
- delete monitor;
- }
-} dinit;
-
-
-
-/*
- want to do a stacktrace .
- */
-void
-mynewhandler()
-{
- assert(false);
-}
-
-void
-float_handler(int)
-{
- cerr << "Floating point exception .. \n"<< flush;
- assert(false);
-}
-
-void
-debug_init()
-{
-#ifndef NDEBUG
- set_new_handler(&mynewhandler);
-#endif
- set_matrix_debug(*monitor);
- signal(SIGFPE, float_handler);
-}
-
-bool check_debug=false;
-
-void
-set_debug(bool b)
-{
- check_debug =b;
-}
-
-
+++ /dev/null
-#include <ctype.h>
-#include "dimen.hh"
-#include "debug.hh"
-#include "string.hh"
-
-Real
-parse_dimen(String dim)
-{
- int i=dim.length_i()-1;
- const char *s = dim;
- while (i > 0 && (isspace(s[i]) || isalpha(s[i])) ){
- i--;
- }
- String unit(s + i+1);
- return convert_dimen(dim.value_f(), unit);
-}
-
-
-Real
-convert_dimen(Real quant, String unit)
-{
- if (unit == "cm")
- return quant * CM_TO_PT;
- if (unit == "pt")
- return quant;
- if (unit == "mm")
- return quant*CM_TO_PT/10;
- if (unit == "in")
- return quant * INCH_TO_PT;
- error ("unknown length unit: `" + unit+"'");
-}
-
-String
-print_dimen(Real r)
-{
- String s(r);
- s += "pt ";
- return s;
-}
+++ /dev/null
-#include "directional-spanner.hh"
-
-Directional_spanner::Directional_spanner()
-{
- dir_i_ = 0;
-}
+++ /dev/null
-//
-// duration.cc -- implement Duration, Plet, Duration_convert, Duration_iterator
-//
-// copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
-
-// split into 4?
-
-#include "proto.hh" // ugh, these all for midi-main.hh
-#include "plist.hh"
-#include "string.hh"
-#include "source-file.hh"
-#include "source.hh"
-#include "midi-main.hh" // *tors
-
-#include "string.hh"
-#include "moment.hh"
-#include "duration.hh"
-
-Duration::Duration( int type_i, int dots_i = 0, Plet* plet_l )
-{
- type_i_ = type_i;
- dots_i_ = dots_i;
- plet_p_ = 0;
- set_plet( plet_l );
-}
-
-Duration::Duration( Duration const& dur_c_r )
-{
- type_i_ = 0;
- dots_i_ = 0;
- plet_p_ = 0;
- *this = dur_c_r;
-}
-
-Duration::~Duration()
-{
- delete plet_p_;
-}
-
-Duration const&
-Duration::operator =( Duration const& dur_c_r )
-{
- if ( &dur_c_r == this )
- return *this;
-
- type_i_ = dur_c_r.type_i_;
- dots_i_ = dur_c_r.dots_i_;
- set_plet( dur_c_r.plet_p_ );
-
- return *this;
-}
-
-void
-Duration::set_plet( Plet* plet_l )
-{
- delete plet_p_;
- plet_p_ = 0;
- if ( plet_l )
- plet_p_ = new Plet( *plet_l );
-}
-
-Plet::Plet( int iso_i, int type_i )
-{
- iso_i_ = iso_i;
- type_i_ = type_i;
-}
-
-Plet::Plet( Plet const& plet_c_r )
-{
- iso_i_ = plet_c_r.iso_i_;
- type_i_ = plet_c_r.type_i_;
-}
-
-String
-Duration_convert::dur2_str( Duration dur )
-{
- String str( dur.type_i_ );
- str += String( '.', dur.dots_i_ );
- if ( dur.plet_p_ )
- str += String( "*" ) + String( dur.plet_p_->iso_i_ )
- + String( "/" ) + String( dur.plet_p_->type_i_ );
- return str;
-}
-
-int
-Duration_convert::dur2_i( Duration dur, int division_1_i )
-{
- return dur2_mom( dur ) * Moment( division_1_i );
-}
-
-Moment
-Duration_convert::dur2_mom( Duration dur )
-{
- if ( !dur.type_i_ )
- return 0;
-
- Moment mom = Moment( 1 , dur.type_i_ );
-
- Moment delta = mom;
- while ( dur.dots_i_-- ) {
- delta /= 2.0;
- mom += delta;
- }
-
- return mom * plet_factor_mom( dur );
-}
-
-Duration
-Duration_convert::mom2_dur( Moment mom )
-{
- /* this is cute,
- but filling an array using Duration_iterator
- might speed things up, a little
- */
- Duration_iterator iter_dur;
- assert( iter_dur );
- while ( iter_dur ) {
- Duration lower_dur = iter_dur++;
- Duration upper_dur( 0 );
- if ( iter_dur )
- upper_dur = iter_dur();
- Moment lower_mom = dur2_mom( lower_dur );
- Moment upper_mom = dur2_mom( upper_dur );
- if ( mom == lower_mom )
- return lower_dur;
- if ( mom == upper_mom ) // don-t miss last (sic)
- return upper_dur;
- if ( ( mom >= lower_mom ) && ( mom <= upper_mom ) ) {
- warning( String( "duration not exact: " ) + String( (Real)mom ) , 0 );
- if ( abs( mom - lower_mom ) < abs( mom - upper_mom ) )
- return lower_dur;
- else
- return upper_dur;
- }
- lower_dur = upper_dur;
- }
- return Duration( 0 );
-}
-
-Moment
-Duration_convert::plet_factor_mom( Duration dur )
-{
- if ( !dur.plet_p_ )
- return 1;
- return Moment( dur.plet_p_->iso_i_, dur.plet_p_->type_i_ );
-}
-
-Real
-Duration_convert::sync_f( Duration dur, Moment mom )
-{
- return mom / dur2_mom( dur );
-}
-
-Moment
-Duration_convert::i2_mom( int time_i, int division_1_i )
-{
- if ( !time_i )
- return Moment( 0 );
-
- if ( division_1_i > 0 )
- return Moment( time_i, division_1_i );
- else
- return Moment( -division_1_i, time_i );
-}
-
-Duration_iterator::Duration_iterator()
-{
- cursor_dur_.type_i_ = 128;
- cursor_dur_.set_plet( 0 );
-}
-
-Duration
-Duration_iterator::operator ++(int)
-{
- return forward_dur();
-}
-
-Duration
-Duration_iterator::operator ()()
-{
- return dur();
-}
-
-Duration_iterator::operator bool()
-{
- return ok();
-}
-
-Duration
-Duration_iterator::dur()
-{
- return cursor_dur_;
-}
-
-Duration
-Duration_iterator::forward_dur()
-{
- // should do smart table? guessing:
- // duration wholes
- // 16 0.0625
- // 32.. 0.0703
- // 8:2/3 0.0833
- // 16. 0.0938
- // 8 0.1250
- // 16.. 0.1406
- // 4:2/3 0.1667
- // 8. 0.1875
-
- assert( ok() );
-
- Duration dur = cursor_dur_;
-
- if ( !cursor_dur_.dots_i_ && !cursor_dur_.plet_p_ ) {
- cursor_dur_.type_i_ *= 2;
- cursor_dur_.dots_i_ = 2;
- }
- else if ( cursor_dur_.dots_i_ == 2 ) {
- assert( !cursor_dur_.plet_p_ );
- cursor_dur_.dots_i_ = 0;
- cursor_dur_.type_i_ /= 4;
- cursor_dur_.set_plet( &Plet( 2, 3 ) );
- }
- else if ( cursor_dur_.plet_p_
- && ( cursor_dur_.plet_p_->iso_i_ == 2 )
- && ( cursor_dur_.plet_p_->type_i_ == 3 ) ) {
- assert( !cursor_dur_.dots_i_ );
- cursor_dur_.set_plet( 0 );
- cursor_dur_.type_i_ *= 2;
- cursor_dur_.dots_i_ = 1;
- }
- else if ( cursor_dur_.dots_i_ == 1 ) {
- assert( !cursor_dur_.plet_p_ );
- cursor_dur_.dots_i_ = 0;
- cursor_dur_.type_i_ /= 2;
- }
-
- // ugh
- if ( no_triplets_bo_g && cursor_dur_.plet_p_ && ok() )
- forward_dur();
-
- return dur;
-}
-
-bool
-Duration_iterator::ok()
-{
- return ( cursor_dur_.type_i_
- && !( ( cursor_dur_.type_i_ == 1 ) && ( cursor_dur_.dots_i_ > 2 ) ) );
-}
+++ /dev/null
-/*
- grouping.cc -- implement Rhythmic_grouping
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-#include "debug.hh"
-#include "grouping.hh"
-#include "interval.hh"
-
-void
-Rhythmic_grouping::init()
-{
- interval_ = 0;
- children.set_size(0);
-}
-
-void
-Rhythmic_grouping::OK()const
-{
-#ifndef NDEBUG
- assert(bool(children.size()) != bool(interval_));
-
- for (int i= 0; i < children.size(); i++) {
- children[i]->OK();
- if (i>0)
- assert(children[i-1]->interval().right ==
- children[i]->interval().left);
- }
-#endif
-}
-
-Moment
-Rhythmic_grouping::length() const
-{
- return interval().length();
-}
-
-MInterval
-Rhythmic_grouping::interval()const
-{
- if (interval_)
- return *interval_;
- else
- return
- MInterval(children[0]->interval().left,
- children.top()->interval().right);
-}
-
-void
-Rhythmic_grouping::split(Rhythmic_grouping r)
-{
- if (interval_)
- return ;
-
- r.intersect(interval());
- split(r.intervals());
-
- for (int i= 0; i < children.size(); i++) {
- if (!children[i]->interval_) {
- Rhythmic_grouping here(r);
- children[i]->split(here);
- }
- }
-}
-
-
-Array<MInterval>
-Rhythmic_grouping::intervals()
-{
- Array<MInterval> r;
- if (interval_ || children.size() == 1) {
- MInterval i(interval());
- MInterval r1(i), r2(i);
- r1.right = r2.left = i.center();
- r.push(r1); r.push(r2);
- } else {
- for (int i=0; i < children.size(); i++)
- r.push(children[i]->interval());
- }
- return r;
-}
-
-void
-Rhythmic_grouping::intersect(MInterval t)
-{
- if (interval_) {
- interval_->intersect(t);
- return;
- }
-
- for (int i=0; i < children.size(); i++) {
- MInterval inter = intersection(t, children[i]->interval());
- if (inter.empty() || inter.length() <= Rational( 0 )) {
- delete children[i];
- children[i] =0;
- } else {
- children[i]->intersect(t);
- }
- }
- for (int i=0; i < children.size(); ) {
- if (!children[i])
- children.del(i);
- else
- i++;
- }
-
-}
-
-/**
- Put our children in branches of #this#.
- The min and max time intervals coincide with elements of #splitpoints#
-
- I really should be documenting what is happening here, but I find
- that difficult, since I don't really understand what's going on here.
-
- */
-void
-Rhythmic_grouping::split(Array<MInterval> splitpoints)
-{
- //check on splitpoints..
- int j = 0, i = 0, starti = 0, startj = 0;
-
- Array<Rhythmic_grouping*> ch;
- while (1) {
- if ( i >= children.size() || j >= splitpoints.size())
- break;
-
- assert(
- children[starti]->interval().left== splitpoints[startj].left);
- if (children[i]->interval().right < splitpoints[j].right) {
- i ++;
- } else if (children[i]->interval().right > splitpoints[j].right ) {
- j ++;
- } else {
-
- if (i == starti) {
- ch.push(children[i]);
- } else {
- Rhythmic_grouping *newchild=new Rhythmic_grouping(
- children.subvec(starti, i+1));
-
- ch.push(newchild);
- }
- i ++;
- j++;
- starti = i;
- startj = j;
-
-
- }
- }
- if (ch.size() != 1)
- children = ch;
- }
-
-
-Rhythmic_grouping::Rhythmic_grouping(MInterval t, int n)
-{
- init();
- if (n == 1 || !n) {
- interval_ = new MInterval(t);
- return;
- }
- Moment dt = t.length()/Rational(n);
- MInterval basic = MInterval(t.left, t.left+dt);
- for (int i= 0; i < n; i++)
- children.push(new Rhythmic_grouping( dt*Rational(i) + basic ));
-}
-
-
-Rhythmic_grouping::Rhythmic_grouping(Array<Rhythmic_grouping*> r)
- :children(r)
-{
- interval_ =0;
-}
-
-Rhythmic_grouping::~Rhythmic_grouping()
-{
- junk();
-}
-
-void
-Rhythmic_grouping::copy(Rhythmic_grouping const&s)
-{
- interval_ = (s.interval_)? new MInterval(*s.interval_) : 0;
- for (int i=0; i < s.children.size(); i++)
- children.push(new Rhythmic_grouping(*s.children[i]));
-}
-
-void
-Rhythmic_grouping::operator=(Rhythmic_grouping const &s)
-{
- junk();
- copy(s);
-}
-
-Rhythmic_grouping::Rhythmic_grouping(Rhythmic_grouping const&s)
-{
- init();
- copy(s);
-}
-
-void
-Rhythmic_grouping::junk()
-{
- delete interval_;
- for (int i=0; i < children.size(); i++)
- delete children[i];
- init();
-}
-
-void
-Rhythmic_grouping::print()const
-{
-#ifndef NPRINT
- mtor << "{ \n";
- if (interval_)
- mtor<<" Interval "<< interval_->str();
- for (int i=0; i < children.size(); i++) {
- children[i]->print();
- }
- mtor << "}\n";
-#endif
-}
-
-bool
-Rhythmic_grouping::child_fit_query(Moment start)
-{
- if (children.size())
- return ( children.top()->interval().right== start);
-
- return true;
-}
-
-void
-Rhythmic_grouping::add_child(Moment start, Moment len)
-{
- Moment stop = start+len;
-
- assert(child_fit_query(start));
- children.push(new Rhythmic_grouping(MInterval(start, stop)));
-}
-
-Rhythmic_grouping::Rhythmic_grouping()
-{
- interval_ =0;
-}
-
-int
-min_elt(Array<int> v)
-{
- int i = 1000; // ugh
- for (int j = 0 ; j < v.size(); j++)
- i = i <? v[j];
- return i;
-}
-
-Array<int>
-Rhythmic_grouping::generate_beams(Array<int> flags, int &flagidx)
-{
- assert (!interval_) ;
-
- Array< Array<int> > children_beams;
- for (int i=0; i < children.size(); i++) {
- Array<int> child_beams;
- if (children[i]->interval_) {
- int f = flags[flagidx++];
- child_beams.push(f);
- } else {
- child_beams = children[i]->
- generate_beams(flags, flagidx);
- }
- children_beams.push(child_beams);
- }
- Array<int> beams;
- int lastm, m, nextm;
- for (int i=0; i < children_beams.size(); i++) {
- bool add_left = (i >0);
- bool add_right = (i < children_beams.size() -1);
-
- if (!i)
- m = min_elt(children_beams[i]);
- if (add_right)
- nextm = min_elt(children_beams[i+1]);
-
- if (children_beams[i].size() == 1) {
- if (add_right)
- beams.push(m);
- if (add_left)
- beams.push(m);
- } else {
- if (add_left)
- beams.push(lastm <? m);
- beams.concat(children_beams[i]);
- if (add_right)
- beams.push(m <? nextm);
- }
- lastm = m;
- m = nextm;
- }
- assert(!(beams.size()%2));
- return beams;
-}
-
-void
-Rhythmic_grouping::translate(Moment m)
-{
- if (interval_)
- *interval_ += m;
- else
- for (int i=0; i < children.size(); i++)
- children[i]->translate(m);
-}
-
-void
-Rhythmic_grouping::extend(MInterval m)const
-{
- assert(m.left >= interval().left);
- while (m.right >interval().right ) {
- Array<Rhythmic_grouping*> a(children);
- for (int i=0; i < a.size(); i++) {
- a[i] =new Rhythmic_grouping(*children[i]);
- a[i]->translate(children.top()->interval().right);
- }
- ((Rhythmic_grouping*)this)->children.concat(a);
- }
- assert(m.right <= interval().right);
- OK();
-}
-
-Rhythmic_grouping
-parse_grouping(Array<int> beat_i_arr, Array<Moment> elt_length_arr)
-{
- Moment here =0;
- assert(beat_i_arr.size() == elt_length_arr.size());
-
- Array<Rhythmic_grouping*> children;
- for (int i=0; i < beat_i_arr.size(); i++) {
- Moment last = here;
- here += elt_length_arr[i] * Moment(beat_i_arr[i]);
- children.push(
- new Rhythmic_grouping(MInterval(last, here),
- beat_i_arr[i] ));
- }
- return Rhythmic_grouping(children);
-}
-
+++ /dev/null
-/*
- headreg.cc -- part of LilyPond
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-#include "rest.hh"
-#include "notehead.hh"
-#include "headreg.hh"
-#include "paper-def.hh"
-#include "complex-walker.hh"
-#include "musicalrequest.hh"
-
-Notehead_register::Notehead_register()
-{
- note_p_ = 0;
- set_feature(Features::dir(0));
- post_move_processing();
-}
-
-bool
-Notehead_register::try_request(Request *req_l)
-{
- if (req_l->note() || req_l->rest())
- note_req_l_=req_l->rhythmic();
- else
- return false;
-
- return true;
-}
-void
-Notehead_register::set_feature(Features d)
-{
- if(d.direction_i_ || d.initialiser_b_)
- dir_i_ = d.direction_i_;
-}
-
-void
-Notehead_register::process_requests()
-{
- if (!note_req_l_)
- return;
-
-
- if (note_req_l_->note()) {
- Notehead*n_p = new Notehead(8); // ugh
- note_p_ = n_p;
- n_p->set_rhythmic(note_req_l_->rhythmic());
- n_p->position = note_req_l_->note()->height() +
- *get_staff_info().c0_position_i_;
- } else {
- note_p_ = new Rest ( note_req_l_->rhythmic()->balltype,
- note_req_l_->rhythmic()->dots);
- if (note_req_l_->rhythmic()->balltype <= 2)
- note_p_->translate(
- Offset(0,
- 6 * paper()->internote()));
- }
- Staff_elem_info itinf(note_p_,note_req_l_);
- announce_element(itinf);
-}
-
-void
-Notehead_register::pre_move_processing()
-{
- if (note_p_) {
- if (dir_i_ && note_p_->name() == Rest::static_name())
- note_p_->translate(Offset(0, 4*dir_i_ * paper()->internote()));
- typeset_element(note_p_);
- note_p_ = 0;
- }
-}
-void
-Notehead_register::post_move_processing()
-{
- note_req_l_ = 0;
-}
+++ /dev/null
-#include "idealspacing.hh"
-#include "pcol.hh"
-#include "pscore.hh"
-#include "pstaff.hh"
-#include "debug.hh"
-
-void
-Idealspacing::print() const
-{
-#ifndef NPRINT
- mtor << "idealspacing {" ;
- mtor << "distance "<<space<< " strength " << hooke ;
- mtor << "left " << left->rank() << " right " << right->rank() << "}\n";
-#endif
-}
-
-Idealspacing::Idealspacing(const PCol * l,const PCol * r)
-{
- space = 0.0;
- hooke = 0.0;
- left = l;
- right = r;
-}
-
-void
-Idealspacing::OK() const
-{
-#ifndef NDEBUG
- assert(hooke >= 0 && left && right);
-#endif
-}
+++ /dev/null
-/*
- identifier.cc -- implement identifier and derived classes
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-#include <assert.h>
-
-#include "identifier.hh"
-#include "lexer.hh"
-#include "debug.hh"
-
-void
-Identifier::error(String expect)
-{
- String e("Wrong identifier type: ");
- e += String(classname()) + "(expected " + expect + ")";
- ::error(e);
-}
-
-void
-Identifier::print()const
-{
- mtor << "identifier \'" << name << "\'=";
- do_print();
-}
-
-/* ugh. */
-#define DEFAULT_PRINT(Class, Content_type, accessor) \
-void \
-Class::do_print() const { \
- ((Class*)this)->accessor(false)->print(); \
-} \
-class Class
-
-DEFAULT_PRINT(Script_id, Script_def, script);
-DEFAULT_PRINT(Lookup_id, Lookup, lookup);
-DEFAULT_PRINT(Symtables_id, Symtables, symtables);
-DEFAULT_PRINT(Staff_id, Input_staff, staff);
-DEFAULT_PRINT(M_chord_id, Music_general_chord, mchord);
-DEFAULT_PRINT(M_voice_id, Music_voice, mvoice);
-
-void
-Real_id::do_print() const
-{
- Identifier::print();
- mtor << *((Real_id*)this)->real(false)<< "\n";
-}
-
-void
-Notetab_id::do_print() const
-{
- mtor << "unknown" << "\n";
-}
+++ /dev/null
-#include "debug.hh"
-#include "input-music.hh"
-#include "voice.hh"
-#include "musicalrequest.hh"
-#include "voice-element.hh"
-
-void
-Input_music::check_plet(Voice_element* velt_l)
-{
- for (iter_top(velt_l->reqs,i); i.ok(); i++)
- if ( i->plet() ) {
- Moment start_moment = 0;
- if ( !find_plet_start_bo( i->plet()->type_c_, start_moment ) ) {
- error( "begin of plet not found", i->defined_ch_c_l_ );
- break;
- }
- Moment moment = 0;
- set_plet_backwards( moment, start_moment, i->plet()->dur_i_, i->plet()->type_i_ );
- i.del();
- break;
- }
-}
-
-void
-Simple_music::add(Voice_element*v)
-{
- voice_.add(v);
-}
-
-Moment
-Simple_music::length()const
-{
- return voice_.last();
-}
-void
-Simple_music::translate_time(Moment t)
-{
- voice_.start += t;
-}
-
-Voice_list
-Simple_music::convert()const
-{
- Voice_list l;
- l.bottom().add(new Voice(voice_));
- return l;
-}
-
-
-void
-Simple_music::print() const
-{
- mtor << "Simple_music {";
- voice_.print();
- mtor << "}\n";
-}
-bool
-Simple_music::find_plet_start_bo(char c, Moment& moment_r)
-{
- return voice_.find_plet_start_bo(c, moment_r);
-}
-void
-Simple_music::set_plet_backwards(Moment& now_moment_r, Moment until_moment, int num_i, int den_i)
-{
- voice_.set_plet_backwards(now_moment_r, until_moment, num_i, den_i);
-}
-
-/* *************** */
-
-void
-Complex_music::add(Input_music*v)
-{
- elts.bottom().add(v);
-}
-
-void
-Complex_music::print() const
-{
- for (iter_top(elts,i); i.ok(); i++)
- i->print();
-}
-
-void
-Complex_music::concatenate(Complex_music*h)
-{
- for (iter_top(h->elts,i); i.ok(); i++)
- add(i->clone());
-}
-
-Complex_music::Complex_music()
-{
-}
-
-Complex_music::Complex_music(Complex_music const&s)
-{
- for (iter_top(s.elts,i); i.ok(); i++)
- add(i->clone());
-}
-void
-Complex_music::set_default_group(String g)
-{
- for (iter_top(elts,i); i.ok(); i++)
- i->set_default_group(g);
-}
-bool
-Complex_music::find_plet_start_bo(char c, Moment& moment_r)
-{
- for (iter_bot(elts,i); i.ok(); i--) {
- if ( i->find_plet_start_bo(c, moment_r) )
- return true;
- }
- return false;
-}
-void
-Complex_music::set_plet_backwards(Moment& now_moment_r, Moment until_moment, int num_i, int den_i)
-{
- for (iter_bot(elts,i); i.ok(); i--) {
- i->set_plet_backwards(now_moment_r, until_moment, num_i, den_i);
- }
-}
-/* *************************************************************** */
-
-void
-Music_voice::print() const
-{
- mtor << "Music_voice {";
- Complex_music::print();
- mtor << "}\n";
-}
-
-void
-Music_voice::add_elt(Voice_element*v)
-{
- PCursor<Input_music*> c(elts.bottom());
- if (!c.ok() || !c->simple()) {
- Simple_music*vs = new Simple_music;
-
- c.add(vs);
- }
-
- c = elts.bottom();
- Simple_music *s = c->simple();
- s->add(v);
-
- check_plet(v);
-}
-
-Moment
-Music_voice::length()const
-{
- Moment l = 0;
-
- for (iter_top(elts,i); i.ok(); i++)
- l += i->length();
- return l;
-}
-
-
-Voice_list
-Music_voice::convert()const
-{
- Voice_list l;
- Moment here = 0;
-
- for (iter_top(elts,i); i.ok(); i++) {
- Moment len = i->length();
- Voice_list k(i->convert());
- k.translate_time(here);
- l.concatenate(k);
- here +=len;
- }
- return l;
-}
-
-void
-Music_voice::translate_time(Moment t)
-{
- elts.bottom()->translate_time(t);
-}
-
-
-
-/* *************** */
-
-void
-Music_general_chord::add_elt(Voice_element*v)
-{
- Simple_music*vs = new Simple_music;
- vs->add(v);
- elts.bottom().add(vs);
-
- check_plet(v);
-}
-
-void
-Music_general_chord::print() const
-{
- mtor << "Music_general_chord {";
- Complex_music::print();
- mtor << "}\n";
-}
-
-void
-Music_general_chord::translate_time(Moment t)
-{
- for (iter_top(elts,i); i.ok(); i++)
- i->translate_time(t);
-}
-
-Moment
-Music_general_chord::length()const
-{
- Moment l =0;
-
- for (iter_top(elts,i); i.ok(); i++)
- l = l >? i->length();
- return l;
-}
-
-Voice_list
-Music_general_chord::convert()const
-{
- Voice_list l;
- for (iter_top(elts,i); i.ok(); i++) {
- Voice_list k(i->convert());
- l.concatenate(k);
- }
- return l;
-}
-
-/* *************** */
-
-void
-Multi_voice_chord::set_default_group(String g)
-{
- int j=0;
- for (iter_top(elts, i); i.ok(); i++) {
- i->set_default_group(g + String(j));
- j++;
- }
-}
-
-
-/* *************** */
-
-void
-Voice_list::translate_time(Moment x)
-{
- for (iter_top(*this,i); i.ok(); i++)
- i->start += x;
-}
-
+++ /dev/null
-/*
- input-score.cc -- implement Input_score
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-#include "debug.hh"
-#include "input-score.hh"
-#include "input-staff.hh"
-#include "input-music.hh"
-#include "score.hh"
-#include "paper-def.hh"
-#include "midi-def.hh"
-#include "staff.hh"
-
-
-void
-Input_score::add(Input_staff*s)
-{
- staffs_.bottom().add(s);
-}
-
-void
-Input_score::set(Paper_def*p)
-{
- delete paper_p_;
- paper_p_ = p;
-}
-
-void
-Input_score::set(Midi_def* midi_p)
-{
- delete midi_p_;
- midi_p_ = midi_p;
-}
-
-Input_score::Input_score(Input_score const&s)
-{
- paper_p_ = (s.paper_p_)? new Paper_def(*s.paper_p_) :0;
- midi_p_ = (s.midi_p_)? new Midi_def(*s.midi_p_) : 0;
- defined_ch_c_l_ = s.defined_ch_c_l_;
- errorlevel_i_ = s.errorlevel_i_;
- score_wide_music_p_ = (s.score_wide_music_p_) ?
- s.score_wide_music_p_->clone():0;
-}
-
-Score*
-Input_score::parse()
-{
- Score *s_p = new Score;
- s_p->defined_ch_c_l_= defined_ch_c_l_;
- s_p->errorlevel_i_ = errorlevel_i_;
- if (midi_p_)
- s_p->set(new Midi_def(*midi_p_));
- if (paper_p_)
- s_p->set( new Paper_def(*paper_p_));
-
- for (iter_top(staffs_,i); i.ok(); i++) {
- Staff* staf_p=i->parse(s_p, score_wide_music_p_);
- s_p->add(staf_p);
- }
-
- return s_p;
-}
-
-void
-Input_score::set(Input_music *m_p)
-{
- delete score_wide_music_p_;
- score_wide_music_p_ =m_p;
-}
-
-
-Input_score::~Input_score()
-{
- delete paper_p_;
- delete score_wide_music_p_;
- delete midi_p_;
-}
-
-Input_score::Input_score()
-{
- score_wide_music_p_ =0;
- defined_ch_c_l_=0;
- paper_p_= 0;
- midi_p_ = 0;
- errorlevel_i_ = 0;
-}
-
-void
-Input_score::print()const
-{
-#ifndef NPRINT
- mtor << "Input_score {\n";
- for (iter_top(staffs_,i); i.ok(); i++) {
- i->print();
- }
- mtor << "}\n";
-#endif
-}
+++ /dev/null
-/*
- input-staff.cc -- implement Input_staff
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-#include "debug.hh"
-#include "score.hh"
-#include "input-music.hh"
-#include "input-staff.hh"
-#include "staff.hh"
-#include "complex-staff.hh"
-#include "lyricstaff.hh"
-
-#include "lexer.hh"
-
-
-Input_staff::Input_staff(String s)
-{
- score_wide_music_p_ =0;
- type= s;
- defined_ch_c_l_ = 0;
-}
-
-void
-Input_staff::add(Input_music*m)
-{
- music_.bottom().add(m);
-}
-
-Staff*
-Input_staff::parse(Score*score_l, Input_music *default_score_wide)
-{
- Staff *p=0;
- if (type == "melodic")
- p = new Complex_staff;
- else if (type == "lyric")
- p = new Lyric_staff;
- else {
- error( "Unknown staff-type `" + type +"\'", defined_ch_c_l_ );
- exit( 1 );
- }
-
- p->score_l_ = score_l;
-
- for (iter_top(music_,i); i.ok(); i++) {
- Voice_list vl = i->convert();
- p->add(vl);
- }
- Voice_list vl = (score_wide_music_p_) ? score_wide_music_p_->convert()
- : default_score_wide->convert();
- p->add(vl);
- return p;
-}
-
-Input_staff::Input_staff(Input_staff const&s)
-{
- for (iter_top(s.music_,i); i.ok(); i++)
- add(i->clone());
- defined_ch_c_l_ = s.defined_ch_c_l_;
- type = s.type;
- score_wide_music_p_ = (s.score_wide_music_p_) ?
- s.score_wide_music_p_->clone() : 0;
-}
-
-void
-Input_staff::print() const
-{
-#ifndef NPRINT
- mtor << "Input_staff {\n";
- for (iter_top(music_,i); i.ok(); i++)
- i->print();
- mtor << "}\n";
-#endif
-}
-void
-Input_staff::set_score_wide(Input_music *m_p)
-{
- delete score_wide_music_p_;
- score_wide_music_p_ = m_p;
-}
-
-Input_staff::~Input_staff()
-{
- delete score_wide_music_p_;
-}
+++ /dev/null
-#include "debug.hh"
-#include "item.hh"
-
-
-
-Item::Item()
-{
- pcol_l_ = 0;
-}
-
-void
-Item::do_print() const
-{
-#ifndef NPRINT
- mtor << "(unknown)";
-#endif
-}
-
+++ /dev/null
-#include "key-item.hh"
-#include "key.hh"
-#include "debug.hh"
-#include "molecule.hh"
-#include "paper-def.hh"
-#include "lookup.hh"
-//#include "clef-reg.hh"
-#include "key-reg.hh"
-
-const int FLAT_TOP_PITCH=2; /* fes,ges,as and bes typeset in lower octave */
-const int SHARP_TOP_PITCH=4; /* ais and bis typeset in lower octave */
-
-
-
-Key_item::Key_item(int c)
-{
- set_c_position(c);
-}
-
-void
-Key_item::read(const Key_register& key_reg_r)
-{
- const Array<int> &idx_arr =key_reg_r.accidental_idx_arr_;
- for (int i = 0 ; i< idx_arr.size(); i++) {
- int note = idx_arr[i];
- int acc = key_reg_r.key_.acc(note);
-
- add(note, acc);
- }
-}
-
-void
-Key_item::set_c_position(int c0)
-{
- int octaves =(abs(c0) / 7) +1 ;
- c_position=(c0 + 7*octaves)%7;
-}
-
-
-void
-Key_item::add(int p, int a)
-{
- if ((a<0 && p>FLAT_TOP_PITCH) ||
- (a>0 && p>SHARP_TOP_PITCH)) {
- p -= 7; /* Typeset below c_position */
- }
- pitch.push(p);
- acc.push(a);
-}
-
-
-Molecule*
-Key_item::brew_molecule_p()const
-{
- Molecule*output = new Molecule;
- Real inter = paper()->internote();
-
- for (int i =0; i < pitch.size(); i++) {
- Symbol s= paper()->lookup_p_->accidental(acc[i]);
- Atom a(s);
- a.translate(Offset(0,(c_position + pitch[i]) * inter));
- Molecule m(a);
- output->add_right(m);
- }
- Molecule m(paper()->lookup_p_->fill(Box(
- Interval(0, paper()->note_width()),
- Interval(0,0))));
- output->add_right(m);
- return output;
-}
+++ /dev/null
-/*
- key-reg.cc -- implement Key_register
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-
- todo: key undo
-
- */
-#include "time-description.hh"
-#include "key-reg.hh"
-#include "key-item.hh"
-#include "commandrequest.hh"
-#include "staff-column.hh"
-#include "local-key-reg.hh"
-#include "musicalrequest.hh"
-
-Key_register::Key_register()
-{
- post_move_processing();
-}
-
-bool
-Key_register::try_request(Request * req_l)
-{
- Command_req* creq_l= req_l->command();
- if (!creq_l|| !creq_l->keychange())
- return false;
-
- assert(!keyreq_l_); // todo
- keyreq_l_ = creq_l->keychange();
- read_req(keyreq_l_);
- return true;
-}
-
-void
-Key_register::acknowledge_element(Staff_elem_info info)
-{
- Command_req * r_l = info.req_l_->command() ;
- if (r_l && r_l->clefchange() && !kit_p_) {
- int c0_i= *get_staff_info().c0_position_i_;
- kit_p_ = new Key_item(c0_i);
- kit_p_->read(*this);
- announce_element(Staff_elem_info(kit_p_, keyreq_l_));
- }
-}
-
-void
-Key_register::process_requests()
-{
- const Time_description *time_l = get_staff_info().time_c_l_;
-
- if (!keyreq_l_ &&
- (!time_l->whole_in_measure_|| !time_l->when_)) {
- default_key_b_ = true;
- }
-
- if ( default_key_b_ || keyreq_l_) {
- int c0_i= *get_staff_info().c0_position_i_;
- kit_p_ = new Key_item(c0_i);
- kit_p_->read(*this);
- announce_element(Staff_elem_info(kit_p_, keyreq_l_));
- }
-}
-
-void
-Key_register::pre_move_processing()
-{
- if (kit_p_) {
- if (default_key_b_)
- typeset_breakable_item(0,0,kit_p_);
- else
- typeset_breakable_item(
- new Key_item(*kit_p_), kit_p_, new Key_item(*kit_p_));
- kit_p_ = 0;
- }
-}
-
-
-
-void
-Key_register::read_req(Key_change_req * r)
-{
- accidental_idx_arr_.set_size(0);
- for (int i = 0; i < r->melodic_p_arr_.size(); i ++) {
- int n_i=r->melodic_p_arr_[i]->notename_i_;
- key_.set(n_i, r->melodic_p_arr_[i]->accidental_i_);
- accidental_idx_arr_.push(n_i);
- }
-}
-
-void
-Key_register::post_move_processing()
-{
- keyreq_l_ = 0;
- default_key_b_ = false;
- kit_p_ = 0;
-}
+++ /dev/null
-#include "key.hh"
-
-const int OCTAVES=14; // ugh..
-const int ZEROOCTAVE=7;
-
-Key::Key()
-{
- accidental_i_arr_.set_size(7);
- for (int i= 0; i < 7 ; i++)
- accidental_i_arr_[i] = 0;
-}
-
-Local_key::Local_key()
-{
- octaves.set_size(OCTAVES);
-}
-
-Key&
-Local_key::oct(int i)
-{
- return octaves[i+ZEROOCTAVE];
-}
-
-void
-Key::set(int i, int a)
-{
- assert(a > -3 && a < 3);
- accidental_i_arr_[i]=a;
-}
-
-
-void
-Local_key::reset(Key k)
-{
- for (int i= 0; i < OCTAVES ; i++)
- octaves[i] = k;
-}
-
+++ /dev/null
-/*
- keyword.cc -- keywords and identifiers
- */
-
-#include <stdlib.h>
-
-#include "glob.hh"
-#include "lexer.hh"
-//#include "mudobs.hh"
-//#include "gram.hh"
-
-/* for the keyword table */
-struct Keyword_ent
-{
- const char *name;
- int tokcode;
-};
-
-struct Keyword_table
-{
- Keyword_ent *table;
- int maxkey;
- Keyword_table(Keyword_ent *);
- int lookup(const char *s) const;
-};
-
-
-/* for qsort */
-int
- tabcmp(const void * p1, const void * p2)
-{
- return strcmp(((const Keyword_ent *) p1)->name,
- ((const Keyword_ent *) p2)->name);
-}
-
-Keyword_table::Keyword_table(Keyword_ent *tab)
-{
- table = tab;
-
- /* count keywords */
- for (maxkey = 0; table[maxkey].name; maxkey++);
-
- /* sort them */
- qsort(table, maxkey, sizeof(Keyword_ent), tabcmp);
-}
-
-/*
- lookup with binsearch, return tokencode.
-*/
-int
-Keyword_table::lookup(const char *s)const
-{
- int lo,
- hi,
- cmp,
- result;
- lo = 0;
- hi = maxkey;
-
- /* binary search */
- do
- {
- cmp = (lo + hi) / 2;
-
- result = strcmp(s, table[cmp].name);
-
- if (result < 0)
- hi = cmp;
- else
- lo = cmp;
- }
- while (hi - lo > 1);
- if (!strcmp(s, table[lo].name))
- {
- return table[lo].tokcode;
- } else
- return -1; /* not found */
-}
-
+++ /dev/null
-#include "leastsquares.hh"
-void
-Least_squares::OK() const
-{
- assert( input.size() > 1 );
- Real dx = 0.0;
- for (int i=1; i < input.size(); i++)
- dx += abs (input[i-1].x - input[i].x);
-
- assert(dx);
-}
-void
-Least_squares::minimise(Real &coef, Real &offset)
-{
- OK();
- Real sx = 0.0;
- Real sy = 0.0;
- Real sqx =0.0;
- Real sxy = 0.0;
-
- for (int i=0; i < input.size();i++) {
- Real x=input[i].x;
- Real y = input[i].y;
- sx += x;
- sy += y;
- sqx += sqr(x);
- sxy += x*y;
- }
- int N = input.size();
-
-
- coef = (N * sxy - sx*sy )/(N*sqx - sqr(sx));
- offset = (sy - coef * sx)/N;
-
-}
+++ /dev/null
-%{ // -*-Fundamental-*-
-
-#include <stdio.h>
-
-#include "string.hh"
-#include "notename.hh"
-#include "lexer.hh"
-#include "varray.hh"
-#include "parser.hh"
-#include "debug.hh"
-#include "input-score.hh"
-#include "parseconstruct.hh"
-#include "main.hh"
-#include "string-convert.hh"
-
-%}
-
-%option c++
-%option noyywrap
-%option nodefault
-%option yylineno
-%option debug
-%option yyclass="My_flex_lexer"
-%option stack
-
-%x notes
-%x incl
-%x quote
-%x lyrics
-
-
-
-A [a-zA-Z]
-AA {A}|_
-N [0-9]
-AN {AA}|{N}
-PUNCT [?!,.:;]
-ACCENT [\\'"^]
-NATIONAL [\241-\377]
-TEX {AA}|-|{PUNCT}|{ACCENT}|{NATIONAL}
-
-WORD {A}{AN}*
-ALPHAWORD {A}+
-INT -?{N}+
-REAL {INT}?(\.{N}*)?
-
-OPTSIGN !?
-PITCHMOD ['`]*{OPTSIGN}
-RESTNAME r|s|p
-NOTECOMMAND \\{WORD}
-NOTENAME [a-z]+
-UNOTENAME [A-Z][a-z]*
-DOTS \.+
-LYRICS {TEX}+
-COMMENT [%#].*\n
-
-%%
-
-\$ {
- yy_push_state(notes);
-}
-
-\@ {
- yy_push_state(lyrics);
-}
-
-<notes>{RESTNAME} {
- const char *s = YYText();
- yylval.string = new String (s);
- mtor << "rest:"<< yylval.string;
- return RESTNAME;
-}
-<notes>{UNOTENAME} {
- int *p=yylval.ii;
- return ret_notename(p, YYText(), -1);
-}
-
-<notes>{NOTENAME} {
- int *p=yylval.ii;
- return ret_notename(p, YYText(), 0);
-}
-
-<notes>{NOTECOMMAND} {
- String c = YYText() +1;
- mtor << "\\word: " << YYText()+1<<eol;
- int l = lookup_keyword(c);
- if (l != -1)
- return l;
- Identifier * id = lookup_identifier(c);
- if (id) {
- yylval.id = id;
- return IDENTIFIER;
- }
- String *sp = new String( c);
- yylval.string=sp;
- return STRING;
-}
-
-<notes>{PITCHMOD} {
- const char *s = YYText();
- mtor << "pitchmod:"<< YYText()<<eol;
- yylval.string = new String (s);
- return PITCHMOD;
-}
-<notes>{DOTS} {
- yylval.i = strlen(YYText());
- return DOTS;
-}
-<notes>{INT} {
- yylval.i = String_convert::dec2_i( String( YYText() ) );
- return INT;
-}
-<notes>{COMMENT} {
-}
-<notes>[ \t\n]+ {
-
-}
-<notes>\$ {
- yy_pop_state();
-}
-<notes>\"[^"]*\" {
- String s (YYText()+1);
- s = s.left_str(s.length_i()-1);
- yylval.string = new String(s);
- return STRING;
-}
-<notes>. {
- return yylval.c = YYText()[0];
-}
-
-\" {
- yy_push_state(quote);
-}
-<quote>[^"]* {
- yylval.string = new String (YYText());
-}
-<quote>\" {
- mtor << "quoted string\n";
- yy_pop_state();
- return STRING;
-}
-
-<lyrics>{DOTS} {
- yylval.i = strlen(YYText());
- return DOTS;
-}
-<lyrics>{INT} {
- yylval.i = String_convert::dec2_i( String( YYText() ) );
- return INT;
-}
-<lyrics>{NOTECOMMAND} {
- String c = YYText() +1;
- mtor << "\\word: " << YYText()+1<<eol;
- int l = lookup_keyword(c);
- if (l != -1)
- return l;
-
-/* let's try passing tex's typesetting macros like \ss \alpha \c */
- String* str_p = new String(YYText());//huh?
- return STRING;
-
-/* and skip identifiers...
- Identifier * id = lookup_identifier(c);
- if (id) {
- yylval.id = id;
- return IDENTIFIER;
- }
- String *sp = new String( c);
-
- yylval.string=sp;
- return STRING;
-*/
-}
-<lyrics>\"[^"]*\" {
- String s (YYText()+1);
- s = s.left_str(s.length_i()-1);
- yylval.string = new String(s);
- return STRING;
-}
-<lyrics>{LYRICS} {
- String s (YYText());
- int i = 0;
- 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 + 1) = 'c';
- s = s.left_str(i+2) + " " + s.right_str(s.length_i()-i-2);
- }
- yylval.string = new String(s);
- return STRING;
-}
-<lyrics>\| {
- return YYText()[0];
-}
-<lyrics>{COMMENT} {
-
-}
-<lyrics>[{}] {
- return YYText()[0];
-}
-<lyrics>[()\[\]|/.^>_-] {
- return yylval.c = YYText()[0];
-}
-<lyrics>[ \t\n]+ {
-}
-<lyrics>@ {
- yy_pop_state();
-}
-
-<<EOF>> {
- mtor << "<<EOF>>";
-
- if (! close_input())
- yyterminate(); // can't move this, since it actually rets a YY_NULL
-}
-
-
-include {
- yy_push_state(incl);
-}
-<incl>[ \t]* { /* eat the whitespace */ }
-<incl>\"[^"]*\"+ { /* got the include file name */
- String s (YYText()+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();
-}
-
-
-{WORD} {
- mtor << "word: " << YYText()<<eol;
- String c = YYText();
- int l = lookup_keyword(c);
- if (l != -1)
- return l;
- Identifier * id = lookup_identifier(c);
- if (id) {
- yylval.id = id;
- return IDENTIFIER;
- }
- String *sp = new String( c);
- mtor << "new id: " << *sp << eol;
- yylval.string=sp;
- return STRING;
-}
-
-{REAL} {
- Real r;
- int cnv=sscanf (YYText(), "%lf", &r);
- assert(cnv == 1);
- mtor << "REAL" << r<<'\n';
- yylval.real = r;
- return REAL;
-}
-
-[{}] {
-
- mtor << "parens\n";
- return YYText()[0];
-}
-[*:=] {
- char c = YYText()[0];
- mtor << "misc char" <<c<<"\n";
- return c;
-}
-[ \t\n]+ {
-
-}
-
-{COMMENT} {
- //ignore
-}
-. {
- error( String( "illegal character: " ) + String( YYText()[0] ), here_ch_c_l() );
- return YYText()[0];
-}
-
-%%
-
+++ /dev/null
-/*
- lexerinit.cc -- implement some stuff
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-#include <iostream.h>
-#include <strstream.h>
-#include "proto.hh"
-#include "plist.hh"
-#include "lexer.hh"
-#include "debug.hh"
-#include "main.hh"
-#include "source-file.hh"
-#include "source.hh"
-
-My_flex_lexer *lexer=0;
-
-int
-yylex() {
- return lexer->yylex();
-}
-
-bool
-busy_parsing()
-{
- return lexer;
-}
+++ /dev/null
-//
-// lily-stream.cc
-//
-// source file of the LilyPond music typesetter
-//
-// (c) 1997 Jan Nieuwenhuizen <jan@digicash.com>
-
-// should i be named Mudela_stream?
-
-#include <fstream.h>
-#include <time.h>
-
-#include "proto.hh"
-#include "plist.hh"
-#include "string.hh"
-
-#include "moment.hh"
-#include "source-file.hh"
-#include "source.hh"
-#include "midi-main.hh" // *tors
-
-#include "duration.hh"
-#include "midi-event.hh"
-#include "lily-stream.hh"
-
-Lily_stream::Lily_stream( String filename_str )
-{
- filename_str_ = filename_str;
- os_p_ = 0;
- open();
- header();
-}
-
-Lily_stream::~Lily_stream()
-{
- delete os_p_;
-}
-
-Lily_stream&
-Lily_stream::operator <<( String str )
-{
- *os_p_ << str;
- return *this;
-}
-
-Lily_stream&
-Lily_stream::operator <<( Midi_event& midi_event_r )
-{
- midi_event_r.output_mudela( *this );
- return *this;
-}
-
-void
-Lily_stream::header()
-{
- *os_p_ << "% Creator: " << version_str() << "\n";
- *os_p_ << "% Automatically generated, at ";
- time_t t( time( 0 ) );
- *os_p_ << ctime( &t );
- *os_p_ << "% from input file: ";
-// *os_p_ << midi_parser_l_g->
- *os_p_ << "\n\n";
-}
-
-void
-Lily_stream::open()
-{
- os_p_ = new ofstream( filename_str_ );
- if ( !*os_p_ )
- error ( "can't open `" + filename_str_ + "\'", 0 );
-}
-
+++ /dev/null
-#include <math.h>
-#include "linespace.hh"
-#include "pcol.hh"
-#include "debug.hh"
-#include "qlp.hh"
-#include "unionfind.hh"
-#include "idealspacing.hh"
-
-const Real COLFUDGE=1e-3;
-
-
-bool
-Spacing_problem::contains(const PCol *w)
-{
- for (int i=0; i< cols.size(); i++)
- if (cols[i].pcol_ == w)
- return true;
- return false;
-}
-
-int
-Spacing_problem::col_id(const PCol *w)const
-{
- for (int i=0; i< cols.size(); i++)
- if (cols[i].pcol_ == w)
- return i;
- assert(false);
- return -1;
-}
-
-void
-Spacing_problem::OK() const
-{
-#ifndef NDEBUG
- Union_find connected(cols.size());
- Array<int> fixed;
- for (int i=0; i < ideals.size(); i++) {
- assert(ideals[i]->hooke > 0);
- int l = col_id(ideals[i]->left);
- int r = col_id(ideals[i]->right);
- connected.connect(l,r);
- }
- for (int i = 0; i < cols.size(); i++)
- if (cols[i].fixed())
- fixed.push(i);
- for (int i = 0; i < cols.size(); i++) {
- bool c=false;
- for (int j =0; j<fixed.size(); j++)
- c |= connected.equiv(fixed[j],i);
- if (!c)
- WARN << "You have unconnected columns. \n"
- "Check if bars and music fit each other\n"
- "(crashing :-)\n";
- assert(c);
- }
-#endif
-}
-
-bool
-Spacing_problem::check_constraints(Vector v) const
-{
- int dim=v.dim();
- for (int i=0; i < dim; i++) {
-
- if (cols[i].fixed()&&
- abs(cols[i].fixed_position() - v(i)) > COLFUDGE)
- return false;
-
- if (!i)
- continue;
-
- Real mindist=cols[i-1].minright()
- +cols[i].minleft();
-
- // ugh... compares
- Real dif =v(i) - v(i-1)- mindist;
- bool b = (dif > - COLFUDGE);
-
-
- if (!b)
- return false;
-
- }
- return true;
-}
-
-bool
-Spacing_problem::check_feasible() const
-{
- Vector sol(try_initial_solution());
- return check_constraints(sol);
-}
-
-// generate a solution which obeys the min distances and fixed positions
-Vector
-Spacing_problem::try_initial_solution() const
-{
- int dim=cols.size();
- Vector initsol(dim);
- for (int i=0; i < dim; i++) {
- if (cols[i].fixed()) {
- initsol(i)=cols[i].fixed_position();
- } else {
- Real mindist=cols[i-1].minright()
- +cols[i].minleft();
- assert(mindist >= 0.0);
- initsol(i)=initsol(i-1)+mindist;
-
- //nog niet
- //if (i>0)
- // assert(initsol(i) > initsol(i-1));
- }
- }
-
- return initsol;
-}
-Vector
-Spacing_problem::find_initial_solution() const
-{
- Vector v(try_initial_solution());
- assert(check_constraints(v));
- return v;
-}
-
-// generate the matrices
-void
-Spacing_problem::make_matrices(Matrix &quad, Vector &lin, Real &c) const
-{
- quad.fill(0);
- lin.fill(0);
- c = 0;
- for (int j=0; j < ideals.size(); j++){
- Idealspacing const*i=ideals[j];
- int l = col_id(i->left);
- int r = col_id(i->right);
-
- quad(r,r) += i->hooke;
- quad(r,l) -= i->hooke;
- quad(l,r) -= i->hooke;
- quad(l,l) += i->hooke;
-
- lin(r) -= i->space*i->hooke;
- lin(l) += i->space*i->hooke;
-
- c += sqr(i->space);
- }
-}
-
-// put the constraints into the LP problem
-void
-Spacing_problem::make_constraints(Mixed_qp& lp) const
-{
- int dim=cols.size();
- for (int j=0; j < dim; j++) {
- Colinfo *c=&(cols[j]);
- if (c->fixed()) {
- lp.add_fixed_var(j,c->fixed_position());
- }
- if (j > 0){
- Vector c1(dim);
-
- c1(j)=1.0 ;
- c1(j-1)=-1.0 ;
- lp.add_inequality_cons(c1, cols[j-1].minright() +
- cols[j].minleft());
- }
- }
-}
-
-Array<Real>
-Spacing_problem::solve() const
-{
- print();
- OK();
- assert(check_feasible());
-
- /* optimalisatiefunctie */
- Mixed_qp lp(cols.size());
- make_matrices(lp.quad,lp.lin, lp.const_term);
- make_constraints(lp);
- Vector start=find_initial_solution();
- Vector sol(lp.solve(start));
- if (!check_constraints(sol)) {
- WARN << "solution doesn't satisfy constraints.\n" ;
- }
-
-
- Array<Real> posns(sol);
- posns.push(lp.eval(sol));
- return posns;
-}
-
-/*
- add one column to the problem.
-*/
-void
-Spacing_problem::add_column(const PCol *col, bool fixed, Real fixpos)
-{
- Colinfo c(col,(fixed)? &fixpos : 0);
- cols.push(c);
-}
-
-void
-Spacing_problem::add_ideal(const Idealspacing *i)
-{
- const PCol *l =i->left;
- const PCol *r= i->right;
-
- if (!contains(l) || !contains(r)) {
- return;
- }
- ideals.push(i);
-}
-
-void
-Spacing_problem::print_ideal(const Idealspacing*id)const
-{
-#ifndef NPRINT
- int l = col_id(id->left);
- int r = col_id(id->right);
-
- mtor << "between " << l <<","<<r<<":" ;
- id->print();
-#endif
-}
-
-void
-Spacing_problem::print() const
-{
-#ifndef NPRINT
- for (int i=0; i < cols.size(); i++) {
- mtor << "col " << i<<' ';
- cols[i].print();
- }
- for (int i=0; i < ideals.size(); i++) {
- print_ideal(ideals[i]);
- }
-#endif
-
-}
-
-/* **************** */
-
-void
-Colinfo::print() const
-{
-#ifndef NPRINT
- mtor << "column { ";
- if (fixed())
- mtor << "fixed at " << fixed_position()<<", ";
- assert(pcol_);
- mtor << "[" << minleft() << ", " << minright() << "]";
- mtor <<"}\n";
-#endif
-}
-
-Colinfo::Colinfo(Colinfo const&c)
-{
- fixpos = (c.fixpos)?new Real(*c.fixpos):0;
- pcol_ = c.pcol_;
- width = c.width;
-}
-
-Colinfo::Colinfo(const PCol*col_p, const Real*fixed_r_p )
-{
- fixpos = (fixed_r_p)? new Real(*fixed_r_p) : 0;
- pcol_ = col_p;
- width = pcol_->width();
-}
-
-Colinfo::~Colinfo()
-{
- delete fixpos;
-}
-
-Colinfo::Colinfo()
-{
- pcol_=0;
- fixpos = 0;
-}
-void
-Colinfo::operator=(Colinfo const&c )
-{
- delete fixpos;
- fixpos = (c.fixpos)?new Real(*c.fixpos):0;
- pcol_ = c.pcol_;
- width = c.width;
-}
+++ /dev/null
-#include "local-key-item.hh"
-#include "molecule.hh"
-#include "scalar.hh"
-#include "lookup.hh"
-#include "paper-def.hh"
-#include "musicalrequest.hh"
-#include "notehead.hh"
-#include "misc.hh"
-
-
-
-Local_key_item::Local_key_item(int i)
-{
- c0_position = i;
-}
-
-void
-Local_key_item::add(Item*head_l)
-{
- support_items_.push(head_l);
- add_dependency(head_l);
-}
-
-void
-Local_key_item::add(Melodic_req*m_l)
-{
- add(m_l->octave_i_, m_l->notename_i_, m_l->accidental_i_);
-}
-void
-Local_key_item::add (int o, int p , int a)
-{
- Local_acc l;
- l.octave = o;
- l.name = p;
- l.acc = a;
- accs.push(l);
-}
-
-void
-Local_key_item::do_pre_processing()
-{
- accs.sort(Local_acc::compare);
-}
-
-Molecule*
-Local_key_item::brew_molecule_p()const
-{
- Molecule* output = new Molecule;
- Molecule*octmol = 0;
- int lastoct = -100;
- for (int i = 0; i < accs.size(); i++) {
- // do one octave
- if (accs[i].octave != lastoct) {
- if (octmol){
- Real dy =lastoct*7*paper()->internote();
- octmol->translate(Offset(0, dy));
- output->add(*octmol);
- delete octmol;
- }
- octmol= new Molecule;
- }
- lastoct = accs[i].octave;
- Symbol s =paper()->lookup_p_->accidental(accs[i].acc);
- Atom a(s);
- Real dy = (accs[i].name + c0_position) * paper()->internote();
- a.translate(Offset(0,dy));
-
- octmol->add_right(a);
- }
-
- if (octmol){
- Real dy =lastoct*7*paper()->internote();
- octmol->translate(Offset(0, dy));
- output->add(*octmol);
- delete octmol;
- }
-
- Interval head_width=itemlist_width(support_items_);
- output->translate(Offset(-output->extent().x.right + head_width.left ,0));
-
- return output;
-}
-
-int
-Local_acc::compare(Local_acc&a, Local_acc&b)
-{
- if (a.octave - b.octave)
- return a.octave - b.octave;
- if (a.name - b.name)
- return a.name - b.name;
-
- assert(false);
-};
+++ /dev/null
-/*
- local-key-reg.cc -- implement Local_key_register
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-#include "musicalrequest.hh"
-#include "commandrequest.hh"
-#include "local-key-reg.hh"
-#include "local-key-item.hh"
-#include "complex-walker.hh"
-#include "key-reg.hh"
-#include "debug.hh"
-#include "key-item.hh"
-
-Local_key_register::Local_key_register()
-{
- key_item_p_ = 0;
- key_c_l_ = 0;
-}
-
-void
-Local_key_register::pre_move_processing()
-{
- if (key_item_p_) {
- typeset_element(key_item_p_);
- key_item_p_ = 0;
- }
-}
-void
-Local_key_register::acknowledge_element(Staff_elem_info info)
-{
- if (info.req_l_->melodic()) {
- Melodic_req * melodic_l_ = info.req_l_->melodic();
-
- if( melodic_l_->forceacc_b_ ||
- local_key_.oct(melodic_l_->octave_i_).acc(melodic_l_->notename_i_)
- != melodic_l_->accidental_i_) {
- Item * support_l_ = info.elem_p_->item();
-
-
- if (!key_item_p_) {
- key_item_p_ = new Local_key_item(*get_staff_info().c0_position_i_);
- }
-
- key_item_p_->add(melodic_l_);
- key_item_p_->add(support_l_);
- local_key_.oct(melodic_l_->octave_i_)
- .set(melodic_l_->notename_i_, melodic_l_->accidental_i_);
- }
- } else if (info.elem_p_->name()==Key_item::static_name()) {
- Key_register * key_reg_l =
- (Key_register*)info.origin_reg_l_arr_[0];
- key_c_l_ = &key_reg_l->key_;
- local_key_.reset(*key_c_l_);
- }
-}
-
-void
-Local_key_register::process_requests()
-{
- const Time_description * time_c_l_ = get_staff_info().time_c_l_;
- if (! time_c_l_->whole_in_measure_){
- if (key_c_l_)
- local_key_.reset(*key_c_l_);
- else if( time_c_l_->when_ >0)
- warning ("Help me! can't figure current key", 0);
- }
-}
+++ /dev/null
-/*
- lookup.cc -- implement simple Lookup methods.
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-#include "lookup.hh"
-#include "debug.hh"
-#include "symtable.hh"
-#include "dimen.hh"
-#include "tex.hh"
-#include "scalar.hh"
-
-Lookup::Lookup()
-{
- texsetting = "\\unknowntexsetting";
- symtables_ = new Symtables;
-}
-
-Lookup::Lookup(Lookup const &s)
-{
- texsetting = s.texsetting;
- symtables_ = new Symtables(*s.symtables_);
-}
-Lookup::~Lookup()
-{
- delete symtables_;
-}
-
-void
-Lookup::add(String s, Symtable*p)
-{
- symtables_->add(s, p);
-}
-
-void
-Lookup::print()const
-{
- mtor << "Lookup: " << texsetting << " {\n";
- symtables_->print();
- mtor << "}\n";
-}
-
-Symbol
-Lookup::text(String style, String text, int dir)
-{
- Array<String> a;
-
- a.push(text);
- Symbol tsym = (*symtables_)("style")->lookup(style);
- a[0] = substitute_args(tsym.tex,a);
-
- Symbol s = (*symtables_)("align")->lookup(dir);
- s.tex = substitute_args(s.tex,a);
- s.dim.y = tsym.dim.y;
- return s;
-}
-
-
-Real
-Lookup::internote()
-{
- return ball(4).dim.y.length()/2;
-}
-
-Symbol
-Lookup::ball(int j)
-{
- if (j > 4)
- j = 4;
-
- Symtable * st = (*symtables_)("balls");
- return st->lookup(String(j));
-}
-
-Symbol
-Lookup::rest(int j)
-{
- return (*symtables_)("rests")->lookup(String(j));
-}
-
-Symbol
-Lookup::fill(Box b)
-{
- Symbol s( (*symtables_)("param")->lookup("fill"));
- s.dim = b;
- return s;
-}
-
-Symbol
-Lookup::accidental(int j)
-{
- return (*symtables_)("accidentals")->lookup(String(j));
-}
-
-
-Symbol
-Lookup::bar(String s)
-{
- return (*symtables_)("bars")->lookup(s);
-}
-
-Symbol
-Lookup::script(String s)
-{
- return (*symtables_)("scripts")->lookup(s);
-}
-
-Symbol
-Lookup::clef(String s)
-{
- return (*symtables_)("clefs")->lookup(s);
-}
-
-Symbol
-Lookup::dots(int j)
-{
- if (j>3)
- error("max 3 dots"); // todo
- return (*symtables_)("dots")->lookup(j);
-}
-
-Symbol
-Lookup::flag(int j)
-{
- return (*symtables_)("flags")->lookup(j);
-}
-
-Symbol
-Lookup::streepjes(int i)
-{
- assert(i);
-
- int arg;
- String idx;
-
- if (i < 0) {
- idx = "botlines";
- arg = -i;
- } else {
- arg = i;
- idx = "toplines";
- }
- Symbol ret = (*symtables_)("streepjes")->lookup(idx);
-
- Array<String> a;
- a.push(arg);
- ret.tex = substitute_args(ret.tex, a);
-
- return ret;
-}
-
-Symbol
-Lookup::hairpin(Real &wid, bool decresc)
-{
- int idx = int(rint(wid / 6 PT));
- if(!idx) idx ++;
- wid = idx*6 PT;
- String idxstr = (decresc)? "decrescendosym" : "crescendosym";
- Symbol ret=(*symtables_)("param")->lookup(idxstr);
-
- Array<String> a;
- a.push(idx);
- ret.tex = substitute_args(ret.tex, a);
- ret.dim.x = Interval(0,wid);
- return ret;
-}
-
-Symbol
-Lookup::linestaff(int lines, Real wid)
-{
- Symbol s;
- s.dim.x = Interval(0,wid);
- Real dy = (lines >0) ? (lines-1)*internote()*2 : 0;
- s.dim.y = Interval(0,dy);
-
- Array<String> a;
- a.push(lines);
- a.push(print_dimen(wid));
-
- s.tex = (*symtables_)("param")->lookup("linestaf").tex;
- s.tex = substitute_args(s.tex, a);
-
- return s;
-}
-
-
-Symbol
-Lookup::meter(Array<Scalar> a)
-{
- Symbol s;
- s.dim.x = Interval( 0 PT, 10 PT);
- s.dim.y = Interval(0, 20 PT); // todo
- String src = (*symtables_)("param")->lookup("meter").tex;
- s.tex = substitute_args(src,a);
- return s;
-}
-
-
-Symbol
-Lookup::stem(Real y1,Real y2)
-{
- if (y1 > y2) {
- Real t = y1;
- y1 = y2;
- y2 = t;
- }
- Symbol s;
-
- s.dim.x = Interval(0,0);
- s.dim.y = Interval(y1,y2);
-
- Array<String> a;
- a.push(print_dimen(y1));
- a.push(print_dimen(y2));
-
- String src = (*symtables_)("param")->lookup("stem").tex;
- s.tex = substitute_args(src,a);
- return s;
-}
+++ /dev/null
-#include "musicalrequest.hh"
-#include "paper-def.hh"
-#include "lyric-item.hh"
-#include "stem.hh"
-#include "molecule.hh"
-#include "lookup.hh"
-#include "text-def.hh"
-#include "source-file.hh"
-#include "source.hh"
-#include "debug.hh"
-#include "main.hh"
-
-Lyric_item::Lyric_item(Lyric_req* lreq_l, int voice_count_i)
- : Text_item(lreq_l,0)
-{
- pos_i_ = -voice_count_i * 4 ; // 4 fontsize dependant. TODO
- dir_i_ = -1;
-}
-
-void
-Lyric_item::do_pre_processing()
-{
-
- // test context-error
- if ( tdef_l_->text_str_.index_i( "Gates" ) >=0)// :-)
- warning( "foul word", tdef_l_->defined_ch_c_l_ );
-}
+++ /dev/null
-#include "musicalrequest.hh"
-#include "voice.hh"
-#include "staff-walker.hh"
-#include "debug.hh"
-#include "staff.hh"
-#include "lyricstaff.hh"
-#include "lyricwalker.hh"
-#include "pscore.hh"
-
-void
-Lyric_staff::set_output(PScore*pscore_l)
-{
- pstaff_l_ = new PStaff(pscore_l);
- pscore_l_ = pscore_l;
- pscore_l_->add(pstaff_l_);
-}
-
-Staff_walker*
-Lyric_staff::get_walker_p()
-{
- return new Lyric_walker(this);
-}
+++ /dev/null
-/*
- lyricwalker.cc -- implement Lyric_walker
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Jan Nieuwenhuizen <jan@digicash.com>
-*/
-
-#include "musicalrequest.hh"
-#include "voice.hh"
-#include "pscore.hh"
-#include "lyricstaff.hh"
-#include "lyricwalker.hh"
-#include "debug.hh"
-#include "lyric-item.hh"
-#include "staff-column.hh"
-
-void
-Lyric_walker::process_requests()
-{
- allow_break();
-
- int req_count=0;
- for (int i = 0; i < ptr()->musicalreq_l_arr_.size(); i++) {
- Lyric_req * lreq_l = ptr()->musicalreq_l_arr_[i]->lreq_l();
- if (!lreq_l)
- continue;
- Item *lp = new Lyric_item(lreq_l,req_count++);
- ptr()->typeset_musical_item( lp);
- }
-}
-
-Lyric_walker::Lyric_walker(Lyric_staff* lstaff_l)
- : Staff_walker(lstaff_l, lstaff_l->pstaff_l_->pscore_l_)
-{
-
-}
-
-
+++ /dev/null
-#include <iostream.h>
-#include <assert.h>
-#include "proto.hh"
-#include "plist.hh"
-#include "lgetopt.hh"
-#include "misc.hh"
-#include "string.hh"
-#include "main.hh"
-#include "path.hh"
-#include "config.hh"
-#include "source-file.hh"
-#include "source.hh"
-
-Source source;
-Source* source_l_g = &source;
-bool only_midi = false;
-extern void parse_file(String,String);
-
-
-void
-destill_inname( String &name_str_r);
-Long_option_init theopts[] = {
- 1, "output", 'o',
- 0, "warranty", 'w',
- 0, "help", 'h',
- 0, "debug", 'd',
- 1, "init", 'i',
- 1, "include", 'I',
- 0, "midi", 'M',
- 0,0,0
-};
-
-void
-help()
-{
- cout <<
- "--help, -h This help\n"
- "--warranty, -w show warranty & copyright\n"
- "--output, -o set default output\n"
- "--debug, -d enable debug output\n"
- "--init, -i set init file\n"
- "--include, -I add to file search path.\n"
- "--midi, -M midi output only\n"
- ;
-
-}
-
-void
-notice()
-{
- cout <<
- "\n"
- "LilyPond, a music typesetter.\n"
- "Copyright (C) 1996,97 by\n"
- " Han-Wen Nienhuys <hanwen@stack.nl>\n"
- "Contributors\n"
- " Jan Nieuwenhuizen <jan@digicash.com>\n"
- " Mats Bengtsson <matsb@s3.kth.se>\n"
- "\n"
- " This program is free software; you can redistribute it and/or\n"
- "modify it under the terms of the GNU General Public License version 2\n"
- "as published by the Free Software Foundation.\n"
- "\n"
- " This program is distributed in the hope that it will be useful,\n"
- "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
- "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
- "General Public License for more details.\n"
- "\n"
- " You should have received a copy (refer to the file COPYING) of the\n"
- "GNU General Public License along with this program; if not, write to\n"
- "the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,\n"
- "USA.\n";
-}
-
-static File_path * path =0;
-struct Main_init {
- Main_init() {
- path = new File_path(LIBDIR);
- path->push(String(LIBDIR)+"init/");
- debug_init();
- }
- ~Main_init() {
- delete path;
- }
-} main_init;
-
-int
-main (int argc, char **argv)
-{
- Getopt_long oparser(argc, argv,theopts);
- cout << get_version();
- String init_str("symbol.ini");
-
- while (Long_option_init * opt = oparser()) {
- switch ( opt->shortname){
- case 'o':
- set_default_output(oparser.optarg);
- break;
- case 'w':
- notice();
- exit(0);
- break;
- case 'I':
- path->push(oparser.optarg);
- break;
- case 'i':
- init_str = oparser.optarg;
- break;
- case 'h':
- help();
- exit(0);
- break;
- case 'd':
- set_debug(true);
- break;
- case 'M':
- only_midi = true;
- break;
- default:
- assert(false);
- break;
- }
- }
-
- int p=0;
- char *arg ;
- while ( (arg= oparser.get_next_arg()) ) {
- String f(arg);
- destill_inname(f);
- parse_file(init_str,f);
- do_scores();
- p++;
- }
- if (!p) {
- parse_file(init_str, "");
- do_scores();
- }
-
- return 0;
-}
-
-String
-find_file(String f)
-{
- return path->find(f);
-}
-
-/// make input file name: add default extension. "" is stdin.
-void
-destill_inname( String &name_str_r)
-{
- if ( name_str_r.length_i() )
- {
- if( name_str_r[ 0 ] != '-' )
- {
- String a,b,c,d;
- split_path(name_str_r,a,b,c,d);
-
- // add extension if not present.
- if (d == "")
- d = ".ly";
- name_str_r = a+b+c+d;
- }
- } else name_str_r = "";
-}
-
+++ /dev/null
-/*
- meter-reg.cc -- implement Meter_register
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-#include "meter-reg.hh"
-#include "meter.hh"
-#include "commandrequest.hh"
-
-Meter_register::Meter_register()
-
-{
- post_move_processing();
-}
-
-bool
-Meter_register::try_request(Request*r_l)
-{
- Command_req* creq_l= r_l->command();
- if (!creq_l || !creq_l->meterchange())
- return false;
-
- assert(!meter_req_l_);
- meter_req_l_ = r_l->command()->meterchange();
-
- return true;
-}
-
-void
-Meter_register::process_requests()
-{
- if (meter_req_l_ ) {
- Array<Scalar> args;
- args.push(meter_req_l_->beats_i_);
- args.push(meter_req_l_->one_beat_i_);
-
- meter_p_ = new Meter(args);
- }
-
- if (meter_p_)
- announce_element(Staff_elem_info(meter_p_, meter_req_l_) );
-}
-
-void
-Meter_register::pre_move_processing()
-{
- if (meter_p_) {
- Meter * post_p =new Meter(*meter_p_);
- Meter * pre_p =new Meter(*meter_p_);
-
- typeset_breakable_item(pre_p, meter_p_, post_p);
- meter_p_ =0;
- }
-}
-
-void
-Meter_register::post_move_processing()
-{
- meter_req_l_ = 0;
- meter_p_ =0;
-}
+++ /dev/null
-#include "scalar.hh"
-#include "molecule.hh"
-#include "meter.hh"
-#include "paper-def.hh"
-#include "lookup.hh"
-
-Meter::Meter(Array<Scalar>a)
- :args(a)
-{
-}
-
-Molecule*
-Meter::brew_molecule_p()const
-{
- Symbol s = paper()->lookup_p_->meter(args);
- return new Molecule(Atom(s));
-}
-
+++ /dev/null
-//
-// midi-def.cc -- implement midi output
-//
-// source file of the LilyPond music typesetter
-//
-// (c) 1997 Jan Nieuwenhuizen <jan@digicash.com>
-
-#include <math.h>
-#include "misc.hh"
-#include "midi-def.hh"
-#include "debug.hh"
-
-// classes, alphasorted
-// statics
-// constructors
-// destructor
-// routines, alphasorted
-
-Midi_def::Midi_def()
-{
- set_tempo( Moment( 1, 4 ), 60 );
- outfile_str_ = "lelie.midi";
-}
-
-Midi_def::Midi_def( Midi_def const& midi_c_r )
-{
- whole_seconds_f_ = midi_c_r.whole_seconds_f_;
- outfile_str_ = midi_c_r.outfile_str_;
-}
-
-Midi_def::~Midi_def()
-{
-}
-
-Real
-Midi_def::duration_to_seconds_f( Moment moment )
-{
- if (!moment)
- return 0;
-
- return whole_seconds_f_ * moment;
-}
-
-int
-Midi_def::get_tempo_i( Moment moment )
-{
- return Moment( whole_seconds_f_ ) * Moment( 60 ) * moment;
-}
-
-void
-Midi_def::print() const
-{
-#ifndef NPRINT
- mtor << "Midi {4/min: " << Real( 60 ) / ( whole_seconds_f_ * 4 );
- mtor << "out: " << outfile_str_;
- mtor << "}\n";
-#endif
-}
-
-void
-Midi_def::set_tempo( Moment moment, int count_per_minute_i )
-{
- whole_seconds_f_ = Moment( count_per_minute_i ) / Moment( 60 ) / moment;
-}
+++ /dev/null
-//
-// midi-event.cc -- implement Midi_event
-//
-// copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
-
-#include <assert.h>
-
-#include "proto.hh"
-#include "plist.hh" // all for midi-main.hh
-#include "string.hh"
-#include "source.hh"
-#include "source-file.hh"
-#include "midi-main.hh" // *tors
-#include "moment.hh"
-#include "duration.hh"
-#include "midi-event.hh"
-#include "lily-stream.hh"
-
-Midi_event::Midi_event()
-{
-}
-
-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;
- minor_i_ = minor_i;
- if ( !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\\" );
- if ( !minor_i_ )
- mudela_str_ += String( (char)( key_i_ - 2 + 'A' ) );
- else
- mudela_str_ += String( (char)( key_i_ - 2 + 'a' ) );
-}
-
-String
-Midi_key::notename_str( int pitch_i )
-{
- // this may seem very smart,
- // but it-s only an excuse not to read a notename table
-
- // major scale: do-do
- // minor scale: la-la ( = + 5 )
- static int notename_i_a[ 12 ] = { 0, 0, 1, 1, 2, 3, 3, 4, 4, 5, 5, 6 };
- int notename_i = notename_i_a[ ( minor_i_ * 5 + pitch_i ) % 12 ];
-
- static int accidentals_i_a[ 12 ] = { 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0 };
- int accidental_i = accidentals_i_a[ minor_i_ * 5 + pitch_i % 12 ];
- if ( accidentals_i_ < 0 ) {
- accidental_i = - accidental_i;
- notename_i = ( notename_i + 1 ) % 7;
- }
-
- String notename_str = (char)( ( ( notename_i + key_i_ - 2 ) % 7 ) + 'a' );
- while ( accidental_i-- > 0 )
- notename_str += "is";
- accidental_i++;
- while ( accidental_i++ < 0 )
- if ( ( notename_str == "a" ) || ( notename_str == "e" ) )
- notename_str += "s";
- else
- notename_str += "es";
- accidental_i--;
- 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 division_1_i, int pitch_i, int time_i )
-{
- 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_ += String( useconds_per_4_i_ );
- mudela_str_ += String( ": " )
- + String( get_tempo_i( Moment( 1, 4 ) ) )
- + String( " 4 per minute" );
-}
-
-Midi_tempo::~Midi_tempo()
-{
-}
-
-int
-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_4_i, int count_32_i )
- : sync_dur_( 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;
- clocks_1_i_ = clocks_4_i * 4;
- mudela_str_ = "% \\Time: ";
- mudela_str_ += String( num_i_ ) + "/" + String( den_i_ )
- + ", " + String( clocks_1_i_ )
- + ": " + String( count_32_i );
-}
-
-Midi_time::~Midi_time()
-{
-}
-
-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 );
- }
-
- return dur;
-}
-
-int
-Midi_time::clocks_1_i()
-{
- return clocks_1_i_;
-}
-
+++ /dev/null
-//
-// midi-item.cc
-//
-// source file of the LilyPond music typesetter
-//
-// (c) 1997 Jan Nieuwenhuizen <jan@digicash.com>
-
-#include <limits.h>
-#include "plist.hh"
-#include "pcol.hh"
-#include "debug.hh"
-#include "misc.hh"
-#include "request.hh"
-#include "musicalrequest.hh"
-#include "voice.hh"
-#include "midi-item.hh"
-#include "midi-stream.hh"
-#include "string-convert.hh"
-
-Midi_chunk::Midi_chunk()
-{
-}
-
-void
-Midi_chunk::add( String str )
-{
- data_str_ += str;
-}
-
-void
-Midi_chunk::set( String header_str, String data_str, String footer_str )
-{
- data_str_ = data_str;
- footer_str_ = footer_str;
- header_str_ = header_str;
-}
-
-String
-Midi_chunk::str()
-{
- String str = header_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_;
- return str;
-}
-
-Midi_duration::Midi_duration( Real seconds_f )
-{
- seconds_f_ = seconds_f;
-}
-
-String
-Midi_duration::str()
-{
- return String( "<duration: " ) + String( seconds_f_ ) + ">";
-}
-
-Midi_header::Midi_header( int format_i, int tracks_i, int clocks_per_4_i )
-{
- String str;
-
- String format_str = String_convert::i2hex_str( format_i, 4, '0' );
- str += String_convert::hex2bin_str( format_str );
-
- String tracks_str = String_convert::i2hex_str( tracks_i, 4, '0' );
- str += String_convert::hex2bin_str( tracks_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::i2varint_str( int i )
-{
- int buffer_i = i & 0x7f;
- while ( (i >>= 7) > 0 ) {
- buffer_i <<= 8;
- buffer_i |= 0x80;
- buffer_i += (i & 0x7f);
- }
-
- String str;
- while ( 1 ) {
- str += (char)buffer_i;
- if ( buffer_i & 0x80 )
- buffer_i >>= 8;
- else
- break;
- }
- return str;
-}
-
-void
-Midi_item::output_midi( Midi_stream& midi_stream_r )
-{
- midi_stream_r << str();
-}
-
-
-Midi_note::Midi_note( Melodic_req* melreq_l, int channel_i, bool on_bo )
-{
- assert(melreq_l);
- pitch_i_ = melreq_l->pitch() + c0_pitch_i_c_;
- channel_i_ = channel_i;
-
- // poor man-s staff dynamics:
- dynamic_byte_ = (melreq_l)? 0x64 - 0x10 * channel_i_:0;
- on_b_ = on_bo;
-}
-
-String
-Midi_note::str()
-{
- if ( pitch_i_ != INT_MAX ) {
- Byte status_byte = ( on_b_ ? 0x90 : 0x80 ) + channel_i_;
- String str = String( (char)status_byte );
- str += (char)pitch_i_;
- // poor man-s staff dynamics:
- str += (char)dynamic_byte_;
- return str;
- }
- return String( "" );
-}
-
-Midi_tempo::Midi_tempo( int tempo_i )
-{
- tempo_i_ = tempo_i;
-}
-
-String
-Midi_tempo::str()
-{
- int useconds_per_4_i = 60 * (int)1e6 / tempo_i_;
- String str = "ff5103";
- str += String_convert::i2hex_str( useconds_per_4_i, 6, '0' );
- return String_convert::hex2bin_str( str );
-}
-
-Midi_track::Midi_track( int number_i )
-{
-// 4D 54 72 6B MTrk
-// 00 00 00 3B chunk length (59)
-// 00 FF 58 04 04 02 18 08 time signature
-// 00 FF 51 03 07 A1 20 tempo
-
-// FF 59 02 sf mi Key Signature
-// sf = -7: 7 flats
-// sf = -1: 1 flat
-// sf = 0: key of C
-// sf = 1: 1 sharp
-// sf = 7: 7 sharps
-// mi = 0: major key
-// mi = 1: minor key
-
- number_i_ = number_i;
-
- char const* data_ch_c_l = "00" "ff58" "0404" "0218" "08"
-// "00" "ff51" "0307" "a120"
-// why a key at all, in midi?
-// key: C
- "00" "ff59" "02" "00" "00"
-// key: F (scsii-menuetto)
-// "00" "ff59" "02" "ff" "00"
- ;
-
- String data_str;
- // only for format 0 (currently using format 1)?
- data_str += String_convert::hex2bin_str( data_ch_c_l );
-
- char const* footer_ch_c_l = "00" "ff2f" "00";
- String footer_str = String_convert::hex2bin_str( footer_ch_c_l );
-
- set( "MTrk", data_str, footer_str );
-}
-
-void
-Midi_track::add( int delta_time_i, String event_str )
-{
- assert(delta_time_i >= 0);
- 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() );
-}
-
+++ /dev/null
-%{
-// midi-lexer.l
-
-//#include <stdio.h>
-
-#include "string.hh"
-#include "proto.hh"
-#include "midi-main.hh"
-#include "my-midi-lexer.hh"
-#include "midi-parser.hh"
-
-%}
-
-%option c++
-%option noyywrap
-%option nodefault
-%option yylineno
-%option debug
-%option yyclass="My_midi_lexer"
-%option stack
-
-%x data
-%x event
-%x int8
-%x int16
-%x int32
-%x meta_event
-%x track
-
-INT8 [\x00-\xff]
-INT16 {INT8}{INT8}
-INT32 {INT16}{INT16}
-INT7_8UNSET [\x00-\x7f]
-INT7_8SET [\x80-\xff]
-VARINT {INT7_8SET}{0,3}{INT7_8UNSET}
-
-HEADER MThd
-TRACK MTrk
-
-XRUNNING_STATUS [\x30-\x4f]
-RUNNING_STATUS [\x00-\x5f]
-DATA_ENTRY [\x60-\x79]
-ALL_NOTES_OFF [\x7a-\x7f]
-NOTE_OFF [\x80-\x8f]
-NOTE_ON [\x90-\x9f]
-POLYPHONIC_AFTERTOUCH [\xa0-\xaf]
-CONTROLMODE_CHANGE [\xb0-\xbf]
-PROGRAM_CHANGE [\xc0-\xcf]
-CHANNEL_AFTERTOUCH [\xd0-\xdf]
-PITCHWHEEL_RANGE [\xe0-\xef]
-
-SYSEX_EVENT1 [\xf0]
-SYSEX_EVENT2 [\xf7]
-
-META_EVENT [\xff]
-
-SEQUENCE [\x00][\x02]
-TEXT [\x01]
-COPYRIGHT [\x02]
-TRACK_NAME [\x03]
-INSTRUMENT_NAME [\x04]
-LYRIC [\x05]
-MARKER [\x06]
-CUE_POINT [\x07]
-
-END_OF_TRACK [\x2f][\x00]
-TEMPO [\x51][\x03]
-SMPTE_OFFSET [\x54][\x05]
-TIME [\x58][\x04]
-KEY [\x59][\x02]
-SSME [\0x7f][\x03]
-
-%%
-
-{HEADER}/{INT32} { // using /{INT32}; longer match than {INT32}
- dtor << "lex: header" << endl;
- yy_push_state( int16 );
- yy_push_state( int16 );
- yy_push_state( int16 );
- yy_push_state( int32 );
- return HEADER;
-}
-
-{TRACK}/{INT32} { // using /{INT32}; longer match than {INT32}
- dtor << "lex: track" << endl;
- yy_push_state( track );
- yy_push_state( int32 );
- return TRACK;
-}
-{INT8} {
- error( String( "top level: illegal byte: " )
- + String_convert::bin2hex_str( String( *YYText() ) ) );
- exit( 1 );
-}
-<int32>{INT32} {
- dtor << "lex: int32" << endl;
- assert( YYLeng() == 4 );
- String str( (Byte const*)YYText(), YYLeng() );
- yylval.i = String_convert::bin2_i( str );
- yy_pop_state();
- return INT32;
-}
-<int16>{INT16} {
- dtor << "lex: int16" << endl;
- assert( YYLeng() == 2 );
- String str( (Byte const*)YYText(), YYLeng() );
- yylval.i = String_convert::bin2_i( str );
- yy_pop_state();
- return INT16;
-}
-<int8>{INT8} {
- dtor << "lex: int8" << endl;
- assert( YYLeng() == 1 );
-// yylval.byte = *(Byte*)YYText();
- yylval.i = *(Byte*)YYText();
- yy_pop_state();
- return INT8;
-}
-
-<track>{VARINT} {
- String str( (Byte const*)YYText(), YYLeng() );
- yylval.i = My_midi_lexer::varint2_i( str );
- dtor << String( "lex: track: varint(" )
- + String( yylval.i ) + "): "
- + String_convert::bin2hex_str( str ) << endl;
- yy_push_state( event );
- return VARINT;
-}
-<track>{INT8} {
- error( String( "track: illegal byte: " )
- + String_convert::bin2hex_str( String( *YYText() ) ) );
- exit( 1 );
-}
-<event>{RUNNING_STATUS} {
-// yylval.byte = *(Byte*)YYText();
- yylval.i = *(Byte*)YYText();
- dtor << String ( "lex: running status: " ) + String( yylval.i ) << endl;
- yy_pop_state();
-// yy_push_state( int8 );
- yy_push_state( int8 );
- return RUNNING_STATUS;
-}
-<event>{DATA_ENTRY} {
-// yylval.byte = *(Byte*)YYText();
- yylval.i = *(Byte*)YYText();
- dtor << String ( "lex: undefined data entry: " ) + String( yylval.i ) << endl;
- yy_pop_state();
- yy_push_state( int8 );
- return DATA_ENTRY;
-}
-<event>{ALL_NOTES_OFF} {
- dtor << "lex: all note off" << endl;
-// yylval.byte = *(Byte*)YYText();
- yylval.i = *(Byte*)YYText();
- dtor << String ( "lex: all notes off: " ) + String( yylval.i ) << endl;
- yy_pop_state();
- yy_push_state( int8 );
- yy_push_state( int8 );
- return ALL_NOTES_OFF;
-}
-<event>{NOTE_OFF} {
- dtor << "lex: note off" << endl;
-// yylval.byte = *(Byte*)YYText();
- yylval.i = *(Byte*)YYText();
- yy_pop_state();
- yy_push_state( int8 );
- yy_push_state( int8 );
- return NOTE_OFF;
-}
-<event>{NOTE_ON} {
- dtor << "lex: note on" << endl;
-// yylval.byte = *(Byte*)YYText();
- yylval.i = *(Byte*)YYText();
- yy_pop_state();
- yy_push_state( int8 );
- yy_push_state( int8 );
- return NOTE_ON;
-}
-<event>{POLYPHONIC_AFTERTOUCH} {
- dtor << "lex: polyphonic aftertouch" << endl;
-// yylval.byte = *(Byte*)YYText();
- yylval.i = *(Byte*)YYText();
- yy_pop_state();
- yy_push_state( int8 );
- yy_push_state( int8 );
- return POLYPHONIC_AFTERTOUCH;
-}
-<event>{CONTROLMODE_CHANGE} {
- dtor << "lex: controlmode change" << endl;
-// yylval.byte = *(Byte*)YYText();
- yylval.i = *(Byte*)YYText();
- yy_pop_state();
- yy_push_state( int8 );
- yy_push_state( int8 );
- return CONTROLMODE_CHANGE;
-}
-<event>{PROGRAM_CHANGE} {
- dtor << "lex: program change" << endl;
-// yylval.byte = *(Byte*)YYText();
- yylval.i = *(Byte*)YYText();
- yy_pop_state();
- yy_push_state( int8 );
- return PROGRAM_CHANGE;
-}
-<event>{CHANNEL_AFTERTOUCH} {
- dtor << "lex: channel aftertouch" << endl;
-// yylval.byte = *(Byte*)YYText();
- yylval.i = *(Byte*)YYText();
- yy_pop_state();
- yy_push_state( int8 );
- yy_push_state( int8 );
- return CHANNEL_AFTERTOUCH;
-}
-<event>{PITCHWHEEL_RANGE} {
- dtor << "lex: pitchwheel range" << endl;
-// yylval.byte = *(Byte*)YYText();
- yylval.i = *(Byte*)YYText();
- yy_pop_state();
- yy_push_state( int8 );
- yy_push_state( int8 );
- return PITCHWHEEL_RANGE;
-}
-<event>{SYSEX_EVENT1} { // len data
- dtor << "lex: sysex1" << endl;
- yy_pop_state();
- yy_push_state( data );
- return SYSEX_EVENT1;
-}
-<event>{SYSEX_EVENT2} { // len data
- dtor << "lex: sysex2" << endl;
- yy_pop_state();
-// yy_push_state( int8 ); //?
- yy_push_state( data );
- return SYSEX_EVENT2;
-}
-<event>{META_EVENT} {
- dtor << "lex: meta" << endl;
- yy_push_state( meta_event );
- return META_EVENT;
-}
-<event>{INT8} {
- error( String( "event: illegal byte: " )
- + String_convert::bin2hex_str( String( *YYText() ) ) );
- exit( 1 );
-}
-<meta_event>{SEQUENCE} { // ssss sequence number
- dtor << "lex: sequence" << endl;
- yy_pop_state();
- yy_pop_state();
- yy_push_state( int16 );
- return SEQUENCE;
-}
-<meta_event>{TEXT} { // len data
- dtor << "lex: text" << endl;
- yy_pop_state();
- yy_pop_state();
- yy_push_state( data );
- return TEXT;
-}
-<meta_event>{COPYRIGHT} {
- dtor << "lex: copyright" << endl;
- yy_pop_state();
- yy_pop_state();
- yy_push_state( data );
- return COPYRIGHT;
-}
-<meta_event>{TRACK_NAME} {
- dtor << "lex: track name" << endl;
- yy_pop_state();
- yy_pop_state();
- yy_push_state( data );
- return TRACK_NAME;
-}
-<meta_event>{INSTRUMENT_NAME} {
- dtor << "lex: instrument name" << endl;
- yy_pop_state();
- yy_pop_state();
- yy_push_state( data );
- return INSTRUMENT_NAME;
-}
-<meta_event>{LYRIC} {
- dtor << "lex: lyric" << endl;
- yy_pop_state();
- yy_pop_state();
- yy_push_state( data );
- return LYRIC;
-}
-<meta_event>{MARKER} {
- dtor << "lex: marker" << endl;
- yy_pop_state();
- yy_pop_state();
- yy_push_state( data );
- return MARKER;
-}
-<meta_event>{CUE_POINT} {
- dtor << "lex: cue point" << endl;
- yy_pop_state();
- yy_pop_state();
- yy_push_state( data );
- return CUE_POINT;
-}
-<meta_event>{TEMPO} { // tttttt usec
- dtor << "lex: tempo" << endl;
- yy_pop_state();
- yy_pop_state();
- yy_push_state( int8 );
- yy_push_state( int8 );
- yy_push_state( int8 );
- return TEMPO;
-}
-<meta_event>{SMPTE_OFFSET} { // hr mn se fr ff
- dtor << "lex: smpte offset" << endl;
- yy_pop_state();
- yy_pop_state();
- yy_push_state( int8 );
- yy_push_state( int8 );
- yy_push_state( int8 );
- yy_push_state( int8 );
- yy_push_state( int8 );
- return SMPTE_OFFSET;
-}
-<meta_event>{TIME} { // nn dd cc bb
- dtor << "lex: time" << endl;
- yy_pop_state();
- yy_pop_state();
- yy_push_state( int8 );
- yy_push_state( int8 );
- yy_push_state( int8 );
- yy_push_state( int8 );
- return TIME;
-}
-<meta_event>{KEY} { // sf mi
- dtor << "lex: key" << endl;
- yy_pop_state();
- yy_pop_state();
- yy_push_state( int8 );
- yy_push_state( int8 );
- return KEY;
-}
-<meta_event>{SSME} { // len data
- dtor << "lex: smme" << endl;
- yy_pop_state();
- yy_pop_state();
- yy_push_state( data );
- return SSME;
-}
-<meta_event>{END_OF_TRACK} {
- dtor << "lex: end of track" << endl;
- yy_pop_state();
- yy_pop_state();
- yy_pop_state();
- return END_OF_TRACK;
-}
-<meta_event>{INT8} {
- warning( String( "meta_event: unimplemented event: " )
- + String_convert::bin2hex_str( String( *YYText() ) ),
- *this->here_ch_c_l() );
- yy_pop_state();
- yy_pop_state();
- yy_push_state( int8 );
- yy_push_state( int8 );
- return INT8;
-}
-
-<data>{VARINT} {
- dtor << "lex: data" << endl;
- String str( (Byte const*)YYText(), YYLeng() );
- int i = My_midi_lexer::varint2_i( str );
- String* str_p = new String;
- while ( i-- )
- *str_p += (char)yyinput();
- yylval.str_p = str_p;
- yy_pop_state();
- return DATA;
-}
-<data>{INT8} {
- error( String( "data: illegal byte: " )
- + String_convert::bin2hex_str( String( *YYText() ) ) );
- exit( 1 );
-}
-
-<<EOF>> {
-// mtor << "<<EOF>>";
-
- if ( !close_i() )
- yyterminate(); // can't move this, since it actually rets a YY_NULL
-}
-
-%%
-
+++ /dev/null
-//
-// midi-main.cc -- implement silly main() entry point
-// should have Root class.
-//
-// copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
-
-#include <iostream.h>
-#include <limits.h>
-#include "proto.hh"
-#include "plist.hh"
-#include "version.hh"
-#include "fversion.hh"
-#include "string.hh"
-#include "lgetopt.hh"
-#include "source.hh"
-#include "source-file.hh"
-#include "midi-main.hh"
-#include "moment.hh"
-#include "duration.hh"
-#include "midi-event.hh"
-#include "midi-track.hh"
-#include "my-midi-lexer.hh"
-#include "my-midi-parser.hh"
-
-Source source;
-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;
-
-// ugh, another global
-String
-find_file( String str )
-{
- return str;
-}
-
-// ugh, copied from warn.cc, cannot use
-void
-message( String message_str, char const* context_ch_c_l )
-{
- String str = "m2m: ";
- Source_file* sourcefile_l = source_l_g->sourcefile_l( context_ch_c_l );
- if ( sourcefile_l ) {
- str += sourcefile_l->file_line_no_str(context_ch_c_l) + String(": ");
- }
- str += message_str;
- if ( sourcefile_l ) {
- str += ":\n";
- str += sourcefile_l->error_str( context_ch_c_l );
- }
-// if ( busy_parsing() )
-// cerr << endl;
- cerr << str << endl;
-}
-
-void
-warning( String message_str, char const* context_ch_c_l )
-{
- message( "warning: " + message_str, context_ch_c_l );
-}
-
-void
-error( String message_str, char const* context_ch_c_l )
-{
- message( message_str, context_ch_c_l );
- // since when exits error again?
- // i-d say: error: errorlevel |= 1; -> no output upon error
- // warning: recovery -> output (possibly wrong)
- if ( midi_lexer_l_g )
- midi_lexer_l_g->errorlevel_i_ |= 1;
-}
-
-void
-help()
-{
- btor <<
- "--debug, -d be really verbose\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"
- ;
-}
-
-void
-identify()
-{
- mtor << version_str() << endl;
-}
-
-void
-notice()
-{
- mtor <<
- "\n"
- "M2m, translate midi to mudela.\n"
- "Copyright (C) 1997 by\n"
- " Han-Wen Nienhuys <hanwen@stack.nl>\n"
-// "Contributors\n"
- " Jan Nieuwenhuizen <jan@digicash.com>\n"
-// " Mats Bengtsson <matsb@s3.kth.se>\n"
- "\n"
- " This program is free software; you can redistribute it and/or\n"
- "modify it under the terms of the GNU General Public License version 2\n"
- "as published by the Free Software Foundation.\n"
- "\n"
- " This program is distributed in the hope that it will be useful,\n"
- "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
- "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
- "General Public License for more details.\n"
- "\n"
- " You should have received a copy (refer to the file COPYING) of the\n"
- "GNU General Public License along with this program; if not, write to\n"
- "the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,\n"
- "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[] )
-{
- long_option_init long_option_init_a[] = {
- 0, "debug", 'd',
- 0, "help", 'h',
-// 1, "include", 'I',
- 0, "no-triplets", 'n',
- 1, "output", 'o',
- 0, "quiet", 'q',
- 0, "verbose", 'v',
- 0, "warranty", 'w',
- 0,0,0
- };
- Getopt_long getopt_long( argc_i, argv_sz_a, long_option_init_a );
- identify();
-
- String output_str;
- while ( long_option_init* long_option_init_p = getopt_long() )
- switch ( long_option_init_p->shortname ) {
- case 'd':
- level_ver = DEBUG_ver;
- break;
- case 'h':
- help();
- exit( 0 );
- break;
-// case 'I':
-// path->push( getopt_long.optarg );
-// break;
- case 'n':
- no_triplets_bo_g = true;
- break;
- case 'o':
- output_str = getopt_long.optarg;
- break;
- case 'q':
- level_ver = QUIET_ver;
- break;
- case 'v':
- level_ver = VERBOSE_ver;
- break;
- case 'w':
- notice();
- exit( 0 );
- break;
- default:
- assert( 0 );
- break;
- }
-
- char* arg_sz = 0;
- while ( ( arg_sz = getopt_long.get_next_arg() ) ) {
- My_midi_parser midi_parser( arg_sz );
- int error_i = midi_parser.parse();
- if ( error_i )
- return error_i;
- 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;
- }
- return 0;
-}
+++ /dev/null
-/*
- midi-output.cc -- implement Midi_output
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>, Jan Nieuwehuizen <jan@digicash.com>
-*/
-
-#include "plist.hh"
-#include "debug.hh"
-#include "score.hh"
-#include "staff.hh"
-#include "midi-stream.hh"
-#include "midi-def.hh"
-#include "midi-output.hh"
-#include "midi-walker.hh"
-#include "midi-item.hh"
-#include "staff-column.hh"
-#include "musicalrequest.hh"
-
-
-Midi_output:: Midi_output(Score* score_l, Midi_def* midi_l )
-{
- midi_l_ = midi_l;
-
- Midi_stream midi_stream(midi_l->outfile_str_,
- score_l->staffs_.size(),
- 384 );
-// oeps, not tempo, but clocks per 4 (384 convention)
-// must set tempo in tempo request
-// midi_l->get_tempo_i(Moment(1, 4)));
-
- midi_stream_l_ = &midi_stream;
- int track_i=0;
-
- for (iter_top(score_l->staffs_,i); i.ok(); i++) {
- do_staff(i, track_i++);
- }
-
-}
-
-void
-Midi_output::do_staff(Staff*st_l,int track_i)
-{
- Midi_track midi_track( track_i );
- Midi_tempo midi_tempo( midi_l_->get_tempo_i( Moment( 1, 4 ) ) );
- midi_track.add( Moment( 0.0 ), &midi_tempo );
- for (Midi_walker w (st_l, &midi_track); w.ok(); w++)
- w.process_requests();
-
- *midi_stream_l_ << midi_track;
-}
+++ /dev/null
-%{
-
-#include <iostream.h>
-
-#include "proto.hh" // ugh, these all for midi-main.hh
-#include "plist.hh"
-#include "string.hh"
-#include "sourcefile.hh"
-#include "source.hh"
-#include "midi-main.hh" // *tors
-
-#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"
-
-#ifndef NDEBUG
-#define YYDEBUG 1
-#endif
-
-//ugh
-static track_i = 0;
-
-%}
-
-%union {
- Byte byte;
- char c;
- int i;
- String* str_p;
- Request* request_p;
- Midi_event* midi_event_p; // Voice_element* ?
- Midi_score* midi_score_p; // Input_score* ?
- Midi_track* midi_track_p; // Input_music* ?
-}
-
-%token HEADER TRACK
-%token SYSEX_EVENT1 SYSEX_EVENT2
-%token META_EVENT
-%token SEQUENCE TEXT COPYRIGHT TRACK_NAME INSTRUMENT_NAME LYRIC MARKER CUE_POINT
-%token END_OF_TRACK TEMPO SMPTE_OFFSET TIME KEY SSME
-
-%token<i> INT8 INT16 INT32 INT7_8UNSET INT7_8SET VARINT
-%token<i> RUNNING_STATUS DATA_ENTRY ALL_NOTES_OFF
-%token<i> NOTE_OFF NOTE_ON
-%token<i> POLYPHONIC_AFTERTOUCH CONTROLMODE_CHANGE PROGRAM_CHANGE
-%token<i> CHANNEL_AFTERTOUCH PITCHWHEEL_RANGE
-%token<str_p> DATA
-
-%type <i> varint
-%type <midi_score_p> header midi_score
-%type <midi_track_p> track
-%type <midi_event_p> event
-%type <midi_event_p> the_event meta_event the_meta_event text_event midi_event sysex_event
-%type <midi_event_p> running_status data_entry all_notes_off
-%type <midi_event_p> note_off note_on
-%type <midi_event_p> polyphonic_aftertouch controlmode_change program_change
-%type <midi_event_p> channel_aftertouch pitchwheel_range
-
-%%
-
-midi: /* empty */
- | midi midi_score {
- midi_parser_l_g->add_score( $2 );
- track_i = 0;
- }
- ;
-
-midi_score:
- header {
- }
- | 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_4( $5 );
- }
- ;
-
-track:
- TRACK INT32 {
- $$ = new Midi_track( track_i++ );
- }
- | track event {
- $$->add_event( midi_parser_l_g->mom(), $2 );
- }
- ;
-
-event:
- varint the_event {
- $$ = $2;
- if ( $2 && $2->mudela_str().length_i() )
- dtor << $2->mudela_str() << " " << flush;
- }
- ;
-
-varint:
- VARINT {
- midi_parser_l_g->forward( $1 );
- }
- ;
-
-the_event:
- meta_event {
- }
- | midi_event {
- }
- | sysex_event {
- }
- ;
-
-meta_event:
- META_EVENT the_meta_event {
- $$ = $2;
- }
- |
- META_EVENT INT8 INT8 INT8 {
- $$ = 0;
- }
- ;
-
-the_meta_event:
- SEQUENCE INT16 {
- }
- | text_event DATA {
- $$ = 0;
- dtor << *$2 << endl;
- delete $2;
- }
- | END_OF_TRACK {
- $$ = 0;
- }
- | TEMPO INT8 INT8 INT8 {
- $$ = new Midi_tempo( ( $2 << 16 ) + ( $3 << 8 ) + $4 );
- 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 {
- $$ = 0;
- }
- | TIME INT8 INT8 INT8 INT8 {
- $$ = new Midi_time( $2, $3, $4, $5 );
- dtor << $$->mudela_str() << endl; // ?? waai not at event:
- midi_parser_l_g->set_time( $2, $3, $4, $5 );
- }
- | KEY INT8 INT8 {
- $$ = new Midi_key( $2, $3 );
- midi_parser_l_g->set_key( $2, $3 );
- }
- | SSME DATA {
- $$ = 0;
- delete $2;
- }
- ;
-
-text_event:
- TEXT {
- dtor << "\n% Text: ";
- }
- | COPYRIGHT {
- dtor << "\n% Copyright: ";
- }
- | TRACK_NAME {
- dtor << "\n% Track name: ";
- }
- | INSTRUMENT_NAME {
- dtor << "\n% Instrument name: ";
- }
- | LYRIC {
- dtor << "\n% Lyric: ";
- }
- | MARKER {
- dtor << "\n% Marker: ";
- }
- | CUE_POINT {
- dtor << "\n% Cue point: ";
- }
- ;
-
-midi_event:
- running_status {
- }
- | data_entry {
- }
- | all_notes_off {
- }
- | note_off {
- }
- | note_on {
- }
- | polyphonic_aftertouch {
- }
- | controlmode_change {
- }
- | program_change {
- }
- | channel_aftertouch {
- }
- | pitchwheel_range {
- }
- ;
-
-running_status:
- RUNNING_STATUS INT8 { //INT8 {
- $$ = 0;
- }
- ;
-
-data_entry:
- DATA_ENTRY INT8 {
- $$ = 0;
- }
- ;
-
-all_notes_off:
- ALL_NOTES_OFF INT8 INT8 {
- $$ = 0;
- }
- ;
-
-note_off:
- NOTE_OFF INT8 INT8 {
- int i = $1;
- i = i & ~0x80;
- $$ = midi_parser_l_g->note_end_midi_event_p( $1 & ~0x80, $2, $3 );
- }
- ;
-
-note_on:
- NOTE_ON INT8 INT8 {
- int i = $1;
- i = i & ~0x90;
- $$ = 0;
- midi_parser_l_g->note_begin( $1 & ~0x90, $2, $3 );
- }
- ;
-
-polyphonic_aftertouch:
- POLYPHONIC_AFTERTOUCH INT8 INT8 {
- $$ = 0;
- }
- ;
-
-controlmode_change:
- CONTROLMODE_CHANGE INT8 INT8 {
- $$ = 0;
- }
- ;
-
-program_change:
- PROGRAM_CHANGE INT8 {
- $$ = 0;
- }
- ;
-
-channel_aftertouch:
- CHANNEL_AFTERTOUCH INT8 INT8 {
- $$ = 0;
- }
- ;
-
-pitchwheel_range:
- PITCHWHEEL_RANGE INT8 INT8 {
- $$ = 0;
- }
- ;
-
-sysex_event:
- SYSEX_EVENT1 DATA {
- $$ = 0;
- }
- | SYSEX_EVENT2 DATA { // INT8 ?
- $$ = 0;
- }
- ;
+++ /dev/null
-//
-// midi-score.cc -- implement Midi_score
-//
-// copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
-
-#include "proto.hh"
-#include "plist.hh"
-#include "string.hh"
-#include "moment.hh"
-#include "duration.hh"
-#include "source-file.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"
-
-Midi_score::Midi_score( int format_i, int tracks_i, int tempo_i )
-{
- format_i_ = format_i;
- tracks_i_ = tracks_i;
- tempo_i_ = tempo_i;
-}
-
-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*> 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*> 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;
-}
-
+++ /dev/null
-//
-// midi-stream.cc
-//
-// source file of the LilyPond music typesetter
-//
-// (c) 1997 Jan Nieuwenhuizen <jan@digicash.com>
-
-#include <fstream.h>
-#include <time.h>
-#include "main.hh"
-#include "misc.hh"
-#include "midi-item.hh"
-#include "midi-stream.hh"
-#include "debug.hh"
-#include "string-convert.hh"
-
-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();
-}
-
-Midi_stream::~Midi_stream()
-{
- delete os_p_;
-}
-
-Midi_stream&
-Midi_stream::operator <<( String str )
-{
- // still debugging...
- if ( check_debug )
- str = String_convert::bin2hex_str( str );
- // string now 1.0.26-2 handles binary streaming
- *os_p_ << str;
- return *this;
-}
-
-Midi_stream&
-Midi_stream::operator <<( Midi_item& mitem_r )
-{
- mitem_r.output_midi( *this );
- if ( check_debug )
- *os_p_ << "\n";
- return *this;
-}
-
-Midi_stream&
-Midi_stream::operator <<( int i )
-{
- // output binary string ourselves
- *this << Midi_item::i2varint_str( i );
- return *this;
-}
-
-void
-Midi_stream::header()
-{
-// *os_p_ << "% Creator: " << get_version();
-// *os_p_ << "% Automatically generated, at ";
-// time_t t(time(0));
-// *os_p_ << ctime(&t);
-
-// 4D 54 68 64 MThd
-// String str = "MThd";
-// 00 00 00 06 chunk length
-// 00 01 format 1
-// 00 01 one track
-// 00 60 96 per quarter-note
-
-// char const ch_c_l = "0000" "0006" "0001" "0001" "0060";
-// str += String_convert::hex2bin_str( ch_c_l );
-// *os_p_ << str;
-
-// *this << Midi_header( 1, 1, tempo_i_ );
- *this << Midi_header( 1, tracks_i_, clocks_per_4_i_ );
-}
-
-void
-Midi_stream::open()
-{
- os_p_ = new ofstream( filename_str_ );
- if ( !*os_p_ )
- error ("can't open `" + filename_str_ + "\'" );
-}
+++ /dev/null
-//
-// midi-template.cc -- implementemplate
-//
-// copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
-
-#include "list.tcc"
-#include "cursor.tcc"
-
-L_instantiate(void *);
-
-class istream;
-class ostream;
-#include "proto.hh"
-#include "plist.tcc"
-#include "pcursor.tcc"
-#include "string.hh"
-#include "source-file.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);
+++ /dev/null
-//
-// midi-track.cc -- implement Midi_track
-//
-// copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
-
-#include "proto.hh"
-#include "plist.hh"
-#include "string.hh"
-#include "source-file.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( int track_i )
-{
- name_str_ = String( "track" ) + String( track_i );
- tcol_p_list_.bottom().add( new Track_column( Moment( 0 ) ) );
-}
-
-Midi_track::~Midi_track()
-{
-}
-
-void
-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<Track_column*> 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<Track_column*> 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;
-}
-
+++ /dev/null
-#include <math.h>
-
-#include "item.hh"
-#include "misc.hh"
-#include "glob.hh"
-#include "moment.hh"
-
-
-// depreciated, see struct Duration*
-Moment
-wholes(int dur, int dots)
-{
- if (!dur)
- return 0;
-
- Moment f = Rational(1)/Moment(dur);
- Moment delta = f;
-
- while (dots--) {
- delta /= 2.0;
- f += delta;
- }
- return f;
-}
-int
-intlog2(int d) {
- int i=0;
- while (!(d&1)) {
- d/= 2;
- i++;
- }
- assert(!(d/2));
- return i;
-}
-
-double
-log_2(double x) {
- return log(x) /log(2.0);
-}
-
-Interval
-itemlist_width(const Array<Item*> &its)
-{
- Interval iv ;
- iv.set_empty();
-
- for (int j =0; j < its.size(); j++){
- iv.unite (its[j]->width());
-
- }
- return iv;
-}
-
+++ /dev/null
-#include "varray.hh"
-#include "interval.hh"
-#include "dimen.hh"
-#include "string.hh"
-#include "molecule.hh"
-#include "symbol.hh"
-#include "debug.hh"
-#include "tex.hh"
-
-void
-Atom::print() const
-{
- mtor << "texstring: " <<sym.tex<<"\n";
-}
-
-Box
-Atom::extent() const
-{
- Box b( sym.dim);
- b.translate(off);
- return b;
-}
-
-Atom::Atom(Symbol s)
-{
- sym=s;
-}
-
-
-String
-Atom::TeXstring() const
-{
- // whugh.. Hard coded...
- String s("\\placebox{%}{%}{%}");
- Array<String> a;
- a.push(print_dimen(off.y));
- a.push(print_dimen(off.x));
- a.push(sym.tex);
- return substitute_args(s, a);
-}
-
-/* *************** */
-
-String
-Molecule::TeXstring() const
-{
- String s;
- for(iter_top(ats,c); c.ok(); c++)
- s+=c->TeXstring();
- return s;
-}
-
-Box
-Molecule::extent() const
-{
- Box b;
- for(iter_top(ats,c); c.ok(); c++)
- b.unite(c->extent());
- return b;
-}
-
-void
-Molecule::translate(Offset o)
-{
- for (iter_top(ats,c); c.ok(); c++)
- c->translate(o);
-}
-
-void
-Molecule::add(const Molecule &m)
-{
- for (iter_top(m.ats,c); c.ok(); c++) {
- add(**c);
- }
-}
-
-void
-Molecule::add_right(const Molecule &m)
-{
- if (!ats.size()) {
- add(m);
- return;
- }
- Real xof=extent().x.right - m.extent().x.left;
- Molecule toadd(m);
- toadd.translate(Offset(xof, 0.0));
- add(toadd);
-}
-
-void
-Molecule::add_left(const Molecule &m)
-{
- if (!ats.size()) {
- add(m);
- return;
- }
- Real xof=extent().x.left - m.extent().x.right;
- Molecule toadd(m);
- toadd.translate(Offset(xof, 0.0));
- add(toadd);
-}
-
-
-void
-Molecule::add_top(const Molecule &m)
-{
- if (!ats.size()) {
- add(m);
- return;
- }
- Real yof=extent().y.right - m.extent().y.left;
- Molecule toadd(m);
- toadd.translate(Offset(0,yof));
- add(toadd);
-}
-
-void
-Molecule::add_bottom(const Molecule &m)
-{
- if (!ats.size()) {
- add(m);
- return;
- }
- Real yof=extent().y.left- m.extent().y.right;
- Molecule toadd(m);
- toadd.translate(Offset(0,yof));
- add(toadd);
-}
-
-void
-Molecule::operator = (const Molecule&)
-{
- assert(false);
-}
-
-Molecule::Molecule(const Molecule&s)
-{
- add(s);
-}
-
-void
-Molecule::print() const
-{
- for (iter_top(ats,c); c.ok(); c++)
- c->print();
-}
+++ /dev/null
-//
-// my-midi-lexer.cc -- implement My_midi_lexer
-//
-// copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
-
-#include "debug.hh"
-#include "input-file.hh"
-#include "source-file.hh"
-#include "my-midi-lexer.hh"
-
-int
-yylex()
-{
- return midi_lexer_l_g->yylex();
-}
-
-My_midi_lexer* midi_lexer_l_g;
-
-My_midi_lexer::My_midi_lexer( String filename_str )
-{
- input_file_p_ = new Input_file( filename_str );
- switch_streams( input_file_p_->is );
- midi_lexer_l_g = this;
- errorlevel_i_ = 0;
-}
-
-My_midi_lexer::~My_midi_lexer()
-{
- delete input_file_p_;
- midi_lexer_l_g = 0;
-}
-
-void
-My_midi_lexer::error( char const* sz_l )
-{
- if ( !input_file_p_ ) {
-// *mlog << "error at EOF" << sz_l << '\n';
- cerr << "error at EOF" << sz_l << '\n';
- } else {
- char const* ch_c_l = here_ch_c_l();
- if ( ch_c_l ) {
- ch_c_l--;
- while ( ( *ch_c_l == ' ' ) || ( *ch_c_l == '\t' ) || ( *ch_c_l == '\n' ) )
- ch_c_l--;
- ch_c_l++;
- }
- errorlevel_i_ |= 1;
-// ::error( sz_l, ch_c_l );
- ::error( sz_l, ch_c_l );
- }
-}
-
-char const*
-My_midi_lexer::here_ch_c_l()
-{
- return input_file_p_->sourcefile_l_->ch_c_l() + yyin->tellg();
-}
-
-int
-My_midi_lexer::varint2_i( String str )
-{
- int var_i = 0;
-
- for ( int i = 0; i < str.length_i(); i++ ) {
- Byte byte = str[ i ];
- var_i <<= 7;
- var_i += byte & 0x7f;
- if ( ! ( byte & 0x80 ) )
- return var_i;
- }
- cout << "\nvarint2_i:" << String_convert::bin2hex_str( str ) << endl;
- assert( 0 ); // illegal varint
- return 0;
-}
-
-int
-My_midi_lexer::close_i()
-{
- return 0;
-}
-
+++ /dev/null
-//
-// my-midi-parser.cc -- implement My_midi_parser
-//
-// copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
-
-#include "proto.hh"
-
-#include "plist.hh" // ugh
-#include "string.hh"
-#include "source-file.hh"
-#include "source.hh"
-#include "midi-main.hh" // *tors
-
-#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"
-
-void
-yyerror(char const* sz_l )
-{
- midi_parser_l_g->error( sz_l );
-}
-
-
-My_midi_parser* midi_parser_l_g;
-
-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 );
- // 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 );
-
- now_i64_ = 0;
-
- for ( int i = 0; i < CHANNELS_i; i++ )
- for ( int j = 0; j < PITCHES_i; j++ )
-// running_i64_i64_a_[ i ][ j ] = -1;
- running_i64_i64_a_[ i ][ j ] = 0;
-}
-
-My_midi_parser::~My_midi_parser()
-{
- delete midi_lexer_p_;
- midi_parser_l_g = 0;
- 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 )
-{
- assert( !midi_score_p_ );
- midi_score_p_ = midi_score_p;
-}
-
-void
-My_midi_parser::error( char const* sz_l )
-{
- midi_lexer_l_g->error( sz_l );
-
- if ( fatal_error_i_ )
- exit( fatal_error_i_ );
-}
-
-void
-My_midi_parser::forward( int i )
-{
- now_i64_ += i;
-}
-
-Moment
-My_midi_parser::mom()
-{
- 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 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 )
-{
- 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_mudela( String filename_str )
-{
- assert( midi_score_p_ );
- return midi_score_p_->output_mudela( filename_str );
-}
-
-int
-My_midi_parser::parse()
-{
- return ::yyparse();
-}
-
-void
-My_midi_parser::set_division_4( int division_4_i )
-{
- division_1_i_ = division_4_i * 4;
- if ( division_4_i < 0 )
- warning( "seconds iso metrical time" , 0 );
-}
-
-void
-My_midi_parser::set_key( int accidentals_i, int minor_i )
-{
- delete midi_key_p_;
- midi_key_p_ = new Midi_key( accidentals_i, minor_i );
-}
-
-void
-My_midi_parser::set_tempo( int useconds_i )
-{
- delete midi_tempo_p_;
- midi_tempo_p_ = new Midi_tempo( useconds_i );
-}
-
-void
-My_midi_parser::set_time( int num_i, int den_i, int clocks_i, int count_32_i )
-{
- delete midi_time_p_;
- midi_time_p_ = new Midi_time( num_i, den_i, clocks_i, count_32_i );
-}
-
+++ /dev/null
-#include <strstream.h>
-
-#include "interval.hh"
-#include "identparent.hh"
-#include "assoc-iter.hh"
-#include "lexer.hh"
-#include "input-file.hh"
-#include "parser.hh"
-#include "keyword.hh"
-#include "assoc.hh"
-#include "lexer.hh"
-#include "debug.hh"
-#include "notename.hh"
-#include "source-file.hh"
-#include "parseconstruct.hh"
-
-static Keyword_ent the_key_tab[]={
- "bar", BAR,
- "cadenza", CADENZA,
- "clef", CLEF,
- "cm", CM_T,
- "command", COMMAND,
- "commands", COMMANDS,
- "duration", DURATIONCOMMAND,
- "geometric", GEOMETRIC,
- "goto", GOTO,
- "in", IN_T,
- "key", KEY,
- "meter", METER,
- "midi", MIDI,
- "mm", MM_T,
- "multivoice", MULTIVOICE,
- "octave", OCTAVECOMMAND,
- "output", OUTPUT,
- "partial", PARTIAL,
- "paper", PAPER,
- "plet", PLET,
- "pt", PT_T,
- "score", SCORE,
- "script", SCRIPT,
- "skip", SKIP,
- "staff", STAFF,
- "start", START_T,
- "stem", STEM,
- "table", TABLE,
- "symboltables", SYMBOLTABLES,
- "notenames", NOTENAMES,
- "tempo", TEMPO,
- "texid", TEXID,
- "textstyle", TEXTSTYLE,
- "unitspace", UNITSPACE,
- "voice", VOICE,
- "voices", VOICES,
- "width", WIDTH,
- "music", MUSIC,
- "grouping", GROUPING,
- 0,0
-};
-
-int
-My_flex_lexer::ret_notename(int *p, String text, int octave_mod)
-{
- text = text.lower_str();
- char const* ch_c_l = here_ch_c_l();
- if ( ch_c_l ) {
- ch_c_l--;
- while ( ( *ch_c_l == ' ' )
- || ( *ch_c_l == '\t' ) || ( *ch_c_l == '\n' ) )
- ch_c_l--;
- ch_c_l++;
- }
-
- lookup_notename(p[0], p[1], text);
- p[2] = octave_mod;
- mtor << "notename: "<< text <<eol;
- if (p[0] < 0) {
-
- errorlevel_i_ |= 1;
- error( String( "notename does not exist: " ) + YYText(), ch_c_l );
- p[0] = p[1] = 0;
- }
- return NOTENAME;
-}
-
-My_flex_lexer::My_flex_lexer()
-{
- keytable = new Keyword_table(the_key_tab);
- the_id_tab = new Assoc<String, Identifier*>;
- defaulttab = 0;
- errorlevel_i_ = 0;
-}
-
-int
-My_flex_lexer::lookup_keyword(String s)
-{
- return keytable->lookup(s);
-}
-
-Identifier*
-My_flex_lexer::lookup_identifier(String s)
-{
- if (!the_id_tab->elt_query(s))
- return 0;
-
- return (*the_id_tab)[s];
-}
-
-char const*
-My_flex_lexer::here_ch_c_l()
-{
- return include_stack.top()->sourcefile_l_->ch_c_l() + yyin->tellg();
-}
-
-void
-My_flex_lexer::add_identifier(Identifier*i)
-{
- delete lookup_identifier(i->name);
- (*the_id_tab)[i->name] = i;
-}
-
-My_flex_lexer::~My_flex_lexer()
-{
- delete keytable;
- delete defaulttab;
- for (Assoc_iter<String,Identifier*> ai(*the_id_tab); ai.ok(); ai++) {
- mtor << "deleting: " << ai.key()<<'\n';
- delete ai.val();
- }
- delete the_id_tab;
-}
-void
-My_flex_lexer::print_declarations()const
-{
- for (Assoc_iter<String,Identifier*> ai(*the_id_tab); ai.ok(); ai++) {
- ai.val()->print();
- }
-}
-
-String
-My_flex_lexer::spot()const
-{
- return include_stack.top()->name + ": " + String( lineno() );
-}
-
-void
-My_flex_lexer::LexerError(const char *s)
-{
- if (lexer->include_stack.empty()) {
- *mlog << "error at EOF" << s << '\n';
- } else {
- char const* ch_c_l = here_ch_c_l();
- if ( ch_c_l ) {
- ch_c_l--;
- while ( ( *ch_c_l == ' ' ) || ( *ch_c_l == '\t' ) || ( *ch_c_l == '\n' ) )
- ch_c_l--;
- ch_c_l++;
- }
- errorlevel_i_ |= 1;
- error( s, ch_c_l );
- }
-}
-
-// set the new input to s, remember old file.
-void
-My_flex_lexer::new_input(String s)
-{
- if (!include_stack.empty()) {
- include_stack.top()->line = lineno();
- // should this be saved at all?
- include_stack.top()->defined_ch_c_l_ = defined_ch_c_l;
- }
-
- Input_file *newin = new Input_file(s);
- include_stack.push(newin);
- switch_streams(newin->is);
-
- yylineno = 1;
-}
-
-// pop the inputstack.
-bool
-My_flex_lexer::close_input()
-{
- Input_file *old = include_stack.pop();
- bool ok = true;
- if (include_stack.empty()) {
- ok = false;
- } else {
- Input_file *i = include_stack.top();
- switch_streams(i->is);
- yylineno = i->line;
- defined_ch_c_l = i->defined_ch_c_l_;
- }
- delete old;
- return ok;
-}
+++ /dev/null
-/*
- could use cleanup
- */
-#include <ctype.h>
-#include "lexer.hh"
-#include "string.hh"
-#include "real.hh"
-#include "debug.hh"
-#include "musicalrequest.hh"
-#include "commandrequest.hh"
-#include "voice.hh"
-#include "notename.hh"
-#include "identparent.hh"
-#include "varray.hh"
-#include "text-def.hh"
-#include "parseconstruct.hh"
-#include "input-music.hh"
-#include "voice-element.hh"
-
-int default_duration = 4, default_dots=0, default_octave=0;
-int default_plet_type = 1, default_plet_dur = 1;
-String textstyle="roman"; // in lexer?
-
-bool last_duration_mode = false;
-
-void
-set_duration_mode(String s)
-{
- s = s.upper_str();
- last_duration_mode = (s== "LAST");
-}
-
-void
-last_duration(int n)
-{
- if (last_duration_mode)
- default_duration = n;
-}
-
-/* triplet is '2/3' */
-void
-set_plet(int num,int den)
-{
- assert(num >0&& den>0);
- default_plet_dur = num;
- default_plet_type = den;
-}
-
-Text_def*
-get_text(String s) return t;
-{
- t= new Text_def;
- t->text_str_= s;
- t->style_str_ = textstyle;
- t->defined_ch_c_l_ = defined_ch_c_l;
- return t;
-}
-
-void
-set_text_style(String s)
-{
- textstyle = s;
-}
-
-void
-parse_octave (const char *a, int &j, int &oct)
-{
- while (1)
- {
- if (a[j] == '\'')
- oct ++;
- else if (a[j] == '`')
- oct --;
- else
- break;
- j++;
- }
-}
-
-void
-parse_pitch( const char *a, Melodic_req* mel_l)
-{
- int j=0;
-
- // octave
- mel_l->octave_i_ = default_octave;
- parse_octave(a,j,mel_l->octave_i_);
-
- // accidental
- mel_l->forceacc_b_ = false;
-
- if (a[j] == '!'){
- mel_l->forceacc_b_ = true;
- j++;
- }
-}
-
-Voice_element *
-get_note_element(String pitch, int * notename, int * duration )
-{
- Voice_element*v = new Voice_element;
- v->defined_ch_c_l_ = defined_ch_c_l;
-
-
- int dur = duration[0];
- int dots = duration[1];
-
- if (dur >= 2) {
- Stem_req * stem_req_p = new Stem_req(dur,dots);
- stem_req_p->plet_factor = Moment(default_plet_dur, default_plet_type);
- stem_req_p->defined_ch_c_l_ = defined_ch_c_l;
- v->add(stem_req_p);
- }
-
- if ( !defined_ch_c_l )
- defined_ch_c_l = lexer->here_ch_c_l();
-
- Note_req * rq = new Note_req;
- rq->notename_i_ =notename[0];
- rq->accidental_i_ = notename[1];
- parse_pitch(pitch, rq);
- rq->octave_i_ += notename[2];
-
- rq->balltype = dur;
- rq->dots = dots;
- rq->plet_factor = Moment(default_plet_dur, default_plet_type);
- rq->defined_ch_c_l_ = defined_ch_c_l;
-
- v->add(rq);
-
- return v;
-}
-
-Voice_element*
-get_word_element(Text_def* tdef_p, int* duration)
-{
- Voice_element* velt_p = new Voice_element;
- velt_p->defined_ch_c_l_ = defined_ch_c_l;
-
- int dur = duration[0];
- int dots=duration[1];
-
- tdef_p->defined_ch_c_l_ = defined_ch_c_l;
-
- Lyric_req* lreq_p = new Lyric_req(tdef_p);
-
- lreq_p->balltype = dur;
- lreq_p->dots = dots;
- lreq_p->plet_factor = Moment(default_plet_dur, default_plet_type);
- lreq_p->print();
- lreq_p->defined_ch_c_l_ = defined_ch_c_l;
-
- velt_p->add(lreq_p);
-
- return velt_p;
-}
-
-Voice_element *
-get_rest_element(String, int * duration )
-{
- Voice_element* velt_p = new Voice_element;
- velt_p->defined_ch_c_l_ = defined_ch_c_l;
-
- Rest_req * rest_req_p = new Rest_req;
- rest_req_p->plet_factor = Moment(default_plet_dur, default_plet_type);
- rest_req_p->balltype = duration[0];
- rest_req_p->dots = duration[1];
- rest_req_p->print();
- rest_req_p->defined_ch_c_l_ = defined_ch_c_l;
-
- velt_p->add(rest_req_p);
-
- return velt_p;
-}
-
-void
-get_default_duration(int *p)
-{
- *p++ = default_duration;
- *p = default_dots;
-}
-
-void
-set_default_duration(int *p)
-{
- default_duration = *p++;
- default_dots = *p++;
-}
-
-
-void
-set_default_octave(String d)
-{
- int i=0;
- default_octave=0;
- parse_octave(d, i, default_octave);
-}
-
-Request*
-get_plet_request( char c, int dur_i, int type_i )
-{
- Plet_req* plet_req_p = new Plet_req;
- plet_req_p->dur_i_ = dur_i;
- plet_req_p->type_i_ = type_i;
- plet_req_p->type_c_ = c;
- return plet_req_p;
-}
-
-Request*
-get_request(char c)
-{
- Request* req_p=0;
- switch (c) {
- case '|':
- req_p = new Barcheck_req;
- break;
-
- case '[':
- case ']':
- {
- Beam_req*b = new Beam_req;
- if (default_plet_type != 1)
- b->nplet = default_plet_type;
- req_p = b;
- }
- break;
-
-
- case ')':
- case '(':
- req_p = new Slur_req;
- break;
- default:
- assert(false);
- break;
- }
-
- switch (c) {
- case '(':
- case '[':
- req_p->span()->spantype = Span_req::START;
- break;
- case ')':
- case ']':
- req_p->span()->spantype = Span_req::STOP;
- break;
-
- default:
- break;
- }
-
- req_p->defined_ch_c_l_ = req_defined_ch_c_l;
- return req_p;
-}
-
-void
-add_requests(Voice_element *v, Array<Request*> &req)
-{
- for (int i = 0; i < req.size(); i++) {
- v->add(req[i]);
- }
- req.set_size(0);
-}
-
-Script_def*
-get_scriptdef(char c)
-{
- String s;
- switch (c) {
- case '^' : s = "marcato";
- break;
- case '+' : s = "stopped";
- break;
- case '-' : s = "tenuto";
- break;
- case '|': s = "staccatissimo";
- break;
- case 'o' : s = "";
- break;
- case '>' : s = "accent";
- break;
- case 'v' : s = "";
- break;
- case '.' : s = "staccato";
- break;
- }
- return lexer->lookup_identifier(s)->script(1);
-}
-
-Request*
-get_script_req(int d , Script_def*def)
-{
- Script_req* script_req_p = new Script_req(d, def);
- return script_req_p;
-}
-
-Request*
-get_text_req(int d , Text_def*def)
-{
- Text_req* text_req_p = new Text_req(d, def);
- return text_req_p;
-}
-
-Request*
-get_stemdir_req(int d)
-{
- Group_feature_req * gfreq_p = new Group_feature_req;
- gfreq_p->stemdir_i_ =d;
- return gfreq_p;
-}
-
-Request*
-get_grouping_req(Array<int> i_arr)
-{
- Measure_grouping_req * mr_p = new Measure_grouping_req;
- for (int i=0; i <i_arr.size(); ) {
- mr_p->beat_i_arr_.push(i_arr[i++]);
- mr_p->elt_length_arr_.push(Moment(1, i_arr[i++]));
- }
- return mr_p;
-}
+++ /dev/null
-#include "misc.hh"
-#include "notehead.hh"
-#include "dimen.hh"
-#include "debug.hh"
-#include "paper-def.hh"
-#include "lookup.hh"
-#include "molecule.hh"
-#include "musicalrequest.hh"
-
-
-
-Notehead::Notehead(int ss)
-{
- x_dir = 0;
- staff_size=ss;
- position = 0;
- balltype = 0;
- dots = 0;
- extremal = 0;
-}
-
-void
-Notehead::set_rhythmic(Rhythmic_req*r_req_l)
-{
- balltype = r_req_l->balltype;
- dots = r_req_l->dots;
-}
-
-void
-Notehead::do_print()const
-{
-#ifndef NPRINT
- mtor << "balltype "<< balltype << ", position = "<< position
- << "dots " << dots;
-#endif
-}
-
-
-int
-Notehead::compare(Notehead *const &a, Notehead * const &b)
-{
- return a->position - b->position;
-}
-
-Molecule*
-Notehead::brew_molecule_p() const return out;
-{
- Paper_def *p = paper();
-
- Real dy = p->internote();
- Symbol s = p->lookup_p_->ball(balltype);
-
- out = new Molecule(Atom(s));
- if (dots) {
- Symbol d = p->lookup_p_->dots(dots);
- Molecule dm;
- dm.add(Atom(d));
- if (!(position %2))
- dm.translate(Offset(0,dy));
- out->add_right(dm);
- }
- out->translate(Offset(x_dir * p->note_width(),0));
- bool streepjes = (position<-1)||(position > staff_size+1);
- if (streepjes) {
- int dir = sign(position);
- int s =(position<-1) ? -((-position)/2): (position-staff_size)/2;
- Symbol str = p->lookup_p_->streepjes(s);
- Molecule sm;
- sm.add(Atom(str));
- if (position % 2)
- sm.translate(Offset(0,-dy* dir));
- out->add(sm);
- }
-
- out->translate(Offset(0,dy*position));
-}
-
+++ /dev/null
-#include "glob.hh"
-#include "string.hh"
-#include "notename.hh"
-#include "lexer.hh"
-#include "identifier.hh"
-
-
-
-void
-Notename_tab::lookup(int &large, int &small, String s)
-{
- large = -1;
- small = 0;
-
- for (int i =0; i < 7*5; i++)
- if (s == notetab[i])
- {
- large = i /5;
- small = i %5 - 2;
- return;
- }
-}
-
-
-void
-Notename_tab::set(int l, int s, String n)
-{
- assert(l < 8 && s <= 2 && s >= -2 && l >=0);
- notetab[l * 5 + s +2] = n;
-}
-/* *************** */
-void
-My_flex_lexer::set(Notename_tab *n)
-{
- delete defaulttab;
- defaulttab = n;
-}
-
-void
-My_flex_lexer::lookup_notename(int &large, int &small, String s)
-{
- if (!defaulttab)
- set(lookup_identifier("default_table")->
- notename_tab(true));
-
- defaulttab->lookup(large, small, s);
-}
+++ /dev/null
-#include <math.h>
-#include "misc.hh"
-#include "paper-def.hh"
-#include "debug.hh"
-#include "lookup.hh"
-#include "dimen.hh"
-
-
-
-// golden ratio
-const Real PHI = (1+sqrt(5))/2;
-
-// see Roelofs, p. 57
-Real
-Paper_def::duration_to_dist(Moment d)
-{
- if (!d)
- return 0;
-
- return whole_width * pow(geometric_, log_2(d));
-}
-
-Real
-Paper_def::rule_thickness()const
-{
- return 0.4 PT;
-}
-
-Paper_def::Paper_def(Lookup *l)
-{
- lookup_p_ = l;
- linewidth = 15 *CM_TO_PT; // in cm for now
- whole_width = 8 * note_width();
- geometric_ = sqrt(2);
- outfile = "lelie.out";
-}
-
-Paper_def::~Paper_def()
-{
- delete lookup_p_;
-}
-Paper_def::Paper_def(Paper_def const&s)
-{
- lookup_p_ = new Lookup(*s.lookup_p_);
- geometric_ = s.geometric_;
- whole_width = s.whole_width;
- outfile = s.outfile;
- linewidth = s.linewidth;
-}
-
-void
-Paper_def::set(Lookup*l)
-{
- assert(l != lookup_p_);
- delete lookup_p_;
- lookup_p_ = l;
-}
-
-Real
-Paper_def::interline() const
-{
- return lookup_p_->ball(4).dim.y.length();
-}
-
-Real
-Paper_def::internote() const
-{
- return lookup_p_->internote();
-}
-Real
-Paper_def::note_width()const
-{
- return lookup_p_->ball(4).dim.x.length( );
-}
-Real
-Paper_def::standard_height() const
-{
- return 20 PT;
-}
-
-void
-Paper_def::print() const
-{
-#ifndef NPRINT
- mtor << "Paper {width: " << print_dimen(linewidth);
- mtor << "whole: " << print_dimen(whole_width);
- mtor << "out: " <<outfile;
- lookup_p_->print();
- mtor << "}\n";
-#endif
-}
+++ /dev/null
-%{ // -*-Fundamental-*-
-#include <iostream.h>
-
-#include "lookup.hh"
-#include "misc.hh"
-#include "lexer.hh"
-#include "paper-def.hh"
-#include "midi-def.hh"
-#include "input-score.hh"
-#include "main.hh"
-#include "keyword.hh"
-#include "debug.hh"
-#include "parseconstruct.hh"
-#include "dimen.hh"
-#include "identifier.hh"
-#include "commandrequest.hh"
-#include "musicalrequest.hh"
-#include "voice-element.hh"
-
-#ifndef NDEBUG
-#define YYDEBUG 1
-#endif
-
-Array<Request*> pre_reqs, post_reqs;
-Array<const char *> define_spots;
-Paper_def*default_paper();
-char const* defined_ch_c_l;
-char const* req_defined_ch_c_l;
-int fatal_error_i = 0;
-
-%}
-
-
-%union {
- Request * request;
- Real real;
- Identifier *id;
- Voice *voice;
- Voice_element *el;
- String *string;
- const char *consstr;
- Paper_def *paper;
- Midi_def* midi;
- Input_music *music;
- Music_general_chord *chord;
- Music_voice *mvoice;
- int i;
- char c;
- int ii[10];
- Moment *moment;
-
- Array<String> * strvec;
- Array<int> *intvec;
- Array<Melodic_req*> *melreqvec;
- Input_staff *staff;
- Input_score *score;
- Symtables * symtables;
- Symtable * symtable;
- Symbol * symbol;
- Lookup*lookup;
- Interval *interval;
- Box *box;
- Notename_tab *notename_tab;
- Script_def * script;
- Text_def * textdef;
-}
-
-%token VOICE STAFF SCORE TITLE BAR OUTPUT MULTIVOICE
-%token CM_T IN_T PT_T MM_T PAPER WIDTH METER UNITSPACE SKIP COMMANDS COMMAND
-%token GEOMETRIC START_T DURATIONCOMMAND OCTAVECOMMAND
-%token KEY CLEF TABLE VOICES STEM
-%token PARTIAL MUSIC GROUPING CADENZA
-%token END SYMBOLTABLES TEXID TABLE NOTENAMES SCRIPT TEXTSTYLE PLET
-%token GOTO
-%token MIDI TEMPO
-
-%token <id> IDENTIFIER
-%token <string> PITCHMOD DURATION RESTNAME
-%token <ii> NOTENAME
-%token <real> REAL
-%token <string> STRING
-
-%token <i> DOTS INT
-%type <real> unit
-%type <melreqvec> pitch_list
-%type <c> open_request_parens close_request_parens close_plet_parens
-%type <id> declaration
-%type <string> declarable_identifier
-%type <paper> paper_block paper_body
-%type <midi> midi_block midi_body
-%type <real> dim real
-%type <ii> default_duration explicit_duration notemode_duration mudela_duration
-%type <ii> notename
-%type <moment> duration_length
-%type <el> voice_elt full_element lyrics_elt command_elt
-
-%type <score> score_block score_body
-%type <staff> staff_block staff_init staff_body
-%type <i> int
-%type <intvec> intastint_list
-%type <request> post_request pre_request command_req
-%type <string> pitchmod
-%type <music> music
-%type <chord> music_chord music_chord_body
-
-%type <mvoice> music_voice_body music_voice
-
-%type <interval> dinterval
-%type <box> box
-%type <symtable> symtable symtable_body
-%type <lookup> symtables symtables_body
-%type <symbol> symboldef
-%type <notename_tab> notename_tab notename_tab_body
-%type <i> script_dir
-%type <script> script_definition script_body mudela_script
-%type <request> script_req textscript_req
-%type <textdef> mudela_text
-
-
-%%
-
-mudela: /* empty */
- | mudela score_block {
- add_score($2);
- }
- | mudela add_declaration { }
- | mudela mudela_command {}
- ;
-
-mudela_command:
- notename_tab { lexer->set($1); }
- ;
-
-/*
- DECLARATIONS
-*/
-add_declaration: declaration {
- lexer->add_identifier($1);
- }
- ;
-
-declarable_identifier:
- STRING { $$ = $1; }
- | IDENTIFIER { $$ = new String($1->name); }
- ;
-
-declaration:
- declarable_identifier '=' staff_block {
- $$ = new Staff_id(*$1, $3);
- delete $1;
- }
- | declarable_identifier '=' music_voice {
- $$ = new M_voice_id(*$1, $3);
- delete $1;
- }
- | declarable_identifier '=' script_definition {
- $$ = new Script_id(*$1, $3);
- delete $1;
- }
- | declarable_identifier '=' music_chord {
- $$ = new M_chord_id(*$1, $3);
- delete $1;
- }
- | declarable_identifier '=' symtables {
- $$ = new Lookup_id(*$1, $3);
- delete $1;
- }
- | declarable_identifier '=' notename_tab {
- $$ = new Notetab_id(*$1, $3);
- delete $1;
- }
- | declarable_identifier '=' real {
- $$ = new Real_id(*$1, new Real($3));
- delete $1;
- }
- | declarable_identifier error '}' {
-
- }
- ;
-
-notename_tab:
- NOTENAMES '{' notename_tab_body '}' { $$ = $3; }
- ;
-
-notename_tab_body: {
- $$ = new Notename_tab;
- }
- | IDENTIFIER {
- $$ = $1->notename_tab(true);
- }
- | notename_tab_body STRING int int {
- $$->set($3, $4, *$2);
- delete $2;
- }
- ;
-
-/*
- SCORE
-*/
-score_block:
- SCORE { define_spots.push(lexer->here_ch_c_l()); }
- /*cont*/ '{' score_body '}' {
- $$ = $4;
- $$->defined_ch_c_l_ = define_spots.pop();
- if (!$$->paper_p_ && ! $$->midi_p_)
- $$->paper_p_ = default_paper();
-
- /* handle error levels. */
- $$->errorlevel_i_ = lexer->errorlevel_i_;
- lexer->errorlevel_i_ = 0;
- }
- ;
-
-score_body: {
- $$ = new Input_score;
- }
- | score_body staff_block { $$->add($2); }
- | score_body COMMANDS '{' music_voice_body '}' {
- $$->set($4);
- }
- | score_body paper_block { $$->set($2); }
- | score_body midi_block { $$->set($2); }
- | score_body error {
-
- }
- ;
-
-intastint_list:
- /* */ { $$ =new Array<int>; }
- | intastint_list int '*' int {
- $$->push($2); $$->push($4);
- }
- ;
-
-
-/*
- PAPER
-*/
-paper_block:
- PAPER
-
- '{' paper_body '}' { $$ = $3; }
- ;
-
-paper_body:
- /* empty */ {
- $$ = default_paper();
- }
- | paper_body WIDTH dim { $$->linewidth = $3;}
- | paper_body OUTPUT STRING { $$->outfile = *$3;
- delete $3;
- }
- | paper_body symtables { $$->set($2); }
- | paper_body UNITSPACE dim { $$->whole_width = $3; }
- | paper_body GEOMETRIC REAL { $$->geometric_ = $3; }
- | paper_body error {
-
- }
- ;
-
-/*
- MIDI
-*/
-midi_block:
- MIDI
-
- '{' midi_body '}' { $$ = $3; }
- ;
-
-midi_body: {
- $$ = new Midi_def;
- }
- | midi_body OUTPUT STRING {
- $$->outfile_str_ = *$3;
- delete $3;
- }
- | midi_body TEMPO mudela_duration ':' int {
- $$->set_tempo( wholes( $3[0], $3[1] ), $5 );
- }
- | midi_body error {
-
- }
- ;
-
-/*
- STAFFs
-*/
-staff_block:
- STAFF { define_spots.push(lexer->here_ch_c_l()); }
-/*cont*/ '{' staff_body '}' {
- $$ = $4;
- $$-> defined_ch_c_l_ = define_spots.pop();
- }
- ;
-
-
-
-staff_init:
- IDENTIFIER { $$ = $1->staff(true); }
- | STRING {
- $$ = new Input_staff(*$1);
- delete $1;
- }
- ;
-
-staff_body:
- staff_init
- | staff_body COMMANDS '{' music_voice_body '}' {
- $$->set_score_wide($4);
- }
- | staff_body music {
- $2->set_default_group( "staff_music" + String($$->music_.size()));
- $$->add($2);
- }
- | staff_body error {
- }
- ;
-
-/*
- MUSIC
-*/
-music:
- music_voice { $$ = $1; }
- | music_chord { $$ = $1; }
- ;
-
-music_voice: MUSIC '{' music_voice_body '}' { $$ = $3; }
- ;
-
-music_voice_body:
- /* */ {
- $$ = new Music_voice;
- }
- | music_voice_body IDENTIFIER {
- $$->concatenate($2->mvoice(true));
- }
- | music_voice_body full_element {
- $$->add_elt($2);
- }
- | music_voice_body voice_command {
- }
- | music_voice_body music {
- $$->add($2);
- }
- | music_voice_body error {
- }
- ;
-
-music_chord: '{' music_chord_body '}' { $$ = $2; }
- ;
-
-music_chord_body:
- /* */ {
- $$ = new Voice_group_chord;
- }
- | MULTIVOICE {
- $$ = new Multi_voice_chord;
- }
- | music_chord_body IDENTIFIER {
- $$->concatenate($2->mchord(true));
- }
- | music_chord_body music {
- $$->add($2);
- }
- | music_chord_body full_element {
- $$ ->add_elt($2);
- }
- | music_chord_body error {
- }
- ;
-
-
-/*
- VOICE ELEMENTS
-*/
-full_element: pre_requests voice_elt post_requests {
- add_requests($2, pre_reqs);
- add_requests($2, post_reqs);
- $$ = $2;
- }
- | pre_requests lyrics_elt post_requests {
- add_requests($2, pre_reqs);
- add_requests($2, post_reqs);
- $$ = $2;
- }
- | command_elt
- ;
-
-command_elt:
-/* empty */ {
- $$ = new Voice_element;
- $$-> defined_ch_c_l_ = lexer->here_ch_c_l();
- }
-/* cont: */
- command_req {
- $2-> defined_ch_c_l_ = $$->defined_ch_c_l_;
- $$->add($2);
-
- }
- ;
-
-command_req:
- '|' {
- $$ = new Barcheck_req;
- }
- | BAR STRING {
- $$ = new Bar_req(*$2);
- delete $2;
- }
- | METER '{' int '*' int '}' {
- Meter_change_req *m = new Meter_change_req;
- m->set($3,$5);
- $$ = m;
- }
- | SKIP '{' duration_length '}' {
- Skip_req * skip_p = new Skip_req;
- skip_p->duration_ = *$3;
- delete $3;
- $$ = skip_p;
- }
- | CADENZA '{' int '}' {
- $$ = new Cadenza_req($3);
- }
- | PARTIAL '{' duration_length '}' {
- $$ = new Partial_measure_req(*$3);
- delete $3;
- }
- | STEM '{' int '}' {
- $$ = get_stemdir_req($3);
- }
- | CLEF STRING {
- $$ = new Clef_change_req(*$2);
- delete $2;
- }
- | KEY '{' pitch_list '}' {
- Key_change_req *key_p= new Key_change_req;
- key_p->melodic_p_arr_ = *$3;
- $$ = key_p;
- delete $3;
- }
- | GROUPING '{' intastint_list '}' {
- $$ = get_grouping_req(*$3); delete $3;
- }
- ;
-
-post_requests:
- {
- assert(post_reqs.empty());
- }
- | post_requests post_request {
- $2->defined_ch_c_l_ = lexer->here_ch_c_l();
- post_reqs.push($2);
- }
- | post_requests close_plet_parens INT '/' INT {
- post_reqs.push( get_request($2) );
- req_defined_ch_c_l = lexer->here_ch_c_l();
- post_reqs.push( get_plet_request( $2, $3, $5 ) );
- }
- ;
-
-post_request:
- close_request_parens {
- $$ = get_request($1);
- }
- | script_req
- | textscript_req
- ;
-
-close_plet_parens:
- ']' {
- req_defined_ch_c_l = lexer->here_ch_c_l();
- $$ = ']';
- }
- ;
-
-close_request_parens:
- '(' {
- $$='(';
- }
- | ']' {
- $$ = ']';
- }
- ;
-
-open_request_parens:
- ')' {
- $$=')';
- }
- | '[' {
- $$='[';
- }
- ;
-
-script_definition:
- SCRIPT '{' script_body '}' { $$ = $3; }
- ;
-
-script_body:
- STRING int int int {
- $$ = new Script_def(*$1,$2, $3,$4);
- delete $1;
- }
- ;
-
-textscript_req:
- script_dir mudela_text { $$ = get_text_req($1,$2); }
- ;
-
-mudela_text:
- STRING {
- defined_ch_c_l = lexer->here_ch_c_l();
- $$ = get_text(*$1);
- delete $1;
- }
- ;
-
-script_req:
- script_dir mudela_script {
- $$ = get_script_req($1, $2);
- }
- ;
-
-mudela_script:
- IDENTIFIER { $$ = $1->script(true); }
- | script_definition { $$ = $1; }
- | '^' { $$ = get_scriptdef('^'); }
- | '+' { $$ = get_scriptdef('+'); }
- | '-' { $$ = get_scriptdef('-'); }
- | '|' { $$ = get_scriptdef('|'); }
- | 'o' { $$ = get_scriptdef('o'); }
- | '>' { $$ = get_scriptdef('>'); }
- | '.' { $$ = get_scriptdef('.'); }
- | DOTS {
- if ( $1 > 1 )
- warning( "too many staccato dots", lexer->here_ch_c_l() );
- $$ = get_scriptdef('.');
- }
- | error {
- $$ = get_scriptdef('.');
- yyerrok;
- }
- ;
-
-script_dir:
- '_' { $$ = -1; }
- |'^' { $$ = 1; }
- |'-' { $$ = 0; }
- ;
-
-pre_requests:
- | pre_requests pre_request {
- pre_reqs.push($2);
- $2->defined_ch_c_l_ = lexer->here_ch_c_l();
- }
- ;
-
-pre_request:
- open_request_parens {
- defined_ch_c_l = lexer->here_ch_c_l();
- $$ = get_request($1);
- }
- ;
-
-voice_command:
- PLET '{' INT '/' INT '}' {
- set_plet($3,$5);
- }
- | DURATIONCOMMAND '{' STRING '}' {
- set_duration_mode(*$3);
- delete $3;
- }
- | DURATIONCOMMAND '{' notemode_duration '}' {
- set_default_duration($3);
- }
- | OCTAVECOMMAND '{' pitchmod '}' {
- set_default_octave(*$3);
- delete $3;
- }
- | TEXTSTYLE STRING {
- set_text_style(*$2);
- delete $2;
- }
- ;
-
-duration_length:
- mudela_duration {
- $$ = new Moment(wholes($1[0], $1[1]));
- }
- |int '*' mudela_duration {
- $$ = new Moment(Rational($1) * wholes($3[0], $3[1]));
- }
- ;
-
-notemode_duration:
- explicit_duration
- | default_duration
- ;
-
-mudela_duration:
- int {
- $$[0] = $1;
- $$[1] = 0;
- }
- | int DOTS {
- $$[0] = $1;
- $$[1] = $2;
- }
- ;
-
-
-explicit_duration:
- INT {
- last_duration($1);
- $$[0] = $1;
- $$[1] = 0;
- }
- | INT DOTS {
- last_duration($1);
- $$[0] = $1;
- $$[1] = $2;
- }
- | DOTS {
- 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:
- {
- get_default_duration($$);
- }
- ;
-
-pitchmod: {
- defined_ch_c_l = lexer->here_ch_c_l();
- $$ = new String;
- }
- | PITCHMOD {
- defined_ch_c_l = lexer->here_ch_c_l();
- $$ = $1;
- }
- ;
-
-notename:
- NOTENAME
- ;
-
-voice_elt:
- pitchmod notename notemode_duration {
- $$ = get_note_element(*$1, $2, $3);
- delete $1;
- }
- | RESTNAME notemode_duration {
- $$ = get_rest_element(*$1, $2);
- delete $1;
-
- }
- ;
-
-lyrics_elt:
- mudela_text notemode_duration {
- $$ = get_word_element($1, $2);
- };
-
-/*
- UTILITIES
- */
-pitch_list: {
- $$ = new Array<Melodic_req*>;
- }
- | pitch_list NOTENAME {
- Melodic_req *m_p = new Melodic_req;
- m_p->notename_i_ = $2[0];
- m_p->accidental_i_ = $2[1];
- $$->push(m_p);
- }
- ;
-
-int:
- real {
- $$ = int($1);
- if ( distance($1,Real(int($$)) ) > 1e-8)
- error( "integer expected", lexer->here_ch_c_l() );
- }
- ;
-
-real:
- INT {
- $$ = Real($1);
- }
- | REAL {
- $$ = $1;
- }
- | IDENTIFIER {
- $$ = * $1->real(0);
- }
- ;
-
-
-
-dim:
- real unit { $$ = $1*$2; }
- ;
-
-
-unit: CM_T { $$ = 1 CM; }
- |IN_T { $$ = 1 INCH; }
- |MM_T { $$ = 1 MM; }
- |PT_T { $$ = 1 PT; }
- ;
-
-/*
- symbol tables
-*/
-symtables:
- SYMBOLTABLES '{' symtables_body '}' { $$ = $3; }
- ;
-
-symtables_body:
- {
- $$ = new Lookup;
- }
- | IDENTIFIER {
- $$ = new Lookup(*$1->lookup(true));
- }
- | symtables_body TEXID STRING {
- $$->texsetting = *$3;
- delete $3;
- }
- | symtables_body STRING '=' symtable {
- $$->add(*$2, $4);
- delete $2;
- }
- ;
-
-symtable:
- TABLE '{' symtable_body '}' { $$ = $3; }
- ;
-
-symtable_body:
- { $$ = new Symtable; }
- | symtable_body STRING symboldef {
- $$->add(*$2, *$3);
- delete $2;
- delete $3;
- }
- ;
-
-symboldef:
- STRING box {
- $$ = new Symbol(*$1, *$2);
- delete $1;
- delete $2;
- }
- | STRING {
- Box b;
- $$ = new Symbol(*$1, b);
- delete $1;
- }
- ;
-
-box:
- dinterval dinterval {
- $$ = new Box(*$1, *$2);
- delete $1;
- delete $2;
- }
- ;
-
-dinterval: dim dim {
- $$ = new Interval($1, $2);
- }
- ;
-
-%%
-
-void
-yyerror(const char *s)
-{
- lexer->LexerError(s);
-
- if ( fatal_error_i )
- exit( fatal_error_i );
-}
-
-void
-parse_file(String init, String s)
-{
- *mlog << "Parsing ... ";
- lexer = new My_flex_lexer;
-
-#ifndef NDEBUG
- yydebug = !monitor->silence("InitParser") && check_debug;
- lexer->set_debug( !monitor->silence("InitLexer") && check_debug);
-#endif
-
- lexer->new_input(init);
-
- yyparse();
-
-#ifndef NDEBUG
- if (check_debug && !monitor->silence("InitDeclarations"))
- lexer->print_declarations();
-
- yydebug = !monitor->silence("Parser") && check_debug;
- lexer->set_debug( !monitor->silence("Lexer") && check_debug);
-#endif
-
- lexer->new_input(s);
- yyparse();
- delete lexer;
- lexer = 0;
-
- if(!define_spots.empty())
- warning("Braces don't match.",0);
-}
-
-Paper_def*
-default_paper()
-{
- return new Paper_def(
- lexer->lookup_identifier("default_table")->lookup(true));
-}
-
-
+++ /dev/null
-#include "pcol.hh"
-#include "pscore.hh"
-#include "pstaff.hh"
-#include "debug.hh"
-
-Interval
-PCol::width() const
-{
- Interval w;
-
- for (iter_top(its,i); i.ok(); i++)
- w.unite(i->width());
- if (w.empty())
- w.unite(Interval(0,0));
- return w;
-}
-
-int
-PCol::rank() const
-{
- if(!pscore_l_)
- return -1;
- PCursor<PCol*> me=pscore_l_->find_col( (PCol*)this);
- if (!me.ok())
- return -1;
- PCursor<PCol*> bot(pscore_l_->cols.top());
- return me - bot;
-}
-
-void
-PCol::print() const
-{
-#ifndef NPRINT
- mtor << "PCol {";
-
- if (rank() >= 0)
- mtor << "rank: " << rank() << '\n';
-
- mtor << "# symbols: " << its.size() ;
- if (breakable_b()){
- mtor << "\npre,post: ";
- prebreak_p_->print();
- postbreak_p_->print();
- } else if (daddy_l_) {
- mtor<<'\n' << ((this == daddy_l_->prebreak_p_) ?
- "prebreak" : "postbreak");
- mtor << '\n';
- }
- mtor << "extent: " << width().str() << "\n";
- mtor << "}\n";
-#endif
-}
-
-int
-PCol::compare(const PCol &c1, const PCol &c2)
-{
- PScore*ps_l = c1.pscore_l_;
- PCursor<PCol*> ac(ps_l->find_col(&c1));
- PCursor<PCol*> bc(ps_l->find_col(&c2));
- assert(ac.ok() && bc.ok());
- return ac - bc;
-}
-
-void
-PCol::OK() const
-{
-#ifndef NDEBUG
- if (prebreak_p_ || postbreak_p_ ) {
- assert(prebreak_p_&&postbreak_p_);
- assert(prebreak_p_->daddy_l_ == this);
- assert(postbreak_p_->daddy_l_ == this);
- }
-#endif
-}
-
-void
-PCol::set_breakable()
-{
- if (breakable_b())
- return;
-
- prebreak_p_ = new PCol(this);
- postbreak_p_ = new PCol(this);
- prebreak_p_->pscore_l_ = pscore_l_;
- postbreak_p_->pscore_l_ = pscore_l_;
-}
-
-bool
-PCol::breakable_b() const
-{
- return prebreak_p_||postbreak_p_;
-}
-
-PCol::PCol(PCol *parent)
-{
- daddy_l_ = parent;
- prebreak_p_=0;
- postbreak_p_=0;
- line_l_=0;
- hpos = -1.0;
- pscore_l_ = 0;
-}
-
-PCol::~PCol()
-{
- delete prebreak_p_;
- delete postbreak_p_;
-}
-
-void
-PCol::add( Item *i)
-{
- its.bottom().add(i);
- i->pcol_l_ = this;
-}
-
-bool
-PCol::used_b()const
-{
- return breakable_b() || its.size();
-}
+++ /dev/null
-#include "idealspacing.hh"
-#include "debug.hh"
-#include "lookup.hh"
-#include "spanner.hh"
-#include "paper-def.hh"
-#include "molecule.hh"
-#include "dimen.hh"
-#include "scoreline.hh"
-#include "pscore.hh"
-#include "tex-stream.hh"
-#include "item.hh"
-#include "break.hh"
-
-Idealspacing*
-PScore::get_spacing(PCol*l, PCol*r)
-{
- assert(l!=r);
-
- Idealspacing*i_p =new Idealspacing(l,r);
- suz.bottom().add(i_p);
-
- return i_p;
-}
-
-
-void
-PScore::clean_cols()
-{
- for (iter_top(cols,c); c.ok(); )
- if (!c->used_b()) {
- delete c.get_p();
- } else
- c++;
-}
-
-
-void
-PScore::add(PStaff *s)
-{
- assert(s->pscore_l_ == this);
- staffs.bottom().add(s);
-}
-
-
-void
-PScore::do_connect(PCol *c1, PCol *c2, Real d, Real h)
-{
- if (!c1 || !c2 )
- return;
- Idealspacing*s_l=get_spacing(c1,c2);
-
-
- s_l->hooke = h;
- s_l->space =d;
-}
-
-void
-PScore::connect(PCol* c1, PCol *c2, Real d, Real h)
-{
- do_connect(c1,c2,d,h);
- do_connect(c1->postbreak_p_, c2,d,h);
- do_connect(c1, c2->prebreak_p_,d,h);
- do_connect(c1->postbreak_p_, c2->prebreak_p_,d,h);
-}
-
-void
-PScore::typeset_item(Item *i, PCol *c, PStaff *s, int breakstat)
-{
- assert(c && i && s);
-
- if (breakstat == 0) {
- typeset_item(i, c->prebreak_p_, s);
- return;
- }
-
- if (breakstat == 2) {
- typeset_item(i, c->postbreak_p_, s);
- return;
- }
-
-
- its.bottom().add(i);
- s->add(i);
- c->add(i);
-
- /* first do this, because i->width() may follow the 0-pointer */
- i->add_processing();
-}
-
-void
-PScore::typeset_spanner(Spanner*span_p, PStaff*ps)
-{
- span_p->pstaff_l_ = ps;
- spanners.bottom().add(span_p);
- ps->spans.bottom().add(span_p);
-
- // do not init start/stop fields. These are for broken spans only.
- span_p->add_processing();
-}
-
-
-void
-PScore::add(PCol *p)
-{
- p->pscore_l_ = this;
- if (p->breakable_b()){
- p->prebreak_p_->pscore_l_ = this;
- p->postbreak_p_->pscore_l_ = this;
- }
- cols.bottom().add(p);
-}
-
-PScore::PScore( Paper_def*p)
-{
- paper_l_ = p;
-}
-
-void
-PScore::output(Tex_stream &ts)
-{
- int l=1;
-
- ts << "\n "<< paper_l_->lookup_p_->texsetting << "%(Tex id)\n";
- for (iter_top(lines,lic); lic.ok(); lic++) {
- ts << "% line of score no. " << l++ <<"\n";
- ts << lic->TeXstring();
- if ((lic+1).ok())
- ts << "\\interscoreline\n";
- }
-}
-
-
-Array<Item*>
-PScore::select_items(PStaff*ps, PCol*pc)
-{
- Array<Item*> ret;
- assert(ps && pc);
- for (iter_top(pc->its,i); i.ok(); i++){
- if (i->pstaff_l_ == ps)
- ret.push((Item*)(const Item*)i);
- }
- return ret;
-}
-
-void
-PScore::OK()const
-{
-#ifdef NDEBUG
- for (iter_top(cols,cc); cc.ok(); cc++)
- cc->OK();
- for (iter_top(suz,i); i.ok(); i++)
- i->OK();
-#endif
-}
-
-void
-PScore::print() const
-{
-#ifndef NPRINT
- mtor << "PScore { ";
- paper_l_->print();
- mtor << "\ncolumns: ";
- for (iter_top(cols,cc); cc.ok(); cc++)
- cc->print();
-
- mtor << "\nideals: ";
- for (iter_top(suz,i); i.ok(); i++)
- i->print();
- mtor << "}\n";
-#endif
-}
-
-void
-PScore::preprocess()
-{
- for (iter_top(spanners,i); i.ok(); i++) {
- i->pre_processing();
- }
- for (iter_top(its,i); i.ok(); i++){
- i->pre_processing();
- }
-}
-
-void
-PScore::postprocess()
-{
- for (iter_top(broken_spans,i); i.ok(); i++) { // could chase spans as well.
- i->post_processing();
- }
- for (iter_top(its,i); i.ok(); i++){
- i->post_processing();
- }
-
- for (iter_top(broken_spans,i); i.ok(); i++) {
- i->molecule_processing();
- }
- for (iter_top(its,i); i.ok(); i++){
- i->molecule_processing();
- }
-
- for (iter_top(lines,i); i.ok(); i++)
- i->process();
-
-}
-
-PCursor<PCol *>
-PScore::find_col(const PCol *c)const
-{
- const PCol*what = c;
- if (what->daddy_l_ )
- what = what->daddy_l_;
-
- return cols.find((PCol*)what);
-}
-
-void
-PScore::add_broken(Spanner*s)
-{
- assert(s->left->line_l_ == s->right->line_l_);
- broken_spans.bottom().add(s);
- s->left->starters.bottom().add (s);
- s->right->stoppers.bottom().add (s);
-}
-
-void
-PScore::set_breaking(Array<Col_hpositions> breaking)
-{
- for (int j=0; j < breaking.size(); j++) {
- Array<PCol*> &curline(breaking[j].cols);
- Array<Real> &config(breaking[j].config);
-
- Line_of_score *s_p = new Line_of_score(curline,this);
- lines.bottom().add(s_p);
- for (int i=0; i < curline.size(); i++){
- curline[i]->hpos = config[i];
- }
- }
-}
-
-void
-PScore::calc_breaking()
-{
- Word_wrap w(*this);
- set_breaking(w.solve());
-}
-
-void
-PScore::process()
-{
- clean_cols();
- *mlog << "Preprocessing ... " <<flush;
- preprocess();
- *mlog << "\nCalculating column positions ... " <<flush;
- calc_breaking();
- *mlog << "\nPostprocessing ..." << endl;
- postprocess();
-}
+++ /dev/null
-#include "pstaff.hh"
-#include "molecule.hh"
-
-PStaff::PStaff(PScore*ps)
-{
- pscore_l_=ps;
-}
-
-void
-PStaff::add(Item *i)
-{
- its.bottom().add(i);
- i->pstaff_l_ = this;
-}
+++ /dev/null
-#include "debug.hh"
-#include "const.hh"
-#include "qlp.hh"
-#include "choleski.hh"
-
-void
-Mixed_qp::add_equality_cons(Vector , double )
-{
- assert(false);
-}
-
-void
-Mixed_qp::add_fixed_var(int i, Real r)
-{
- eq_cons.push(i);
- eq_consrhs.push(r);
-}
-
-void
-Ineq_constrained_qp::add_inequality_cons(Vector c, double r)
-{
- cons.push(c);
- consrhs.push(r);
-}
-
-Ineq_constrained_qp::Ineq_constrained_qp(int novars):
- quad(novars),
- lin(novars),
- const_term (0.0)
-{
-}
-
-void
-Ineq_constrained_qp::OK() const
-{
-#ifndef NDEBUG
- assert(cons.size() == consrhs.size());
- Matrix Qdif= quad - quad.transposed();
- assert(Qdif.norm()/quad.norm() < EPS);
-#endif
-}
-
-
-Real
-Ineq_constrained_qp::eval (Vector v)
-{
- return v * quad * v + lin * v + const_term;
-}
-
-/**
- eliminate appropriate variables, until we have a Ineq_constrained_qp
- then solve that.
-
- PRE
- cons should be ascending
- */
-Vector
-Mixed_qp::solve(Vector start) const
-{
- print();
- Ineq_constrained_qp pure(*this);
-
- for (int i= eq_cons.size()-1; i>=0; i--) {
- pure.eliminate_var(eq_cons[i], eq_consrhs[i]);
- start.del(eq_cons[i]);
- }
- Vector sol = pure.solve(start);
- for (int i= 0; i < eq_cons.size(); i++) {
- sol.insert( eq_consrhs[i],eq_cons[i]);
- }
- return sol;
-}
-
-/*
- assume x(idx) == value, and adjust constraints, lin and quad accordingly
-
- TODO: add const_term
- */
-void
-Ineq_constrained_qp::eliminate_var(int idx, Real value)
-{
- Vector row(quad.row(idx));
- row*= value;
-
- quad.delete_row(idx);
-
- quad.delete_column(idx);
-
- lin.del(idx);
- row.del(idx);
- lin +=row ;
-
- for (int i=0; i < cons.size(); i++) {
- consrhs[i] -= cons[i](idx) *value;
- cons[i].del(idx);
- }
-}
-
-
-
-void
-Ineq_constrained_qp::assert_solution(Vector sol) const
-{
- Array<int> binding;
- for (int i=0; i < cons.size(); i++) {
- Real R=cons[i] * sol- consrhs[i];
- assert(R> -EPS);
- if (R < EPS)
- binding.push(i);
- }
- // KKT check...
- // todo
-}
-
-void
-Ineq_constrained_qp::print() const
-{
-#ifndef NPRINT
- mtor << "Quad " << quad;
- mtor << "lin " << lin <<"\n"
- << "const " << const_term<<"\n";
- for (int i=0; i < cons.size(); i++) {
- mtor << "constraint["<<i<<"]: " << cons[i] << " >= " << consrhs[i];
- mtor << "\n";
- }
-#endif
-}
-
-/* *************** */
-
-Mixed_qp::Mixed_qp(int n)
- : Ineq_constrained_qp(n)
-{
-}
-
-void
-Mixed_qp::OK() const
-{
-#ifndef NDEBUG
- Ineq_constrained_qp::OK();
- assert(eq_consrhs.size() == eq_cons.size());
-#endif
-}
-
-void
-Mixed_qp::print() const
-{
-#ifndef NPRINT
- Ineq_constrained_qp::print();
- for (int i=0; i < eq_cons.size(); i++) {
- mtor << "eq cons "<<i<<": x["<<eq_cons[i]<<"] == " << eq_consrhs[i]<<"\n";
- }
-#endif
-}
-
+++ /dev/null
-#include "qlpsolve.hh"
-#include "const.hh"
-#include "debug.hh"
-#include "choleski.hh"
-
-const Real TOL=1e-2; // roughly 1/10 mm
-
-String
-Active_constraints::status() const
-{
- String s("Active|Inactive [");
- for (int i=0; i< active.size(); i++) {
- s += String(active[i]) + " ";
- }
-
- s+="| ";
- for (int i=0; i< inactive.size(); i++) {
- s += String(inactive[i]) + " ";
- }
- s+="]";
-
- return s;
-}
-
-void
-Active_constraints::OK()
-{
- #ifndef NDEBUG
- H.OK();
- A.OK();
- assert(active.size() +inactive.size() == opt->cons.size());
- assert(H.dim() == opt->dim());
- assert(active.size() == A.rows());
- Array<int> allcons;
-
- for (int i=0; i < opt->cons.size(); i++)
- allcons.push(0);
- for (int i=0; i < active.size(); i++) {
- int j = active[i];
- allcons[j]++;
- }
- for (int i=0; i < inactive.size(); i++) {
- int j = inactive[i];
- allcons[j]++;
- }
- for (int i=0; i < allcons.size(); i++)
- assert(allcons[i] == 1);
-#endif
-}
-
-Vector
-Active_constraints::get_lagrange(Vector gradient)
-{
- Vector l(A*gradient);
-
- return l;
-}
-
-void
-Active_constraints::add(int k)
-{
- // add indices
- int cidx=inactive[k];
- active.push(cidx);
-
- inactive.swap(k,inactive.size()-1);
- inactive.pop();
-
- Vector a( opt->cons[cidx] );
- // update of matrices
- Vector Ha = H*a;
- Real aHa = a*Ha;
- Vector addrow(Ha.dim());
- if (abs(aHa) > EPS) {
- /*
- a != 0, so if Ha = O(EPS), then
- Ha * aH / aHa = O(EPS^2/EPS)
-
- if H*a == 0, the constraints are dependent.
- */
- H -= Matrix(Ha/aHa , Ha);
-
-
- /*
- sorry, don't know how to justify this. ..
- */
- addrow=Ha;
- addrow/= aHa;
- A -= Matrix(A*a, addrow);
- A.insert_row(addrow,A.rows());
- }else
- WARN << "degenerate constraints";
-}
-
-void
-Active_constraints::drop(int k)
-{
- int q=active.size()-1;
-
- // drop indices
- inactive.push(active[k]);
- active.swap(k,q);
- A.swap_rows(k,q);
- active.pop();
-
- Vector a(A.row(q));
- if (a.norm() > EPS) {
- /*
-
- */
- Real q = a*opt->quad*a;
- H += Matrix(a,a/q);
- A -= A*opt->quad*Matrix(a,a/q);
- }else
- WARN << "degenerate constraints";
- #ifndef NDEBUG
- Vector rem_row(A.row(q));
- assert(rem_row.norm() < EPS);
- #endif
-
- A.delete_row(q);
-}
-
-
-Active_constraints::Active_constraints(Ineq_constrained_qp const *op)
- : A(0,op->dim()),
- H(op->dim()),
- opt(op)
-{
- for (int i=0; i < op->cons.size(); i++)
- inactive.push(i);
- Choleski_decomposition chol(op->quad);
- H=chol.inverse();
-}
-
-/** Find the optimum which is in the planes generated by the active
- constraints.
- */
-Vector
-Active_constraints::find_active_optimum(Vector g)
-{
- return H*g;
-}
-
-/* *************************************************************** */
-
-int
-min_elt_index(Vector v)
-{
- Real m=INFTY; int idx=-1;
- for (int i = 0; i < v.dim(); i++){
- if (v(i) < m) {
- idx = i;
- m = v(i);
- }
- assert(v(i) <= INFTY);
- }
- return idx;
-}
-
-
-/**the numerical solving. Mordecai Avriel, Nonlinear Programming: analysis and methods (1976)
- Prentice Hall.
-
- Section 13.3
-
- This is a "projected gradient" algorithm. Starting from a point x
- the next point is found in a direction determined by projecting
- the gradient onto the active constraints. (well, not really the
- gradient. The optimal solution obeying the active constraints is
- tried. This is why H = Q^-1 in initialisation) )
-
-
- */
-Vector
-Ineq_constrained_qp::solve(Vector start) const
-{
- Active_constraints act(this);
-
-
- act.OK();
-
-
- Vector x(start);
- Vector gradient=quad*x+lin;
-// Real fvalue = x*quad*x/2 + lin*x + const_term;
-// it's no use.
-
- Vector last_gradient(gradient);
- int iterations=0;
-
- while (iterations++ < MAXITER) {
- Vector direction= - act.find_active_optimum(gradient);
-
- mtor << "gradient "<< gradient<< "\ndirection " << direction<<"\n";
-
- if (direction.norm() > EPS) {
- mtor << act.status() << '\n';
-
- Real minalf = INFTY;
-
- Inactive_iter minidx(act);
-
-
- /*
- we know the optimum on this "hyperplane". Check if we
- bump into the edges of the simplex
- */
-
- for (Inactive_iter ia(act); ia.ok(); ia++) {
-
- if (ia.vec() * direction >= 0)
- continue;
- Real alfa= - (ia.vec()*x - ia.rhs())/
- (ia.vec()*direction);
-
- if (minalf > alfa) {
- minidx = ia;
- minalf = alfa;
- }
- }
- Real unbounded_alfa = 1.0;
- Real optimal_step = min(minalf, unbounded_alfa);
-
- Vector deltax=direction * optimal_step;
- x += deltax;
- gradient += optimal_step * (quad * deltax);
-
- mtor << "step = " << optimal_step<< " (|dx| = " <<
- deltax.norm() << ")\n";
-
- if (minalf < unbounded_alfa) {
- /* bumped into an edge. try again, in smaller space. */
- act.add(minidx.idx());
- mtor << "adding cons "<< minidx.idx()<<'\n';
- continue;
- }
- /*ASSERT: we are at optimal solution for this "plane"*/
-
-
- }
-
- Vector lagrange_mult=act.get_lagrange(gradient);
- int m= min_elt_index(lagrange_mult);
-
- if (m>=0 && lagrange_mult(m) > 0) {
- break; // optimal sol.
- } else if (m<0) {
- assert(gradient.norm() < EPS) ;
-
- break;
- }
-
- mtor << "dropping cons " << m<<'\n';
- act.drop(m);
- }
- if (iterations >= MAXITER)
- WARN<<"didn't converge!\n";
-
- mtor << ": found " << x<<" in " << iterations <<" iterations\n";
- assert_solution(x);
- return x;
-}
-
-
+++ /dev/null
-/*
- register.cc -- implement Request_register
-
- Sourcefile of LilyPond musictypesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-#include "voice.hh"
-#include "musicalrequest.hh"
-#include "register.hh"
-#include "notehead.hh"
-#include "complex-walker.hh"
-#include "local-key-item.hh"
-#include "complex-staff.hh"
-#include "registergroup.hh"
-#include "debug.hh"
-
-
-bool
-Request_register::try_request(Request*)
-{
- return false;
-}
-
-Request_register::Request_register()
-{
- daddy_reg_l_ = 0;
-}
-
-void
-Request_register::announce_element(Staff_elem_info i)
-{
- i.origin_reg_l_arr_.push(this);
- daddy_reg_l_->announce_element(i);
-}
-
-void
-Request_register::typeset_element(Staff_elem*p)
-{
- daddy_reg_l_->typeset_element(p);
-}
-
-Paper_def*
-Request_register::paper()const
-{
- return daddy_reg_l_->paper();
-}
-
-void
-Request_register::typeset_breakable_item(Item * pre_p , Item * nobreak_p,
- Item * post_p)
-{
- daddy_reg_l_->typeset_breakable_item(pre_p, nobreak_p, post_p);
-}
-
-bool
-Request_register::acceptable_request_b(Request*)const
-{
- return false;
-}
-
-bool
-Request_register::contains_b(Request_register *reg_l)
-{
- return this == reg_l;
-}
-
-Staff_info
-Request_register::get_staff_info() return inf;
-{
- inf = daddy_reg_l_->get_staff_info();
-}
-
-void
-Request_register::print() const
-{
-#ifndef NPRINT
- mtor << name() << " {";
- do_print();
- mtor << "}\n";
-#endif
-}
-
-void
-Request_register::do_print()const
-{
-}
+++ /dev/null
-/*
- registergroup.cc -- implement Register_group_register
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-#include "registergroup.hh"
-#include "register.hh"
-
-bool
-Register_group_register::acceptable_request_b(Request* r)
-{
- for (iter_top(reg_list_, i); i.ok(); i++) {
- if (i->acceptable_request_b(r))
- return true;
- }
- return false;
-}
-
-void
-Register_group_register::set_feature(Features d)
-{
- for (iter_top(reg_list_, i); i.ok(); i++) {
- i->set_feature(d);
- }
-}
-
-void
-Register_group_register::pre_move_processing()
-{
- for (iter_top(reg_list_, i); i.ok(); i++)
- i->pre_move_processing();
-}
-
-void
-Register_group_register::process_requests()
-{
- for (iter_top(reg_list_, i); i.ok(); i++)
- i->process_requests();
-}
-
-void
-Register_group_register::post_move_processing()
-{
- for (iter_top(reg_list_, i); i.ok(); i++)
- i->post_move_processing();
-}
-
-void
-Register_group_register::acknowledge_element(Staff_elem_info info)
-{
- if (!contains_b(info.origin_reg_l_arr_[0]))
- return;
-
- for (iter_top(reg_list_, i); i.ok(); i++)
- i->acknowledge_element(info);
-}
-
-bool
-Register_group_register::contains_b(Request_register* reg_l)
-{
- bool parent_b = Request_register::contains_b(reg_l);
-
- if (parent_b)
- return true;
- for (iter_top(reg_list_, j); j.ok(); j++)
- if (j->contains_b(reg_l))
- return true;
- return false;
-}
-
-
-
-bool
-Register_group_register::try_request(Request*req_l)
-{
- for (iter_top(reg_list_, i); i.ok(); i++)
- if (i->try_request(req_l))
- return true;
- return false;
-}
-
-void
-Register_group_register::add(Request_register *reg_p)
-{
- reg_list_.bottom().add(reg_p);
- reg_p->daddy_reg_l_ = this;
-}
-
-
-Register_group_register::~Register_group_register()
-{
-
-}
-
-Request_register *
-Register_group_register::get_register_p(Request_register*reg_l)
-{
- iterator(reg_list_) reg_cur= reg_list_.find(reg_l);
- assert(reg_cur.ok());
- return reg_cur.get_p();
-}
-
-void
-Register_group_register::terminate_register(Request_register*r_l)
-{
- delete get_register_p(r_l);
-}
-
-void
-Register_group_register::do_print()const
-{
-#ifndef NPRINT
- for (iter_top(reg_list_, i); i.ok(); i++)
- i->print();
-#endif
-}
+++ /dev/null
-/*
- request.cc -- implement all musical requests.
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-#include "musicalrequest.hh"
-#include "misc.hh"
-#include "debug.hh"
-#include "script-def.hh"
-#include "text-def.hh"
-#include "voice.hh"
-#include "voice-element.hh"
-
-void
-Stem_req::do_print() const
-{
- Rhythmic_req::do_print();
- mtor << "dir : " << dir_i_;
-}
-
-Stem_req::Stem_req(int s, int d)
- : Rhythmic_req(s,d)
-{
- dir_i_ = 0;
-}
-
-/* ************** */
-void Musical_req::do_print()const{}
-void Request::do_print() const{}
-
-/* *************** */
-
-void
-Request::print() const
-{
- mtor << name() << " {";
- do_print();
- mtor << "}\n";
-}
-
-
-
-void
-Span_req::do_print() const
-{
-#ifndef NPRINT
- mtor << spantype ;
-#endif
-}
-
-Request::Request()
-{
- elt_l_ = 0;
- defined_ch_c_l_ = 0;
-}
-Request::Request(Request const&src)
-{
- elt_l_ = 0;
- defined_ch_c_l_ = src.defined_ch_c_l_;
-}
-/* *************** */
-Spacing_req::Spacing_req()
-{
- next = 0;
- distance = 0;
- strength = 0;
-}
-void
-Spacing_req::do_print()const
-{
- mtor << "next " << next << "dist " << distance << "strength\n";
-}
-
-void
-Blank_req::do_print()const
-{
- Spacing_req::do_print();
-}
-/* *************** */
-Melodic_req::Melodic_req()
-{
- notename_i_ = 0;
- octave_i_ = 0;
- accidental_i_ = 0;
- forceacc_b_ = false;
-}
-
-void
-Melodic_req::do_print() const
-{
- mtor << "notename: " << notename_i_ << " acc: " <<accidental_i_<<" oct: "<< octave_i_;
-}
-
-int
-Melodic_req::height() const
-{
- return notename_i_ + octave_i_*7;
-}
-
-/*
- should be settable from input to allow "viola"-mode
- */
-static Byte pitch_byte_a[ 7 ] = { 0, 2, 4, 5, 7, 9, 11 };
-
-int
-Melodic_req::pitch() const
-{
- return pitch_byte_a[ notename_i_ % 7 ] + accidental_i_ + octave_i_ * 12;
-}
-
-Plet_req::Plet_req()
-{
- type_c_ = ']';
- dur_i_ = 1;
- type_i_ = 1;
-}
-
-void
-Plet_req::do_print() const
-{
- mtor << "plet: " << type_c_ << ": " << dur_i_ << "/" << type_i_;
-}
-
-/* *************** */
-int
-Rhythmic_req::compare(const Rhythmic_req &r1, const Rhythmic_req &r2)
-{
- return sign(r1.duration() - r2.duration());
-}
-Rhythmic_req::Rhythmic_req(int b, int d)
-{
- plet_factor = 1;
- balltype = b;
- dots = d;
-}
-
-Rhythmic_req::Rhythmic_req()
-{
- plet_factor = 1;
- balltype = 1;
- dots = 0;
-}
-
-void
-Rhythmic_req::do_print() const
-{
- mtor << "ball: " << balltype ;
- int d =dots;
- while (d--)
- mtor << '.';
-
- mtor<<", plet factor"<<plet_factor<<"\n";
-}
-
-
-Moment
-Rhythmic_req::duration() const {
- return wholes(balltype,dots)*plet_factor;
-}
-/* *************** */
-
-Lyric_req::Lyric_req(Text_def* def_p)
- :Text_req(0, def_p)
-{
- def_p->align_i_ = 0; // centre
- dir_i_ = -1; // lyrics below (invisible) staff
-}
-
-void
-Lyric_req::do_print() const
-{
- Rhythmic_req::do_print();
- Text_req::do_print();
-}
-/* *************** */
-void
-Note_req::do_print() const
-{
- Melodic_req::do_print();
- Rhythmic_req::do_print();
-}
-/* *************** */
-void
-Rest_req::do_print() const
-{
- Rhythmic_req::do_print();
-}
-
-/* *************** */
-Beam_req::Beam_req()
-{
- nplet = 0;
-}
-
-void Beam_req::do_print()const{}
-/* *************** */
-void Slur_req::do_print()const{}
-/* *************** */
-int
-Span_req:: compare(const Span_req &r1, const Span_req &r2)
-{
- return r1.spantype - r2.spantype;
-}
-
-Span_req::Span_req()
-{
- spantype = NOSPAN;
-}
-
-/* *************** */
-Script_req::Script_req(int d , Script_def*def)
-{
- dir_i_ = d;
- scriptdef_p_ = def;
-}
-
-int
-Script_req::compare(const Script_req &d1, const Script_req &d2)
-{
- return d1.dir_i_ == d2.dir_i_ &&
- d1.scriptdef_p_->compare(*d2.scriptdef_p_);
-}
-
-Script_req::Script_req(Script_req const &s)
- : Request( s )
-{
- dir_i_ = s.dir_i_;
- scriptdef_p_ = new Script_def(*s.scriptdef_p_);
-}
-
-void
-Script_req::do_print() const
-{
- mtor << " dir " << dir_i_ ;
- scriptdef_p_->print();
-}
-
-
-Script_req::~Script_req()
-{
- delete scriptdef_p_;
-}
-/* *************** */
-int
-Text_req:: compare(const Text_req &r1, const Text_req &r2)
-{
- bool b1 = (r1.dir_i_ == r2.dir_i_);
- bool b2 = (r1.tdef_p_ ->compare(*r2.tdef_p_));
- return b1 && b2;
-}
-Text_req::~Text_req()
-{
- delete tdef_p_;
- tdef_p_ = 0;
-}
-
-Text_req::Text_req(Text_req const& src)
-{
- tdef_p_ = new Text_def(*src.tdef_p_);
- dir_i_ = src.dir_i_;
-}
-
-Text_req::Text_req(int dir_i, Text_def* tdef_p)
-{
- dir_i_ = dir_i;
- tdef_p_ = tdef_p;
-}
-
-void
-Text_req::do_print() const
-{
- mtor << " dir " << dir_i_ ;
- tdef_p_->print();
-}
-
-/* *************** */
-
-Moment
-Skip_req::duration() const
-{
- return duration_;
-}
-
-void
-Skip_req::do_print() const
-{
- mtor << "duration: " << duration();
-}
-
-Voice *
-Request::voice_l()
-{
- if (!elt_l_)
- return 0;
- else
- return (Voice*)elt_l_->voice_l_;
-}
+++ /dev/null
-#include "rest.hh"
-#include "dimen.hh"
-#include "debug.hh"
-#include "paper-def.hh"
-#include "lookup.hh"
-#include "molecule.hh"
-
-
-Rest::Rest(int t, int d)
-{
- balltype = t;
- dots = d;
-}
-
-
-void
-Rest::do_print()const
-{
-#ifndef NPRINT
- mtor << "Rest "<<balltype<< "dots " << dots;
- Item::print();
-#endif
-}
-
-Molecule*
-Rest::brew_molecule_p()const
-{
- Paper_def *p =paper();
-
- Symbol s;
- s = p->lookup_p_->rest(balltype);
-
- Molecule *m = new Molecule(Atom(s));
- if (dots) {
- Symbol d =p->lookup_p_->dots(dots);
- Molecule dm;
- dm.add(Atom(d));
- m->add_right(dm);
- }
- return m;
-}
-
+++ /dev/null
-/*
- score-column.cc -- implement Score_column
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-#include "debug.hh"
-#include "pcol.hh"
-#include "score-column.hh"
-
-int
-Score_column::compare(Score_column & c1, Score_column &c2)
-{
- return sign(c1.when_ - c2.when_);
-}
-
-void
-Score_column::set_breakable()
-{
- pcol_l_->set_breakable();
-}
-
-Score_column::Score_column(Moment w)
-{
- when_ = w;
- pcol_l_ = new PCol(0);
- musical_b_ = false;
-}
-
-bool
-Score_column::used_b() {
- return pcol_l_->used_b();
-}
-
-void
-Score_column::print() const
-{
-#ifndef NPRINT
- mtor << "Score_column { mus "<< musical_b_ <<" at " << when_<<'\n';
- mtor << "durations: [";
- for (int i=0; i < durations.size(); i++)
- mtor << durations[i] << " ";
- mtor << "]\n";
- pcol_l_->print();
- mtor << "}\n";
-#endif
-}
-
-int
-Moment_compare(Moment &a , Moment& b)
-{
- return sign(a-b);
-}
-
-void
-Score_column::preprocess()
-{
- durations.sort(Moment_compare);
-}
-void
-Score_column::add_duration(Moment d)
-{
- assert(d);
- for (int i = 0; i< durations.size(); i++) {
- if (d == durations[i])
- return ;
- }
- durations.push(d);
-}
-
-bool
-Score_column::breakable_b()
-{
- return pcol_l_->breakable_b();
-}
+++ /dev/null
-/*
- score-walker.cc -- implement Score_walker
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-#include "debug.hh"
-#include "plist.hh"
-#include "score-walker.hh"
-#include "score.hh"
-#include "staff-walker.hh"
-#include "staff.hh"
-#include "score-column.hh"
-
-Score_walker::Score_walker(Score *s)
- :PCursor<Score_column *> (s->cols_)
-{
- score_l_ = s;
- for (iter_top(s->staffs_,i); i.ok(); i++) {
- Staff_walker* w_p=i->get_walker_p();
- w_p->score_walk_l_ =this;
- walker_p_arr_.push(w_p);
- }
-
- if(ok()) {
- s->find_col(0, false)->set_breakable();
- s->find_col(s->last(), false)->set_breakable();
- }
- reinit();
-}
-
-
-void
-Score_walker::reinit()
-{
- disallow_break_walk_l_arr = walker_p_arr_;
- disallow_break_count_ = disallow_break_walk_l_arr.size();
-}
-
-
-/** Advance the cursor, and all Staff_walkers contained in this. Reset
- runtime fields */
-void
-Score_walker::operator ++(int )
-{
- Moment last = ptr()->when();
-
- PCursor<Score_column *>::operator++(0);
- if (ok() && ptr()->when() == last)
- PCursor<Score_column *>::operator++(0);
- reinit();
- if (!ok())
- return;
- for (int i=0; i< walker_p_arr_.size(); i++) {
- if (walker_p_arr_[i]->ok() &&
- walker_p_arr_[i]->when() < when()) {
-
- walker_p_arr_[i]->operator++(0);
- }
- }
-}
-
-/** Allow the command_column to be breakable for one staff. If all
- staffs allow, then allow a break here. */
-void
-Score_walker::allow_break(Staff_walker*w)
-{
- for (int i=0; i < disallow_break_walk_l_arr.size(); i++) {
- if (w == disallow_break_walk_l_arr[i]) {
- disallow_break_count_ --;
- disallow_break_walk_l_arr[i] =0;
-
- if (!disallow_break_count_) {
- PCursor<Score_column*> col_cursor = *this;
- if (ptr()->musical_b())
- col_cursor --;
- col_cursor->set_breakable();
- }
- }
- }
-}
-
-Moment
-Score_walker::when()
-{
- return ptr()->when();
-}
-
-void
-Score_walker::process()
-{
- for (int i=0; i < walker_p_arr_.size(); i++) {
- Staff_walker *w = walker_p_arr_[i];
- if ( w->ok() && w->when() == when() ) {
- walker_p_arr_[i]->process();
- }
- }
- if (when().denominator() == 1) {
- *mlog << "." <<flush;
- }
-}
-
-Score_walker::~Score_walker()
-{
- for (int i=0; i < walker_p_arr_.size(); i++)
- delete walker_p_arr_[i];
- assert( !score_l_->find_col(score_l_->last(), true)->used_b());
-}
-
-
+++ /dev/null
-/*
- score.cc -- implement Score
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-#include "tex-stream.hh"
-#include "score.hh"
-#include "score-column.hh"
-#include "pscore.hh"
-#include "staff.hh"
-#include "debug.hh"
-#include "paper-def.hh"
-#include "main.hh"
-#include "source.hh"
-#include "source-file.hh"
-#include "score-walker.hh"
-#include "midi-output.hh"
-#include "midi-def.hh"
-
-extern String default_out_fn;
-
-void
-Score::setup_music()
-{
- *mlog << "\nSetting up music ..." << flush;
- if (last() == Moment(0)) {
- errorlevel_i_ |= 1;
- error("Need to have music in a score.", defined_ch_c_l_);
- }
-
- for (iter_top(staffs_,i); i.ok(); i++) {
- i->setup_staffcols();
- i->OK();
- }
-}
-
-void
-Score::process_music()
-{
- *mlog << "Processing music ..." << flush;
- for (Score_walker w(this); w.ok(); w++) {
- w.process();
- }
-}
-
-void
-Score::process()
-{
- setup_music();
-
- paper();
- midi();
-}
-
-void
-Score::paper()
-{
- if (!paper_p_)
- return;
-
- pscore_p_ = new PScore(paper_p_);
-
- find_col(0, false)->set_breakable(); // ugh
- find_col(last(), false)->set_breakable();
- do_cols();
-
- for (iter_top(staffs_,i); i.ok(); i++)
- i->set_output(pscore_p_);
-
-
- process_music();
- clean_cols(); // can't move clean_cols() farther up.
- print();
- calc_idealspacing();
-
- // debugging
- OK();
- *mlog << endl;
- pscore_p_->process();
-
- // output
- paper_output();
-
-}
-
-/**
- Remove empty cols, preprocess other columns.
- */
-void
-Score::clean_cols()
-{
- for (iter_top(staffs_,i); i.ok(); i++)
- i->clean_cols();
-
- for (iter_top(cols_,c); c.ok(); ) {
- if (!c->pcol_l_->used_b()) {
- delete c.get_p();
- } else {
- c->preprocess();
- c++;
- }
- }
-}
-
-/**
- Create columns at time #w#.
- this sux. We should have Score_column create the appropriate PCol.
- Unfortunately, PCols don't know about their position.
-
- @return cursor pointing to the nonmusical (first) column
- */
-PCursor<Score_column*>
-Score::create_cols(Moment w)
-{
- Score_column* c1 = new Score_column(w);
- Score_column* c2 = new Score_column(w);
-
- c1->musical_b_ = false;
- c2->musical_b_ = true;
-
- iter_top(cols_,i);
-
- for (; i.ok(); i++) {
- assert(i->when() != w);
- if (i->when() > w)
- break;
- }
-
- if (!i.ok()) {
- cols_.bottom().add(c1);
- cols_.bottom().add(c2);
- i = cols_.bottom();
- i --;
- } else {
- i.insert(c1);
- i.insert(c2);
- i -= 2;
- }
- return i;
-}
-
-PCursor<Score_column*>
-Score::find_col(Moment w, bool mus)
-{
- iter_top( cols_,i);
-
- for (; i.ok(); i++) {
- if (i->when() == w && i->musical_b_ == mus)
- return i;
- if (i->when() > w)
- break;
- }
- i = create_cols(w);
- if (mus)
- i++;
- return i;
-}
-
-void
-Score::do_cols()
-{
- iter_top(cols_,i);
- for (; i.ok(); i++) {
- pscore_p_->add(i->pcol_l_);
- }
-}
-
-Moment
-Score::last() const
-{
- Moment l = 0;
- for (iter_top(staffs_,i); i.ok(); i++) {
- l = l>? i->last();
- }
- return l;
-}
-
-void
-Score::set(Paper_def *pap_p)
-{
- delete paper_p_;
- paper_p_ = pap_p;
-}
-
-void
-Score::set(Midi_def* midi_p)
-{
- delete midi_p_;
- midi_p_ = midi_p;
-}
-
-void
-Score::OK() const
-{
-#ifndef NDEBUG
- for (iter_top(staffs_,i); i.ok(); i++) {
- i->OK();
- assert(i->score_l_ == this);
- }
- staffs_.OK();
- cols_.OK();
- for (iter_top(cols_,cc); cc.ok() && (cc+1).ok(); cc++) {
- assert(cc->when() <= (cc+1)->when());
- }
-#endif
-}
-
-
-void
-Score::print() const
-{
-#ifndef NPRINT
- mtor << "score {\n";
- for (iter_top(staffs_,i); i.ok(); i++) {
- i->print();
- }
- for (iter_top(cols_,i); i.ok(); i++) {
- i->print();
- }
- if (pscore_p_)
- pscore_p_->print();
- if (midi_p_)
- midi_p_->print();
-
- mtor << "}\n";
-#endif
-}
-
-Score::Score()
-{
- pscore_p_=0;
- paper_p_ = 0;
- midi_p_ = 0;
- errorlevel_i_ = 0;
- defined_ch_c_l_ = 0;
-}
-
-Score::~Score()
-{
- delete pscore_p_;
- delete paper_p_;
- delete midi_p_;
-}
-
-void
-Score::paper_output()
-{
- OK();
- if (paper_p_->outfile=="")
- paper_p_->outfile = default_out_fn + ".out";
-
- if ( errorlevel_i_ ) {
- *mlog << "lilypond: warning: no output to: " << paper_p_->outfile
- << " (errorlevel=" << errorlevel_i_ << ")" << endl;
- return;
- }
-
- *mlog << "TeX output to " << paper_p_->outfile << " ...\n";
-
- Tex_stream the_output(paper_p_->outfile);
-
- the_output << "% outputting Score, defined at: " <<
- source_l_g->
- sourcefile_l (defined_ch_c_l_)->file_line_no_str(defined_ch_c_l_) << "\n";
- pscore_p_->output(the_output);
-}
-
-void
-Score::midi()
-{
- if (!midi_p_)
- return;
-
- if (midi_p_->outfile_str_ == "")
- midi_p_->outfile_str_ = default_out_fn + ".midi";
-
- *mlog << "midi output to " << midi_p_->outfile_str_ << " ...\n";
- Midi_output(this, midi_p_);
-}
-
-void
-Score::add(Staff*s)
-{
- s->score_l_ = this;
- staffs_.bottom().add(s);
-}
+++ /dev/null
-#include "scoreline.hh"
-#include "staffline.hh"
-#include "dimen.hh"
-#include "spanner.hh"
-#include "symbol.hh"
-#include "paper-def.hh"
-#include "pcol.hh"
-#include "pscore.hh"
-
-
-String
-Line_of_score::TeXstring() const
-{
- String s("\\vbox{%<- line of score\n");
- for (iter_top(staffs,sc); sc.ok(); sc++){
- s += sc->TeXstring();
- if ((sc+1).ok())
- s+= "\\interstaffline\n";
- }
- s += "}";
- return s;
-}
-
-
-Line_of_score::Line_of_score(Array<PCol *> sv,
- PScore *ps)
-{
- pscore_l_ = ps;
- for (int i=0; i< sv.size(); i++) {
- PCol *p=(PCol *) sv[i];
- cols.bottom().add(p);
- p->line_l_=this;
- }
-
- for (iter_top(pscore_l_->staffs,sc); sc.ok(); sc++)
- staffs.bottom().add(new Line_of_staff(this, sc));
-}
-/* construct a line with the named columns. Make the line field
- in each column point to this
-
- #sv# isn't really const!!
- */
-
-
-void
-Line_of_score::process()
-{
- for (iter_top(staffs,i); i.ok(); i++)
- i->process();
-}
-
+++ /dev/null
-#include "main.hh"
-#include "input-score.hh"
-#include "score.hh"
-#include "string.hh"
-#include "paper-def.hh"
-#include "debug.hh"
-
-static Array<Input_score*> score_array_global;
-String default_out_fn = "lelie";
-
-void
-do_scores()
-{
- for (int i=0; i < score_array_global.size(); i++) {
- Input_score* &is_p = score_array_global[i];
- if (is_p->errorlevel_i_) {
- warning("Score contains errors. Will not process it. ",
- is_p->defined_ch_c_l_);
- delete is_p;
- continue;
- }
-
- if (only_midi) {
- delete is_p->paper_p_;
- is_p->paper_p_ = 0;
- }
-
- Score * s_p = is_p->parse();
- delete is_p;
- s_p->print ();
- s_p->process();
- delete s_p;
- }
- score_array_global.set_size(0);
-}
-
-void
-add_score(Input_score * s)
-{
- score_array_global.push(s);
-}
-
-void
-set_default_output(String s)
-{
- default_out_fn = s;
-}
-
+++ /dev/null
-#include "debug.hh"
-#include "script-def.hh"
-
-Script_def::Script_def(String idx, int stem, int staff ,bool invert)
-{
- symidx = idx ;
- stemdir =stem;
- staffdir = staff;
- invertsym = invert;
-}
-void
-Script_def::print() const
-{
- mtor << "Script_def{ idx: " << symidx
- << " direction, stem: " << stemdir << " staff : " << staffdir << "}\n";
-}
-int
-Script_def::compare(Script_def const & c)
-{
- return !(symidx == c.symidx &&
- stemdir == c.stemdir&&
- staffdir == c.staffdir&&
- invertsym == c.invertsym);
-}
+++ /dev/null
-/*
- script-reg.cc -- implement Script_register
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-#include "script-reg.hh"
-#include "script.hh"
-#include "musicalrequest.hh"
-#include "complex-walker.hh"
-#include "stem.hh"
-
-Script_register::Script_register()
-{
- script_p_ = 0;
- post_move_processing();
-}
-
-bool
-Script_register::try_request(Request *r_l)
-{
- if (!r_l->script())
- return false ;
-
- if (script_req_l_
- && Script_req::compare(*script_req_l_, *r_l->script()))
-
- return false;
-
- script_req_l_ = r_l->script();
-
- return true;
-}
-
-void
-Script_register::process_requests()
-{
- if (script_req_l_) {
- script_p_ = new Script(script_req_l_, 10);
- announce_element(
- Staff_elem_info(script_p_, script_req_l_));
- }
-}
-
-void
-Script_register::acknowledge_element(Staff_elem_info info)
-{
- if (!script_p_)
- return;
- if (info.elem_p_->name() == Stem::static_name())
- script_p_->set_stem((Stem*)info.elem_p_);
- else if (info.req_l_->rhythmic())
- script_p_->set_support(info.elem_p_->item());
-}
-
-void
-Script_register::pre_move_processing()
-{
- if (script_p_){
- script_p_->dir = dir_i_;
- typeset_element(script_p_);
- script_p_ = 0;
- }
-}
-void
-Script_register::post_move_processing()
-{
- script_req_l_ = 0;
-}
-
-void
-Script_register::set_feature(Features i)
-{
- if (i.direction_i_|| i.initialiser_b_)
- dir_i_ = i.direction_i_;
-}
+++ /dev/null
-#include "musicalrequest.hh"
-#include "paper-def.hh"
-#include "script.hh"
-#include "stem.hh"
-#include "molecule.hh"
-#include "lookup.hh"
-
-
-
-void
-Script::set_stem(Stem*st_l)
-{
- stem_l_ = st_l;
- add_dependency(st_l);
-}
-
-void
-Script::set_support(Item*i)
-{
- support.push(i);
- add_dependency(i);
-}
-
-Script::Script(Script_req* rq, int staflen)
-{
- staffsize =staflen;
- specs_l_ = rq->scriptdef_p_;
- stem_l_ = 0;
- pos = 0;
- symdir=1;
- dir =rq->dir_i_;
-}
-
-void
-Script::set_symdir()
-{
- if (specs_l_->invertsym)
- symdir = (dir < 0) ? -1:1;
-}
-
-void
-Script::set_default_dir()
-{
- if (specs_l_->stemdir) {
- if (!stem_l_)
- dir = 1;
- else
- dir = stem_l_->dir * specs_l_->stemdir;
- }
-}
-
-Interval
-Script::support_height() const return r;
-{
- for (int i=0; i < support.size(); i++)
- r.unite(support[i]->height());
-}
-
-void
-Script::set_default_index()
-{
- Real inter_f= paper()->internote();
- Interval dy = symbol().dim.y;
-
- int d = specs_l_->staffdir;
- Real y ;
- if (!d) {
- Interval v= support_height();
- y = v[dir] -dy[-dir] + 2*dir*inter_f;
- } else {
- y = (d > 0) ? staffsize + 2: -2; // ug
- y *=inter_f;
- Interval v= support_height();
-
- if (d > 0) {
- y = y >? v.max();
- } else if (d < 0) {
- y = y <? v.min();
- }
- }
-
- if (stem_l_) {
- Interval v= stem_l_->height();
-
- if (d > 0 || (!d && dir > 0)) {
- y = y >? v.max();
- }else if (d < 0 || (!d && dir < 0)) {
- y = y <? v.min();
- }
- }
-
- pos = int(rint(Real(y)/inter_f));
-}
-
-Interval
-Script::width() const
-{
- return symbol().dim.x;
-}
-
-Symbol
-Script::symbol()const
-{
- String preidx_str = (symdir < 0) ?"-" :"";
- return paper()->lookup_p_->script(preidx_str + specs_l_->symidx);
-}
-
-void
-Script::do_pre_processing()
-{
- set_default_dir();
- set_symdir();
-}
-
-void
-Script::do_post_processing()
-{
- set_default_index();
-}
-
-Molecule*
-Script::brew_molecule_p() const
-{
- Real dy = paper()->internote();
-
- Molecule*out = new Molecule(Atom(symbol()));
- out->translate(Offset(0,dy * pos));
- return out;
-}
+++ /dev/null
-/*
- slur-reg.cc -- implement Slur_register
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-#include "plist.hh"
-#include "musicalrequest.hh"
-#include "complex-walker.hh"
-#include "slur-reg.hh"
-#include "slur.hh"
-#include "debug.hh"
-#include "notehead.hh"
-
-void
-Slur_register::set_feature(Features i)
-{
- dir_i_ = i.direction_i_;
-}
-
-Slur_register::Slur_register()
-{
- set_feature(Features::dir(0));
-}
-
-bool
-Slur_register::try_request(Request *req_l)
-{
- if(!req_l->slur())
- return false;
-
- new_slur_req_l_arr_.push(req_l->slur());
- return true;
-}
-
-void
-Slur_register::acknowledge_element(Staff_elem_info info)
-{
- if (info.elem_p_->name() == Notehead::static_name()) {
- Notehead *head_p =(Notehead*) info.elem_p_ ;// ugh
- for (int i = 0; i < slur_l_stack_.size(); i++)
- slur_l_stack_[i]->add(head_p );
- for (int i = 0; i < end_slur_l_arr_.size(); i++)
- end_slur_l_arr_[i]->add(head_p);
- }
-}
-/*
- abracadabra
- */
-void
-Slur_register::process_requests()
-{
- Array<Slur*> start_slur_l_arr_;
- for (int i=0; i< new_slur_req_l_arr_.size(); i++) {
- Slur_req* slur_req_l = new_slur_req_l_arr_[i];
- // end slur: move the slur to other array
- if (slur_req_l->spantype == Span_req::STOP) {
- if (slur_l_stack_.empty())
- warning("can't find slur to end",
- slur_req_l->defined_ch_c_l_);
- else {
- end_slur_l_arr_.push(slur_l_stack_.pop());
- requests_arr_.pop();
- }
- } else if (slur_req_l->spantype == Span_req::START) {
- // push a new slur onto stack.
- //(use temp. array to wait for all slur STOPs)
- Slur * s_p =new Slur;
- requests_arr_.push(slur_req_l);
- start_slur_l_arr_.push(s_p);
- announce_element(Staff_elem_info(s_p, slur_req_l));
- }
- }
- for (int i=0; i < start_slur_l_arr_.size(); i++)
- slur_l_stack_.push(start_slur_l_arr_[i]);
-}
-
-void
-Slur_register::pre_move_processing()
-{
- for (int i = 0; i < end_slur_l_arr_.size(); i++) {
- if (dir_i_)
- end_slur_l_arr_[i]->dir_i_ = dir_i_;
- typeset_element(end_slur_l_arr_[i]);
- }
- end_slur_l_arr_.set_size(0);
-}
-
-void
-Slur_register::post_move_processing()
-{
- new_slur_req_l_arr_.set_size(0);
-}
-Slur_register::~Slur_register()
-{
- for (int i=0; i < requests_arr_.size(); i++) {
- warning("unterminated slur", requests_arr_[i]->defined_ch_c_l_);
- }
-}
+++ /dev/null
-/*
-
- TODO:
- think about crossing stems.
- */
-#include "slur.hh"
-#include "scalar.hh"
-#include "lookup.hh"
-#include "paper-def.hh"
-#include "notehead.hh"
-#include "pcol.hh"
-#include "molecule.hh"
-#include "debug.hh"
-#include "boxes.hh"
-
-
-
-Slur::Slur()
-{
- open_right=open_left=false;
-}
-
-Offset
-Slur::center() const
-{
- int pos1 = encompass.top()->position;
- int pos2 = encompass[0]->position;
-
- int dy = pos1-pos2;
-
- Real w = width().length();
-
- return Offset(w/2,dy * paper()->internote());
-}
-
-void
-Slur::add(Notehead*n)
-{
- encompass.push(n);
- add_dependency(n);
-}
-
-void
-Slur::set_default_dir()
-{
- int sumpos=0;
- for (int i=0; i < encompass.size(); i ++) {
- sumpos += encompass[i]->position;
- }
-
- /* should consult stems */
- Real meanpos = sumpos/Real(encompass.size());
- if (meanpos < 5) // todo
- dir_i_ = -1;
- else
- dir_i_ = 1;
-}
-
-void
-Slur::do_pre_processing()
-{
- right = encompass.top()->pcol_l_;
- left = encompass[0]->pcol_l_;
-}
-
-Spanner*
-Slur::do_break_at(PCol*l, PCol*r) const
-{
- assert(l->line_l_ == r->line_l_);
- Slur*ret = new Slur(*this);
-
- ret->encompass.set_size(0);
- for (int i =0; i < encompass.size(); i++) {
- if (encompass[i]->pcol_l_->line_l_==l->line_l_)
- ret->encompass.push(encompass[i]);
- }
- if (right != r)
- ret->open_right = true;
- if (left != l)
- ret->open_left = true;
-
-
- return ret;
-}
-
-void
-Slur::do_post_processing()
-{
- if (!dir_i_)
- set_default_dir();
-}
-
-Molecule*
-Slur::brew_molecule_p() const
-{
- Molecule*output = new Molecule;
-
- int minp=1000, maxp=-1000; // todo
- for (int i=0; i<encompass.size(); i++) {
- minp = encompass[i]->position <? minp;
- maxp = encompass[i]->position >? maxp;
- }
- assert(encompass.size()>0); // todo
-
- Notehead *lnote_p =encompass[0];
- Notehead *rnote_p =encompass.top();
- int lpos_i = lnote_p->position;
- int rpos_i = rnote_p->position;
- Offset left_off(lnote_p->x_dir, lpos_i + 2*dir_i_);
- Offset right_off(lnote_p->x_dir, rpos_i + 2*dir_i_);
- if (!lnote_p->extremal)
- left_off += Offset(0.5, -dir_i_);
- if (!rnote_p->extremal)
- right_off+= Offset(-0.5, -dir_i_);
-
- int dy = int(right_off.y - left_off.y);
-
- Real nw_f = paper()->note_width();
- Real nh_f = paper()->internote();
- Real w = width().length();
-
- w+= (right_off.x - left_off.x) * nw_f ;
- Real round_w = w; // slur lookup rounds the slurwidth .
-
- Symbol sl = paper()->lookup_p_->slur(dy , round_w, dir_i_);
-
- Real error = w-round_w;
-
- Atom a(sl);
- a.translate(Offset((left_off.x + 0.5 )*nw_f + error/2,
- left_off.y * nh_f));
- output->add(a);
- return output;
-}
-
+++ /dev/null
-//
-// source-file.cc
-//
-
-#include <sys/types.h> // open, mmap
-#include <sys/stat.h> // open
-#include <sys/mman.h> // mmap
-#include <limits.h> // INT_MAX
-#include <fcntl.h> // open
-#include <unistd.h> // close, stat
-#include <stdio.h> // fdopen
-#include <string.h> // strerror
-#include <errno.h> // errno
-#include <assert.h>
-#include <strstream.h>
-
-#include "string.hh"
-#include "proto.hh"
-#include "plist.hh"
-#include "lexer.hh"
-#include "debug.hh"
-#include "parseconstruct.hh"
-#include "main.hh" // find_file
-
-#include "source-file.hh"
-
-Source_file::Source_file( String &filename_str )
-{
- data_caddr_ = 0;
- fildes_i_ = 0;
- size_off_ = 0;
- name_str_ = filename_str;
- istream_p_ = 0;
-
- open();
- map();
- // ugh!?, should call name_str() !
- filename_str = name_str_;
-}
-
-Source_file::~Source_file()
-{
- delete istream_p_;
- istream_p_ = 0;
- unmap();
- close();
-}
-
-char const*
-Source_file::ch_c_l()
-{
- assert( this );
- return (char const*)data_caddr_;
-}
-
-void
-Source_file::close()
-{
- if ( fildes_i_ ) {
- ::close( fildes_i_ );
- fildes_i_ = 0;
- }
-}
-
-String
-Source_file::error_str( char const* pos_ch_c_l )
-{
- assert( this );
- if ( !in_b( pos_ch_c_l ) )
- return "";
-
- char const* begin_ch_c_l = pos_ch_c_l;
- char const* data_ch_c_l = ch_c_l();
- while ( begin_ch_c_l > data_ch_c_l )
- if ( *--begin_ch_c_l == '\n' ) {
- begin_ch_c_l++;
- break;
- }
-
- char const* end_ch_c_l = pos_ch_c_l;
- while ( end_ch_c_l < data_ch_c_l + size_off_ )
- if ( *end_ch_c_l++ == '\n' ) {
- break;
- }
- end_ch_c_l--;
-
-#if 1
-// String( char const* p, int length ) is missing!?
- String line_str( (Byte const*)begin_ch_c_l, end_ch_c_l - begin_ch_c_l );
-#else
- int length_i = end_ch_c_l - begin_ch_c_l;
- char* ch_p = new char[ length_i + 1 ];
- strncpy( ch_p, begin_ch_c_l, length_i );
- ch_p[ length_i ] = 0;
- String line_str( ch_p );
- delete ch_p;
-#endif
-
- int error_col_i = 0;
- char const* scan_ch_c_l = begin_ch_c_l;
- while ( scan_ch_c_l < pos_ch_c_l )
- if ( *scan_ch_c_l++ == '\t' )
- error_col_i = ( error_col_i / 8 + 1 ) * 8;
- else
- error_col_i++;
-
- String str = line_str.left_str( pos_ch_c_l - begin_ch_c_l )
- + String( '\n' )
- + String( ' ', error_col_i )
- + line_str.mid_str( pos_ch_c_l - begin_ch_c_l + 1, INT_MAX ); // String::mid should take 0 arg..
- return str;
-}
-
-bool
-Source_file::in_b( char const* pos_ch_c_l )
-{
- return ( pos_ch_c_l && ( pos_ch_c_l >= ch_c_l() ) && ( pos_ch_c_l < ch_c_l() + size_off_ ) );
-}
-
-istream*
-Source_file::istream_l()
-{
- assert( fildes_i_ );
- if ( !istream_p_ ) {
- if ( size_off_ ) // can-t this be done without such a hack?
- istream_p_ = new istrstream( ch_c_l(), size_off_ );
- else {
- istream_p_ = new istrstream( "", 0 );
- istream_p_->set(ios::eofbit);
- }
- }
- return istream_p_;
-}
-
-off_t
-Source_file::length_off()
-{
- return size_off_;
-}
-
-int
-Source_file::line_i( char const* pos_ch_c_l )
-{
- if ( !in_b( pos_ch_c_l ) )
- return 0;
-
- int i = 1;
- char const* scan_ch_c_l = ch_c_l();
- while ( scan_ch_c_l < pos_ch_c_l )
- if ( *scan_ch_c_l++ == '\n' )
- i++;
- return i;
-}
-
-void
-Source_file::map()
-{
- if ( fildes_i_ == -1 )
- return;
-
- data_caddr_ = (caddr_t)mmap( (void*)0, size_off_, PROT_READ, MAP_SHARED, fildes_i_, 0 );
-
- if ( (int)data_caddr_ == -1 )
- // ugh: defined_ch_c_l...
- warning( String( "can't map: " ) + name_str_ + String( ": " ) + strerror( errno ), defined_ch_c_l ); //lexer->here_ch_c_l() );
-}
-
-String
-Source_file::name_str()
-{
- return name_str_;
-}
-
-void
-Source_file::open()
-{
- String name_str = find_file( name_str_ );
- if ( name_str != "" )
- name_str_ = name_str;
-
- fildes_i_ = ::open( name_str_, O_RDONLY );
-
- if ( fildes_i_ == -1 ) {
- warning( String( "can't open: " ) + name_str_ + String( ": " ) + strerror( errno ), defined_ch_c_l ); // lexer->here_ch_c_l() );
- return;
- }
-
- struct stat file_stat;
- fstat( fildes_i_, &file_stat );
- size_off_ = file_stat.st_size;
-}
-
-void
-Source_file::unmap()
-{
- if ( data_caddr_ ) {
- munmap( data_caddr_, size_off_ );
- data_caddr_ = 0;
- size_off_ = 0;
- }
-}
-String
-Source_file::file_line_no_str(char const *ch_c_l )
-{
- return name_str() + ": "
- + String( line_i( ch_c_l ) );
-}
+++ /dev/null
-//
-// source.cc
-//
-
-#include <assert.h>
-
-#include "string.hh"
-#include "proto.hh"
-#include "plist.hh"
-
-#include "source-file.hh"
-#include "source.hh"
-
-Source::Source()
-{
-}
-
-Source::~Source()
-{
-}
-
-void
-Source::add( Source_file* sourcefile_p )
-{
- sourcefile_p_iplist_.bottom().add( sourcefile_p );
-}
-
-Source_file*
-Source::sourcefile_l( char const* ch_c_l )
-{
- PCursor<Source_file*> sourcefile_l_pcur( sourcefile_p_iplist_.top() );
- for ( ; sourcefile_l_pcur.ok(); sourcefile_l_pcur++ )
- if ( sourcefile_l_pcur->in_b( ch_c_l ) )
- return *sourcefile_l_pcur;
- return 0;
-}
+++ /dev/null
-#include "debug.hh"
-#include "spanner.hh"
-#include "pcol.hh"
-
-
-
-void
-Spanner::do_print()const
-{
- mtor << " (unknown) ";
-}
-
-Spanner*
-Spanner::broken_at(PCol*c1, PCol *c2)const
-{
- Spanner *span_p = do_break_at(c1,c2);
-
- for (int i=0; i < dependants.size(); i++) {
- dependants[i]->substitute_dependency((Staff_elem*)this, span_p);
- }
-
- span_p->left = c1;
- span_p->right = c2;
-
- return span_p;
-}
-
-Spanner::Spanner()
-{
- left = right = 0;
-}
-
-
-Interval
-Spanner::width()const
-{
- Real r = right->hpos;
- Real l = left->hpos;
- assert(*left < *right);
- assert(r>=l);
-
- return Interval(0, r-l);
-}
+++ /dev/null
-/*
- staff-column.cc -- implement Staff_column
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-#include "staff.hh"
-#include "voice.hh"
-#include "time-description.hh"
-#include "score-column.hh"
-#include "staff-column.hh"
-#include "commandrequest.hh"
-#include "musicalrequest.hh"
-#include "interval.hh"
-#include "pscore.hh"
-#include "item.hh"
-#include "pcol.hh"
-#include "voice-element.hh"
-
-void
-Staff_column::OK() const
-{
-#ifndef NDEBUG
- assert (command_column_l_->when() == musical_column_l_->when());
-#endif
-}
-
-Moment
-Staff_column::when() const
-{
- return (command_column_l_)?
- command_column_l_->when():
- musical_column_l_->when();
-}
-
-void
-Staff_column::add(Voice_element*ve)
-{
- for (iter_top(ve->reqs,j); j.ok(); j++) {
- if (j->command()) {
- Command_req * c_l = j->command();
- if (c_l->timing()) {
- timing_req_l_arr_.push(j->command()->timing());
- }
- if (c_l->groupchange())
- creationreq_l_arr_.push(c_l);
- else if (!c_l->barcheck() && !c_l->partial() &&
- !c_l->measuregrouping())
- setup_one_request(j); // no need to bother children
- } else {
- if (j->rhythmic()) {
- musical_column_l_->add_duration(j->rhythmic()->duration());
- }
- if (!j->musical()->skip())
- setup_one_request(j);
- }
- }
-}
-
-Staff_column::Staff_column()
-{
- musical_column_l_ = 0;
- command_column_l_ = 0;
- staff_l_ = 0;
-}
-
-
-
-
-Staff_column::~Staff_column()
-{
-}
-
-void
-Staff_column::set_cols(Score_column*c1, Score_column*c2)
-{
- command_column_l_ = c1;
- musical_column_l_ = c2;
-}
-
-void
-Staff_column::setup_one_request(Request * j)
-{
- if (j->command()) // ugh
- commandreq_l_arr_.push(j);
- else if (j->musical())
- musicalreq_l_arr_.push(j);
-}
-
-void
-Staff_column::typeset_musical_item(Item*i)
-{
- assert(i);
- Score_column * scorecolumn_l = musical_column_l_;
- musical_column_l_->pcol_l_->pscore_l_->typeset_item(i, scorecolumn_l->pcol_l_,
- staff_l_->pstaff_l_);
-}
-
-/**
- align items in #item_l_arr#,
-
- @return the width of the items after aligning.
- */
-Interval
-align_items(Array<Item*> item_l_arr)
-{
- Interval wid(0,0);
- for (int i =0; i < item_l_arr.size(); i++) {
- Interval item_width= item_l_arr[i]->width();
- Real dx =wid.right - item_width.left;
- item_width += dx;
- item_l_arr[i]->translate(Offset(dx ,0));
- wid.unite(item_width);
- }
- return wid;
-}
-
-void
-translate_items(Real x, Array<Item*> item_l_arr)
-{
- for (int i =0; i < item_l_arr.size(); i++)
- item_l_arr[i]->translate(Offset(x, 0));
-}
-/*
- UGR
- This still sux
- */
-void
-Staff_column::typeset_breakable_items(Array<Item *> &pre_p_arr,
- Array<Item *> &nobreak_p_arr,
- Array<Item *> &post_p_arr)
-{
- PCol * c= command_column_l_->pcol_l_;
- PScore *ps_l=command_column_l_->pcol_l_->pscore_l_;
-
- if (!c->breakable_b()) {
- for (int i =0; i < pre_p_arr.size(); i++)
- delete pre_p_arr[i];
- pre_p_arr.set_size(0);
- for (int i =0; i < post_p_arr.size(); i++)
- delete post_p_arr[i];
- post_p_arr.set_size(0);
- }
-
-
- for (int i =0; i < pre_p_arr.size(); i++) {
- ps_l->typeset_item(pre_p_arr[i], c, staff_l_->pstaff_l_,0);
- }
- for (int i =0; i < nobreak_p_arr.size(); i++) {
- ps_l->typeset_item(nobreak_p_arr[i], c, staff_l_->pstaff_l_,1);
- }
- for (int i =0; i < post_p_arr.size(); i++) {
- ps_l->typeset_item(post_p_arr[i], c, staff_l_->pstaff_l_,2);
- }
-
- Interval pre_wid= align_items(pre_p_arr);
- translate_items( -pre_wid.right, pre_p_arr);
- align_items(nobreak_p_arr);
- Interval post_wid =align_items(post_p_arr);
- translate_items (-post_wid.left , post_p_arr);
-
- pre_p_arr.set_size(0);
- post_p_arr.set_size(0);
- nobreak_p_arr.set_size(0);
-}
+++ /dev/null
-/*
- staff-elem-info.cc -- implement Staff_elem_info
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-#include "staff-elem-info.hh"
-#include "request.hh"
-
-Staff_elem_info::Staff_elem_info(Staff_elem*s_l, Request*r_l)
-{
- elem_p_ = s_l;
- voice_l_ = (r_l)?r_l->voice_l():0;
- req_l_ = r_l;
-}
-
-Staff_elem_info::Staff_elem_info()
-{
- elem_p_ = 0;
- voice_l_ = 0;
-
- req_l_ = 0;
-}
-
-Features::Features()
-{
- direction_i_ = 0;
- initialiser_b_ = false;
-}
-
-Features
-Features::dir(int d) return f;
-{
- f.initialiser_b_ = true;
- f.direction_i_ = d;
-}
+++ /dev/null
-#include "pscore.hh"
-#include "symbol.hh"
-#include "pstaff.hh"
-#include "molecule.hh"
-#include "staff-elem.hh"
-#include "debug.hh"
-
-String
-Staff_elem::TeXstring() const
-{
- Molecule m(*output);
- m.translate(offset_); // ugh?
- return m.TeXstring();
-}
-
-Staff_elem::Staff_elem(Staff_elem const&s)
- : dependants(s.dependants),
- dependencies(s.dependencies)
-{
- status = s.status;
- assert(!s.output);
- output = 0;
- pstaff_l_ = s.pstaff_l_;
- offset_ = Offset(0,0);
-}
-/**
- TODO:
- If deleted, then remove dependants depency!
- */
-Staff_elem::~Staff_elem()
-{
- delete output;
-}
-
-void
-Staff_elem::translate(Offset O)
-{
- offset_ += O;
-}
-Interval
-Staff_elem::width() const
-{
- Interval r;
-
- if (!output){
- Molecule*m = brew_molecule_p();
- r = m->extent().x;
- delete m;
- } else
- r = output->extent().x;
-
- if (!r.empty()) // float exception on DEC Alpha
- r+=offset_.x;
-
- return r;
-}
-Interval
-Staff_elem::height() const
-{
- Interval r;
-
- if (!output){
- Molecule*m = brew_molecule_p();
- r = m->extent().y;
- delete m;
- } else
- r = output->extent().y;
-
- if (!r.empty())
- r+=offset_.y;
-
-
- return r;
-}
-
-void
-Staff_elem::print()const
-{
-#ifndef NPRINT
- mtor << name() << "{\n";
- do_print();
- if (output)
- output->print();
-
- mtor << "}\n";
-#endif
-}
-
-
-
-Staff_elem::Staff_elem()
-{
- pstaff_l_=0;
- offset_ = Offset(0,0);
- output = 0;
- status = ORPHAN;
-}
-
-
-Paper_def*
-Staff_elem::paper() const
-{
- assert(pstaff_l_);
- return pstaff_l_->pscore_l_->paper_l_;
-}
-
-void
-Staff_elem::add_processing()
-{
- if (status >= VIRGIN)
- return;
- status = VIRGIN;
- do_add_processing();
-}
-
-void
-Staff_elem::pre_processing()
-{
- if (status >= PRECALCED )
- return;
- assert(status != PRECALCING); // cyclic dependency
- status = PRECALCING;
-
- for (int i=0; i < dependencies.size(); i++)
- if (dependencies[i])
- dependencies[i]->pre_processing();
-
-
- do_pre_processing();
- status = PRECALCED;
-}
-void
-Staff_elem::post_processing()
-{
- if (status >= POSTCALCED)
- return;
- assert(status != POSTCALCING);// cyclic dependency
- status=POSTCALCING;
-
- for (int i=0; i < dependencies.size(); i++)
- if (dependencies[i])
- dependencies[i]->post_processing();
- do_post_processing();
- status=POSTCALCED;
-}
-
-void
-Staff_elem::molecule_processing()
-{
- if (status >= OUTPUT)
- return;
- status = OUTPUT; // do it only once.
- for (int i=0; i < dependencies.size(); i++)
- if (dependencies[i])
- dependencies[i]->molecule_processing();
-
- output= brew_molecule_p();
-}
-
-void
-Staff_elem::do_post_processing()
-{
-}
-
-void
-Staff_elem::do_pre_processing()
-{
-}
-
-void
-Staff_elem::do_add_processing()
-{
-}
-
-void
-Staff_elem::substitute_dependency(Staff_elem * old, Staff_elem * newdep)
-{
- bool hebbes_b=false;
- for (int i=0; i < dependencies.size(); i++) {
- if (dependencies[i] == old){
- dependencies[i] = newdep;
- hebbes_b = true;
- } else if (dependencies[i] == newdep) {
- hebbes_b = true;
- }
- }
- if (!hebbes_b)
- dependencies.push(newdep);
-}
-
-void
-Staff_elem::add_dependency(Staff_elem * p)
-{
- for (int i=0; i < dependencies.size(); i ++)
- if (dependencies[i] == p)
- return;
-
- dependencies.push(p);
- p->dependants.push(p);
-}
+++ /dev/null
-/*
- staff-walker.cc -- implement Staff_walker
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-#include "grouping.hh"
-#include "staff.hh"
-#include "musicalrequest.hh"
-#include "staff-walker.hh"
-#include "staff-column.hh"
-#include "score-column.hh"
-#include "debug.hh"
-#include "time-description.hh"
-#include "commandrequest.hh"
-#include "grouping.hh"
-#include "score-walker.hh"
-
-Staff_walker::~Staff_walker()
-{
- do_pre_move();
-}
-
-Staff_walker::Staff_walker(Staff_walker const &s)
- :PCursor<Staff_column*> (s)
-{
- assert(false);
-}
-
-Staff_walker::Staff_walker(Staff * s, PScore*ps )
- : PCursor<Staff_column*> (s->cols_)
-{
- staff_l_ = s;
- pscore_l_ = ps;
-
- // should be in tdes. TODO
- default_grouping = new Rhythmic_grouping(MInterval(0, 1), 4);
- score_walk_l_ = 0;
-}
-
-Moment
-Staff_walker::when() const
-{
- return ptr()->when();
-}
-
-
-void
-Staff_walker::process_timing_reqs()
-{
- for (int i=0; i < ptr()->timing_req_l_arr_.size(); i++) {
- Timing_req * tr_l = ptr()->timing_req_l_arr_[i];
- if (tr_l->meterchange()) {
- int b_i=tr_l->meterchange()->beats_i_;
- int o_i = tr_l->meterchange()->one_beat_i_;
- time_.set_meter(b_i, o_i);
-
- *default_grouping = Rhythmic_grouping(
- MInterval(0,Moment(b_i, o_i)), b_i);
- }
- }
-
- for (int i=0; i < ptr()->timing_req_l_arr_.size(); i++) {
- Timing_req * tr_l = ptr()->timing_req_l_arr_[i];
- if (tr_l->partial()) {
- time_.setpartial(tr_l->partial()->duration_);
- } else if (tr_l->barcheck() && time_.whole_in_measure_) {
- warning( "Barcheck failed", tr_l->defined_ch_c_l_ );
- } else if (tr_l->cadenza()) {
- time_.set_cadenza(tr_l->cadenza()->on_b_);
- } else if (tr_l->measuregrouping()) {
- *default_grouping = parse_grouping(
- tr_l->measuregrouping()->beat_i_arr_,
- tr_l->measuregrouping()->elt_length_arr_);
- }
- }
- time_.OK();
-}
-
-void
-Staff_walker::operator++(int i)
-{
- Moment last = when();
-
- do_pre_move();
- PCursor<Staff_column*>::operator++(i);
- if (ok() ) {
- Moment delta_t = when() - last;
- assert(delta_t >0);
- time_.add( delta_t );
- }
- do_post_move();
-}
-
-void
-Staff_walker::process()
-{
- process_timing_reqs();
- process_requests();
-}
-
-void
-Staff_walker::allow_break()
-{
- score_walk_l_->allow_break(this);
-}
-
+++ /dev/null
-#include "staff.hh"
-#include "score.hh"
-#include "voice.hh"
-#include "staff-walker.hh"
-#include "staff-column.hh"
-#include "score-column.hh"
-#include "voice-element.hh"
-#include "debug.hh"
-#include "musicalrequest.hh"
-#include "commandrequest.hh" // todo
-#include "midi-stream.hh"
-
-void
-Staff::add(PointerList<Voice*> const &l)
-{
- for (iter_top(l,i); i.ok(); i++)
- voice_list_.bottom().add(i);
-}
-
-Paper_def *
-Staff::paper() const
-{
- return score_l_->paper_p_;
-}
-
-void
-Staff::clean_cols()
-{
- iter_top(cols_,i);
- for(; i.ok(); ){
- if (!i->musical_column_l_->used_b())
- i->musical_column_l_ = 0;
- if (!i->command_column_l_->used_b())
- i->command_column_l_ =0;
-
- if (!i->command_column_l_&& !i->musical_column_l_)
- delete i.get_p();
- else
- i++;
- }
-}
-
-Staff_column *
-Staff::get_col(Moment w, PCursor<Staff_column*> *last)
-{
- iter_top(cols_,i);
- if (last && last->ok() && (*last)->when() <= w)
- i = *last;
-
- for (; i.ok(); i++) {
- if (i->when() == w) {
- if (last)
- *last = i;
- return i;
- } else if (i->when() > w)
- break;
- }
-
-
- PCursor<Score_column*> scorecolumns(score_l_->find_col(w, false));
- Staff_column* staffcolumn_p = new Staff_column;
- staffcolumn_p->staff_l_ = this;
- Score_column* comcol_l = scorecolumns++;
- staffcolumn_p->set_cols(comcol_l, scorecolumns);
-
- if (!i.ok()) {
- cols_.bottom().add( staffcolumn_p);
- i = cols_.bottom();
- } else {
- i.insert(staffcolumn_p);
- i--;
- }
- if (last)
- *last = i;
- return i;
-}
-
-/**
- put all stuff grouped vertically in the Staff_cols.
- Do the preprarations for walking the cols. not virtual
- */
-void
-Staff::setup_staffcols()
-{
- for (iter_top(voice_list_,i); i.ok(); i++) {
- PCursor<Staff_column*> last(cols_);
- Moment now = i->start;
- for (iter_top(i->elts,j); j.ok(); j++) {
-
- Staff_column *s_l= get_col(now, &last);
- assert(now == s_l->when());
- s_l->add(j);
- now += j->duration;
- }
-
- }
- OK();
-}
-
-void
-Staff::OK() const
-{
-#ifndef NDEBUG
- cols_.OK();
- voice_list_.OK();
- iter_top(cols_, i);
- iter_top(cols_, j);
- i++;
- for (; i.ok(); j++,i++) {
- assert(j->when () < i->when() );
- }
- assert(score_l_);
-#endif
-}
-
-
-Moment
-Staff::last() const
-{
- Moment l = 0;
- for (iter_top(voice_list_,i); i.ok(); i++) {
- l = l >? i->last();
- }
- return l;
-}
-
-void
-Staff::print() const
-{
-#ifndef NPRINT
- mtor << "Staff {\n";
- for (iter_top(voice_list_,i); i.ok(); i++) {
- i->print();
- }
- mtor <<"}\n";
-#endif
-}
-
-Staff::Staff()
-{
- score_l_ =0;
- pscore_l_ =0;
- pstaff_l_ =0;
-}
+++ /dev/null
-#include "staffline.hh"
-#include "scoreline.hh"
-#include "dimen.hh"
-#include "spanner.hh"
-#include "symbol.hh"
-#include "paper-def.hh"
-#include "molecule.hh"
-#include "pcol.hh"
-#include "pscore.hh"
-
-static String
-make_vbox(Interval i)
-{
- Real r = (i.empty()) ? 0.0 : i.length();
- String s("\\vbox to ");
- s += print_dimen(r);
- s += "{\\vskip "+print_dimen(i.right)+" ";
- return s;
-}
-
-
-String
-Line_of_staff::TeXstring() const
-{
- String s("%line_of_staff\n");
-
- s+=make_vbox(height());
- // the staff itself: eg lines, accolades
- s += "\\hbox{";
- {
- iter_top(line_of_score_l_->cols,cc);
- Real lastpos=cc->hpos;
-
- // all items in the current line & staff.
- for (; cc.ok(); cc++) {
- Real delta=cc->hpos - lastpos;
- lastpos = cc->hpos;
-
- // moveover
- if (delta)
- s +=String( "\\kern ") + print_dimen(delta);
-
- // now output the items.
- for (iter_top(cc->its,i); i.ok(); i++) {
- if (i->pstaff_l_ == pstaff_l_)
- s += i->TeXstring();
- }
- // spanners.
- for (iter_top(cc->starters,i); i.ok(); i++)
- if (i->pstaff_l_ == pstaff_l_)
- s += i->TeXstring();
- }
- }
- s+="\\hss}\\vss}";
- return s;
-}
-
-Line_of_staff::Line_of_staff(Line_of_score * sc, PStaff*st)
-{
- line_of_score_l_=sc;
- pstaff_l_=st;
-
- PCol *linestart = sc->cols.top();
- PCol *linestop = sc->cols.bottom();
-
- for (iter_top(pstaff_l_->spans,i); i.ok(); i++) {
- PCol *brokenstart = &max(*linestart, *i->left);
- PCol *brokenstop = &min(*linestop, *i->right);
- if ( *brokenstart < *brokenstop) {
- Spanner*span_p =i->broken_at(brokenstart,brokenstop);
- line_of_score_l_->pscore_l_-> // higghl
- add_broken(span_p);
- }
- }
-}
-
-
-Interval
-Line_of_staff::height() const
-{
- Interval y(0,0);
-
- iter_top(line_of_score_l_->cols,cc);
-
- // all items in the current line & staff.
- for (; cc.ok(); cc++) {
- for (iter_top(cc->its,i); i.ok(); i++) {
- if (i->pstaff_l_ == pstaff_l_)
- y.unite(i->height());
-
- }
- // spanners.
- for (iter_top(cc->starters,i); i.ok(); i++)
- if (i->pstaff_l_ == pstaff_l_) {
- y.unite(i->height());
- }
- }
-
- return y;
-}
-
-void
-Line_of_staff::process()
-{
-#if 0
- if (!pstaff_l_->stafsym_p_)
- pstaff_l_->brew_molecule_p(line_of_score_l_->pscore_l_->
- paper_l_->linewidth);
-#endif
-}
+++ /dev/null
-/*
- staffsym.cc -- implement Staff_symbol
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-#include "staffsym.hh"
-#include "lookup.hh"
-#include "paper-def.hh"
-#include "debug.hh"
-
-
-
-Staff_symbol::Staff_symbol(int l)
-{
- no_lines_i_ = l;
-}
-
-void
-Staff_symbol::do_print()const
-{
- mtor << "lines: " << no_lines_i_;
-}
-
-Molecule*
-Staff_symbol::brew_molecule_p() const
-{
- Atom a = paper()->lookup_p_->linestaff(no_lines_i_, width().length());
- return new Molecule(a);
-}
-
-Spanner*
-Staff_symbol::do_break_at(PCol*p1, PCol*p2)const
-{
- Staff_symbol *span_p=new Staff_symbol(*this);
- return span_p;
-}
-
-void
-Staff_symbol::set_extent(PCol*p1, PCol*p2)
-{
- assert(p1&&p2);
- left = p1;
- right = p2;
-}
+++ /dev/null
-/*
- stem-beam-reg.cc -- part of LilyPond
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-#include "musicalrequest.hh"
-#include "stem-beam-reg.hh"
-#include "beam.hh"
-#include "stem.hh"
-#include "grouping.hh"
-#include "textspanner.hh"
-#include "complex-walker.hh"
-#include "complex-staff.hh"
-#include "debug.hh"
-#include "grouping.hh"
-#include "notehead.hh"
-
-Stem_beam_register::Stem_beam_register()
-{
- post_move_processing();
- current_grouping = 0;
- beam_p_ = 0;
- set_feature(Features::dir(0));
- start_req_l_ = 0;
-}
-
-bool
-Stem_beam_register::try_request(Request*req_l)
-{
- if ( req_l->beam() ) {
- if (bool(beam_p_ ) == bool(req_l->beam()->spantype == Span_req::START))
- return false;
-
- if (beam_req_l_ && Beam_req::compare(*beam_req_l_ , *req_l->beam()))
- return false;
-
- beam_req_l_ = req_l->beam();
- return true;
- }
-
- if ( req_l->stem() ) {
- if (current_grouping && !current_grouping->child_fit_query(
- get_staff_info().time_c_l_->whole_in_measure_))
- return false;
-
- if (stem_req_l_ && Stem_req::compare(*stem_req_l_, *req_l->stem()))
- return false;
-
- stem_req_l_ = req_l->stem();
- return true;
- }
- return false;
-}
-
-void
-Stem_beam_register::process_requests()
-{
- if (beam_req_l_) {
- if (beam_req_l_->spantype == Span_req::STOP) {
- end_beam_b_ = true;
- start_req_l_ = 0;
- } else {
- beam_p_ = new Beam;
- start_req_l_ = beam_req_l_;
-
- current_grouping = new Rhythmic_grouping;
- if (beam_req_l_->nplet) {
- Text_spanner* t = new Text_spanner();
- t->set_support(beam_p_);
- t->spec.align_i_ = 0;
- t->spec.text_str_ = beam_req_l_->nplet;
- t->spec.style_str_="italic";
- typeset_element(t);
- }
-
- }
- }
-
- if (stem_req_l_) {
- stem_p_ = new Stem(4);
- if (current_grouping)
- current_grouping->add_child(
- get_staff_info().time_c_l_->whole_in_measure_,
- stem_req_l_->duration());
-
- stem_p_->flag = stem_req_l_->balltype;
-
- if (beam_p_) {
- if (stem_req_l_->balltype<= 4)
- warning( "stem doesn't fit in Beam",
- stem_req_l_->defined_ch_c_l_);
- else
- beam_p_->add(stem_p_);
- stem_p_->print_flag = false;
- } else {
- stem_p_->print_flag = true;
- }
-
- announce_element(Staff_elem_info(stem_p_, stem_req_l_));
- }
-}
-
-void
-Stem_beam_register::acknowledge_element(Staff_elem_info info)
-{
- if (!stem_p_)
- return;
-
- if (info.elem_p_->name() == Notehead::static_name() &&
- stem_req_l_->duration() == info.req_l_->rhythmic()->duration())
-
- stem_p_->add((Notehead*)info.elem_p_);
-}
-
-void
-Stem_beam_register::pre_move_processing()
-{
- if (stem_p_) {
- if (default_dir_i_)
- stem_p_->dir = default_dir_i_;
-
- typeset_element(stem_p_);
- stem_p_ = 0;
- }
- if (beam_p_ && end_beam_b_) {
- const Rhythmic_grouping * rg_c_l = get_staff_info().rhythmic_c_l_;
- rg_c_l->extend(current_grouping->interval());
- beam_p_->set_grouping(*rg_c_l, *current_grouping);
- typeset_element(beam_p_);
- delete current_grouping;
- current_grouping = 0;
- beam_p_ = 0;
- }
- end_beam_b_ = false;
-}
-void
-Stem_beam_register::post_move_processing()
-{
- stem_p_ = 0;
- beam_req_l_ = 0;
- stem_req_l_ = 0;
- end_beam_b_ = false;
-}
-
-Stem_beam_register::~Stem_beam_register()
-{
- if (beam_p_)
- warning("unterminated beam", start_req_l_->defined_ch_c_l_);
-}
-
-void
-Stem_beam_register::set_feature(Features i)
-{
- default_dir_i_ = i.direction_i_;
-}
+++ /dev/null
-#include "stem.hh"
-#include "dimen.hh"
-#include "debug.hh"
-#include "paper-def.hh"
-#include "notehead.hh"
-#include "lookup.hh"
-#include "molecule.hh"
-#include "pcol.hh"
-#include "misc.hh"
-
-const int STEMLEN=7;
-
-
-Stem::Stem(int c) //, Moment len)
-{
- beams_left = 0;
- beams_right = 0;
- minnote = 1000; // invalid values
- maxnote = -1000;
- bot = top = 0;
- flag = 4;
- dir =0;
- staff_center=c;
- stemlen=0;
- print_flag=true;
- stem_xoffset=0;
-}
-
-void
-Stem::do_print() const
-{
-#ifndef NPRINT
- mtor << "flag "<< flag << " print_flag " << print_flag
- << "min,max [" << minnote << ", " << maxnote << "]";
-#endif
-}
-void
-Stem::set_stemend(Real se)
-{
-
- // todo: margins
- if (! ((dir > 0 && se >= maxnote) || (se <= minnote && dir <0)) )
- warning("Weird stem size; check for narrow beams",0);
-
- top = (dir < 0) ? maxnote : se;
- bot = (dir < 0) ? se : minnote;
- flag = dir*abs(flag);
-}
-
-void
-Stem::add(Notehead *n)
-{
- assert(status < PRECALCED);
-
- if (n->balltype == 1)
- return;
- int p = n->position;
- if (p < minnote)
- minnote = p;
- if (p > maxnote)
- maxnote = p;
- heads.push(n);
- n->add_dependency(this);
-}
-
-
-int
-Stem::get_default_dir()
-{
- if (dir)
- return dir;
- Real mean = (minnote+maxnote)/2;
- return (mean > staff_center) ? -1: 1;
-}
-
-void
-Stem::set_default_dir()
-{
- dir = get_default_dir();
-}
-
-void
-Stem::set_default_stemlen()
-{
- if (!dir)
- set_default_dir();
-
- int stafftop = 2*staff_center;
- stemlen = STEMLEN + (maxnote - minnote);
-
- // uhh... how about non 5-line staffs?
- if (maxnote < -2 && dir == 1){
- int t = staff_center - staff_center/2;
- stemlen = t - minnote +2;
- } else if (minnote > stafftop + 2 && dir == -1) {
- int t = staff_center + staff_center/2;
- stemlen = maxnote -t +2;
- }
-
- assert(stemlen);
-}
-
-
-void
-Stem::set_default_extents()
-{
- if (minnote > maxnote) {
- warning("Empty stem. Ugh!", 0);
- minnote = -10;
- maxnote = 20;
- }
-
- if (!stemlen)
- set_default_stemlen();
-
- set_stemend((dir< 0) ? maxnote-stemlen: minnote +stemlen);
- if (dir > 0){
- stem_xoffset = paper()->note_width()-paper()->rule_thickness();
- } else
- stem_xoffset = 0;
-}
-
-void
-Stem::set_noteheads()
-{
- if(!heads.size())
- return;
- heads.sort(Notehead::compare);
- heads[0]->extremal = -1;
- heads.top()->extremal = 1;
- int parity=1;
- int lastpos = heads[0]->position;
- for (int i=1; i < heads.size(); i ++) {
- int dy =abs(lastpos- heads[i]->position);
-
- if (dy <= 1) {
- if (parity)
- heads[i]->x_dir = (stem_xoffset>0) ? 1:-1;
- parity = !parity;
- } else
- parity = 0;
- lastpos = heads[i]->position;
- }
-}
-
-void
-Stem::do_pre_processing()
-{
- if (bot == top)
- set_default_extents();
- set_noteheads();
-}
-
-
-Interval
-Stem::width()const
-{
- if (!print_flag || abs(flag) <= 4)
- return Interval(0,0); // TODO!
- Paper_def*p= paper();
- Interval r(p->lookup_p_->flag(flag).dim.x);
- r+= stem_xoffset;
- return r;
-}
-
-Molecule*
-Stem::brew_molecule_p()const return out;
-{
- assert(bot!=top);
-
-
- Paper_def *p =paper();
-
- Real dy = p->internote();
- Symbol ss =p->lookup_p_->stem(bot*dy,top*dy);
-
-
- out = new Molecule(Atom(ss));
-
- if (print_flag&&abs(flag) > 4){
- Symbol fl = p->lookup_p_->flag(flag);
- Molecule m(fl);
- if (flag < -4){
- out->add_bottom(m);
- } else if (flag > 4) {
- out->add_top(m);
- } else
- assert(false);
- }
-
- out->translate(Offset(stem_xoffset,0));
-}
-
-Real
-Stem::hindex()const
-{
- return pcol_l_->hpos + stem_xoffset; // hmm. + offset_.x;
-}
-
-
+++ /dev/null
-#include "symbol.hh"
-#include "varray.hh"
-
-
-Symbol::Symbol()
- : dim(Interval(0,0),Interval(0,0))
-{
- tex = "\\unknown";
-}
-Symbol::Symbol(String s, Box b)
- : dim(b)
-{
- tex = s;
-}
-
-
-String
-Symbol::str()const return s;
-{
- s = "symbol(\'"+tex+"\', (" + dim.x.str() + ", " + dim.y.str() + "))";
-}
+++ /dev/null
-#include "misc.hh"
-#include "dimen.hh"
-#include "debug.hh"
-#include "real.hh"
-#include "symbol.hh"
-#include "assoc.hh"
-#include "assoc-iter.hh"
-#include "symtable.hh"
-
-Symtables::Symtables()
-{
-}
-
-Symtables::Symtables(Symtables const &s)
-{
- for (Assoc_iter<String, Symtable*> i(s); i.ok(); i++) {
- add(i.key(), new Symtable(*i.val()));
- }
-}
-
-Symtables::~Symtables()
-{
- for (Assoc_iter<String, Symtable*> i(*this); i.ok(); i++) {
- delete i.val();
- }
-}
-
-Symbol
-Symtable::lookup(String s) const
-{
- if (elt_query(s))
- return (*this)[s];
- else {
- error( "Unknown symbol `" +s+"'\n");
- }
- Symbol sy; // unreachable
- return sy;
-}
-
-Symtable*
-Symtables::operator()(String s)
-{
- return Assoc<String, Symtable*>::operator[](s);
-}
-void
-Symtables::print() const
-{
- for (Assoc_iter<String, Symtable*> i(*this); i.ok(); i++) {
- mtor << "table \'" << i.key() << "\' {\n";
- i.val()->print();
- mtor << "}\n";
- }
-}
-void
-Symtable::print() const
-{
- for (Assoc_iter<String, Symbol> i(*this); i.ok(); i++) {
- mtor << "\'" << i.key() << "\'->" << i.val().str() << "\n";
- }
-}
-
+++ /dev/null
-#include "idealspacing.hh"
-#include "plist.hh"
-#include "pcol.hh"
-#include "item.hh"
-#include "musicalrequest.hh"
-#include "spanner.hh"
-#include "scoreline.hh"
-#include "staffline.hh"
-
-#include "pcursor.tcc"
-#include "plist.tcc"
-
-
-#define IPLC_instantiate(a) IPL_instantiate(a); PL_instantiate(const a)
-
-
-IPLC_instantiate(Line_of_score);
-IPLC_instantiate(Line_of_staff);
-IPLC_instantiate(Item);
-IPLC_instantiate(Spanner);
-IPLC_instantiate(PStaff);
-IPLC_instantiate(Idealspacing);
-IPLC_instantiate(PCol);
-
+++ /dev/null
-/*
- template2.cc -- instantiate some list templates.
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-#include "symbol.hh"
-#include "voice.hh"
-#include "voice-element.hh"
-#include "musicalrequest.hh"
-#include "staff.hh"
-#include "score-column.hh"
-#include "staff-column.hh"
-#include "spanner.hh"
-#include "plist.tcc"
-#include "pcursor.tcc"
-
-IPL_instantiate(Request);
-IPL_instantiate(Score_column);
-IPL_instantiate(Staff_column);
-IPL_instantiate(Staff);
-IPL_instantiate(Voice_element);
-IPL_instantiate(Voice);
-
-
+++ /dev/null
-#include "request.hh"
-#include "input-score.hh"
-#include "input-staff.hh"
-#include "input-music.hh"
-#include "molecule.hh"
-#include "source-file.hh"
-#include "voice-element.hh"
-#include "plist.tcc"
-#include "pcursor.tcc"
-
-IPL_instantiate(Atom);
-IPL_instantiate(Atom);
-IPL_instantiate(Input_staff);
-IPL_instantiate(Input_music);
-IPL_instantiate(Source_file);
+++ /dev/null
-/*
- template4.cc -- instantiate PointerList baseclass.
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-#include "proto.hh"
-#include "list.tcc"
-#include "cursor.tcc"
-
-L_instantiate(void *);
+++ /dev/null
-#include "proto.hh"
-#include "string.hh"
-#include "moment.hh"
-#include "real.hh"
-
-#include "interval.tcc"
-
-Interval__instantiate(Real);
-Interval__instantiate(Rational);
+++ /dev/null
-#include "proto.hh"
-#include "plist.tcc"
-#include "register.hh"
-#include "voice-group-regs.hh"
-#include "voice-regs.hh"
-
-
-IPL_instantiate(Voice_registers);
-IPL_instantiate(Voice_group_registers);
-IPL_instantiate(Request_register);
+++ /dev/null
-/*
- tex-stream.cc -- implement Tex_stream
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-#include <fstream.h>
-#include <time.h>
-
-#include "tex.hh"
-#include "main.hh"
-#include "tex-stream.hh"
-#include "debug.hh"
-
-Tex_stream::Tex_stream(String filename)
-{
- os = new ofstream(filename);
- if (!*os)
- error("can't open `" + filename+"\'");
- nest_level = 0;
- outputting_comment=false;
- header();
-}
-void
-Tex_stream::header()
-{
- *os << "% Creator: " << get_version();
- *os << "% Automatically generated, at ";
- time_t t(time(0));
- *os << ctime(&t);
-}
-Tex_stream::~Tex_stream()
-{
- delete os;
- assert(nest_level == 0);
-}
-
-// print string. don't forget indent.
-Tex_stream &
-Tex_stream::operator<<(String s)
-{
-
- for (const char *cp = s; *cp; cp++) {
- if (outputting_comment) {
- *os << *cp;
- if (*cp == '\n') {
- outputting_comment=false;
-
- }
- continue;
- }
- switch(*cp)
- {
- case '%':
- outputting_comment = true;
- *os << *cp;
- break;
- case '{':
- nest_level++;
- *os << *cp;
- break;
- case '}':
- nest_level--;
- *os << *cp;
-
- if (nest_level < 0) {
- delete os; // we want to see the remains.
- assert(nest_level>=0);
- }
- /* FALLTHROUGH */
-
- case '\n':
- *os << "%\n";
- *os << String(' ', nest_level);
- break;
- default:
- *os << *cp;
- break;
- }
- }
- return *this;
-}
-
-
-/* *************************************************************** */
+++ /dev/null
-#include "dimen.hh"
-#include "tex.hh"
-#include "symbol.hh"
-#include "const.hh"
-#include "varray.hh"
-
-String
-vstrut(Real h)
-{
- return String("\\vrule height ") + print_dimen(h) + "depth 0pt width 0pt";
-}
-
-
-static void
-substitute_arg(String& r, String arg)
-{
- int p = r.index_i('%');
- if (p < 0)
- return ;
-
- r = r.left_str(p) + arg + r.right_str(r.length_i() - p -1);
-}
-
-
-String
-substitute_args(String source, Array<String> args)
-{
- String retval (source);
- for (int i = 0 ; i < args.size(); i++)
- substitute_arg(retval, args[i]);
- while (retval.index_i('%') >= 0)
- substitute_arg(retval, "");
- return retval;
-}
-
-String
-substitute_args(String source, Array<Scalar> args)
-{
- Array<String> sv;
- for (int i = 0 ; i < args.size(); i++)
- sv.push(args[i]);
-
- return substitute_args(source, sv);
-}
+++ /dev/null
-/*
-
- Code to generate beams for TeX
-
- */
-
-#include <math.h>
-#include "symbol.hh"
-#include "molecule.hh"
-#include "tex.hh"
-#include "symtable.hh"
-#include "dimen.hh"
-#include "debug.hh"
-#include "lookup.hh"
-
-Symbol
-Lookup::beam_element(int sidx, int widx, Real slope)
-{
- Symbol bs=(*symtables_)("beamslopes")->lookup("slope");
-
- Array<String> args;
- args.push(sidx);
- args.push(widx);
- bs.tex = substitute_args(bs.tex,args);
- int w = 2 << widx;
- Real width = w PT;
- bs.dim.x = Interval(0,width);
- bs.dim.y = Interval(0,width*slope);
- return bs;
-}
-
-// ugh.. hard wired tex-code.
-static int
-slope_index(Real &s)
-{
- if (abs(s) > 0.5) {
- WARN << "beam steeper than 0.5 (" << s << ")\n";
- s = sign(s) * 0.5;
- }
-
- int i = int(rint(s * 20.0));
-
- s = i/20.0;
- if (s>0)
- return 6*i +122;
- else
- return -6 * i+ 186;
-}
-
-Symbol
-Lookup::rule_symbol(Real height, Real width)
-{
- Symbol bs=(*symtables_)("beamslopes")->lookup("horizontal");
- Array<String> args;
- args.push(print_dimen(height));
- args.push(print_dimen(width));
- bs.tex = substitute_args(bs.tex,args);
- bs.dim.x = Interval(0,width);
- bs.dim.y = Interval(0,height);
- return bs;
-}
-
-Symbol
-Lookup::beam(Real &slope, Real width)
-{
- int sidx = slope_index(slope);
- if (!slope)
- return rule_symbol(2 PT, width);
- if (width < 2 PT) {
- WARN<<"Beam too narrow. (" << print_dimen(width) <<")\n";
- width = 2 PT;
- }
- Real elemwidth = 64 PT;
- int widx = 5;
-
- Molecule m;
-
- while (elemwidth > width) {
- widx --;
- elemwidth /= 2.0;
- }
- Real overlap = elemwidth/4;
- Real last_x = width - elemwidth;
- Real x = overlap;
- Atom elem(beam_element(sidx, widx, slope));
- Atom a(elem);
- m.add(a);
- while (x < last_x) {
- a=elem;
- a.translate(Offset(x-overlap, (x-overlap)*slope));
- m.add(a);
- x += elemwidth - overlap;
- }
- a=elem;
- a.translate(Offset(last_x, (last_x) * slope));
- m.add(a);
-
- Symbol ret;
- ret.tex = m.TeXstring();
- ret.dim.y = Interval(0,width*slope);
- ret.dim.x = Interval(0,width);
-
- return ret;
-}
-
-
+++ /dev/null
-#include <math.h>
-#include "misc.hh"
-#include "lookup.hh"
-#include "molecule.hh"
-#include "dimen.hh"
-#include "debug.hh"
-
-static
-char direction_char(int y_sign)
-{
- char c='#';
- switch(y_sign){
- case -1:
- c = 'd';
- break;
- case 0:
- c = 'h';
- break;
- case 1:
- c = 'u';
- break;
- default:
- assert(false);
- }
- return c;
-}
-
-Symbol
-Lookup::half_slur_middlepart(Real &dx, int dir)
-{
- if (dx >= 400 PT) {// todo
- WARN<<"halfslur too large" <<print_dimen(dx)<< "shrinking (ugh)\n";
- dx = 400 PT;
- }
- int widx = int(floor(dx / 4.0));
- dx = widx * 4.0;
- if (widx) widx --;
- else {
- WARN << "slur too narrow\n";
- }
-
- Symbol s;
-
- s.dim.y = Interval(min(0,0), max(0,0)); // todo
- s.dim.x = Interval(0,dx);
-
- String f = String("\\hslurchar");
- f += direction_char(0);
-
- int idx = widx;
- if (dir < 0)
- idx += 128;
-
-
- f+=String( "{" ) + String( idx ) + "}";
- s.tex = f;
- Atom a(s);
- a.translate(Offset(dx/2,0));
- s.tex = a.TeXstring();
-
- return s;
-}
-Symbol
-Lookup::half_slur(int dy, Real &dx, int dir, int xpart)
-{
- Real orig_dx = dx;
- if (!xpart)
- return half_slur_middlepart(dx, dir);
-
- int widx;
-
- if (dx >= 96 PT) {
- WARN << "Slur half too wide." << print_dimen(orig_dx) << " shrinking (ugh)\n";
- dx = 96 PT;
- }
-
- widx = int(rint(dx/12.0));
- dx = widx*12.0;
- if (widx)
- widx --;
- else {
- WARN << "slur too narrow " << print_dimen(orig_dx)<<"\n";
- }
-
- Symbol s;
- s.dim.x = Interval(0,dx);
- s.dim.y = Interval(min(0,dy), max(0,dy));
-
-
- String f = String("\\hslurchar");
-
- f+= direction_char(dir);
-
- int hidx = dy;
- if (hidx <0)
- hidx = -hidx;
- hidx --;
- int idx =-1;
-
-
- idx = widx * 16 + hidx;
- if (xpart < 0)
- idx += 128;
-
- f+=String( "{" ) + String( idx ) + "}";
-
-
- s.tex = f;
-
- return s;
-}
-
-Symbol
-Lookup::slur (int dy , Real &dx, int dir)
-{
- assert(dx >=0 && abs(dir) <= 1);
- int y_sign = sign(dy);
-
- bool large = dy > 16;
-
- if (y_sign) {
- large |= dx>= 4*16 PT;
- } else
- large |= dx>= 4*54 PT;
-
- if (large) {
- return big_slur(dy, dx, dir);
- }
- Real orig_dx = dx;
- int widx = int(floor(dx/4.0)); // slurs better too small..
- dx = 4.0 * widx;
- if (widx)
- widx --;
- else {
- WARN << "slur too narrow: " << print_dimen(orig_dx) << "\n";
- }
-
- int hidx = dy;
- if (hidx <0)
- hidx = -hidx;
- hidx --;
- if (hidx > 16) {
- WARN<<"slur to steep: " << dy << " shrinking (ugh)\n";
- }
-
- Symbol s;
- s.dim.x = Interval(0,dx);
- s.dim.y = Interval(min(0,dy), max(0,dy));
-
- String f = String("\\slurchar") + String( direction_char(y_sign) );
-
- int idx=-1;
- if (y_sign) {
- idx = hidx * 16 + widx;
- if (dir < 0)
- idx += 128;
- } else {
- if (dx >= 4*54 PT) {
- WARN << "slur too wide: " << print_dimen(dx) <<
- " shrinking (ugh)\n";
- dx = 4*54 PT;
- }
- idx = widx;
- if (dir < 0)
- idx += 54;
- }
-
- f+=String( "{" ) + String( idx ) + "}";
- s.tex = f;
-
- Atom a(s);
- a.translate(Offset(dx/2,0));
- s.dim = a.extent();
- s.tex = a.TeXstring();
- return s;
-}
-
-Symbol
-Lookup::big_slur(int dy , Real &dx, int dir)
-{
- assert(dx >= 24 PT);
- Real slur_extra =abs(dy) /2.0 + 2;
- int l_dy = int(Real (dy)/2 + slur_extra*dir);
- int r_dy = dy - l_dy;
-
- Real left_wid = dx/4.0;
- Real right_wid = left_wid;
-
- Atom l = half_slur(l_dy, left_wid, dir, -1);
- Atom r = half_slur(r_dy, right_wid, dir, 1);
- Real mid_wid = dx - left_wid - right_wid;
-
- Atom m = half_slur(0, mid_wid, dir, 0);
-
- Molecule mol;
- mol.add(l);
- Atom a(m);
- a.translate(Offset(0,slur_extra * internote()));
- mol.add_right(m);
- mol.add_right(r);
- mol.translate(Offset(0, l_dy * internote()));
- Symbol s;
- s.tex = mol.TeXstring();
- s.dim = mol.extent();
- return s;
-}
-
-
+++ /dev/null
-#include "debug.hh"
-#include "lookup.hh"
-#include "paper-def.hh"
-#include "molecule.hh"
-#include "text-def.hh"
-
-Text_def::Text_def()
-{
- align_i_ = 1; // right
- style_str_ = "roman";
- defined_ch_c_l_ = 0;
-}
-bool
-Text_def::compare(const Text_def&def)
-{
- return align_i_ == def.align_i_ && text_str_ == def.text_str_
- && style_str_ == def.style_str_;
-}
-
-Atom
-Text_def::create_atom(Paper_def*p) const
-{
- return p->lookup_p_->text(style_str_, text_str_, -align_i_);
-}
-
-void
-Text_def::print() const
-{
- mtor << "Text `" << text_str_ << "\', style " <<
- style_str_ << "align " << align_i_ << '\n';
-}
+++ /dev/null
-/*
- text-reg.cc -- implement Text_register
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-#include "musicalrequest.hh"
-#include "text-reg.hh"
-#include "textitem.hh"
-
-Text_register::Text_register()
-{
- text_p_ = 0;
- set_feature(Features::dir(0));
- post_move_processing();
-}
-
-bool
-Text_register::try_request(Request*req_l)
-{
- if (!req_l->text())
- return false;
- if (text_req_l_ &&
- Text_req::compare(*req_l->text(), *text_req_l_))
-
- return false;
-
- text_req_l_ = req_l->text();
- return true;
-}
-
-void
-Text_register::process_requests()
-{
-
- if (text_req_l_) {
- text_p_ = new Text_item(text_req_l_, 10); // UGH
- announce_element(Staff_elem_info(text_p_, text_req_l_));
- }
-}
-void
-Text_register::pre_move_processing()
-{
- if (text_p_) {
- text_p_->dir_i_ = dir_i_;
- typeset_element(text_p_);
- text_p_ = 0;
- }
-}
-void
-Text_register::set_feature(Features i)
-{
- dir_i_ = i.direction_i_;
-}
-void
-Text_register::post_move_processing()
-{
- text_req_l_ = 0;
-}
+++ /dev/null
-/*
- textitem.cc -- implement Text_item
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-
- #include "musicalrequest.hh"
-#include "paper-def.hh"
-#include "textitem.hh"
-#include "stem.hh"
-#include "molecule.hh"
-#include "lookup.hh"
-
-
-
-Text_item::Text_item(Text_req* treq_l, int staffsize_i)
-{
- staffsize_i_ = staffsize_i;
- dir_i_ = treq_l->dir_i_;
- if (!dir_i_)
- dir_i_ = -1;
- tdef_l_ = treq_l->tdef_p_;
-}
-
-void
-Text_item::set_default_index()
-{
- pos_i_ = (dir_i_ > 0) ? staffsize_i_ + 2: -4;
-}
-
-void
-Text_item::do_pre_processing()
-{
- set_default_index();
-}
-
-
-Molecule*
-Text_item::brew_molecule_p() const
-{
- Molecule* mol_p = new Molecule(tdef_l_->create_atom(paper()));
- mol_p->translate(Offset(0, pos_i_ * paper()->internote()));
-
- if(dir_i_<0)
- mol_p->translate(Offset(0, -mol_p->extent().y.length() ));
-
- return mol_p;
-}
+++ /dev/null
-#include "molecule.hh"
-#include "boxes.hh"
-#include "textspanner.hh"
-#include "text-def.hh"
-#include "debug.hh"
-#include "paper-def.hh"
-
-
-
-void
-Text_spanner::set_support(Directional_spanner*d)
-{
- support = d;
- add_dependency(d);
-}
-
-Text_spanner::Text_spanner()
-{
- support = 0;
-}
-
-void
-Text_spanner::do_print() const
-{
- spec.print();
-}
-
-void
-Text_spanner::do_post_processing()
-{
- switch(spec.align_i_) {
- case 0:
- text_off_ = support->center() +
- Offset(0,support->dir_i_ * paper()->internote() * 4); // todo
- break;
- default:
- assert(false);
- break;
- }
-}
-
-Molecule*
-Text_spanner::brew_molecule_p() const
-{
- Atom tsym (spec.create_atom(paper()));
- tsym.translate(text_off_);
-
- Molecule*output = new Molecule;
- output->add( tsym );
- return output;
-}
-
-void
-Text_spanner::do_pre_processing()
-{
- right = support->right;
- left = support->left;
- assert(left && right);
-}
-
-Interval
-Text_spanner::height()const
-{
- return brew_molecule_p()->extent().y;
-}
-
-Spanner*
-Text_spanner::do_break_at(PCol*c1, PCol*c2)const
-{
- return new Text_spanner(*this); // todo
-}
+++ /dev/null
-/*
- time-description.cc -- implement Time_description
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-#include "time-description.hh"
-#include "debug.hh"
-
-String
-Time_description::str()const
-{
- String s( "Time_description { ");
- if (cadenza_b_)
- s+=String( " (cadenza) ");
- s+= "at ";
- s+=when_;
- s+="\nmeter " + String(whole_per_measure_/one_beat_) +":" +
- String(Rational(Rational(1)/one_beat_));
- s+= "\nposition "+String( bars_i_) + ":"+ whole_in_measure_ +"\n}\n";
- return s;
-}
-
-void
-Time_description::print() const
-{
-#ifndef NPRINT
- mtor << str();
-#endif
-}
-void
-Time_description::OK() const
-{
-#ifndef NDEBUG
- if (!cadenza_b_)
- assert(whole_in_measure_ < whole_per_measure_);
- assert(0 <= whole_in_measure_);
- assert(one_beat_);
-#endif
-}
-
-void
-Time_description::set_cadenza(bool b)
-{
- if (cadenza_b_ && !b) {
- if (whole_in_measure_) {
- bars_i_ ++;
- whole_in_measure_ = 0;
- }
- }
- cadenza_b_ = b ;
-}
-
-Time_description::Time_description()
-{
- whole_per_measure_ = 1;
- whole_in_measure_ =0;
- one_beat_ = Moment(1,4);
- when_ = 0;
- bars_i_ = 0;
- cadenza_b_ = false;
-}
-
-void
-Time_description::add(Moment dt)
-{
- assert(dt >= Rational(0));
- when_ += dt;
- whole_in_measure_ += dt;
-
- while ( !cadenza_b_ && whole_in_measure_ >= whole_per_measure_ ) {
- whole_in_measure_ -= whole_per_measure_;
- bars_i_ ++;
- }
-}
-
-void
-Time_description::set_meter(int l, int o)
-{
- assert(o);
- one_beat_ = Rational(1)/Moment(o);
- whole_per_measure_ = Moment(l) * one_beat_;
- if(whole_in_measure_)
- error_t("Meterchange should be at start of measure", *this);
-}
-
-void
-Time_description::setpartial(Moment p)
-{
- if (when_)
- error_t ("Partial measure only allowed at beginning.", *this);
- if (p<Rational(0)||p > whole_per_measure_)
- error_t ("Partial measure has incorrect size", *this);
- whole_in_measure_ = whole_per_measure_ - p;
-}
-
-Moment
-Time_description::barleft()
-{
- assert(!cadenza_b_);
- return whole_per_measure_-whole_in_measure_;
-}
-
-int
-Time_description::compare(Time_description &t1, Time_description&t2)
-{
- int i = sign(t1.when_-t2.when_);
-
- if (!i) {
- assert(t1.bars_i_==t2.bars_i_);
- assert(t1.one_beat_ == t2.one_beat_);
- assert(t1.whole_in_measure_ == t2.whole_in_measure_);
- assert(t1.whole_per_measure_ == t2.whole_per_measure_);
- }
-
- return i;
-}
+++ /dev/null
-//
-// track-column.cc -- implement Track_column
-//
-// copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
-
-#include "proto.hh"
-#include "plist.hh"
-#include "string.hh"
-#include "moment.hh"
-#include "duration.hh"
-#include "midi-event.hh"
-#include "lily-stream.hh"
-#include "track-column.hh"
-#include "midi-track.hh"
-
-Track_column::Track_column( Moment mom )
-{
- mom_ = mom;
-}
-
-Track_column::~Track_column()
-{
-}
-
-void
-Track_column::add_event( Midi_event* midi_event_p )
-{
- midi_event_p_list_.bottom().add( midi_event_p );
-}
-
-Moment
-Track_column::mom()
-{
- return mom_;
-}
+++ /dev/null
-#include "version.hh"
-#include "fversion.hh"
-
-static char *s = "LilyPond " VERSIONSTR "/FlowerLib " FVERSIONSTR
-". Compile: " __DATE__ ", " __TIME__ " (" COMPILER ")\n";
-
-const char *
-get_version()
-{
- return s;
-}
+++ /dev/null
-/*
- voicegroup.cc -- implement Voice_group_registers
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-#include "plist.hh"
-#include "musicalrequest.hh"
-#include "voice-regs.hh"
-#include "voice-group-regs.hh"
-#include "register.hh"
-#include "text-reg.hh"
-#include "stem-beam-reg.hh"
-#include "script-reg.hh"
-#include "complex-walker.hh"
-#include "commandrequest.hh"
-#include "debug.hh"
-
-static int temp_id_count;
-
-Voice_group_registers::Voice_group_registers(String id)
-{
- add(new Text_register);
- add(new Stem_beam_register);
- add(new Script_register);
-
- if (id=="") // UGH
- id = __FUNCTION__ + String(temp_id_count++);
- group_id_str_ = id;
-}
-
-bool
-Voice_group_registers::try_request(Request*r_l)
-{
- for (int i=0; i < voice_regs_l_.size(); i++) {
- if (voice_regs_l_[i]->voice_l_ == r_l->voice_l())
- goto gotcha;
- }
- return false;
-gotcha:
- if (r_l->groupfeature()) {
- set_feature(Features::dir(r_l->groupfeature()->stemdir_i_));
- return true;
- }
- return Register_group_register::try_request(r_l);
-}
-
-
-bool
-Voice_group_registers::static_acceptable_request_b(Request*r)
-{
- return (r->stem() || r->beam() || r->text() || r->script() ||
- r->groupfeature());
-}
-
-void
-Voice_group_registers::terminate_register(Request_register*r_l)
-{
- if (r_l->name() == Voice_registers::static_name()) {
- for (int i=0; i <voice_regs_l_.size(); i++) {
- if (r_l == voice_regs_l_[i])
- voice_regs_l_.del(i);
- Register_group_register::terminate_register(r_l);
- return;
- }
- }
- assert(false);
-}
-void
-Voice_group_registers::do_print() const
-{
-#ifndef NPRINT
- mtor << "ID: " << group_id_str_<<"\n";
- Register_group_register::do_print();
-#endif
-}
-void
-Voice_group_registers::add(Request_register*r_l)
-{
- Register_group_register::add(r_l);
- if (r_l->name() == Voice_registers::static_name())
- voice_regs_l_.push( (Voice_registers*)r_l );
-}
+++ /dev/null
-/*
- voice-regs.cc -- implement Voice_registers
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-#include "commandrequest.hh"
-#include "musicalrequest.hh"
-#include "voice-regs.hh"
-#include "register.hh"
-#include "slur-reg.hh"
-#include "headreg.hh"
-#include "walkregs.hh"
-#include "debug.hh"
-
-Voice_registers::Voice_registers(Voice *v_p)
-{
- voice_l_ = v_p;
- add(new Notehead_register);
- add(new Slur_register);
-}
-
-void
-Voice_registers::acknowledge_element(Staff_elem_info i)
-{
- if (i.voice_l_ != voice_l_)
- return;
- Register_group_register::acknowledge_element(i);
-}
-
-bool
-Voice_registers::try_request(Request*r_l)
-{
- if (r_l->voice_l() !=voice_l_)
- return false;
-
- Command_req *c=r_l->command();
- if (c&&c->terminate()) {
- daddy_reg_l_->terminate_register(this);
- return true; // scary. We're deleted now..
- } else if (c&&c->groupchange()) {
-
- ((Walker_registers*)daddy_reg_l_->daddy_reg_l_)-> // scary.
- change_group(c->groupchange(), this,
- (Voice_group_registers*)daddy_reg_l_); // UGR!
- return true;
- }
-
- return Register_group_register::try_request(r_l);
-}
-
-bool
-Voice_registers::acceptable_request_b(Request*r)
-{
-// return (r->rest() || r->note() || r->slur() || r->groupchange());
- return r->groupchange()
- || Register_group_register::acceptable_request_b(r);
-}
-void
-Voice_registers::do_print() const
-{
- mtor << "Voice= " << voice_l_<<'\n';
- Register_group_register::do_print();
-}
+++ /dev/null
-/*
- voice.cc -- implement Voice
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-#include "debug.hh"
-#include "voice.hh"
-#include "musicalrequest.hh"
-#include "commandrequest.hh"
-#include "midi-item.hh"
-#include "midi-stream.hh"
-#include "voice-element.hh"
-
-void
-Voice::set_default_group(String s)
-{
- elts.top()->set_default_group(s);
-}
-
-bool
-Voice::find_plet_start_bo(char c, Moment& moment_r)
-{
- for (iter_bot(elts, i); i.ok(); i--)
- if ( i->find_plet_start_bo(c, moment_r) )
- return true;
- return false;
-}
-
-void
-Voice::set_plet_backwards(Moment& now_moment_r, Moment until_moment,
- int num_i, int den_i)
-{
- for (iter_bot(elts, i); i.ok(); i--)
- if ( now_moment_r <= until_moment )
- i->set_plet_backwards(now_moment_r, until_moment, num_i, den_i);
- else
- return;
-}
-
-Voice::Voice(Voice const&src)
-{
- for (iter_top(src.elts, i); i.ok(); i++)
- add(new Voice_element(**i));
-
- start = src.start;
-}
-
-Voice::Voice()
-{
- start = 0;
-}
-
-void
-Voice::add(Voice_element*v)
-{
- v->voice_l_ = this;
- elts.bottom().add(v);
-}
-
-void
-Voice::print() const
-{
-#ifndef NPRINT
- mtor << "Voice { start: "<< start<<eol;
- for (iter_top(elts,i); i.ok(); i++)
- i->print();
- mtor << "}\n";
-#endif
-}
-
-Moment
-Voice::last() const
-{
- Moment l =0;
- if (elts.size())
- l = start;
-
- for (iter_top(elts,i); i.ok(); i++)
- l += i->duration;
- return l;
-}
-
+++ /dev/null
-/*
- voiceelt.cc -- implement Voice_element
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-#include "debug.hh"
-#include "voice.hh"
-#include "voice-element.hh"
-#include "musicalrequest.hh"
-#include "commandrequest.hh"
-
-
-void
-Voice_element::print() const
-{
-#ifndef NPRINT
- mtor << "voice_element { dur :"<< duration <<"\n";
- for (iter_top(reqs,rc); rc.ok(); rc++) {
- rc->print();
- }
- mtor << "}\n";
-#endif
-}
-
-void
-Voice_element::add(Request*r)
-{
- if (r->duration()) {
- assert (!duration || duration == r->duration());
- duration = r->duration();
- }
-
- r->elt_l_ = this;
- reqs.bottom().add(r);
-}
-
-
-Voice_element::Voice_element()
-{
- voice_l_ = 0;
- duration = 0;
- defined_ch_c_l_ = 0;
-}
-
-Voice_element::Voice_element(Voice_element const&src)
-{
- defined_ch_c_l_ = src.defined_ch_c_l_;
-
- voice_l_=0;
- for (iter_top(src.reqs, i); i.ok(); i++)
- add(i->clone());
-
-}
-bool
-Voice_element::find_plet_start_bo(char c, Moment& moment_r)
-{
- assert( c == ']' );
- moment_r += duration;
- for ( PCursor<Request*> req_l_pcur( reqs.top() ); req_l_pcur.ok(); req_l_pcur++ ) {
- if (req_l_pcur->beam() && req_l_pcur->beam()->spantype == Span_req::START )
- return true;
- }
- return false;
-}
-
-void
-Voice_element::set_default_group(String s)
-{
- for (iter_top(reqs, i); i.ok(); i++)
- if (i->groupchange())
- return ;
- Group_change_req *greq = new Group_change_req;
- greq->newgroup_str_ = s;
- add(greq);
-}
-
-void
-Voice_element::set_plet_backwards(Moment& now_moment_r,
- Moment until_moment, int num_i, int den_i)
-{
- now_moment_r += duration;
- if ( now_moment_r > until_moment )
- return;
- for ( PCursor<Request*> req_l_pcur( reqs.top() ); req_l_pcur.ok(); req_l_pcur++ ) {
- if (req_l_pcur->beam() && req_l_pcur->beam()->spantype == Span_req::START )
- req_l_pcur->beam()->nplet = den_i;
- if (req_l_pcur->rhythmic())
- req_l_pcur->rhythmic()->plet_factor = Moment(num_i, den_i);
- if (req_l_pcur->stem())
- req_l_pcur->stem()->plet_factor = Moment(num_i, den_i);
- }
-}
+++ /dev/null
-/*
- walkregs.cc -- implement Walker_registers
-
- source file of the LilyPond music typesetter
-
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
-*/
-
-#include "debug.hh"
-#include "clef-reg.hh"
-#include "local-key-reg.hh"
-#include "key-reg.hh"
-#include "meter-reg.hh"
-#include "bar-reg.hh"
-#include "bar.hh"
-#include "walkregs.hh"
-#include "staff-elem.hh"
-#include "staff.hh"
-#include "complex-walker.hh"
-#include "staff-column.hh"
-#include "voice-group-regs.hh"
-#include "voice-regs.hh"
-#include "commandrequest.hh"
-
-
-Walker_registers::Walker_registers(Complex_walker *w)
-{
- walk_l_ = w;
- add( new Bar_register);
- add( new Clef_register);
- add( new Key_register);
- add( new Meter_register);
- add( new Local_key_register);
-}
-
-void
-Walker_registers::announce_element(Staff_elem_info info)
-{
- if (info.elem_p_->name() == Bar::static_name()) {
- walk_l_->allow_break();
- }
- announce_info_arr_.push(info);
-}
-
-void
-Walker_registers::acknowledge_element(Staff_elem_info )
-{
- assert(false);
-}
-
-void
-Walker_registers::do_announces()
-{
- Request dummy_req;
- for (int i = 0; i < announce_info_arr_.size(); i++){
- Staff_elem_info info = announce_info_arr_[i];
-
- if (!info.req_l_)
- info.req_l_ = &dummy_req;
- Register_group_register::acknowledge_element(info);
- }
- announce_info_arr_.set_size(0);
-}
-
-void
-Walker_registers::typeset_element(Staff_elem *elem_p)
-{
- typeset_musical_item(elem_p);
-}
-
-void
-Walker_registers::typeset_musical_item(Staff_elem * elem_p)
-{
- walk_l_->typeset_element(elem_p);
-}
-
-void
-Walker_registers::typeset_breakable_item(Item * pre_p , Item * nobreak_p,
- Item * post_p)
-{
- if (pre_p)
- prebreak_item_p_arr_.push(pre_p);
- if (nobreak_p)
- nobreak_item_p_arr_.push(nobreak_p);
- if (post_p)
- postbreak_item_p_arr_.push(post_p);
-}
-
-void
-Walker_registers::pre_move_processing()
-{
- // this generates all items.
- Register_group_register::pre_move_processing();
- walk_l_->ptr()->typeset_breakable_items(prebreak_item_p_arr_,
- nobreak_item_p_arr_,
- postbreak_item_p_arr_);
-}
-void
-Walker_registers::post_move_processing()
-{
- Register_group_register::post_move_processing();
-}
-
-void
-Walker_registers::change_group(Group_change_req * greq_l,
- Voice_registers *voice_regs_l,
- Voice_group_registers * old_group)
-{
- Voice_registers *regs_p = (old_group)
- ? (Voice_registers*) old_group->get_register_p(voice_regs_l)
- : new Voice_registers(greq_l->voice_l());
- Voice_group_registers * new_group_l = get_group(greq_l->newgroup_str_);
- new_group_l->add(regs_p);
-
- mtor << "processed change request";
- print();
-}
-
-Voice_group_registers *
-Walker_registers::get_group(String id)
-{
- for (int i=0; i < group_l_arr_.size(); i++) {
- if (group_l_arr_[i]->group_id_str_ == id)
- return group_l_arr_[i];
- }
- Voice_group_registers *group_p = new Voice_group_registers(id);
- group_l_arr_.push(group_p);
- add(group_p);
- return group_p;
-}
-
-void
-Walker_registers::terminate_register(Request_register * reg)
-{
- for (int i=0; i < group_l_arr_.size(); i++) {
- if (group_l_arr_[i] == reg) {
- group_l_arr_.del(i);
- Register_group_register::terminate_register(reg);
- return;
- }
- }
- assert(false);
-}
-
-bool
-Walker_registers::try_request(Request * r)
-{
- bool b = Register_group_register::try_request(r);
- if (!b) {
- Command_req * cr_l = r->command() ;
-
- if (cr_l && cr_l->groupchange()) {
- change_group(cr_l->groupchange(), 0, 0);
- } else
- warning("junking request: " + String(r->name()),
- r->defined_ch_c_l_);
- }
- return b;
-}
-
-
-Staff_info
-Walker_registers::get_staff_info() return inf;
-{
- inf.c0_position_i_ = &walk_l_->c0_position_i_;
- inf.walk_l_ = walk_l_;
- inf.time_c_l_ = &walk_l_->time_;
- inf.rhythmic_c_l_ = walk_l_->default_grouping;
-}
-Paper_def*
-Walker_registers::paper()const
-{
- return walk_l_->staff_l_->paper();
-}
+++ /dev/null
-#include "debug.hh"
-#include "lexer.hh"
-#include "moment.hh"
-#include "time-description.hh"
-#include "proto.hh"
-#include "plist.hh"
-#include "source-file.hh"
-#include "source.hh"
-#include "main.hh"
-
-ostream &warnout (cerr);
-ostream *mlog(&cerr);
-/*
-void
-warning(String s)
-{
- WARN << s;
-}
-*/
-
-void
-error(String s)
-{
- if (busy_parsing())
- yyerror(s);
- else
- cerr << "error: " << s << "\n";
-
- exit(1);
-}
-
-void
-error_t(const String& s, const Moment& r)
-{
- String t_mom = String(trunc(r)) + String(r - Moment(trunc(r)));
- String e=s+ " (t = " + t_mom + ")";
- error(e);
-}
-
-void
-error_t(const String& s, Time_description const &t_tdes)
-{
- String e=s+ " (at t=" + String(t_tdes.bars_i_) + ": " + String(t_tdes.whole_in_measure_) + ")\n";
- error(e);
-}
-
-void
-message( String message_str, char const* context_ch_c_l )
-{
- String str = "lilypond: ";
- Source_file* sourcefile_l = source_l_g->sourcefile_l( context_ch_c_l );
- if ( sourcefile_l ) {
- str += sourcefile_l->file_line_no_str(context_ch_c_l) + String(": ");
- }
- str += message_str;
- if ( sourcefile_l ) {
- str += ":\n";
- str += sourcefile_l->error_str( context_ch_c_l );
- }
- if ( busy_parsing() )
- cerr << endl;
- cerr << str << endl;
-}
-
-void
-warning( String message_str, char const* context_ch_c_l )
-{
- message( "warning: " + message_str, context_ch_c_l );
-}
-
-void
-error( String message_str, char const* context_ch_c_l )
-{
- message( message_str, context_ch_c_l );
- // since when exits error again?
- // i-d say: error: errorlevel |= 1; -> no output upon error
- // warning: recovery -> output (possibly wrong)
- if ( lexer )
- lexer->errorlevel_i_ |= 1;
-// exit( 1 );
-}
+++ /dev/null
-//
-// windhoos.cc
-//
-#ifdef _WIN32
-
-#include <sys/types.h>
-#include <sys/mman.h>
-#include <winbase.h>
-
-/*
-HANDLE CreateFileMapping(
- HANDLE hFile, // handle to file to map
- LPSECURITY_ATTRIBUTES lpFileMappingAttributes, // optional security attributes
- DWORD flProtect, // protection for mapping object
- DWORD dwMaximumSizeHigh, // high-order 32 bits of object size
- DWORD dwMaximumSizeLow, // low-order 32 bits of object size
- LPCTSTR lpName // name of file-mapping object
- );
-
-
-LPVOID MapViewOfFile(
- HANDLE hFileMappingObject, // file-mapping object to map into address space
- DWORD dwDesiredAccess, // access mode
- DWORD dwFileOffsetHigh, // high-order 32 bits of file offset
- DWORD dwFileOffsetLow, // low-order 32 bits of file offset
- DWORD dwNumberOfBytesToMap // number of bytes to map
- );
-
-
-io.h:
-long _get_osfhandle( int filehandle );
-*/
-
-// cygnus's gnu-win32-b17.1 does not have _get_osfhandle
-// however, after some hacking, it turns out that:
-
-static const int OSF_OFFSET_i = 72;
-static const int OSF_BASE_i = -3;
-static const int OSF_FACTOR_i = 8;
-// let-s hope bill doesn-t change his mind any time soon :-)
-
-// so that, while waiting for cygnus's mmap, we can write:
-
-// #define HAVE_GET_OSFHANDLE // no we still cannot; works only with cl.exe
-long
-_get_osfhandle( int filedes_i )
-{
- return (long)( OSF_OFFSET_i + ( filedes_i + OSF_BASE_i ) * OSF_FACTOR_i );
-}
-
-#ifdef HAVE_GET_OSFHANDLE
-
-#include <iostream.h>
-
-caddr_t
-mmap(caddr_t addr, size_t len, int prot, int flags, int fd, off_t offset)
-{
- (void)flags;
- (void)prot;
- (void)addr;
- HANDLE osf = (HANDLE)_get_osfhandle( fd );
- HANDLE file_handle = CreateFileMapping( osf, (void*)0, PAGE_READONLY,
- 0, len, 0 );
- return (caddr_t)MapViewOfFile( file_handle, FILE_MAP_READ, 0, offset, len );
-}
-
-
-int
-munmap(caddr_t addr, size_t len)
-{
- (void)len;
- return UnmapViewOfFile( addr );
-}
-
-#else // ! HAVE_GET_OSFHANDLE //
-
-caddr_t
-mmap(caddr_t addr, size_t len, int prot, int flags, int fd, off_t offset)
-{
- (void)flags;
- (void)prot;
- (void)addr;
- (void)offset;
- char* ch_p = new char[ len ];
- if ( ch_p )
- read( fd, (void*)ch_p, len );
- return ch_p;
-}
-
-
-int
-munmap(caddr_t addr, size_t len)
-{
- (void)len;
- delete (char*)addr;
- return 0;
-}
-
-#endif // !HAVE_GET_OSFHANDLE //
-
-
-#endif // _WIN32 //
+++ /dev/null
-#include "break.hh"
-#include "pscore.hh"
-#include "debug.hh"
-
-/** el stupido. This should be done more accurately:
-
- It would be nice to have a Dynamic Programming type of algorithm
- similar to TeX's
-
- */
-Array<Col_hpositions>
-Word_wrap::solve()
-{
- problem_OK();
- iter_top(pscore_.cols,curcol);
- Array<Col_hpositions> breaking;
- Line_of_cols breakpoints(find_breaks());
- assert(breakpoints.size()>=2);
-
- int break_idx_i=0;
- while ( break_idx_i < breakpoints.size() -1) {
- Col_hpositions minimum;
- Col_hpositions current;
-
- // do another line
- PCol *post = breakpoints[break_idx_i]->postbreak_p_;
- current.add( post);
- curcol++; // skip the breakable.
- break_idx_i++;
-
- while (break_idx_i < breakpoints.size()) {
-
- // add another measure.
- while (breakpoints[break_idx_i] != curcol.ptr()){
- current.add(curcol);
- curcol++;
- }
- current.add(breakpoints[break_idx_i]->prebreak_p_ );
-
- // try to solve
- if (!feasible(current.cols)) {
- if (!minimum.cols.size())
- error("sorry, this measure is too long, breakpoint: "
- + String(break_idx_i) );
- current.energy = INFTY; // make sure we go back
- } else {
- current = solve_line(current.cols);
- current.print();
- }
-
- // update minimum, or backup.
- if (current.energy < minimum.energy) {
- minimum = current;
- } else { // we're one col too far.
- break_idx_i--;
- while (curcol.ptr() != breakpoints[break_idx_i])
- curcol --;
- break; // do the next line.
- }
-
-
- // add nobreak version of breakable column
- current.cols.top()=breakpoints[break_idx_i];
- curcol ++;
- break_idx_i++;
- }
-
- *mlog << "[" <<break_idx_i<<"]"<<flush;
- breaking.push(minimum);
- }
-
- return breaking;
-}
-
-Word_wrap::Word_wrap(PScore&ps)
- : Break_algorithm(ps)
-{
-}
+++ /dev/null
-\input lilyponddefs
-\input lelie.out
-\vfil\bye
\ No newline at end of file
--- /dev/null
+# tex/Makefile
+
+# subdir level:
+#
+depth = ..
+#
+
+build = ./$(depth)/lily/.build
+
+# generic stuff/Makefile
+#
+include ./$(depth)/make/Stuff.make
+#
+
+# list of distribution files:
+#
+TEXFILES = $(shell ls *.tex)
+DISTFILES = Makefile $(TEXFILES)
+#
+
--- /dev/null
+\font\musicfont=musixsps
+\font\slurfont=xslu16
+\def\thefont{\musicfont}
+
+\def\mb#1{{\thefont\char#1}}
+
+\newdimen\wid
+\newdimen\inc
+\newdimen\here
+\def\hruler#1{%
+ \wid=#1pt
+ \inc=\wid
+ \divide\inc by #1
+ \divide\wid by 2
+ \here=-\wid
+ \loop\ifdim\here<\wid\advance\here by\inc
+ \hbox to0pt{\kern\here\vrule width0.05pt height 2pt\hss}%
+ \repeat%
+}
+
+\def\vruler#1{%
+ \wid=#1pt
+ \inc=\wid
+ \divide\inc by #1
+ \divide\wid by 2
+ \here=-\wid
+ \loop\ifdim\here<\wid\advance\here by\inc
+ \vbox to0pt{\vskip\here\vrule width2pt height 0.05pt\vss}%
+ \repeat%
+}
+\def\twhrul{\hbox to 0pt{\hbox{\hruler{20}\vrule
+ width0.1pt height 3ptdepth 1pt}}}
+\def\twvrul{\hbox{\vbox to 20pt{\vruler{20}\vrule
+ width3pt height 0.1pt}}}
+
+\def\doitem#1{
+ #1 %
+ %\twvrul%doesn't work
+ \hbox to 50pt{\qquad\twhrul\mb{#1}\hss}\setbox0=\hbox{\mb{#1}} width \the\wd0\ depth \the\dp0 \ height \the\ht0}
+
+\newcount\n
+\def\charn{\n=-1
+ \loop\ifnum\n<255\advance\n by1
+ \doitem{\number\n}\endgraf\repeat}
+
+
+ \charn
+
+\bye
\ No newline at end of file
--- /dev/null
+%%
+%% include file for LilyPond
+
+\def\mdef#1#2{\def#1{\mchar{#2}}}
+\def\mchar#1{\musicfnt\char#1}
+\def\rationalmultiply#1*#2/#3{\multiply #1 by #2 \divide #1 by #3}
+\def\maccentraise#1#2{\dimen0=\noteheight
+ \rationalmultiply\dimen0*#2%
+ \raise\dimen0\hbox{#1}}
+\def\maccentdef#1#2#3{\def#1{\maccentraise{\mchar{#2}}{#3}}}
+\def\vcenter#1{\vbox to 0pt{\vss #1\vss}}
+
+\def\topalign#1{\vbox to 0pt{#1\vss}}
+\def\botalign#1{\vbox to 0pt{\vss #1}}
+
+\def\centeralign#1{\hbox to 0pt{\hss#1\hss}}
+\def\leftalign#1{\hbox to 0pt{#1\hss}}
+\def\rightalign#1{\hbox to 0pt{\hss#1}}
+
+
+%% musix defs
+\parindent=0pt
+\newdimen\smallspace
+\newdimen\interlinedist
+ \newcount\n
+ \newdimen\balkhoog
+ \newdimen\notewidth
+ \newdimen\noteheight
+ \newdimen\notewidthhalf
+ \newdimen\notewidthdouble
+ \newdimen\staffrulethickness
+ \newdimen\interstaffrule
+\newdimen\balkhalf
+\def\musixtwentydefs{
+ \font\textfont=cmr10
+ \font\meterfont=cmbx12
+ \font\slurufont=xslu20
+ \font\slurdfont=xsld20
+ \font\slurhfont=xslz20
+ \font\hslurufont=xslhu20
+ \font\hslurdfont=xslhd20
+ \font\hslurhfont=xslhz20
+ \font\musicfnt=musix20
+ \font\italicfont=cmti10
+ \font\dynfont=cmbxti10 scaled \magstep1
+ \balkhoog=20pt
+ \notewidth=6pt
+ \noteheight=5pt
+ \staffrulethickness=0.4pt
+ \musixcalc
+}
+
+
+\def\musixsixteendefs{
+ \font\textfont=cmr8
+ \font\meterfont=cmbx12
+ \font\italicfont=cmti8
+ \font\slurufont=xslu16
+ \font\slurdfont=xsld16
+ \font\slurhfont=xslz20 % sigh
+ \font\hslurufont=xslhu16
+ \font\hslurdfont=xslhd16
+ \font\hslurhfont=xslhz20
+ \font\musicfnt=musix16
+ \font\dynfont=cmbxti10
+ \balkhoog=16pt
+ \staffrulethickness=0.4pt
+ \notewidth=5pt
+ \noteheight=4pt
+ \musixcalc
+}
+
+\def\musixcalc{
+ \interlinedist=\fontdimen5\musicfnt
+ \smallspace=.3\interlinedist
+ \interstaffrule=\balkhoog
+ \advance\interstaffrule by-\staffrulethickness
+ \divide\interstaffrule by 4
+ \advance\interstaffrule by -\staffrulethickness
+ \notewidthhalf=\notewidth
+ \notewidthdouble=\notewidth
+ \rationalmultiply \notewidthhalf*1/2
+ \multiply \notewidthdouble by 2
+ \balkhalf=\balkhoog
+ \rationalmultiply\balkhalf*1/2
+}
+% \def\dyn{\italicfont}
+\def\dyn{\dynfont}
+\def\dynf{f\kern-.1ex}
+\def\dynm{f\kern-.15ex}
+\def\dynp{p\kern-.15ex}
+\def\ppp{\dynfont\dynp\dynp p}
+\def\pp{\dynfont\dynp p}
+\def\p{\dynfont p}
+\def\mp{\dynfont\dynm p}
+\def\mf{\dynfont\dynm f}
+\def\f{\dynfont f}
+\def\ff{\dynfont\dynf f}
+\def\fff{\dynfont\dynf\dynf f}
+
+\def\slurcharh#1{{\slurhfont\char#1}}
+\def\slurcharu#1{{\slurufont\char#1}}
+\def\slurchard#1{{\slurdfont\char#1}}
+\def\hslurcharh#1{{\hslurhfont\char#1}}
+\def\hslurcharu#1{{\hslurufont\char#1}}
+\def\hslurchard#1{{\hslurdfont\char#1}}
+
+\mdef\quartball{'007}
+\mdef\halfball{'010}
+\mdef\wholeball{'011}
+\mdef\halfrest{'074}
+\mdef\wholerest{'075}
+\mdef\quartrest{62}
+\mdef\eighthrest{63}
+\mdef\sixteenthrest{64}
+\mdef\thirtysecondrest{65}
+\mdef\sharp{52}
+\mdef\flat{50}
+\mdef\natural{54}
+\mdef\sharpsharp{53}
+\mdef\flatflat{51}
+
+\mdef\singledot{'00}
+\mdef\doubledot{'01}
+\mdef\tripledot{'02}
+\mdef\mussepline{155}
+
+\mdef\violinclef{71}
+\mdef\bassclef{73}
+\mdef\altoclef{75}
+\mdef\cviolinclef{72}
+\mdef\cbassclef{74}
+\mdef\caltoclef{76}
+
+\mdef\deigthflag{45}
+\mdef\dsixteenthflag{46}
+\mdef\dthirtysecondflag{47}
+
+% pointing up
+\mdef\ueigthflag{40}
+\mdef\usixteenthflag{41}
+\mdef\uthirtysecondflag{42}
+
+\maccentdef\repeatcolon{55}{2/1}
+\def\emptybar{}
+
+\def\thinbar{\vrule height\balkhoog}
+%? what-s wrong with rightalign?
+\def\thickbar{\vrule height\balkhoog width 2\smallspace}
+\def\maatstreep{\thinbar}
+% \def\finishbar{\rightalign{\thinbar\kern\smallspace\thickbar}}
+\def\finishbar{\hss\rightalign{\thinbar\kern\smallspace\thickbar}}
+% \def\repeatstopbar{\rightalign{\repeatcolon\hskip2\smallspace\thinbar\hskip\smallspace\thickbar}}
+\def\repeatstopbar{\hss\rightalign{\repeatcolon\hskip2\smallspace\thinbar\hskip\smallspace\thickbar}}
+% \def\repeatstopbar{\kern-3\smallspace\rightalign{\repeatcolon\kern2\smallspace\thinbar\kern\smallspace\thickbar}\kern3\smallspace}
+\def\repeatstartbar{\hbox{\thickbar\kern\smallspace\thinbar\kern2\smallspace\repeatcolon}}
+\def\repeatstopstart{\hbox{\repeatcolon\kern2\smallspace\thinbar\kern\smallspace\thickbar\kern\smallspace\thickbar\kern\smallspace\thinbar\kern2\smallspace\repeatcolon}}
+\def\doublebar{\hbox{\thinbar\hskip\smallspace\thinbar}}
+
+%compatability
+\def\repeatbar{\repeatstopbar}
+\def\startrepeat{\repeatstartbar}
+\def\repeatbarstartrepeat{\repeatstopstart}
+
+\def\generalmeter#1#2{\botalign{\vbox to\balkhalf{\vss \meterfont#1}%
+ \nointerlineskip
+ \vbox to \balkhalf{\vss\meterfont #2}}}
+\def\defaultlineseparator{\vbox{\mussepline\vskip -5pt\mussepline}}
+\def\lineseparator{\defaultlineseparator}
+\def\beauty{%
+ \par\vskip 10pt plus 30pt minus 10pt\par
+ \hskip -5pt\lineseparator
+ \par\vskip 10pt plus 30pt minus 10pt\par
+}
+
+\def\interstaffline{%
+ \vskip 10pt
+}
+\def\ugly{\nointerlineskip\par
+\vskip 40pt\par\vbox{\leftalign{\vrule width30pt height1pt}}\par\vskip 40pt
+}
+\def\interscoreline{\beauty}
+
+
+\def\lines#1#2{%
+ \vbox{\kern-\interstaffrule
+ \n=0\nointerlineskip%
+ \loop\ifnum\n<#1\advance\n by1%
+ \kern\interstaffrule
+ \hrule height \staffrulethickness width#2
+ \repeat
+ }}
+
+\def\toplines#1{ % why space needed here?
+ \topalign{\hbox{\kern-\notewidth\lines{#1}{\notewidthdouble}}}}
+\def\botlines#1{ % idem ditto
+ \botalign{\hbox{\kern-\notewidth\lines{#1}{\notewidthdouble}}}}
+
+%
+% a staffsymbol with #1 lines, width #2
+% bottom at baseline
+\def\linestafsym#1#2{\leftalign{\botalign{\lines{#1}{#2}}}}
+
+\def\eigthflag{\topalign{\ueigthflag}}
+\def\sixteenthflag{\topalign{\usixteenthflag}}
+\def\thirtysecondflag{\topalign{\uthirtysecondflag}}
+
+\def\cquartrest{\vcenter\quartrest}
+\def\ceighthrest{\vcenter\eighthrest}
+\def\csixteenthrest{\vcenter\sixteenthrest}
+\def\cthirtysecondrest{\vcenter\thirtysecondrest}
+
+\def\lsingledot{\kern-\notewidth\singledot}
+\def\ldoubledot{\kern-\notewidth\doubledot}
+\def\ltripledot{\kern-\notewidth\tripledot}
+
+\maccentdef\sforzato{30}{-3/2}
+\maccentdef\marcato{20}{-1/1}
+\maccentdef\imarcato{21}{1/1}
+\maccentdef\staccato{24}{-1/1}
+\maccentdef\istaccato{25}{1/1}
+\maccentdef\staccatissimo{28}{-1/1}
+\maccentdef\istaccatissimo{29}{1/1}
+\maccentdef\portato{18}{-9/10}
+\maccentdef\iportato{19}{9/10}
+\maccentdef\tenuto{26}{0/1}
+\maccentdef\itenuto{27}{0/1}
+\maccentdef\fermata{80}{-1/1}
+\maccentdef\ifermata{81}{1/1}
+
+
+
+\mdef\spicato{28}
+\mdef\ispicato{29}
+\mdef\upbow{23}
+\mdef\downbow{22}
+\mdef\portato{26}
+
+\def\stem#1#2{\vrule height#2 depth-#1}
+
+\def\placebox#1#2#3{%
+ \botalign{\hbox{\raise #1\leftalign{\kern #2{}#3}}}%
+}
+
+
+\def\beamslope#1#2{{\count0=#2\advance\count0 by#1\musicfnt\char\count0}}
+\def\rulesym#1#2{\vrule height #1 width #2}
+\def\crescendosym#1{\count0=84\advance\count0 by #1}
+\def\decrescendosym#1{\count0=116\advance\count0 by #1}
+\def\settext#1{\textfont #1}
+\def\setitalic#1{\italicfont #1}
--- /dev/null
+% Mats Bengtsson
+\documentclass[a4paper, 10pt]{article}
+
+% Allow for 8-bit characters:
+\usepackage[latin1]{inputenc}
+\usepackage[T1]{fontenc}
+
+\begin{document}
+\input lilyponddefs
+\input titledefs
+
+\def\settext#1{\normalfont #1} % Allow for 8-bit characters
+
+\input lelie.out
+\end{document}
--- /dev/null
+\input lilyponddefs
+\input lelie.out
+\vfil\bye
\ No newline at end of file
--- /dev/null
+\def\thetitle{}
+\def\thecomposer{}
+\def\theinstrument{}
+\def\title#1{\def\thetitle{#1}}
+\def\composer#1{\def\thecomposer{#1}}
+\def\instrument#1{\def\theinstrument{#1}}
+
+\def\maketit{
+ \begin{center}
+ {\Large\bfseries\thetitle}\\
+ \vskip12pt
+ {\bfseries\theinstrument}\hfill{\scshape\thecomposer}
+ \end{center}
+ \bigskip
+ }
\ No newline at end of file
+++ /dev/null
-\def\thetitle{}
-\def\thecomposer{}
-\def\theinstrument{}
-\def\title#1{\def\thetitle{#1}}
-\def\composer#1{\def\thecomposer{#1}}
-\def\instrument#1{\def\theinstrument{#1}}
-
-\def\maketit{
- \begin{center}
- {\Large\bfseries\thetitle}\\
- \vskip12pt
- {\bfseries\theinstrument}\hfill{\scshape\thecomposer}
- \end{center}
- \bigskip
- }
\ No newline at end of file