COM-JUMP-TO-HERE and click to move cursor interface
[gsharp.git] / Doc / gsharp.tex
blob1b0abbad3f5f6449b85df1280dead3dc47a13494
1 \documentclass[11pt]{book}
2 \newcommand{\Comment}[1]{\begin{center}\tt #1 \end{center}}
3 % \usepackage{doublespace}
4 \usepackage[T1]{fontenc}
5 \usepackage[latin1]{inputenc}
6 \usepackage{alltt}
7 \usepackage{moreverb}
8 \usepackage{epsfig}
9 \usepackage{makeidx}
11 \setlength{\parskip}{0.3cm}
12 \setlength{\parindent}{0cm}
14 \def\lispout#1{\underline{#1}}
15 \def\commonlisp{Common Lisp}
16 \def\scheme{Scheme}
17 \def\gs{Gsharp}
18 \def\midifile{Midifile}
19 \def\midi{MIDI}
20 \def\obseq{Obseq}
21 \def\clos{CLOS}
22 \def\clim{CLIM}
23 \def\rs{Robert Strandh}
24 \def\kerhoas{Laurent Kerhoas}
25 \def\rms{Richard Stallman}
26 \def\lisp{Lisp}
27 \def\tcl{Tcl}
28 \def\elk{Elk}
29 \def\gnu{GNU}
30 \def\guile{Guile}
31 \def\scm{SCM}
32 \def\xwin{the X Window System}
33 \def\freetype{FreeType}
34 \def\metafont{METAFONT}
35 \def\bs{$\backslash$}
36 \def\lispobj#1{\textsl{#1}}
37 \def\lispobjindex#1{\lispobj{#1}\index{#1@\lispobj{#1}}}
38 \def\syntax#1{\texttt{#1}}
39 \def\metavar#1{\textit{#1}}
40 \def\unimp#1{\footnote{This feature is not yet implemented. #1}}
42 \def\kbd#1{`#1'}
43 \def\command#1{``#1''}
45 \def\inputfig#1{\input #1}
46 \def\inputtex#1{\input #1}
48 \newenvironment{itemize0}{
49 \begin{itemize}
50 \setlength{\parskip}{0cm}%
52 {\end{itemize}}
54 \newenvironment{enumerate0}{
55 \begin{enumerate}
56 \setlength{\parskip}{0cm}%
58 {\end{enumerate}}
60 \newenvironment{smalltt}{
61 \begin{alltt}
62 \small
64 {\end{alltt}}
66 \inputtex{spec-macros.tex}
68 \title{{\Huge {\gs}}\\{\huge The Extensible, Interactive Score Editor}}
70 \author{{\Large Robert Strandh}}
72 \date{September 2003}
74 \makeindex
75 \begin{document}
76 \pagenumbering{roman}
78 \maketitle
80 \newpage
82 \vspace*{\fill}
83 \copyright{} 2003, Robert Strandh
85 I intend to distribute this document according to some kind of free
86 license, such as the GNU Free Documentation License, but I have not
87 had the time to figure out how it works yet.
89 \newpage
91 {\setlength{\parskip}{0cm}
92 \tableofcontents}
94 \inputtex{intro.tex}
96 % ***********************************************************
97 \part{Getting started}
99 %======================================================
100 \chapter{Installing and running {\gs}}
102 \section{Installing {\gs}}
104 We have not worked on the installation procedure at all, and in fact,
105 we have not decided exactly in what form the releases will be made
106 available to the public. For that reason, these instructions may
107 change in the future.
109 {\gs} uses a number of programs and libraries that you need to install
110 before installing {\gs} itself.
113 Most importantly, you will need an implementation of {\commonlisp}.
114 We recommend SBCL on GNU/Linux x86 and OpenMCL on MacOS PPC.
116 To install the libraries and {\gs} itself, you will need ASDF, which
117 comes with some {\commonlisp} implementations. If not, you will have
118 to install it first.
120 You will need a copy of the Flexichain library which you can find on
121 common-lisp.net.
123 You will need to download a copy of McCLIM, the free implementation of
124 the Common Lisp Interface Manager. Again, you will find it on
125 common-lisp.net.
127 {\gs} uses a library on top of McCLIM called ESA (for Emacs-Style
128 Application). For now, the ESA library is distributed with {\gs}, but
129 that might change in the future, in which case you will need a copy of
130 it as well, again from common-lisp.net.
132 If you have downloaded a \emph{tar}-file of {\gs}, you need to untar
133 it (using something like \texttt{tar xvf gsharp.tar}) in some
134 directory. If you have downloaded {\gs} from a CVS repository, you
135 already have the directory structure required.
137 First make the fonts. In the \texttt{Fonts} subdirectory, type
138 \texttt{make}.
140 To compile and load {\gs}, you have two possibilities (as with most of
141 the libraries): either load the \texttt{gsharp.asd} file manually, or
142 put the directory in which {\gs} resides in the
143 \texttt{asdf:*central-registry*} list of software that can compiled
144 and installed using ASDF.
146 Next, follow the instructions for installing ASDF, Flexichain, and
147 McCLIM. When you have all these libraries in a running {\lisp} image,
148 type:
150 \texttt{(asdf:operate 'asdf:load-op :gsharp)}
152 which will compile and load all the files of {\gs}. To start {\gs} type
154 \texttt{(gsharp::gsharp)}
156 \section{The different editing panes}
158 When you start {\gs}, you should see a number of windows (called
159 \emph{panes}) that are described briefly in this section.
161 \subsection{The score pane}
162 \label{sec-score-pane}
164 The largest pane is the \emph{score pane}\index{score
165 pane}\index{pane!score|)} where you will do most of the editing,
167 When prompted for some item on display in the score pane, you can
168 usually click on it. For instance, if you have issued a command that
169 operates on a particular staff, you can usually click on a visual
170 representation of the staff in the score pane to satisfy the request
171 for the staff.
173 \subsection{The minibuffer}
174 \label{sec-minibuffer}
176 The pane at the bottom is called the
177 \emph{minibuffer}\index{minibuffer}. In it, you can type
178 \emph{extended commands} (invoked by the keystroke M-x) that do not
179 have keyboard shortcuts.
181 The minibuffer is also where you get prompted for arguments to various
182 {\gs} commands. In those cases, you usually have a choice between
183 clicking on a visual representation of the argument you would like to
184 supply as mentioned in section \ref{sec-score-pane}, typing some
185 textual representation of it directly at the prompt, or using the
186 right mouse button to get a menu of all possibilities from which you
187 can select the one you want.
189 When typing some textual representation of some existing object, such
190 as the name of a layer or of a staff, you can usually use
191 \emph{completion}\index{completion}, which means that you can type a
192 unique prefix of the text and then use the \kbd{TAB} key to get {\gs}
193 to fill in the rest. Using completion after having been prompted for
194 some argument is usually faster (provided you have some idea of what
195 the textual representation is) than to grab the mouse and click on the
196 object in the score pane.
198 \subsection{Other panes}
200 In the upper-right corner, you will see a the pane that determines the
201 \emph{input state}\index{input state}\index{pane!input state|)} The
202 input state shows a stylized version of a notehead, possibly with a
203 stem, augmentation dots, and beaming information. If the stem is
204 down, all the new clusters (a cluster is rougly the same thing as a
205 chord) entered will have their stems down. If the stem is up, all the
206 new clusters entered will have their stems up. If the input state
207 shows both a stem up and a stem down, all new clusters will have a
208 stem direction of \emph{auto}, indicating that {\gs} will determine
209 stem direction based on position of the notes on the staff and beaming
210 information.
212 In the lower-right corner, you will see a pane that gives more detail
213 about \emph{current element}\index{current
214 element}\index{element!current|)}, i.e., the element (if any)
215 immediately to the left of the cursor), namely the \emph{current
216 element pane}\index{current element pane}\index{pane!current
217 element|)}. (We may eliminate this pane in the
218 future if we can figure out a way to display this information in a not
219 to disturbing way directly in the score pane).
221 \section{The cursor}
223 In the score pane, you will see a yellow vertical line across the
224 single staff on display and two parallel vertical red lines that are
225 usually near the yellow line. This is the {\gs}
226 \emph{cursor}\index{cursor} where all editing takes place.
228 The cursor is either before all the elements, after all the elements,
229 or between two element. Newly created elements will be inserted
230 immediately to the left of the cursor (which will make the newly
231 inserted element the \emph{current} one).
233 The yellow line indicates the staff to which newly inserted elements
234 will belong. The red lines indicate the interval of pitches that will
235 be used for newly inserted notes. This interval is centered around
236 the last note that was inserted. You can change this interval by
237 moving it up or down one octave using the commands \kbd{L} (Lower) and
238 \kbd{H} (Higher).
240 \chapter{Basic editing and cursor motion}
242 \section{Entering single-note elements}
244 To enter single-note elements, you use the keyboard and type names of
245 notes such as \kbd{c}, \kbd{d}, \kbd{e}, \kbd{f}, \kbd{g}, \kbd{a}, or
246 \kbd{b} (in lower case). Each time you type the name of a note, a new
247 single-note element will be inserted to the left of the cursor.
249 {\gs} will try to guess which octave you want from the previous note
250 you typed, so that the pitch distance between the two is minimized.
251 If this choice is not right, you can type a capital \kbd{L} (for
252 \command{Lower}) in order to tell {\gs} to decrease its idea of what
253 notes to enter next by one octave, or \kbd{H} (for \command{Higher})
254 in order to tell {\gs} to increase its idea of what notes to enter
255 next by one octave.
257 The visible cursor will indicate what interval {\gs} thinks is the
258 best for the next inserted note with two parallel vertical red lines.
260 \section{Adding notes to existing elements}
262 In order to add a new note to the current element, you type the note
263 name with a capital letter such as \kbd{C}, \kbd{D}, \kbd{E}, \kbd{F},
264 \kbd{G}, \kbd{A}, or \kbd{B}.
266 Again, {\gs} will try to guess which octave you want from the previous
267 note you typed, so that the pitch distance between the two is
268 minimized.
270 Currently, there is no way to remove a single note from an element
271 (though we may implement that in the future). For now, if you add a
272 note by mistake, the only way you can fix it is by erasing the entire
273 element and start over.
275 \section{Adding a rest}
277 A rest is another kind of element. You enter a rest by typing \kbd{,}
278 (\command{Insert Rest}). Conceptually, every rest has a notehead as
279 well as rbeams and lbeams in addition to augmentation dots. These are
280 used to determine the duration and what kind of rest to display.
282 \section{Deleting elements}
284 To erase the current element, type \kbd{Control-h} (\command{Erase
285 Element}), i.e. hold the \kbd{control} key down while hitting the
286 \kbd{h} key.
288 It is also possible to delete the next element after the cursor by
289 typing \kbd{Control-d} (\command{Delete Element}).
291 In general, we speak about \emph{erasing}\index{erasing} when the
292 material removed is to the left of the cursor, and
293 \emph{deleting}\index{deleting} when it is to the right.
295 \section{Moving by element}
297 To move backward and forward over the elements that you have typed,
298 you can type \kbd{Control-b} (for \command{Backward Element}) or
299 \kbd{Control-f} (\command{Forward Element}).
301 \section{Adding and removing augmentation dots}
303 If you would like to add an augmentation dot to the current element,
304 or more generally, to add another dot to the ones already there, you
305 type \kbd{.} (\command{More Dots}). To erase one of the dots, type
306 \kbd{x.} (\command{Fewer Dots}).
308 The key \kbd{x} can be used in many other situations as a prefix to
309 indicate the opposite command from the one indicated without the
310 \kbd{x} prefix.
312 \section{Adding and removing beaming and flags}
314 {\gs} maintains beaming information for each element in the following
315 way. Each element has a number of right beams (or \emph{rbeams} for
316 short) and a number of left beams (or \emph{lbeams} for short).
318 If the element has neither lbeams nor rbeams, the element is
319 considered as having neither flags nor beams. Its duration as far as
320 layout is concerned will then be determined by the notehead and the
321 augmentation dots. The duration of the element will be determined by
322 the maximum number of lbeams and rbeams. As usual, the value of the
323 notehead is divided by two for each beam (and then increased by any
324 augmentation dots).
326 If the element has rbeams or lbeams, but neither the element to its
327 left has any rbeams nor does the element to its right have any lbeams,
328 the element will be displayed with a number of flags corresponding to
329 the maximum of its lbeams and rbeams.
331 If the element has lbeams and the element to the left has rbeams, then
332 a beam will be displayed between the two elements. The number of
333 beams that will be displayed is the minimum of the rbeams of the
334 element to the left and the lbeams of the element itself. Remaining
335 beams are displayed as fractional beams \unimp{We only show a single
336 beam at the moment}. The symmetric rule holds for the element to
337 the right.
339 To increase the number of rbeams of the current element, type \kbd{]}
340 (\command{More Rbeams}). To decrease the number or rbeams of the
341 current element, type \kbd{x]} (\command{Fewer Rbeams}). The
342 corresponding commands for the lbeams are \kbd{[} (\command{More
343 Lbeams}) and \kbd{x[} (\command{Fewer Lbeams}).
345 Thus, to obtain a two-element beam group, the first with a C and the
346 second with a D, you would type the sequence \kbd{c]d[} (think of it
347 as ``c, beam right, d, beam left'').
349 \section{Changing the notehead}
351 In order to change the notehead of the current element, you type
352 \kbd{Meta-h} (\command{Rotate Notehead}). If the notehead of the current
353 element is \emph{whole}, it will change to \emph{half}, if it is
354 \emph{half}, it will change to \emph{filled}, and if it is
355 \emph{filled}, it will change to \emph{whole}.
357 When the notehead is \emph{whole}, no stem, flags or beams will be
358 displayed, nor taken into account to compute the duration of the
359 element. The information will not be removed if present, however, so
360 that if you change the notehead from \emph{filled} to \emph{whole} and
361 then back to \emph{filled}, you will be back to the original element.
363 When the notehead is \emph{half}, a stem will be displayed, but no
364 beams or flags. Again, the information is not erased, in case you
365 would like to change back to a \emph{filled} notehead.
367 \chapter{Changing individual notes in an element}
369 {\gs} maintains a concept of a \emph{current note}\index{current
370 note}\index{note!current|)} of the current cluster. A note that has
371 just been inserted or added to an existing element becomes the
372 current note. Several commands act upon the current note.
374 To add a pitch alteration to the current note, you can type \kbd{\#}
375 (\command{sharper}) to make the key sharper (if you repeat this
376 command again, it will become double sharp) or \kbd{@}
377 (\command{flatter}). Whether or not this operation results in an
378 accidental being displayed, depends on the key signature of the staff.
379 You can change the key signature of the staff by using the command
380 \kbd{Meta-\#} (More Sharps) to add another sharp sign to (or to remove
381 a flat sign from) the signature or the command \kbd{Meta-@} (More
382 Flats) to add another flat sign to (or to remove a sharp sign from)
383 the signature.
385 To change the pitch of the current note, you can type \kbd{Meta-u}
386 (Up) to increase it or \kbd{Meta-d} (Down) to decrease it. Notice
387 that {\gs} does not allow for two different notes having the same
388 pitch in a cluster. An attempt to move the pitch of the current note
389 so that it ends up on top of an existing one, will remove one of the
390 notes.
392 The commands \kbd{Meta-u} and \kbd{Meta-d} can also be used on a rest,
393 in which case they change the vertical staff position of the rest.
394 This is useful if you have several voices on one staff and you would
395 like to have one voice higher on the staff than the other. In the
396 future, we will implement the possibility for a voice to have a
397 default staff line for rests.
399 In a multi-notehead cluster, you will have to change the current
400 note. You can do this by typing \kbd{p} to make the note with the next
401 higher pitch the current one, or \kbd{n} to make the note with the
402 next lower pitch the current one.
404 Occasionally, you might want to display an accidental even though the
405 layout engine decided it was not necessary because the staff position
406 of the note has the same pitch alteration inherited from the key
407 signature. \unimp{This is a matter of adding another slot to a
408 note}.
410 \chapter{Changing the input state}
412 If you have a long sequence of elements, each with (say) three flags
413 to type, you would not want to enter these flags for each element,
414 since you would have to type something like
415 \kbd{c]]]d]]]e]]]f]]]g]]]}. A better idea would be to change the
416 input state (or istate for short) so that each new element has three
417 rbeams and then just to type \kbd{cdefg}.
419 Changes to the input state are made in the score pane, but they have
420 an immediate effect on the presentation in the input state pane.
422 Commands to change input state mimic those of changes to the current
423 element, except prefixed by \kbd{i}. Thus, to add in rbeam to the
424 input state, you would type \kbd{i]}, and to erase one rbeam you would
425 type \kbd{ix]}. Adding and removing lbeams and dots work in the
426 analogous way.
428 Similarly, in order to change the notehead of the input state, you
429 type \kbd{in} (\command{Istate Rotate Notehead}). If the notehead of
430 the input state is \emph{whole}, it will change to \emph{half}, if
431 it is \emph{half}, it will change to \emph{filled}, and if it is
432 \emph{filled}, it will change to \emph{whole}.
434 \chapter{Operations on measures}
436 You add a barline at the cursor location by typing \kbd{|}. As
437 with other element, the cursor will be positioned right after the
438 newly created barline. In fact, a barline is just like any
439 other element as far as editing operations are concerned.
441 Thus, to delete a barline, you simply use the ordinary commands
442 for erasing or deleting elements.
444 \chapter{Operations on staves}
445 \label{chap-op-staves}
447 Initially, when {\gs} starts up, there is a single staff on display.
448 It is a standard five-line staff with a treble clef on staff step 2
449 (we count the bottom line of the staff as staff step 0).
451 \section{Renaming and existing staff}
453 Staves have unique names in {\gs}. Initially, the name of the first
454 staff on display is some default name such as ``default staff''. You
455 typically want to use names of staves that suggest the kind of musical
456 material displayed on it, such as ``Trumpets'' or ``Piano right
457 hand'', etc.
459 You can give a different name to an existing staff by issuing the
460 command \command{Rename Staff}, either from a menu or form the
461 minibuffer. This command prompts for a staff to rename and a new name
462 for the staff. At the prompt for the staff to rename, you have a
463 choice of clicking on a staff on display as indicated in section
464 \ref{sec-score-pane}, or typing its name in the minibuffer possibly
465 with \emph{completion}\index{completion} as indicated in section
466 \ref{sec-score-pane}. Renaming a staff is such an infrequent
467 operation that there is no keyboard shortcut for it.
469 \section{Inserting a new staff}
470 \label{sec-inserting-staff}
472 Unless you are writing some very simple music, or a part for a
473 monophonic instrument, you probably want to be able to add new staves
474 to the score. Because adding new staves are done fairly infrequently,
475 there is no keyboard shortcut for doing it. Instead, you have to
476 issue one of the commands for doing this either by typing it (with
477 completion, see \ref{sec-minibuffer}) in the minibuffer or using
478 the mouse to select one from a menu.
480 {\gs} imposes an \emph{order} on the staves of a score. This order is
481 the one used to display the staves from top to bottom. There are two
482 commands available for inserting new staves, \command{Insert Staff
483 Below} to insert a staff \emph{below} an existing one, and \command{Insert
484 Staff Above} to insert a staff \emph{above} an existing one.
486 In both cases, you will be prompted for some required information, in
487 order for {\gs} to be able to create the new staff. First, you will
488 be prompted for an existing staff below which (in the case of
489 \command{Insert Staff Below} or above which (in the case of
490 \command{Insert Staff Above} you would like to insert the new staff.
491 As usual, you can either click on a visual representation of the staff
492 in the score pane (see section \ref{sec-score-pane}) or type its name
493 in the minibuffer with completion (see section
494 \ref{sec-minibuffer}).
496 Next, you are prompted for the type of the staff to create. There are
497 currently two types of staves, namely `fiveline' and `lyrics'. At the
498 moment, the only way to answer this question is to type it in the
499 minibuffer (again, completion is available).
501 If you requested a five-line staff to be created, you will also be
502 prompted for the type of clef you would like the staff to have. There
503 are three possible choices `treble', `bass', and `c', which you have
504 to type in the minibuffer at the prompt. You will also be prompted
505 for a `line' number on which the clef is to be placed. Recall that
506 the lines are numbered with even numbers starting with `0' for the
507 bottom line of the staff. The normal place for a treble clef is thus
508 `2' and the normal place for a bass clef is `6'. For the c clef it
509 varies.
511 If instead you requested a lyrics staff to be created, there is no
512 more information to supply.
514 \section{Deleting a staff}
516 To delete an existing staff, you issue the \command{Delete Staff}
517 command, either from a menu or in the minibuffer. Deleting an
518 existing staff is such an infrequent operation that no keyboard
519 shortcut is provided.
521 The command prompts for a staff to be deleted. As usual, you can
522 either satisfy the request by clicking on the visual representation of
523 a staff in the score pane (see section \ref{sec-score-pane}) or typing
524 a response in the minibuffer (see section \ref{sec-minibuffer}).
526 \section{Changing the key signature}
528 To alter the key signature of a staff, use the commands \kbd{Meta-\#}
529 \command{More Sharps} and \kbd{Meta-@} \command{More Flats}.
531 \chapter{Operations on layers}
533 {\gs} organizes musical material into \emph{layers}\index{layer}. A
534 {\gs} layer corresponds roughly to a \emph{voice}\index{voice} in
535 traditional music terminology. The reason a different term was chosen
536 is that there might be some notations that require a voice to be split
537 into several layers. Each layer can be displayed on one or more
538 staves, one of which is always the \emph{current}\index{current staff}
539 one.
541 In {\gs}, layers have unique names. Initially, when {\gs} starts up,
542 it has a single layer with some default name such as ``default
543 layer''. It has a single staff on which it is displayed, namely the
544 default staff (see chapter \ref{chap-op-staves}).
546 You typically want to choose names for layers that suggest the kind of
547 music material that is contained in it. Since a layer has (or will
548 have) a unique \emph{instrument}\index{instrument} associated with it,
549 we advice you not to mix material for different instruments in a
550 layer. Therefore, when a part plays several instruments (presumably
551 not simultaneously) we advice you to use a different layer for each
552 instrument in the part. Typically, then, a layer name would be the
553 name of an instruments playing a single part, such as ``First Violin''
554 or ``Solo Guitar''.
556 \section{Renaming an existing layer}
558 You can rename any layer by issuing the command \command{Rename
559 Layer}, either in the minibuffer (see section
560 \ref{sec-minibuffer}) or from a menu.
562 You will first be prompted for a layer to rename. Currently the only
563 way to satisfy this request is by typing the name of the layer to the
564 prompt in the minibuffer. Completion is possible as usual (see
565 section \ref{sec-minibuffer}).
567 Next, you will be prompted for a new name of the layer. To satisfy
568 the request, you type any string at the prompts. Notice that names
569 must be unique. If you type the name of an existing layer, your
570 entire command will be rejected.
572 \section{Selecting a layer}
574 {\gs} has the concept of a \emph{current layer}\index{current layer}
575 which receives all music material typed in the score pane, such as
576 notes, rests, etc.
578 To change the current layer, issue the \command{Select Layer} either
579 from a menu or in the minibuffer.
581 You will be prompted for a layer to be used as the current one. At
582 the moment, the only way to satisfy this request is to type its unique
583 name (with completion, see \ref{sec-minibuffer}) at the prompt in
584 the minibuffer.
586 \section{Adding a new layer}
588 Before adding a new layer, make sure you have created one of the
589 staves on which you would like for its material to be displayed (see
590 section \ref{sec-inserting-staff}).
592 Adding a new layer is done by issuing the command \command{Add
593 Layer}. You will be prompted for a unique name of the new layer,
594 and for an existing staff to use as the initial staff of the layer.
596 The type of the layer that is created as a result of this command
597 depends on the type of the initial staff. If the initial staff is an
598 ordinary five-line staff, then a melody layer is created. If instead
599 the initial staff is a lyrics staff, a lyrics layer is created.
601 \section{Deleting a layer}
603 To delete the current layer, you have to use the minibuffer (since
604 this is an operation that is presumably rare). The command to use is
605 \command{Delete Layer}. You will be prompted for a layer to delete.
607 \section{Adding an existing staff to a layer}
609 A layer can be displayed on one or several \emph{staves}. Most layers
610 will have a single staff associated with them, but is occasionally
611 useful to have two or more. Clusters within such a layer with notes
612 in different staves will have their stems span those staves. At other
613 times, it is useful simply to have some elements of the layer
614 displayed on one staff and some other elements on a different
615 staff.
617 To add a staff to the possible staves of a layer, use the command
618 \command{Add Staff To Layer}. You will be prompted for a staff to add
619 and a layer to add it to.
621 \section{Stem direction of a layer}
623 A layer can have a preferred stem direction for all clusters in
624 it\unimp{It is not hard to do, though}. The user can override this
625 stem direction for individual elements, but if the stem direction of
626 the cluster is \emph{auto}\index{auto!stem direction|)}, then it will
627 be displayed with the stem direction determined by the layer. If the
628 stem direction of the layer is also \emph{auto}, the layout engine
629 will determine the stem direction.
631 % ***********************************************************
632 \part{Reference manual}
633 \inputtex{model.tex}
634 \inputtex{commands.tex}
636 % ***********************************************************
637 \part{Internals}
639 %======================================================
640 \chapter{Implementation of the user model}
642 The implementation of the user model pretty much reflects the model
643 itself, except that the implementation of the \emph{slice} is not a
644 simple sequence of elements.
646 Instead, a \emph{slice} is a sequence of a user-invisible type called
647 a \emph{bar}. We introduced this additional type to simplify the
648 layout algorithm. A bar contains all the non-barline elements
649 between two barlines. The layout algorithm therefore does not
650 have to start by finding the barlines in the sequence, but can
651 directly line up the material between barlines.
653 The implementation of the model is actually spread out in three
654 different files:
656 \begin{itemize}
657 \item \texttt{buffer.lisp}: This file is the one that most immediately
658 corresponds to the user model. Generic functions allow insertion
659 and deletion of the different types used to implement the model.
660 Currently, the implementation of various sequences is in the form of
661 simple Lisp lists. We might change that one day for performance
662 reasons, but then again, it may not be necessary.
663 \item \texttt{numbering.lisp}: This file observes the action (through
664 :before, :after, and :around methods) of the basic operations in
665 order to number different instances of the basic types. This allows
666 us to know at any point in time whether an instance precedes another
667 in a sequence. The implementation of the numbering scheme is not
668 very efficient at the moment, but it might not matter since
669 sequences are fairly short in general.
670 \item \texttt{cursor.lisp}: This file implements cursor operations.
671 It observes operations in the preceding two files in order to move
672 around cursors.
673 \end{itemize}
675 A cursor has two slots, a bar in which it is located, and the position
676 within the bar. Cursors are inserted on most of the model types (bar,
677 slice, segment, buffer) so that when one of those elements is deleted,
678 the cursor can be moved accordingly. Things get complicated because
679 we want to allow for an arbitrary number of cursors, each attached to
680 a different window, though we do not currently take advantage of that
681 possibility.
683 %======================================================
684 \inputtex{buffer.tex}
685 %======================================================
686 \chapter{The Layout algorithm}
688 \section{Purpose}
690 The purpose of the layout algorithm is to divide the entire score into
691 displayed units. Currently, these units are \emph{lines}, where a
692 line is the part of system displayed in sequence from left to right.
693 In the future, it will be possible to use \emph{pages} as units which
694 will make things a bit more realistic. Since we currently do not have
695 pages, our display is mostly in the form of a ``roll of paper''.
697 \section{What it needs to recompute}
699 The layout algorithm is invoked after each keystroke. But in order to
700 do its work correctly, it has to know what has been damaged between
701 two invocations. The user can have executed some arbitrary code
702 between two such invocations, and in order not to have to recompute
703 the entire score each time, it preserves the result of its calculation
704 between invocations and only recompute what is necessary.
706 To know what has been damaged, the layout algorithm (in the file
707 \texttt{measure.lisp}) installs a different set of \texttt{:before},
708 \texttt{:after}, and \texttt{:around} methods to observe the
709 operations on the fundamental implementation of the user model.
710 Currently, it does its work in a very crude way. Whenever the
711 structure has been modified in any way, the entire segment is marked
712 as modified and will be totally recomputed at the next invocation.
714 Recomputing the layout involves computing, for each segment, a
715 sequence of \emph{measures}\index{measure}. This is a user-invisible
716 type that corresponds to the superimposition of simultaneous bars in
717 overlapping layers. We could be more careful about marking things as
718 damaged, and preserve measures that contain bars that have not been
719 modified. We might do that if performance requires it. At the
720 moment, we have no reason to believe that it will be necessary.
722 \section{The importance of segments}
724 The importance of the concept of a segment should now be clear.
725 If the user deletes a barline, all measures to the right of the
726 point of deletion \emph{within the same segment} must be recomputed,
727 since the musical material will no longer line up the same way. Had
728 the score been a single segment, we would have had to potentially
729 recompute the entire score in such situations. In addition, it would
730 be pretty annoying to the user not to be able to count on finished
731 material far from the cursor to remain intact. Thus, the concept of a
732 segment both helps the user organize his material and helps the
733 implementor limit the damage that needs to be repaired by the layout
734 algorithm.
736 \section{Head and tail slices}
738 There is a slight problem with \emph{head slices} and \emph{tail
739 slices} which is why they are not implemented yet. While
740 conceptually these slices belong to the segment of their
741 corresponding layer, the layout algorithm must align them with the
742 last measure of the previous segment and the first measure of the
743 next segment. To make it impossible for those slices to stick out
744 arbitrarily far, we do not allow for head and tail slices to contain
745 barlines. This limits the stick-out to the previous and the
746 next segments. We have not yet decided how to manage these slices.
747 Probably, a modification would have to mark the previous or the next
748 segment as damaged, or at least the last measure or the first measure
749 in these segments.
751 \section{The concept of a measure}
753 A measure, as far as the layout algorithm is concerned, only contains
754 some very limited amount of information about its bars so that it will
755 know how much room the measure will take up on a given line of musical
756 material.
758 The main problem we need to address is the fact that a measure takes
759 up a different amount of space according to the contents of the other
760 measures of the same line. The remainder of this section will discuss
761 how we solve that problem.
763 First, let us introduce the concept of a \emph{time line}\index{time
764 line}. A time line represents a moment in time in a given measure such
765 that the measure has some event (like notes) that start at that moment
766 in time. The \emph{duration}\index{duration!of a time line|)} of the
767 time line is the temporal distance between it and the following one in
768 the measure, or, if it is the last one, the duration of the longest
769 lasting event that starts at the moment in time.
771 From the art of music engraving, we know that a longer temporal
772 distance requires a longer geographic distance on the score as well,
773 but that is not all there is to it. In fact, we also know that
774 \emph{on a given line}, the smallest geographic distance possible (a
775 global parameter of the score that determines denseness and that we
776 will call $w_{min}$) is assigned to the shortest temporal distance on
777 that line, \emph{independently of the absolute value of that temporal
778 distance}. The other geographic distances are adjusted accordingly.
779 Thus, a measure can take up a lot more space on a line if other
780 measures on the same line have shorter minimal temporal distances
781 between time lines than itself.
783 From the articles published about the Lime score editor, we use the
784 following formula relating the ratio between the geographic distance
785 of two time lines to the ratio of their durations:
787 $w_2 / w_1 = {(d_2 / d_1)}^k$
789 where $w_1$ and $w_2$ are the ``widths'', i.e. geographic distances of
790 the two time lines, and $d_1$ and $d_2$ are their durations. The
791 parameter $k$ takes on values between $0$ and $1$, where $0$ gives
792 constant spacing (space is independent of duration) and $1$ gives
793 proportional spacing. A good value for $k$ seems to be around $0.6$.
795 On a given line, with a smallest temporal distance $d_{min}$ between
796 any adjacent time lines, we can express the geographic distance
797 $w$ following any time line with duration $d$ as:
799 $w = w_{min} {(d / d_{min})}^k$
801 Let us now define the \emph{natural width} of a measure as:
803 $W_{nm} = \sum_i w_{min} {(d_i / d_{min})}^k$
805 where $d_i$ is the duration of the $i$th time line of the measure, and
806 the \emph{natural width} of a line $W_{nl}$ as the sum of the natural
807 widths of the measures of the line.
809 We can rewrite the formula above as:
811 $W_{nm} = {(1 / d_{min})}^k w_{min} \sum_i {d_i}^k$
813 Where $w_{min} \sum_i {d_i}^k$ is a property of a measure that
814 remains constant as long as the two global parameters $w_{min}$ and
815 $k$ do not change. We shall call this property the \emph{measure
816 coefficient}. To get the natural width of the measure, it suffices to
817 multiply its coefficient with ${(1 / d_{min})}^k$, which varies
818 between different lines. Thus, we can compute the coefficient for a
819 measure once and for all (again as long as the global parameters stay
820 the same).
822 To compute the natural width of a line, we have to compute the sum of
823 the coefficients of the measures on the line and the minimum of their
824 respective minimal time line durations. This is a constant time
825 operation that does not require looping over individual measures of
826 the line.
828 Now that we know how to compute the natural width of a line, we need
829 to divide the score into lines in such a way that we have the best
830 possible layout. For that, we need to define the \emph{cost} of a
831 line.so that we can compare two different suggested lines. In {\gs}
832 we currently use the amount we have to stretch or compress it compared
833 to its natural width in order for it to fit on a line. Let us define
834 the \emph{compress factor} of the line as the quotient between the
835 natural width of the line and the width of the page. We then define
836 the \emph{cost} of a line as the maximum between the compress factor
837 and the its inverse. That is not the only way to do it. We might
838 imagine penalizing compressions more than stretches, as it might be
839 much harder to fit the musical material on the line when it needs to
840 be compressed.
842 Our definition of the natural width of a measure does not take into
843 account extra material such as accidental that need more room. We
844 could do a more precise job by adding in some extra room for such
845 material and count it toward the natural width of the line only if the
846 measure does not need to be stretched (i.e. only if the minimum
847 duration of the line is the same as that of the measure). This would
848 only slightly complicate the method of combining measure parameters
849 into line parameters and it might give a considerably better result.
851 However, it might not be very important to improve this calculation.
852 The result of the calculation is only used to divide the score into
853 lines and pages. Once we display the few visible pages of the score,
854 we have great freedom to reorganize the material on the page. Dense
855 measures might have to borrow space from less dense ones on the same
856 line. As I recall, the article on the Lime music editor describes how
857 to do this in great detail, although it is not yet implemented in
858 {\gs}. Since usually even under very crowded conditions, space can be
859 reorganized within the line, the only risk we run of not having a very
860 precise calculation of the natural width of a line is that one line
861 might look slightly denser than another one on the same page, because
862 we did not take into account all of its accidentals.
864 \section{Breaking measures into lines}
866 Breaking the sequence of all measures in the score into subsequences
867 corresponding to lines is done by an algorithm that is similar to
868 \emph{dynamic programming}. Essentially, we compute all possible line
869 breaks and choose the best one, but thanks to dynamic programming we
870 avoid a possibly exponential complexity.
872 But even the cubic complexity of dynamic programming would be
873 unacceptable for our purposes. We transform that complexity from
874 cubic to constant by a series of tricks, which are documented in a
875 separate (unpublished) article in the same directory as this one.
877 %======================================================
878 \chapter{{\gs} as a {\clim} application}
880 %======================================================
881 \chapter{The {\obseq} library}
883 %======================================================
884 \chapter{Fonts}
885 \label{chap-fonts}
887 In order for {\gs} to have a nice appearance on the screen, it was
888 determined essential to use anti-aliased fonts. The problem is that
889 {\xwin} does not have such fonts in the standard. There is an
890 extension to the XFree86 server for {\xwin} which uses anti-aliased
891 fonts, but it is not an official standard for {\xwin}. In addition,
892 this extension requires the \emph{client} to convert glyphs to
893 rasters, which traditionally has been the responsibility of the server
894 of {\xwin}. Gilbert Baumann has created a new server for {\xwin} that
895 is capable of anti-aliased fonts, but again, this is not available in
896 all servers for {\xwin}.
898 As mentioned above, in recent extensions to {\xwin}, converting the
899 glyph to a raster is a client-side operation. Usually, this operation
900 is done by a library such as {\freetype}, which can use font of type
901 TrueType or PostScript Type 1. Each of these systems has its own
902 method for rendering low-resolution fonts.
904 I decided that if converting glyphs to rasters were to be a
905 client-side operation, I might as well have full control over it, and
906 use the {\metafont} program for this purpose. {\metafont} is a
907 universal programming language that does not suffer from the
908 limitations of the \emph{hints}\index{hints} in systems such as
909 PostScript Type 1. Using {\metafont}, it would even be possible to
910 create fonts specifically useful for anti-aliasing.
912 The font used by {\gs} (called SDL, for Score Drawing Library), is
913 created by a {\metafont} program that generates glyphs that are
914 magnified a factor four. The resulting \texttt{gf} file is parsed by
915 a {\commonlisp} library that creates a {\clim} pixmap which contains an
916 anti-aliased version of the glyph.
918 The difference between this solution and the (more general) one based
919 on a library such as {\freetype}, is that {\freetype} (together with
920 the \emph{render}-extension of {\xwin}) provides \emph{transparency}
921 (also known as an \emph{alpha}-channel), which greatly simplifies
922 high-quality output, whereas using pixmaps makes it necessary to
923 display musical output in a certain order, and to do a certain amount
924 of cheating.
926 The great advantage of the {\gs} solution, though, is that it will
927 work with any basic server for {\xwin}, and that it is very fast.
929 The main problem with our solution (and this is why cheating is
930 necessary) is that glyphs can partly overlap on the page. In
931 particular, this occurs in stacks of noteheads that may or may not
932 belong to the same cluster (they could come from different layers,
933 only be placed a staff step apart), but also trivially between any
934 music character and the staff lines. When that happens with ordinary
935 fonts, no problem results, but when gray-scale fonts are used, they do
936 not combine very well.
938 For staff lines, stems, and ledger lines, we solve the problem easily
939 by imposing that these characters always be pixel aligned (and thus
940 completely black). It then suffices to draw these characters
941 \emph{after} the ones they overlap with.
943 For stacks of noteheads, the problem is greater. We solve it by
944 substituting different glyphs that correspond to combinations of
945 noteheads in a stack. To avoid having an unbounded number of such
946 combinations, we have one glyph for the lower half of a notehead, one
947 for the upper half, and one for the combination of the upper half of
948 one notehead and the lower half of the one on top of it. All these
949 glyphs are properly anti-aliased and their bounding boxes do not
950 overlap so combining them does not create any problems \unimp{We still
951 need to use the {\clim} output recording mechanism to remember
952 positions of noteheads and to substitute these alternative glyphs}.
954 The way we are planning to substitute alternative glyphs is by using
955 the \emph{output recording} mechanism of {\clim}. This mechanism is
956 responsible for repainting windows that have had their contents
957 partially lost due to being covered or invisible. It work by
958 capturing output and storing output records in the pane. We plan to
959 use it to introduce a new kind of output record that guarantees that
960 repainting will be done in the right order, and that alternative
961 glyphs will be substituted.
963 %======================================================
964 \chapter{Beam drawing}
966 It might seem like drawing beams would be trivial. {\xwin} provides
967 adequate primitives to draw filled polygons that would be
968 generalizations of beams in a score. As with fonts (see chapter
969 \ref{chap-fonts}) the problem is that anti-aliasing is called for in
970 order for the visual appearance to be acceptable, and that {\xwin}
971 does not provide for anti-aliasing in the basic protocol.
973 A possibility would be to treat beams as any other character glyphs
974 and to write a {\metafont} program for creating beams. The problem
975 with this solution is that there is a large number of different beam
976 slopes possible, and that a font would have to include a very large
977 number of them. Furthermore, beams having fairly small slopes, turn
978 out to use only a small fraction of the 16 different gray-levels that
979 we would like to use for anti-aliasing.
981 For that reason, we generate beams on an as-needed basis. A beam is
982 divided into segments, each with a $\Delta y$ of $1$ (but each
983 possibly with a different $\Delta x$. Each segment is drawn as a
984 central black rectangle surrounded by two pixmaps, each of height $1$
985 and the length of the segment. One of the pixmaps provides
986 gray-levels from black to white and the other one from white to
987 black. This method gives a smoother impression than if polygon
988 drawing were used. Each new segment is similar to the previous one
989 (its length might vary a little) and positioned one position higher or
990 lower than the previous one.
992 % ***********************************************************
993 \part{Appendices}
994 \appendix
996 \inputtex{history.tex}
997 \inputtex{beaming-algo.tex}
998 \inputtex{accidentals.tex}
999 \inputtex{release-notes.tex}
1000 \inputtex{plans.tex}
1002 %======================================================
1003 \chapter{{\clim} terminology}
1004 \label{clim-terminology}
1006 Talk about frames, panes, streams, etc.
1008 \nocite{ross-1987} \nocite{haken-1993} \nocite{haken-1995}
1009 \nocite{aho-hopcroft-ullman} \nocite{blostein-1991}
1010 \nocite{blostein-1994} \nocite{gourlay-1987-spacing}
1011 \nocite{gourlay-1987-formatting} \nocite{hegazy-1987}
1012 \nocite{hegazy-1987-breaking} \nocite{rader-1996} \nocite{tex}
1015 \printindex
1017 \newpage
1018 \bibliographystyle{alpha}
1019 \bibliography{gsharp}
1020 \end{document}