home *** CD-ROM | disk | FTP | other *** search
/ Sound Sensations! / sound_sensations.iso / midifile / cmtcmu / cmtman.doc < prev    next >
Text File  |  1990-06-28  |  150KB  |  3,453 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.                              THE CMU MIDI TOOLKIT
  17.  
  18.                            ``Charles Ives'' Edition
  19.  
  20.  
  21.                               Roger B. Dannenberg
  22.                                 14 January 1988
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.                           Carnegie Mellon University
  34.  
  35.                          Pittsburgh, PA 15213, U.S.A.
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.     The  CMU  MIDI  Toolkit (CMT), consisting of software and documentation, is
  44. provided ``as is'' without warranty of any kind, either expressed  or  implied.
  45. Should CMT prove defective, you (and not Carnegie-Mellon University) assume the
  46. entire cost of  all  necessary  servicing,  repair  or  correction.    Further,
  47. Carnegie-Mellon   University   does   not   warrant,   guarantee  or  make  any
  48. representation regarding your requirements or that CMT is free of errors.
  49.  
  50.   Neither Carnegie-Mellon University nor anyone else who has been  involved  in
  51. the  creation,  production,  or delivery of CMT program shall be liable for any
  52. direct, indirect, consequential or incidental damages arising  out  of  use  or
  53. inability to use CMT.
  54.  
  55.  
  56.  
  57.                                     Preface
  58.   This  manual  is  a  guide  for  users of the Carnegie Mellon University MIDI
  59. Toolkit, also known as CMT, a collection of software for experimental  computer
  60. music  using  standard  Musical  Instrument Digital Interface (MIDI) equipment.
  61. This manual corresponds to CMT Version 2.00.
  62.  
  63.   This is the Charles Ives edition, the first  CMT  manual.    This  manual  is
  64. updated  periodically  as  new  programs are contributed to CMT and as bugs are
  65. discovered and fixed.  I solicit your help in making this manual more  accurate
  66. and  complete.   PLEASE help us by noting any errors, omissions, or suggestions
  67. you may have.    You  can  send  your  suggestions  to  Dannenberg@A.CS.CMU.EDU
  68. (ARPAnet)  via  computer mail, or by campus mail to Roger B. Dannenberg, Center
  69. for Art and Technology, CFA, or by ordinary mail to Roger B. Dannenberg, Center
  70. for  Art and Technology, Carnegie Mellon University, Pittsburgh, PA 15213-3890,
  71. USA.  A bug report form can be found at the end of this manual.
  72.  
  73.   Many people have contributed to CMT which grew out of earlier computer  music
  74. systems  used  in  the  CMU  Computer and Electronic Music Studio.  Dean Rubine
  75. wrote the first MPU-401 interface routines with  help  from  Dale  Amon.    Joe
  76. Newcomer  ported  this  first version to his IBM-AT and helped clear up many of
  77. our interrupt problems.  Aaron Wohl wrote routines to use the PC timer and made
  78. many  good  suggestions  for  improvements.  The Tuning program and the initial
  79. tuning software were written by Michael Cressman.  Most of the development work
  80. was  done  on the IBM-XT in the CMU Computer and Electronic Music Studio.  This
  81. machine was part of a grant from IBM.
  82.  
  83.   I also wish to acknowledge support from CMU through the Music Department, the
  84. Computer   Science  Department,  the  Center  for  the  Design  of  Educational
  85. Computing, and especially the Center for Art and Technology.
  86.  
  87.  
  88.  
  89. 1. Introduction and Overview
  90.   The CMU MIDI Toolkit (CMT) is a software package  designed  for  experimental
  91. computer music education, composition, performance, and research.  CMT includes
  92. a compiler for a simple, text-based music language, and software for recording,
  93. playing,  and  computing  MIDI  data  in  real  time.    CMT  has  three  major
  94. attractions:  the flexibility of an  open-ended  design,  the  availability  of
  95. source code, and low system cost.
  96.  
  97.   What does CMT do?  The major components and their functions are:
  98.  
  99.    - Adagio  is  a language and an associated compiler.  In Adagio, a note
  100.      is represented by a line of text that specifies  attributes  such  as
  101.      pitch,  duration,  and  loudness.    Adagio  is quite flexible and is
  102.      compatible with several different ways of thinking about scores.  For
  103.      example,  ``Q''  stands  for a quarter note, but duration can also be
  104.      indicated by ``U87'', which means 0.87 seconds.  Adagio also supports
  105.      arbitrary tuning systems.
  106.  
  107.    - Transcribe  reads input from a MIDI keyboard or other MIDI controller
  108.      and produces an Adagio score.  The score can  be  played  back  using
  109.      Adagio,  or  it can be edited with a text editor to make alterations.
  110.      Since Transcribe output is at least somewhat readable by  people,  it
  111.      can also be used for performance analysis.
  112.  
  113.    - Record  is  a  combination  of  Adagio  and  Transcribe.  It plays an
  114.      existing Adagio  score  while  transcribing  a  performance.    Thus,
  115.      complex  compositions can be created one part at a time as if using a
  116.      multi-track tape recorder.
  117.  
  118.    - DXGet and DXPut are programs for recording and replaying MIDI  system
  119.      exclusive  messages.    These programs are typically used to save and
  120.      restore synthesis parameters for a digital synthesizer.
  121.  
  122.    - Moxc is a real-time programming environment that is ideal for writing
  123.      interactive   music  programs.    Moxc  is  an  extension  of  the  C
  124.      programming  language  and  is  based  on  Douglas  Collinge's  Moxie
  125.      language.
  126.  
  127.    - Also  provided  are  routines  (in C) that allow direct production of
  128.      MIDI output.  Other routines are available to read MIDI data  from  a
  129.      circular  input  buffer  and to get the current time with 0.01 second
  130.      resolution.
  131.  
  132.   Required hardware and software.  CMT runs on  an  IBM-XT  or  IBM-AT  with  a
  133. Roland  MPU-401  MIDI  interface and IBM-PC interface adapter.  You should also
  134. have a screen-based text editor.  To use  Moxc,  you  will  need  a  Lattice  C
  135. compiler.
  136.  
  137.   Other  details.  CMT is distributed by the CMU Center for Art and Technology,
  138. Carnegie-Mellon University, Pittsburgh, PA, 15213.  We  hope  that  users  will
  139. contribute  new  software  to  the  system and enhance the existing software in
  140. various ways.  We will encourage this by helping to integrate and document  new
  141. software and by distributing software updates to CMT users.
  142.  
  143. 1.1. Installing CMT
  144.   CMT comes on a set of two floppy disks.  Disk #1 contains executable programs
  145. and some example files.  Disk #2 contains source code and  files  you  need  in
  146. order  to recompile CMT programs.  If you have a hard disk, you should copy the
  147. contents of the floppy disks that come with CMT onto the hard disk.   Put  Disk
  148. #1 in the floppy disk drive and type:
  149.  
  150.     c:
  151.     cd \
  152.     mkdir cmt
  153.     cd cmt
  154.     copy a:*.*
  155.  
  156. There  are some test files in the directory test on Disk #1.  You can copy them
  157. as well by typing:
  158.  
  159.     mkdir test
  160.     cd test
  161.     copy a:\test\*.*
  162.  
  163. Some useful non-music programs are included with CMT.  They are make, grep, and
  164. ls.  To install these programs, type:
  165.  
  166.     cd \bin
  167.     copy a:\bin\*.*
  168.  
  169. If  you want to use CMT to write programs, you should copy the contents of Disk
  170. #2 into your cmt directory.  Put Disk #2 into the floppy disk drive and type:
  171.  
  172.     cd \cmt
  173.     copy a:*.*
  174.  
  175. Finally, you add c:\cmt to the path in your autoexec.bat file so that  DOS  can
  176. find CMT programs.
  177.  
  178.   Assuming you have installed an MPU-401 MIDI interface, you should now connect
  179. your synthesizer(s).  At Carnegie Mellon, we generally  use  a  Yamaha  DX7  as
  180. input  and a TX816 as output.  Thus, we connect the DX7 MIDI OUT to the MPU-401
  181. MIDI IN and the MPU-401 MIDI OUT to the TX816 MIDI IN.  You should not  connect
  182. the  MPU-401 OUT to the DX7 IN.  Doing so will cause outputs from the DX7 to be
  183. returned as inputs.  This can cause problems in the DX7.
  184.  
  185.   If you want to use the same synthesizer for both input and output, a slightly
  186. different  approach  is  necessary.  Here, you should go ahead and connect both
  187. MPU-401 IN and OUT to your synthesizer OUT and IN, respectively.  To avoid  the
  188. problem  of  having  outputs  returned as inputs, you should use the ``-block''
  189. option on all CMT software.  When the  software  is  not  running,  it  may  be
  190. necessary  to  disconnect  either  of  the  two MIDI cables because the MPU-401
  191. default is to resend all inputs as outputs.  In  some  cases,  the  DX7  cannot
  192. handle having its output data returned to its input.
  193.  
  194.  
  195.  
  196. 2. DOS Utilities
  197.   Before  describing  music software that comes with the CMU MIDI Toolkit, some
  198. DOS commands and utility programs are described.  Three programs  are  provided
  199. with  CMT  to  help  make  your  life easier.  These are make, ls, and grep.  A
  200. section on backing up files, intended for novice users,  is  also  included  in
  201. this chapter.
  202.  
  203. 2.1. make
  204.   The  make  program  is based on the Unix(Unix is a trademark of A.T.& T. Bell
  205. Laboratories) program of the same name, and is documented in the file make.man.
  206. The  purpose of make is to figure out what has to be recompiled when you edit a
  207. file.  A file called makefile contains  a  list  of  file  dependencies  and  a
  208. command  that  specifies  how  to recompile a dependent file.  The make program
  209. figures out what files have changed by examining their ``last modified''  times
  210. and  dates.   Therefore, if you use make, you must always tell DOS the time and
  211. date when you turn on your machine.    An  example  of  an  entry  in  makefile
  212. describing a dependency is
  213.  
  214.     ADOBJ = adagio.obj phase1.obj phase2.obj adaspace.obj noteoff.obj
  215.     MUSICLIB = cmt.lib
  216.  
  217.     adagio.exe : #(ADOBJ) #(MUSICLIB)
  218.             link #(COBJ) #(ADOBJ),adagio,,#(LIBS)
  219.  
  220. In  this  example,  ADOBJ is a symbol that is defined in the first line to be a
  221. list of files.  The line with the colon (:) says that adagio.exe  depends  upon
  222. everything  on  the  right  of  the  colon,  that  is,  all of the object files
  223. represented by ADOBJ and also the file cmt.lib, represented by  MUSICLIB.    If
  224. adagio.exe does not exist or is older than one of the files it depends upon, it
  225. should be remade by executing the lines after the line stating the  dependency.
  226. In this case, there is only one command (starting with the word link) needed.
  227.  
  228.   The  file  makefile,  from which this example was taken, is provided with CMT
  229. and contains a complete list of CMT file dependencies.  It is a good  reference
  230. if you have questions about how to write a makefile.
  231.  
  232.   To  use  make,  simply  give  it  the  file you want to make up-to-date.  For
  233. example,
  234.  
  235.     make adagio.exe
  236.  
  237. will make adagio.exe up to date.  To make sure the entire  CMT  is  up-to-date,
  238. you can type
  239.  
  240.     make everything
  241.  
  242. Note:  the makefile provided with CMT assumes you are in the directory with all
  243. the CMT source files when you run make.  To clean up leftover files, type:
  244.  
  245.     make clean
  246.  
  247. This will not remove .OBJ files.  You can get rid of  unneeded  .OBJ  files  by
  248. typing:
  249.  
  250.     make cleanobjs
  251.  
  252. 2.2. ls
  253.   The  ls  program is like the DOS dir command, except it lists file names only
  254. (no size and date information), and the names are  formatted  into  columns  in
  255. alphabetical  order.    The  current  version  of  ls  does not work with large
  256. directories, although this may be fixed by the time you read this.
  257.  
  258. 2.3. grep
  259.   The grep program searches one or more files for a text string.  If the string
  260. is  found, the line containing the string is printed. grep is indispensable for
  261. reading someone else's code.  For  example,  to  find  out  where  fileopen  is
  262. declared (as well as where it is used), type
  263.  
  264.     grep fileopen *.c
  265.  
  266. in the CMT source code directory.
  267.  
  268. 2.4. Backing up files
  269.   Note:    This  section  is  intended  for new users of the CMU Computer Music
  270. Studio, but it  is  worth  reading  if  you  are  inexperienced  with  personal
  271. computers.
  272.  
  273.   The  IBM  XT  system  has  a  built-in  disk  that can store about 10 million
  274. characters of information.  Unfortunately, that may not be enough to  meet  the
  275. demands  of  all of the studio users.  Fortunately, there is an alternative way
  276. to store information called the floppy disk.  Floppy disks are also a good  way
  277. to  make  copies of your work for safe keeping.  There is always a small chance
  278. that all of your data will be lost  from  the  Studio  computer.    To  protect
  279. yourself, you should keep a backup copy of any critical files on a floppy disk.
  280. Floppy disks are thin magnetic disks that  come  in  a  protective  sleeve  and
  281. insert into the slot in front of the IBM XT.
  282.  
  283.   To make a backup copy of your directory,
  284.  
  285.    1. put a floppy disk into the disk drive slot and push down the door
  286.  
  287.    2. if you have not used the disk before, type
  288.  
  289.           format a:
  290.  
  291.       This will completely erase your disk, so only do this if the disk is
  292.       new or there is nothing on the disk you want to keep.
  293.  
  294.    3. type
  295.  
  296.           copy *.* a:
  297.  
  298. This will copy all files from your directory to the floppy disk.  If there is a
  299. file  on  the  floppy  disk whose name is the same as a file in your directory,
  300. then it will be erased and replaced.  For example, if you copied a file  called
  301. tune.gio  to your floppy disk last week, then edited tune.gio, and now you back
  302. up you directory, then you will lose last week's version of tune.gio from  your
  303. floppy disk.  It will be replaced by the current version.
  304.  
  305.   To copy individual files, type
  306.  
  307.     copy filename a:
  308.  
  309. where  filename  is  the  file  you  want  to  save  on  floppy.  To recover an
  310. individual file from floppy disk to your directory, type
  311.  
  312.     copy a:filename
  313.  
  314.  
  315.  
  316. 3. The Adagio Language
  317.   Adagio  is an easy-to-use, non-procedural notation for scores.    In  Adagio,
  318. text commands are used to specify each note.  If you are new to Adagio, you may
  319. want to glance at the examples in Section 3.3 starting on page 5 before reading
  320. any further.
  321.  
  322.   A  note  is described in Adagio by a set of attributes, and any attribute not
  323. specified is ``inherited'' from the previous line.  Attributes  may  appear  in
  324. any  order  and  must be separated by one or more blanks.  An attribute may not
  325. contain any blanks.  The attributes are:  time, pitch, loudness, voice  number,
  326. duration, and timbre.
  327.  
  328.   Adagio  has  been  used  to  program  a  variety  of  hardware  and  software
  329. synthesizers,  and  the  Adagio  compiler  can  be  easily   adapted   to   new
  330. environments.    Although  not originally intended for MIDI, Adagio works quite
  331. well as a representation for MIDI scores.  The MIDI version of Adagio currently
  332. uses  the  timbre  attribute to select a MIDI ``program'' (synthesizer preset).
  333. Adagio has been extended to allow  MIDI  controller  data  such  as  modulation
  334. wheels, pitch bend, and volume.
  335.  
  336.   A  note command in Adagio must be separated from other notes.  Usually, notes
  337. are distinguished by writing each one on a separate line.  Notes  can  also  be
  338. separated by using a comma or semicolon as will be described below.
  339.  
  340.   Besides notes, there are several other types of commands:
  341.  
  342.    1. An  asterisk  (*)  in  column  one  (or immediately after a comma or
  343.       semicolon) indicates that the rest of the line is a  comment.    The
  344.       line  is  ignored  by  Adagio, and is therefore a good way to insert
  345.       text to be read by people.
  346.  
  347.    2. An empty command (a blank line, for example) is  ignored  as  if  it
  348.       were  a  comment(To  be consistent, a blank line ought to generate a
  349.       note that inherits all of its  attributes  from  the  previous  one.
  350.       Adagio is intentionally inconsistent in this respect.  ).
  351.  
  352.    3. An exclamation point (!) in column one (or immediately after a comma
  353.       or semicolon) indicates a special command.  A special  command  does
  354.       not  generate  a  note, and currently, the only special commands are
  355.       the Rate and Tempo commands,  described  below.    Special  commands
  356.       extend to the end of the line.
  357.  
  358.    4. Control  change  commands  are used to control parameters like pitch
  359.       bend that can change as a note is playing.  Control change  commands
  360.       can  be specified along with notes or by themselves.  A command that
  361.       specifies only control changes will not produce a note.
  362.  
  363.   Adagio is insensitive to case, thus ``A'' is equivalent to ``a'', and you can
  364. mix upper and lower case letters freely.
  365.  
  366. 3.1. Specifying Attributes
  367.  
  368.  
  369.  
  370. 3.1.1. Time
  371.   The  time attribute specifies when to start the note.  A time is specified by
  372.                                              th
  373. a ``T'' followed by a number representing 100  's of a second or by a  duration
  374. (durations are described below).  Examples:
  375.  
  376.     T150    --1.5 sec
  377.     TQ3     --3 quarter note's duration
  378.  
  379. If  no  time is specified, the default time is the sum of the time and duration
  380. attributes of the previous note.  (But see Section  3.1.4.)  Time  is  measured
  381. relative  to  the  time  of  the  most  recent Tempo or Rate command.  (See the
  382. examples in Section 3.3 for some clarification of this point.)
  383.  
  384.  
  385.  
  386. 3.1.2. Pitch
  387.   The pitch attribute specifies what frequency  to  produce.    Standard  scale
  388. pitches  are named by name, using "S" for sharp, "F" for flat, and (optionally)
  389. "N" for natural.  For example, "C" and "CN" represent the  same  pitch,  as  do
  390. "FS" and "GF" (F sharp and G flat).
  391.  
  392.   Octaves are specified by number. C4 is middle C, and B3 is a half step lower.
  393. F5 is the top line of the treble clef, etc.  Accidentals can go before or after
  394. the octave number, so FS3 and F3S have the same meaning.  An alternate notation
  395. for pitch is Pn, where n is an integer representing the pitch.  Middle  C  (C4)
  396. is  equivalent  to  P48,  CS4  is  P49, etc.  [If you know MIDI codes, you will
  397. notice that P48 in Adagio results in a MIDI pitch code of 60.  The ``middle C =
  398. 48''  convention  was borrowed from Gary Nelson's MPL and it is consistent with
  399. MUSIC V, cmusic, and many other computer music languages.  I decided  to  stick
  400. with  the  convention  on  the assumption that if you know enough about MIDI to
  401. know that middle C is 60, then you know enough not to be confused by Adagio and
  402. other  CMT  software.]  If you do not specify an octave, Adagio will choose one
  403. for you.  This is done by picking the octave that will make the  current  pitch
  404. as  close  to the previous pitch as possible.  In the case of augmented fourths
  405. or diminished fifths, there are two equally good choices.  Adagio  chooses  the
  406. lower octave.
  407.  
  408.  
  409.  
  410. 3.1.3. Duration
  411.   Duration  is  specified by a letter indicating a number of beats, followed by
  412. one or several modifiers.  The basic duration codes are:  W (whole, 4 beats), H
  413. (half,  2  beats), Q (quarter, 1 beat), I (eighth, 1/2 beat), and S (sixteenth,
  414. 1/4 beat).  The default tempo is 100 beats  per  minute  (see  Section  3.1.9).
  415. These codes may be followed by a "T" (triplet), indicting a duration of 2/3 the
  416. normal.  A dot (".") after a duration code  extends  it  by  half  to  3/2  the
  417. normal.    Finally,  an  integer  after  a  note multiplies its duration by the
  418. indicated value (the result is still just one note).  Examples:
  419.  
  420.     Q       -- 1   beat (quarter note)
  421.     QT      -- 2/3 beat (quarter triplet)
  422.     W.      -- 6   beats(dotted whole note)
  423.     ST6     -- 1   beat (6 sixteenth triplets)
  424.     H5      -- 10  beats(5 half notes)
  425.  
  426. Finally, a duration may be noted by  Un,  where  n  is  an  integer  indicating
  427.    th
  428. 100  's of a second.  For example, U25 is one quarter of one second.
  429.  
  430.  
  431.  
  432. 3.1.4. Next Time
  433.   The time of the next command (the next command in the Adagio program text) is
  434. normally the time of the current note command plus the duration of the  current
  435. note.    This  can  be  overridden  by  a  field consisting of the letter ``N''
  436. followed by a number  indicating  hundredths  of  seconds,  or  followed  by  a
  437. duration  as described above.  The next note will then start at the time of the
  438. current note plus the duration specified after ``N''.  If the next note has  an
  439. explicit  time attribute (``T''), then the specified time will override the one
  440. based on the previous note.  Examples:
  441.  
  442.     N0      -- start the next note at the same time as the current one
  443.     N50     -- start the next note 0.5 seconds after the current one
  444.     NQT     -- start the next note 2/3 beat after the current one
  445.  
  446.  
  447.  
  448. 3.1.5. Rest
  449.   Rests are obtained by including the field ``R''  in  a  note  command.    The
  450. effect  of an ``R'' field is to omit the note that would otherwise occur as the
  451. result of the current note command.  In all  other  respects,  the  command  is
  452. processed  just  like  any  other  line.    This  means that attributes such as
  453. duration, loudness, and pitch can be specified, and anything specified will  be
  454. inherited  by the note in the next command.  Normally, a rest will include just
  455. ``R'' and a duration.  The fact that a note command specifies  a  rest  is  not
  456. inherited.  For example:
  457.  
  458.     R H     -- a half (two beat) rest
  459.     RH      -- illegal, R must be separated from other fields by space(s)
  460.  
  461. Because  some  synthesizers  (e.g.  a  DX7)  cannot  change  programs (presets)
  462. rapidly, it may be desirable to change programs at the beginning of a  rest  so
  463. that the synthesizer will be ready to play by the end of the rest.  See Section
  464. 3.1.8 for an example.
  465.  
  466.  
  467.  
  468. 3.1.6. Loudness
  469.   Loudness is indicated by an ``L'' followed by  a  dynamic  marking  from  the
  470. following:  PPP,  PP, P, MP, MF, F, FF, FFF.  Alternatively, a number from 0 to
  471. 127 may be used.  The loudness attribute  is  the  MIDI  note  velocity.    The
  472. dynamic markings are translated into numbers as follows:
  473.  
  474.     Lppp    20                    Lmf     58
  475.     Lpp     26                    Lf      75
  476.     Lp      34                    Lff     98
  477.     Lmp     44                    Lfff    127
  478.  
  479.  
  480.  
  481. 3.1.7. Voice
  482.   The  voice attribute tells which of the 16 MIDI channels to use for the note.
  483. The voice attribute consists of a ``V'' followed by  an  integer  from  1  (the
  484. default)  to  16.  There is a limit to how many notes can be played at the same
  485. time on a given voice (MIDI  channel).    Since  the  limit  depends  upon  the
  486. synthesizer,  Adagio  cannot  tell  you  when you exceed the limit.  Similarly,
  487. Adagio cannot tell whether your synthesizer is set up to  respond  to  a  given
  488. channel, so there is no guarantee that what you write will actually be heard.
  489.  
  490.  
  491.  
  492. 3.1.8. Timbre (MIDI program)
  493.   A  MIDI  program  (synthesizer  preset)  can  be selected using the attribute
  494. ``Zn'', where n is the program number.   Notice  that  in  MIDI,  changing  the
  495. program  on  a  given channel will effect all notes on that channel.  Also, for
  496. many synthesizers, you will not be able to change programs at the  start  of  a
  497. note or during a note.  Change the program during a rest instead.  For example:
  498.  
  499.     R I Z23 V4      -- change MIDI channel 4 to program 23 during rest
  500.     A4              -- play a note on channel 4
  501.  
  502. The  cartridge  programs on a DX7 can be accessed by adding 32 to the cartridge
  503. program number.  For example, cartridge program number 10 is specified by Z42.
  504.  
  505.  
  506.  
  507. 3.1.9. Tempo
  508.   The length of a beat may be changed using a Tempo command:
  509.  
  510.     !TEMPO n
  511.  
  512. where n indicates beats per minute.  The exclamation  mark  tells  Adagio  that
  513. this  is  a  special  command  line  rather  than a note definition.  A special
  514. command takes the place of a note specification.  No other attributes should be
  515. written on a line with a special command.  The new tempo affects all succeeding
  516. notes.  The time attribute of all succeeding notes is now measured relative  to
  517. the  time  of  the Tempo command.  Durations specified in hundredths of seconds
  518. (for example U58, N15, or T821) are not affected by the Tempo command.
  519.  
  520.   The Tempo command is fairly clever about default  durations.    If  the  last
  521. duration  specified before the Tempo command is symbolic (using one of S, I, Q,
  522. H, or W), then the default duration for the node after the Tempo  command  will
  523. be  modified  according  to  the  tempo  change.   Consider the following tempo
  524. change:
  525.  
  526.     !TEMPO 60
  527.     A4 H
  528.     !TEMPO 120
  529.     G
  530.  
  531. In this example, the first note will last 2 seconds (2 beats at  60  beats  per
  532. minute).  The second note inherits the duration (H) from the first note, but at
  533. 120 beats per minute, the second note will last only 1 second.  If the duration
  534. had  been  specified U200 (also a duration of 2 seconds), the second note would
  535. also last 2 seconds  because  the  Tempo  command  does  not  affect  times  or
  536. durations specified in hundredths of seconds.
  537.  
  538.  
  539.  
  540. 3.1.10. Rate
  541.   The  rate command scales all times including those specified in hundredths of
  542. seconds.  A rate of 100 means no change, 200 means twice as fast, and 50  means
  543. half  as  fast.   For example, to make a piece play 10% faster, you can add the
  544. following command at the beginning of the score:
  545.  
  546.     !RATE 110
  547.  
  548. Rate and Tempo commands combine, so
  549.  
  550.     !RATE 200
  551.     !TEMPO 70
  552.  
  553. will play 70 beats per minute at double the normal  speed,  or  140  beats  per
  554. minute.    Like  Tempo,  the  time  of  the  Rate  command is added to the time
  555. attribute of all following notes up to the next Time or Rate command.
  556.  
  557. 3.2. Default Attributes
  558.   If an attribute is omitted, the previous one is used  by  default  (with  the
  559. exception of the time attribute).  The default values for the first note, which
  560. are inherited by succeeding notes until something else is specified, are  given
  561. below in Adagio notation:
  562.  
  563.     Time           T0
  564.     Pitch          C4
  565.     Duration       Q
  566.     Loudness       LFFF
  567.     Voice          V1
  568.     Timbre         Z1
  569.     Tempo          !TEMPO 100
  570.     Rate           !RATE 100
  571.  
  572.     Pitch Bend     Y128
  573.     After Touch    O0
  574.     Porta Rate     J99
  575.     Porta Switch   K0
  576.     Mod Wheel      M0
  577.     Foot Pedal     X0
  578.  
  579. 3.3. Examples
  580.   The  following  plays  the  first  two bars of ``Happy Birthday''.  Note that
  581. Adagio knows nothing of bar lines, so the fact that the first  note  occurs  on
  582. beat 3 or that the meter is three-four is of no consequence:
  583.  
  584.     *Example 1 -- Happy Birthday tune (C major)
  585.     !TEMPO 120
  586.     G4 I. LF
  587.     G4 S
  588.     A4 Q
  589.     G4
  590.     C5
  591.     B4 H
  592.  
  593. The  time attribute for the first note is zero (0).  The second note will occur
  594. a dotted eighth later, etc.  Notice that  no  timbre  or  rate  was  specified.
  595. Adagio will provide reasonable default values of 1 and 100, respectively.
  596.  
  597.   The  following example plays the first four bars of an exercise from Bartok's
  598. Mikrokosmos (Vol.  1, No.  12).  An extra  quarter  note  is  inserted  at  the
  599. beginning  of  each  voice in order to allow time to change MIDI programs.  The
  600. right hand part is played on voice (MIDI channel) 1 and the left hand  part  on
  601. voice 2.  Notice the specification of the time attribute to indicate that voice
  602. 2 starts at time 0.  Also, I have taken advantage of default octaves to  reduce
  603. typing.
  604.  
  605.     *Example 2 -- Bartok
  606.     *voice 1, right hand
  607.     R Q Z10 V1
  608.     A4 H
  609.     B Q
  610.     C
  611.     D H
  612.     C
  613.     D Q
  614.     C
  615.     B
  616.     A
  617.     B
  618.     C
  619.     D
  620.     R
  621.  
  622.     *voice 2, left hand
  623.     T0 R Q Z15 V2
  624.     G3 H
  625.     F Q
  626.     E
  627.     D H
  628.     E
  629.     D Q
  630.     E
  631.     F
  632.     G
  633.     F
  634.     E
  635.     D
  636.     R
  637.  
  638.   The  next  example  is  the  same  piece  expressed  in  a  different manner,
  639. illustrating the interaction between the Tempo command and the time  attribute.
  640. Recall  that  the  time  attribute is measured relative to the time of the last
  641. Tempo command:
  642.  
  643.     *Example 3 -- 4 measures in 2 sections
  644.     !Tempo 100
  645.     *Voice 1, Measures 1 & 2
  646.     R Q Z10 V1
  647.     A4 H
  648.     B Q
  649.     C
  650.     D H
  651.     C
  652.  
  653.     *Voice 2, Measures 1 & 2
  654.     T0 R Q Z15 V2
  655.     G3 H
  656.     F Q
  657.     E
  658.     D H
  659.     E H
  660.  
  661.     !TEMPO 100
  662.     *Voice 1, Measures 3 & 4
  663.     T0 V1 D4 Q
  664.     C
  665.     B
  666.     A
  667.     B
  668.     C
  669.     D
  670.     R
  671.  
  672.     *Voice 2, Measures 3 & 4
  673.     T0 V2 D3 Q
  674.     E
  675.     F
  676.     G
  677.     F
  678.     E
  679.     D
  680.     R
  681.  
  682.   Notice that the piece is written in 4 sections.    The  first  plays  a  rest
  683. followed  by  two  measures,  starting at time 0.  The next section changes the
  684. time back to zero and plays two measures of the left hand part (voice 2).   The
  685. next  command  (!TEMPO  100) sets the tempo to 100 (it already is) and sets the
  686. reference time to be two measures into the piece.   Therefore,  the  next  note
  687. (D4) will begin measure 3.  The D3 that begins the last group of notes has a T0
  688. attribute, so it will also start at measure 3.  Notice how the  !TEMPO  command
  689. can serve to divide a piece into sections.
  690.  
  691.   The last example will show yet another way to express the same piece of music
  692. using the ``Next'' attribute.  Only the first bar of music is given.
  693.  
  694.     *Example 4 -- use of the Next attribute
  695.     !Tempo 100
  696.     R Q Z10 V1 N0
  697.     R Q Z15 V2
  698.  
  699.     A4 H V1 N0
  700.     G3   V2
  701.  
  702.     B4 Q V1 N0
  703.     F3   V2
  704.  
  705.     C4 Q V1 N0
  706.     E3   V2
  707.  
  708. Here, each pair of  lines  represents  two  simultaneous  notes.    The  ``N0''
  709. attribute forces the second line to start at the same time as the first line of
  710. each pair.
  711.  
  712. 3.4. Advanced features
  713.   Adagio allows you to write multiple commands  on one line and to program MIDI
  714. control functions.  It is also possible to write music with multiple tempi.
  715.  
  716.  
  717.  
  718. 3.4.1. Multiple notes per line
  719.   Notes  can  be separated by commas or semicolons as well as by starting a new
  720. line.  A comma is equivalent to typing N0 and starting a new line.  A semicolon
  721. is  equivalent  to  starting  a new line.  Here is yet another rendition of the
  722. Bartok:
  723.  
  724.     *Example 5 -- use of semicolons
  725.     !Tempo 100
  726.     R Q Z10 V1
  727.     A4 H; B Q; C; D H; C; D Q; C; B; A; B; C; D; R
  728.  
  729.     T0 R Q Z15 V2
  730.     G3 H; F Q; E; D H; E; D Q; E; F; G; F; E; D; R
  731.  
  732. This example is similar to Example 2, except semicolons are  used.    The  next
  733. example  is  similar  to  Example  4,  except commas are used and four bars are
  734. notated:
  735.  
  736.     *Example 6 -- use of commas
  737.     !Tempo 100
  738.     R Q Z10 V1, R Q Z15 V2
  739.     A4 H V1, G3 V2
  740.     B4 Q V1, F3 V2
  741.     C4   V1, E3 V2
  742.     D4 H V1, D3 V2
  743.     C4   V1, E3 V2
  744.     D4 Q V1, D3 V2
  745.     C4   V1, E3 V2
  746.     B4   V1, F3 V2
  747.     A4   V1, G3 V2
  748.     B4   V1, F3 V2
  749.     C4   V1, E3 V2
  750.     D4   V1, D3 V2
  751.     R
  752.  
  753.  
  754.  
  755. 3.4.2. Control change commands
  756.   The current version of Adagio can control the following functions:
  757.  
  758.     Portamento rate (J)
  759.     Portamento switch (K)
  760.     Modulation wheel (M)
  761.     Aftertouch (O)
  762.     Foot pedal (X)
  763.     Pitch bend (Y)
  764.  
  765. The letter listed beside each control function is the  Adagio  command  letter.
  766. For example, M23 is the command for setting the modulation wheel to 23.  Except
  767. for pitch bend and the portamento switch, all  values  range  from  0  to  127.
  768. Pitch  bend is ``off'' or centered at 128, and has a range from 0 to 255.  Turn
  769. on portamento with K127 and off with K0.
  770.  
  771.   There is no convenient way to get smoothly varying functions.  You can either
  772. type  in many control changes to achieve the effect you want or generate a file
  773. with the transcribe program containing the data you want.
  774.  
  775.   Control changes can be part of a note specification or independent.   In  the
  776. following  example,  a middle C is played with a modulation wheel setting of 50
  777. and a pitch bend of 120.  Then, at 0.1 second  intervals,  the  pitch  bend  is
  778. decreased by 10:
  779.  
  780.     *Example 7 --
  781.     C4 LMF M50 Y120 U100 N10
  782.     Y110 N10; Y100 N10; Y90 N10; Y80 N10; Y70 N10; Y60 N10; Y50 N10
  783.  
  784.  
  785.  
  786. 3.4.3. Multiple Tempi
  787.   Writing  a  piece with multiple tempi requires no new commands; you just have
  788. to be clever in the use of Tempo and Time.    The  following  plays  a  7  note
  789. diatonic scale on voice 1, and a 12 note chromatic scale on voice 2:
  790.  
  791.     *Example 8 -- multiple tempi
  792.     !TEMPO 70
  793.     V1 C4; D; E; F; G; A; B
  794.     T0 R N0
  795.  
  796.     !TEMPO 120
  797.     V2 C4; CS; D; DS; E; F; FS; G; GS; A; AS; B
  798.  
  799.     !TEMPO 100
  800.     V1 C5, V2 C5
  801.  
  802. The  third  line  plays  the  7-note  diatonic scale on voice 1.  The next line
  803. contains the tricky part:  notice that the time is set back to zero, there is a
  804. rest,  and  a  next (N) attribute is used to specify that the next default time
  805. will be at the same time as the current one.  Thus, the time of the !TEMPO  120
  806. command  is  zero.   After the 12 note scale, the tempo is changed to 100 and a
  807. final note is played on each voice.  A little arithmetic will show that 7 notes
  808. at  tempo  70 and 12 notes at tempo 120 each take 6 seconds, so the final notes
  809. (C5) of each scale will happen at the same time.
  810.  
  811. 3.5. Running Adagio
  812.   To use Adagio, create an Adagio score using a text editor.    By  convention,
  813. Adagio  scores  are  named something.gio, where something is any name you like,
  814. and ``.gio'' is a hint that this is an Adagio score.
  815.  
  816.   To listen to the score, type
  817.  
  818.     adagio something
  819.  
  820. Notice that typing the ``.gio'' is optional with Adagio (but you must type  the
  821. full  file  name  when you use the editor).  If all goes well, you will get the
  822. following prompt:
  823.  
  824.     Type <RETURN> to play notes, q<RETURN> to quit, ?<RETURN> for help:
  825.  
  826.   If you type ``?RETURN'', you get a complete list of commands:
  827.  
  828.       <return>       Play music
  829.      q<return>       Quit Adagio (Exit)
  830.  
  831.      r<return>       Read tuning file
  832.      m<return>       Turn on MIDI byte trace
  833.     -m<return>       Turn off MIDI byte trace
  834.      s<return>       Report state
  835.      t<return>       Turn on music operation trace
  836.     -t<return>       Turn off music operation trace
  837.      ?<return>       This message
  838.  
  839.   If you type RETURN to start your piece, Adagio first  sends  a  MIDI  program
  840. change  to  program  1 on each of the 16 MIDI channels.  Exactly 1 second after
  841. typing RETURN, Adagio starts playing your score.
  842.  
  843.   If you type ``qRETURN'', Adagio will exit.
  844.  
  845.   If you type ``rRETURN'', you will get a prompt for a tuning file (see Chapter
  846. 4).    This command is useful for playing a single score with different tunings
  847. without exiting Adagio.
  848.  
  849.   The ``m'' command causes Adagio to print a trace of all MIDI data.   This  is
  850. not  useful  for  anything  other than debugging changes to Adagio.  The ``-m''
  851. command turns tracing off.
  852.  
  853.   The ``s'' command reports what data will be traced.
  854.  
  855.   The ``t'' command causes Adagio to print a trace  of  all  music  operations.
  856. The  information  printed  in  a fairly readable form as opposed to the numbers
  857. printed using the ``m''  switch.    The  ``-t''  switch  turns  off  the  music
  858. operation trace.
  859.  
  860.  
  861.  
  862. 3.5.1. Debugging Adagio Scores
  863.   While  the  score  is  playing,  you  can  type  the  space  bar  to stop the
  864. performance.  The computer screen will then tell you where it was at the moment
  865. you hit the space bar.  This is very handy for finding the source of bad notes.
  866. For example, if you hear a bad note, play the score again and type a space when
  867. you  hear  the  mistake.   Suppose the screen says that you were playing a note
  868. from line 123 and another from line 259.  Remember these numbers,  quit  Adagio
  869. (type ``Q''), and type
  870.  
  871.     edit something.gio
  872.  
  873. Now type (to the editor(I assume you have an emacs-like editor.))  CTRL-U 1 2 2
  874. CTRL-N.  This moves the cursor down 122 lines to  line  number  123.    If  the
  875. mistake is not found, put the cursor back at the top of the file (ESC <) and go
  876. down 258 lines (CTRL-U 2 5 8 CTRL-N) to get to line 259.
  877.  
  878.  
  879.  
  880. 3.5.2. Command Line Options
  881.   The following options can be specified in the command line:
  882.  
  883.    - -debug (or -d): turn on debugging code.
  884.  
  885.    - -help: print a list of command line options.
  886.  
  887.    - -miditrace (or -m): turn on MIDI byte trace.
  888.  
  889.    - -trace (or -t): turn on music operation trace.
  890.  
  891.    - -at: tell Adagio that you are running on an  AT.    (This  option  is
  892.      redundant  information for debugging.  There is no advantage to using
  893.      it because Adagio and other CMT software can  determine  the  machine
  894.      type automatically.)
  895.  
  896.    - -metronome  (or  -met):  turn on the MPU-401 metronome.  This is only
  897.      useful for debugging because there is no way  to  set  the  metronome
  898.      speed.
  899.  
  900.    - -simulated  (or -s): simulate the MPU-401 but do not use it.  This is
  901.      only useful for debugging and may not be implemented.
  902.  
  903.    - -xt: tell Adagio that you are running on an XT.  (This option is  for
  904.      debugging _ see -at.)
  905.  
  906.    - -print: tells Adagio to print details of each note on the console.
  907.  
  908.    - -block: turns off the MPU-401 MIDI THRU function so that the input is
  909.      not passed to the output.
  910.  
  911.    - -tune filename: tells Adagio to use filename to specify tuning.
  912.  
  913.  
  914.  
  915. 3.5.3. Examples
  916.   Run Adagio with score.gio as the score:
  917.  
  918.     adagio score
  919.  
  920.   Run Adagio with score.gio as the score  and  using  meantone.tun  to  specify
  921. tuning:
  922.  
  923.     adagio score -tune meantone
  924.  
  925.  
  926.  
  927. 4. Defining Nonstandard Tunings
  928.   Tuning  in  MIDI  is  normally  twelve-tone  equal  temperment.   MIDI has no
  929. provisions to change this except by using the pitch bend control.  In  general,
  930. a  different  setting  of  pitch  bend  is  needed  for  each pitch in a scale.
  931. Needless to say, this can be very tedious to program  explicitly;  however  CMT
  932. has  a  way  to  automate  the  use  of pitch bend to obtain the desired scale.
  933. Notice that pitch bend affects every note on a given channel; therefore, it  is
  934. generally  not possible to play several notes on one channel whenever alternate
  935. tunings are  desired.    (Ignoring  this  limitation  can  lead  to  some  very
  936. interesting effects, however.)
  937.  
  938.   The  tuning  mechanism  in  CMT  is quite simple: whenever a program (Adagio,
  939. Record, Transcribe, Moxc, etc.) goes to play a note, the note's pitch  is  used
  940. as an index into a table of (pitch, pitch bend) pairs.  The pitch bend is sent,
  941. followed immediately by the pitch from the table.    Using  the  table,  it  is
  942. possible  to  translate every specified pitch into an arbitrary pitch and pitch
  943. bend.
  944.  
  945.   Important: CMT assumes that you have set up  your  synthesizer  so  that  the
  946. pitch  bend  range is one semitone (100 cents) and that the synthesizer changes
  947. frequency exponentially with  respect  to  the  pitch  bend  value.    If  your
  948. synthesizer is different, it will be necessary to modify CMT to make its tuning
  949. mechanism more general.  The current system seems to work fine with a DX7.  The
  950. formula used to calculate the MIDI pitch bend data is 
  951.  
  952.                         PitchBend = (8192 * c) + 8192,
  953.  
  954. where c is the pitch bend in cents (not the velocity of light).
  955.  
  956.   A  scale  is  defined  by a ``tuning'' file (``.tun'' is the default suffix),
  957. which can be created with the help of a program called tuning, described below.
  958. The  format  of  the file is simple.  Each line of text in the file consists of
  959. three numbers.  The first is a note number (48 is middle  C)  between  -12  and
  960. 115.    The  second  is a pitch, also between -12 and 115, and the third is the
  961. pitch bend, between -100, and 100.  Any pitches that are not mentioned  in  the
  962. file are given their normal equal-temperment interpretation.
  963.  
  964.   To  use  a  tuning  file,  say  meantone.tun,  you  type the following option
  965. anywhere in the command line:
  966.  
  967.     -tune meantone
  968.  
  969. If no tuning is specified, then notes are not  translated  and  no  pitch  bend
  970. commands are sent.
  971.  
  972. 4.1. The Tuning Program
  973.   The tuning program lets you define scales in terms of ratios or cents.
  974.  
  975.   You run Tuning by typing
  976.  
  977.     tuning myscale
  978.  
  979. where  myscale.tun  is  the  name  of  the tuning file you want to create.  (An
  980. extension of ``.tun'' will  automatically  be  appended.)    The  program  then
  981. prints:
  982.  
  983.     You will now create a pitch file.
  984.  
  985.     r - enter a range of values
  986.     o - enter one octave (that will be generalized)
  987.     p - enter one pitch (you choose)
  988.     q - quit
  989.     Command >>
  990.  
  991. To  which you should respond with one of r, o, p, or q.  The actions associated
  992. with each command are described below:
  993.  
  994.  
  995.  
  996. 4.1.1. Entering a range of pitches.
  997.   The r command prompts you for a range of pitches and then prompts you  for  a
  998. pitch  and  pitch bend for each pitch in the range.  For example, The following
  999. is a transcript of what you would do to make C4 through D4 sound 1 step and  10
  1000. cents (110 cents) higher (user typein is in italics):
  1001.  
  1002.     Command >>r
  1003.     Adagio note range is -12..115
  1004.     What range of notes would you like to enter ?
  1005.     From >> 48
  1006.     To >> 50
  1007.     For the given Adagio note number, enter the desired pitch
  1008.     and the amount of pitchbend in cents
  1009.         Bend range =  -100 .. 100,  '0' for no pitch bend
  1010.              (100 cents = 1 semitone)
  1011.         Pitch range = 1 .. 128, 48 is middle C
  1012.  
  1013.  
  1014.     Adagio Note 48
  1015.        pitch >>49
  1016.        bend >>10
  1017.     Adagio Note 49
  1018.        pitch >>50
  1019.        bend >>10
  1020.     Adagio Note 50
  1021.        pitch >>51
  1022.        bend >>10
  1023.  
  1024.  
  1025.  
  1026. 4.1.2. Entering an octave
  1027.   The   o   command  lets  you  enter  information  for  one  octave  and  then
  1028. automatically transpose that information (by octaves)  to  provide  information
  1029. for  all  possible  pitches.    Here  is an abbreviated sample transcript for a
  1030. tuning in which every other note is 50 cents sharp:
  1031.  
  1032.     Command >>o
  1033.  
  1034.     You will input the information for one octave and that
  1035.       will be generalized for all octaves.
  1036.  
  1037.     Would you like to enter the information as
  1038.        (1)  frequency ratios of notes to a tonic
  1039.     or (2)  semitones (integer) + pitchbend (in cents)
  1040.  
  1041.  
  1042.     >>2
  1043.  
  1044.     For the given note number, enter the desired pitch
  1045.     and the amount of pitchbend in cents based on given tonic
  1046.  
  1047.     1 unit of pitch = 1 semitone -- the tonic (note 0) has pitch 0 and
  1048.     bend 0.
  1049.        Bend range =  -100 .. 100 cents,  0 for no pitch bend
  1050.          (100 cents = 1 semitone)
  1051.  
  1052.     Octave note 1
  1053.        pitch >>1
  1054.        bend >>50
  1055.  
  1056.     Octave note 2
  1057.        pitch >>2
  1058.        bend >>0
  1059.  
  1060.     Octave note 3
  1061.        pitch >>3
  1062.        bend >>50
  1063.  
  1064.     -- six entries are omitted here --
  1065.  
  1066.     Octave note 10
  1067.        pitch >>10
  1068.        bend >>0
  1069.  
  1070.     Octave note 11
  1071.        pitch >>11
  1072.        bend >>50
  1073.  
  1074.     What note would you like your octave to start on?
  1075.     C   C#  D   D#  E   F   F#   G   G#   A   A#   B
  1076.     0   1   2   3   4   5   6    7   8    9   10   11
  1077.      >>0
  1078.  
  1079.  
  1080.  
  1081. 4.1.3. Entering one pitch
  1082.   You can use the p command to modify just one pitch.  This  is  useful  to  go
  1083. back and change information you have entered with the r or o commands.  Here is
  1084. an example that makes A4 (pitch number 57) play an octave higher:
  1085.  
  1086.     Command >>p
  1087.     Adagio note range is -12..115.  Which note would you like to enter ?
  1088.      (type return to quit)
  1089.     Note >>57
  1090.  
  1091.     For the given pitch number, enter pitch parameters
  1092.        Bend range =  -100 .. 100 cents,      0 for no pitch bend
  1093.              (100 cents = 1 semitone)
  1094.        Pitch range = 1 .. 128, 48 is middle C
  1095.  
  1096.     Adagio note 57
  1097.        pitch >>69
  1098.        bend >>0
  1099.  
  1100.     Adagio note range is -12..115.  Which note would you like to enter ?
  1101.      (type return to quit)
  1102.     Note >>
  1103.  
  1104.  
  1105.  
  1106. 4.1.4. Saving a tuning file.
  1107.   When you are done, use the q command to save the tuning file:
  1108.  
  1109.     Command >>q
  1110.  
  1111.   As discussed above, you can use the resulting file with Adagio,  Record,  and
  1112. Moxc to control tuning.
  1113.  
  1114. 4.2. The Retune Program
  1115.   A  simple  demonstration  program  is  included  with  CMT  to  allow  you to
  1116. ``retune'' a MIDI controller.  To use it, you should connect a MIDI  controller
  1117. (e.g. a DX7) to MIDI IN or your computer interface, and connect MIDI OUT of the
  1118. interface to a synthesizer (e.g. a TX816).  Run Retune by typing:
  1119.  
  1120.     retune -tune myscale
  1121.  
  1122. where myscale.tun is a tuning file previously created.  Now, as you play on the
  1123. controller,  the  Retune program will use pitch bend in real time to adjust the
  1124. pitch of each note.
  1125.  
  1126.   Note: The Retune program is \test\retune.exe on CMT DISK 1.  You may have  to
  1127. copy  it  to your \cmt directory to use it from another directory.  Also notice
  1128. that since pitch bends apply to the whole keyboard, polyphonic notes  interfere
  1129. with one another.
  1130.  
  1131.  
  1132.  
  1133. 5. The Transcribe Program
  1134.  
  1135. 5.1. Overview
  1136.   The  Transcribe  program  is  used  to  record  performances  via MIDI and to
  1137. translate them into Adagio.  Rather than attempt  to  guess  musical  durations
  1138. (like  a  dotted-quarter),  Transcribe  records  all  times  and  durations  in
  1139. hundredths of seconds.  This program, together  with  Record  makes  it  fairly
  1140. simple to build up complex Adagio scores one part at a time.  Transcribed music
  1141. can be copied, edited, or repeated using an ordinary text editor.   The  output
  1142. from   Transcribe   might  also  be  useful  in  the  study  or  evaluation  of
  1143. performances.
  1144.  
  1145. 5.2. Tutorial
  1146.   To use Transcribe, type
  1147.  
  1148.     transcri filename
  1149.  
  1150. where filename is the name of the file you want to create.  If  you  just  type
  1151. transcri,  you  will  be  prompted  for a file name.  In either case, a default
  1152. extension of ``.gio'' will be assumed.  Transcribe will then  ask  you  if  you
  1153. want to record control information:
  1154.  
  1155.     Pitch bend, etc. on? [n]
  1156.  
  1157. Type  ``y'',  ``n'', or just RETURN for the default (n).  Generally, you should
  1158. type RETURN.  At present, recording control information tends  to  use  up  the
  1159. available  recording  memory  very  quickly, so it is of limited use.  When you
  1160. have finished what you want to play, type the space  bar  on  the  IBM.    This
  1161. signals  the  program  to  stop  and write out the notes.  This file can now be
  1162. played by Adagio and what comes out will be very similar to what you just heard
  1163. yourself play.
  1164.  
  1165. 5.3. Timbre
  1166.   When you start Transcribe, it sends MIDI program change commands to program 1
  1167. on all MIDI channels.  When you make  a  program  change  on  the  synthesizer,
  1168. Transcribe  records  the  change  and translates it into an Adagio Z attribute.
  1169. This corresponds to the default Z1 attribute in Adagio and  to  the  fact  that
  1170. Adagio also initializes all MIDI channels to program 1.
  1171.  
  1172.   Note:  Transcribe  (and  Record)  record Z attributes whenever they receive a
  1173. MIDI Program Change command.  Synthesizers normally send this when you change a
  1174. preset  sound using the controls on the synthesizer.  One noteable exception is
  1175. that if a Yamaha synthesizer is in the ``Sys Info Avail''  mode, then  pressing
  1176. a  button  to  change  the  program  causes  the synthesizer to dump all of the
  1177. internal data comprising the program.  No MIDI Program Change command is  sent,
  1178. so  Transcribe  records nothing.  You can find out what is happening by running
  1179. the MM (Midi Monitor)  program and pushing a  program  change  button  on  your
  1180. synthesizer.  For Yamaha synthesizers, the mode should be ``Sys Info Unavail'',
  1181. which is a fairly cryptic way to say ``send program numbers instead of  program
  1182. data''.
  1183.  
  1184. 5.4. Command Line Options
  1185.   The following options can be specified in the command line:
  1186.  
  1187.    - -debug (or -d): turn on debugging code.
  1188.  
  1189.    - -help: print a list of command line options.
  1190.  
  1191.    - -miditrace (or -m): turn on MIDI byte trace.
  1192.  
  1193.    - -trace (or -t): turn on music operation trace.
  1194.  
  1195.    - -block: turns off the MPU-401 MIDI THRU function so that the input is
  1196.      not passed to the output.
  1197.  
  1198.    - -control (or -c) on: record control information, do not  present  the
  1199.      ``Pitch bend, etc. on?'' query.
  1200.  
  1201.    - -control  (or  -c)  off:  do  not  record control information, do not
  1202.      present the ``Pitch bend, etc. on?'' query.
  1203.  
  1204.  
  1205.  
  1206. 5.4.1. Examples
  1207.   Print information about command line options:
  1208.  
  1209.     transcri -help
  1210.  
  1211.   Record data into file foo.gio, do not record control  information,  and  turn
  1212. off the MIDI THRU function of the MPU-401:
  1213.  
  1214.     transcri foo -c off -block
  1215.  
  1216.  
  1217.  
  1218. 6. The Record Program
  1219.  
  1220. 6.1. Overview
  1221.   The  Record program is a combination of Adagio and Transcribe.  It is used to
  1222. record  performances  via  MIDI  and  to  translate  them  into  Adagio   while
  1223. simultaneously  playing  an  Adagio score.  This allows you to enter scores one
  1224. part at a time.  Section 6.3 discusses  how  you  can  combine  several  Adagio
  1225. scores into one.
  1226.  
  1227. 6.2. Instructions
  1228.   Before  using Record, you should first create an Adagio score, either with an
  1229. editor or with Transcribe.  This will be the  score  that  Record  plays  while
  1230. recording a new score.  Let us assume that the existing score is called old.gio
  1231. and you want to record another part called new.gio.  Run Record by typing:
  1232.  
  1233.     record old
  1234.  
  1235. Record uses the Adagio compiler to get old.gio ready to play.  It then  prompts
  1236. you with:
  1237.  
  1238.     Type <RETURN> to record, q<RETURN> to quit, ?<RETURN> for help:
  1239.  
  1240. The  possible  responses are described in detail in Section 3.5.  Normally, you
  1241. should just type RETURN to start playing and recording.  Next, you will  get  a
  1242. prompt for the file you want to create:
  1243.  
  1244.     Name of output file:
  1245.  
  1246. Type new.  The extension .gio will be added automatically if you do not provide
  1247. any extension.
  1248.  
  1249.   After a delay of one second, Record begins to play the score  in  old.    The
  1250. delay  is  not precise, so you would normally put something into old to ``count
  1251. off'' the start  of  the  piece.    Record  also  records  anything  you  play.
  1252. Recording  does  not  stop  until  you type the space bar, even if old finishes
  1253. playing.
  1254.  
  1255.   After you type the space bar, you will again get the prompt:
  1256.  
  1257.     Type <RETURN> to record, q<RETURN> to quit, ?<RETURN> for help:
  1258.  
  1259. You can erase and re-record new by  repeating  the  instructions  given  above.
  1260. (This  time,  you  will  have  to  confirm  that  you  want  to erase new.gio.)
  1261. Otherwise, just type q to quit.
  1262.  
  1263.   You now have two files, old.gio and new.gio.  The next section describes  how
  1264. to merge files to create a single file for Adagio.
  1265.  
  1266. 6.3. Merging Adagio Scores
  1267.   A  few tricks are helpful in merging two scores into one.  In this section, I
  1268. will describe the basics of making two scores play at the same time as well  as
  1269. getting  two scores to play in sequence.  It should be remembered that the goal
  1270. is simply to create an Adagio score.  If you try something that does not  work,
  1271. you should be able to look at your scores and figure out where the problem is.
  1272.  
  1273.  
  1274.  
  1275. 6.3.1. Playing two scores in sequence
  1276.   To  play two scores in sequence, you should edit the first score file so that
  1277. the last line contains the last event of that score.  Since Adagio  scores  are
  1278. not  necessarily  written  in  time  order,  this  may  or may not be the case.
  1279. Transcribe and Record always write scores in the order  of  note  start  times.
  1280. The  last  note  will specify a next (N) attribute that corresponds to the time
  1281. you typed the space bar.
  1282.  
  1283.   Once you get the timing of the last note right, it should be apparent that if
  1284. you  insert  some  notes at the end of the score, they will be played after the
  1285. score (unless they specify a time (T) attribute).  You might want to conduct an
  1286. experiment to find out where your score ends.  If you insert the line
  1287.  
  1288.     C6 LFFF U20
  1289.  
  1290. at  the end of your file, you should here a distinctively loud and high note at
  1291. the end of your score.  If the ``end'' comes too early or too late, you  should
  1292. edit your file accordingly.
  1293.  
  1294.   You  can  insert an entire file at the end of another file using the DOS copy
  1295. command:
  1296.  
  1297.     copy score1.gio+score2.gio
  1298.  
  1299. DOS knows nothing about Adagio, so the .gio extensions must be specified.  This
  1300. command  will  modify score1.gio by appending the contents of score2.gio, which
  1301. is not modified.  An alternative form is
  1302.  
  1303.     copy score1.gio+score2.gio score3.gio
  1304.  
  1305. which puts the  result  into  score3.gio,  leaving  score1.gio  and  score2.gio
  1306. intact.
  1307.  
  1308.   If  score2.gio  does  not  specify  (T) attributes, then appending the scores
  1309. should be adequate.  On the other hand, if score2.gio specifies times  relative
  1310. to  the  beginning  of  the  score,  you  can  insert  a  !TEMPO command at the
  1311. beginning.  Then, when score2.gio is appended to score1.gio, the !TEMPO command
  1312. will  occur  at  the  end  of  score1.gio, and everything in score2.gio will be
  1313. measured relative to the !TEMPO command.
  1314.  
  1315.  
  1316.  
  1317. 6.3.2. Playing two scores at the same time
  1318.   To get two scores to play at the same time, you should  make  sure  that  the
  1319. second  score  includes  a  time  (T)  attribute  on  or before its first note.
  1320. Otherwise, the second score will be  played  after  the  first  one.    (Record
  1321. automatically  inserts  a  time  attribute  on  the  first note of each file it
  1322. creates.  The time is the correct one assuming you want to merge  the  recorded
  1323. file  (e.g. new.gio with the played file (e.g.  old.gio).  The DOS copy command
  1324. is used to merge the two files as described above.
  1325.  
  1326.   A typical problem is trying to play  two  scores  on  the  same  voice  (MIDI
  1327. channel).    This is only a problem if both scores try to play the same note at
  1328. the same time.  MIDI assumes that notes are turned on by pressing keys, and  it
  1329. is  impossible  to  press  the same key twice without first releasing it.  This
  1330. problem usually manifests itself as notes that get cut off early.  If  you  are
  1331. trying  to  merge  two  files with the same voice, you might want to change the
  1332. voice specified for the second  file  to  make  sure  the  two  scores  do  not
  1333. interfere.    (This of course assumes you have several synthesizers so that you
  1334. can play several channels at once.)
  1335.  
  1336. 6.4. Command Line Options
  1337.   The following options can be specified in the command line:
  1338.  
  1339.    - -debug (or -d): turn on debugging code.
  1340.  
  1341.    - -help: print a list of command line options.
  1342.  
  1343.    - -miditrace (or -m): turn on MIDI byte trace.
  1344.  
  1345.    - -trace (or -t): turn on music operation trace.
  1346.  
  1347.    - -at: tell Record that you are running on an  AT.    (This  option  is
  1348.      redundant  information for debugging.  There is no advantage to using
  1349.      it because Record and other CMT software can  determine  the  machine
  1350.      type automatically.)
  1351.  
  1352.    - -metronome  (or  -met):  turn on the MPU-401 metronome.  This is only
  1353.      useful for debugging because there is no way  to  set  the  metronome
  1354.      speed.
  1355.  
  1356.    - -simulated  (or -s): simulate the MPU-401 but do not use it.  This is
  1357.      only useful for debugging and may not be implemented.
  1358.  
  1359.    - -xt: tell Record that you are running on an XT.  (This option is  for
  1360.      debugging -- see -at.)
  1361.  
  1362.    - -print:  tells  Record  to print details of each compiled note on the
  1363.      console.
  1364.  
  1365.    - -block: turns off the MPU-401 MIDI THRU function so that the input is
  1366.      not passed to the output.
  1367.  
  1368.    - -control  (or  -c) on: record control information, do not present the
  1369.      ``Pitch bend, etc. on?'' query.
  1370.  
  1371.    - -control (or -c) off: do  not  record  control  information,  do  not
  1372.      present the ``Pitch bend, etc. on?'' query.
  1373.  
  1374.  
  1375.  
  1376. 6.4.1. Examples
  1377.   Print information about command line options:
  1378.  
  1379.     record -help
  1380.  
  1381.   Play  score  in file foo.gio, do not record control information, and turn off
  1382. the MIDI THRU function of the MPU-401:
  1383.  
  1384.     record foo -c off -block
  1385.  
  1386.  
  1387.  
  1388. 7. DXGet and DXPut
  1389.   DXGet and DXPut are used to  store  and  recall  programs  for  synthesizers.
  1390. These  are generally voice programs, but in general they can be any sequence of
  1391. MIDI system exclusive messages.
  1392.  
  1393. 7.1. DXGet
  1394.   The DXGet program is used to record MIDI system exclusive messages and  store
  1395. them  in  files.    The  program  is  designed  to  work  with  DX7  and  TX816
  1396. synthesizers, although it should work with any others.  To run DXGet, type
  1397.  
  1398.     dxget filename
  1399.  
  1400. where filename is the name of a file you want to create.  If you leave off  the
  1401. extension,  DXGet  will  use  the  extension ``.dx7''.  If you do not specify a
  1402. file, you will be prompted for one.  After  DXGet  starts,  you  will  get  the
  1403. following prompt:
  1404.  
  1405.     Do you want instructions? [y]
  1406.  
  1407. to  which  you  can  respond with "y," "n," or just RETURN to indicate yes.  If
  1408. your response is yes, the following instructions are printed:
  1409.  
  1410.       This program will let you save DX7 and TX816 voice programs.  To save
  1411.     DX7  programs,  you  must connect DX7 MIDI OUT to MPU 401 MIDI IN.  For
  1412.     TX816 programs, connect TX816 MIDI OUT to MPU 401 MIDI IN, and set  the
  1413.     OUT  SLOT  (leftmost  display)  to the module from which you want data.
  1414.     For DX7: push the orange FUNCTION key,  then  the  green  8.    Push  8
  1415.     repeatedly  until  the display says SYS INFO AVAIL or SYS INFO UNAVAIL.
  1416.     If the display says SYS INFO UNAVAIL, push YES to change the display to
  1417.     SYS  INFO  AVAIL.    Now, select a voice with the INTERNAL or CARTRIDGE
  1418.     button followed by a (green) number.  For ALL DX7 voices: after getting
  1419.     the  SYS INFO AVAIL display, push 8 again to get MIDI TRANSMIT ?.  Push
  1420.     YES.  For TX816: Hold down SELECT until you see UT in the display.  Let
  1421.     up  on  SELECT and then push it once more to get the flashing dU.  Push
  1422.     YES to dump all data from this module.  Hold down SELECT until you  see
  1423.     digits  in the display.  After data is dumped, dxget will tell you what
  1424.     it got and write data to a file.  Use dxput to copy  a  file  to  a  dx
  1425.     module.
  1426.  
  1427.   Next, you are prompted as follows:
  1428.  
  1429.     Ready for your data. Type space when you are done...
  1430.  
  1431. and  you  should  cause  your  synthesizer  to  send  whatever system exclusive
  1432. messages you want to save.  One or more messages can be  saved.    Notice  that
  1433. DXGet  will not request information automatically.  This would require DXGet to
  1434. know about types of synthesizers.  To be more general, DXGet  is  very  simple.
  1435. Consequently,  you  must  manually  cause  your synthesizer to send the desired
  1436. information to DXGet.
  1437.  
  1438.   After one or more messages have  been  sent,  type  the  space  bar  and  the
  1439. messages  will  be  saved in the file you specified.  The file format is simply
  1440. bytes in hexadecimal separated by spaces.  As the data is  output,  DXGet  will
  1441. check to make sure the data has not been garbled.  A warning will be printed if
  1442. any errors are detected.  DXGet will also try to print  a  description  of  the
  1443. exclusive messages it received.  You can send the data back to your synthesizer
  1444. using the DXPut program described below.
  1445.  
  1446.   NOTE: If you find that you are sending two messages instead of one  when  you
  1447. use  DXGet,  here  is  what  is  probably happening:  When you push the ``yes''
  1448. button to send data, the DX7 sends a MIDI message that means ``push  the  `yes'
  1449. button'',  analogous  to  sending  a MIDI note-on message whey you press a key.
  1450. Next, the DX7 sends voice data as requested.  Meanwhile, the first MIDI message
  1451. has  gone  into the MPU-401 MIDI IN port and has been forwarded to the MIDI OUT
  1452. port.  If the MPU-401 MIDI OUT is connected to the DX7 MIDI IN,  then  the  DX7
  1453. gets  a  second  request  (via  MIDI)  to  send  data!    You can avoid this by
  1454. disconnecting the DX7 MIDI IN cable or by using the ``-block'' switch when  you
  1455. run DXGet.
  1456.  
  1457. 7.2. DXPut
  1458.   The DXPut program takes files created by DXGet and sends them as MIDI output.
  1459. To run DXPut, type
  1460.  
  1461.     dxput filename
  1462.  
  1463. where filename is the file created by DXGet.  A default extension of ``dx7'' is
  1464. assumed if you do not specify one.  After starting, DXPut will ask:
  1465.  
  1466.     Do you want instructions? [y]
  1467.  
  1468. The instructions are as follows:
  1469.  
  1470.       This program will let you send voice programs to a DX7 or TX816.  You
  1471.     must send a file previously created by the dxget program.  To send  DX7
  1472.     programs,  you must connect MPU 401 MIDI OUT to DX7 MIDI IN.  For TX816
  1473.     programs, connect MPU 401 MIDI OUT to TX816 MIDI IN.  For a DX7  voice:
  1474.     push  the  orange  FUNCTION  key,  then the green 8.  Push 8 repeatedly
  1475.     until the display says SYS INFO AVAIL or SYS  INFO  UNAVAIL.    If  the
  1476.     display  says  SYS  INFO UNAVAIL, push YES to change to SYS INFO AVAIL.
  1477.     Next, push MEMORY PROTECT/INTERNAL,  then  NO,  and  then  then  MEMORY
  1478.     SELECT/INTERNAL. Now, type the name of a file created by dxget and then
  1479.     the space bar to send data.  To store the voice  program  on  the  DX7,
  1480.     hold  down STORE while you push a (green) number.  The current voice at
  1481.     this number will be erased and replaced by the new voice.  For ALL  DX7
  1482.     voices:  Same  as  for a single DX7 voice, but all 32 voice programs on
  1483.     the DX7 will be replaced when you type Y in response to `Are you sure?'
  1484.     on  the computer.  For all TX816 voices: To store into one module, push
  1485.     NO until the MEMORY PROTECT light goes out.   Make  sure  other  MEMORY
  1486.     PROTECT  lights  are  ON.  Type Y in response to 'Are you sure?' on the
  1487.     computer.
  1488.  
  1489.   Assuming the file you specified contains valid data, you will  next  see  the
  1490. prompt:
  1491.  
  1492.     Ready with your data. Type space when you are ready...
  1493.  
  1494. Type  space to send the data.  If a message is one which DXPut knows will cause
  1495. a major change, you will be asked for confirmation before the data is sent.  At
  1496. present  DXPut only asks you to confirm Yamaha 32 voice and 64 performance data
  1497. messages.
  1498.  
  1499.   After the data in the file is sent, you are prompted by:
  1500.  
  1501.     Type Q to quit, RETURN to send another file:
  1502.  
  1503. As the computer says, you can quit or continue to send more  data.    Typing  a
  1504. file name gets you back to the prompt: ``Do you want instructions? [y]'', which
  1505. even if you asked for them earlier have by now have scrolled off the screen.
  1506.  
  1507.  
  1508.  
  1509. 8. Programming in C
  1510.  
  1511. 8.1. Introduction
  1512.   This chapter is not about how to write in C Major, nor is  it  about  how  to
  1513. reallize  a  piece  by  Terry  Riley  with  a  computer.  Rather, it is about a
  1514. programming language called ``C''.  Specifically, this chapter is about how  to
  1515. use a somewhat twisted subset of the C language to make music with CMT.  I hope
  1516. to expand this chapter in the future, but for now, it's going to look more like
  1517. lecture notes than a complete guide to programming.
  1518.  
  1519. 8.2. Writing a Program
  1520.   Let's  say  you want to write a program called ``foo'' that plays a couple of
  1521. notes.  First use the editor to make a file called ``foo.c'':
  1522.  
  1523.     edit foo.c
  1524.  
  1525. When you get into the editor, type the following program:
  1526.  
  1527.     /* a simple program */
  1528.     #include "cmtprog.h"
  1529.  
  1530.     mainscore()
  1531.         begin
  1532.             note(48, 100);
  1533.             note(50, 50);
  1534.             note(52, 50);
  1535.             note(53, 100)
  1536.         end
  1537.  
  1538. This program will play 4 notes in sequence by ``calling'' note 4  times.    You
  1539. indicate  what  kind  of  note you want by giving two parameters in parentheses
  1540. after the word ``note''.  The parameters for note specify pitch  and  duration.
  1541. The  pitch  parameter  is  48  for  middle  C (C4), and goes up by one for each
  1542. semitone.  Thus, the pitches in this program are C4,  D4,  E4,  and  F4.    The
  1543. second  parameter  is  the  duration  parameter,  expressed  in hundredths of a
  1544. second.  Thus, the first note will be 1 second long, the next two will  be  0.5
  1545. seconds, and the last will be 1 second.
  1546.  
  1547.   A few more observations:  notice that the ``score'' consists of calls to note
  1548. preceded by a name, ``mainscore()'', and is bracketed by  the  words  ``begin''
  1549. and  ``end''.   Also notice that calls to note are separated by semicolons (;).
  1550. All of these details are essential, and C is not very forgiving of even trivial
  1551. mistakes.  The first line of the program is called a comment.  Any text between
  1552. /* and */ is ignored by C.  You will find it useful to use comments  to  remind
  1553. yourself  what  your  program  does,  when it was written, and so on.  The next
  1554. line, beginning with ``#include''  tells  the  C  compiler  to  read  the  file
  1555. ``musiprog.h''   from  the  system  library.    This  file  contains  important
  1556. definitions for music, so every program you write should contain this line.
  1557.  
  1558.   Unlike Adagio, C is a case sensitive language.  This  means  that  mainscore,
  1559. MainScore,  MAINSCORE,  and MaInScOrE are all distinct identifiers.  Because of
  1560. this, I suggest that you never use upper case letters in C programs, except  in
  1561. strings and comments.
  1562.  
  1563.   To  hear  the results of this program, you have to compile your program, then
  1564. link it, and then execute it.  The Lattice C compiler (invoked by  the  command
  1565. cmtc) translates your program into a machine language form which is stored in a
  1566. file.  This file is then linked, or combined with other programs to produce  an
  1567. executable  program  file.    This  file can then be executed, meaning that the
  1568. machine instructions in the file  are  loaded  into  working  memory,  and  the
  1569. computer  then  carries them out.  To compile your program (called foo.c), type
  1570. the following:
  1571.  
  1572.     cmtc foo.c
  1573.  
  1574. If your program has errors, the line number where the error was discovered will
  1575. be  printed  along  with  a brief description of the error.  You must fix these
  1576. errors by editing your program and then compiling  again.    When  the  compile
  1577. phase  and  then  the  link  phase  completes without errors, you can link your
  1578. program by typing:
  1579.  
  1580.     cmtl foo
  1581.  
  1582. The command cmtl is short for cmt link.  Be sure  the  last  character  is  the
  1583. letter  l,  not  the  numeral 1.  If no errors are reported by the linker, your
  1584. program is ready to run.  Otherwise, you will have to fix your program with the
  1585. editor, recompile, and relink.  To run your program, type
  1586.  
  1587.     foo
  1588.  
  1589. To  run  your  program  again,  you  need  not recompile unless you change your
  1590. program with the editor.
  1591.  
  1592. 8.3. Stopping a Program
  1593.   Sometimes you need to stop programs in progress before they finish  on  their
  1594. own.   You can type CTRL-C (hold down the CTRL key and type ``C'' or CTRL-BREAK
  1595. to stop your program in most cases.  It is  possible  to  write  programs  that
  1596. cannot   be  stopped  except  by  turning  off  the  computer,  but  these  are
  1597. unusual[Typing CTRL-C or CTRL-BREAK sets a flag but  does  not  terminate  your
  1598. program  immediately,  because  doing so might leave the MPU-401 interface in a
  1599. state that would cause problems later on.  Instead, the gettime function checks
  1600. the flag and carefully exits your program if the flag is set.  Since gettime is
  1601. called by almost every procedure that takes any  significant  time  to  execute
  1602. (e.g.  note,  rest, and rest until), it is a pretty safe bet that typing CTRL-C
  1603. will terminate any program.]
  1604.  
  1605. 8.4. Writing a Procedure
  1606.   Procedures allow you to give a name to a musical phrase.  The phrase can then
  1607. be  called  from  several  places.  This saves your having to retype all of the
  1608. calls to note every time you want  to  hear  the  phrase.    In  the  following
  1609. example,  there  are  two phrases, or procedures, up and down, which are called
  1610. from mainscore:
  1611.  
  1612.     #include "cmtprog.h"
  1613.  
  1614.     mainscore()
  1615.         begin
  1616.             up();
  1617.             down();
  1618.             up();
  1619.             note(48, 100)
  1620.         end
  1621.  
  1622.     up()
  1623.         begin
  1624.             note(48, 20);
  1625.             note(50, 20);
  1626.             note(52, 20);
  1627.             note(53, 20)
  1628.         end
  1629.  
  1630.     down()
  1631.         begin
  1632.             note(55, 20);
  1633.             note(53, 20);
  1634.             note(52, 20);
  1635.             note(50, 20)
  1636.         end
  1637.  
  1638. Notice that up and down obey the same rules as mainscore:  procedure names  are
  1639. followed  by a pair of parentheses and the word begin.  Then there is a list of
  1640. calls to note or other procedures separated by semicolons.  While note has  two
  1641. parameters, up and down each have zero parameters.  You indicate the absence of
  1642. parameters when you call up or down by not putting anything  between  the  open
  1643. and close parentheses.  However, you must always type the parentheses after the
  1644. name of any procedure you call.  Finally, the sequence of calls is ended by the
  1645. word end.
  1646.  
  1647.   When  this  program  is  run, the computer will do what mainscore says to do.
  1648. The first call is to up, so the computer finds the definition of  up  and  does
  1649. what  up says to do.  In this case, up plays four notes (C, D, E, F).  Now that
  1650. up is finished, mainscore continues by calling down, which in turn plays (G, F,
  1651. E,  D).    When  down returns, mainscore continues with another call to up, and
  1652. again up will play C, D, E, F.  Finally, up returns and mainscore  plays  a  C.
  1653. At this point the mainscore program is finished.
  1654.  
  1655. 8.5. Repeats
  1656.   Repetition is important in both programming and music.  To repeat a phrase, a
  1657. special ``repeat'' construct is provided.  Consider the following example:
  1658.  
  1659.     #include "cmtprog.h"
  1660.  
  1661.     mainscore()
  1662.         begin
  1663.             repeat(i, 5)
  1664.                 note(48, 30);
  1665.                 note(60, 30)
  1666.             endrep
  1667.         end
  1668.  
  1669. Look at the two calls to note above.  By themselves, these calls would play the
  1670. phrase C4 C5.  The repeat construct consists of the form 
  1671.  
  1672.     repeat(counter, howmany) phrase endrep
  1673.  
  1674. where  counter  is  just  the  name you want the computer to give to a variable
  1675. number that keeps track of which  repeat  is  being  played  (more  about  this
  1676. later),  howmany  is the number of repeats to take, and phrase is a sequence of
  1677. calls to note or any other procedure.  The example above will play  the  phrase
  1678. C4 C5 C4 C5 C4 C5 C4 C5 C4 C5 because we wrote 5 for the number of repeats.  If
  1679. you like, you can repeat up to about 30,000 times.
  1680.  
  1681.   The phrase could just as well have been calls to other procedures.  The  next
  1682. example  uses  repeat  to  play C4 D4 E4 F4 three times, using the up procedure
  1683. used earlier.
  1684.  
  1685.     #include "cmtprog.h"
  1686.  
  1687.     mainscore()
  1688.         begin
  1689.             repeat(i, 3)
  1690.                 up()
  1691.             endrep
  1692.         end
  1693.  
  1694.     up()
  1695.         begin
  1696.             note(48, 20);
  1697.             note(50, 20);
  1698.             note(52, 20);
  1699.             note(53, 20)
  1700.         end
  1701.  
  1702. 8.6. Conditions
  1703.   Computer programs are made more flexible by the use of conditionals, that is,
  1704. the  ability  to  test  a  condition  and act upon the result of the test.  For
  1705. example, suppose you want to repeat a phrase, but you want the phrase to have a
  1706. first  and  second ending.  In other words, the first time through you want the
  1707. end of the phrase to be played one way, and the second time through,  you  want
  1708. the  ending to be played another way.  How would you do this using just repeats
  1709. and procedures?    The  following  program  uses  a  new  construct  (the  when
  1710. construct) that makes this programming task easy:
  1711.  
  1712.     #include "cmtprog.h"
  1713.  
  1714.     mainscore()
  1715.         begin
  1716.             repeat(i, 2)
  1717.                 note(60, 30);
  1718.                 note(59, 15);
  1719.                 note(57, 15);
  1720.                 note(55, 15);
  1721.                 note(53, 15);
  1722.                 note(52, 15);
  1723.                 when i == 1 then
  1724.                     note(53, 15);
  1725.                     note(55, 120)
  1726.                 otherwise
  1727.                     note(50, 15);
  1728.                     note(48, 120)
  1729.                 endwhen
  1730.             endrep
  1731.         end
  1732.  
  1733. This is a program with a repeat construct, but notice that the last part of the
  1734. repeated phrase is of the form:  
  1735.  
  1736.     when condition then phrase1 otherwise phrase2 endwhen
  1737.  
  1738. The computer interprets  this  construct  as  follows:    whenever  a  when  is
  1739. encountered,  the computer evaluates the following condition.  In this case the
  1740. condition is ``i == 1'', which is true when the repeat counter (i) is equal  to
  1741. one  (the first time through) and false when the repeat counter is not equal to
  1742. one[The double equal symbol ``=='' is interpreted by C to mean ``is equal to''.
  1743. A single equal symbol ``='' is called the assignment operator, and should never
  1744. be used unless you know what you  are  doing.    Even  experienced  programmers
  1745. occasionally slip and write ``='' when they mean to write ``==''.  It is a good
  1746. idea to use the editor to search for all occurrences of ``='' to make sure your
  1747. program  is  correct.].  If the condition is true (which happens the first time
  1748. through in this example), the phrase following then is performed up to the word
  1749. otherwise,  and  the  phrase  between otherwise and endwhen is skipped.  If the
  1750. condition is false, the phrase between then and otherwise is skipped,  and  the
  1751. phrase between otherwise and endwhen is performed.  As usual, these phrases can
  1752. be calls to other procedures like up and down.
  1753.  
  1754.   The when construct is used to  select  between  two  alternatives  where  the
  1755. selection is based on a condition.  Useful conditions are:
  1756.  
  1757.     a == b -- true if a is equal to b
  1758.     a > b  -- true if a is greater than b
  1759.     a < b  -- true if a is less than b
  1760.     a >= b -- true if a is greater than or equal to b
  1761.     a <= b -- true if a is less than or equal to b
  1762.     a != b -- true if a is not equal to b
  1763.  
  1764. Here,  a and b stand for repeat counters (like i) or numbers (like 0, 1, etc.).
  1765. Like the repeat construct, the when construct can be used anywhere in a phrase.
  1766. The  following example plays a phrase three times.  On the second time through,
  1767. the middle of the phrase is extended.  The procedures p1, p2, and  p3  are  not
  1768. shown.
  1769.  
  1770.     #include "cmtprog.h"
  1771.  
  1772.     mainscore()
  1773.         begin
  1774.             repeat(i, 3)
  1775.                 p1();
  1776.                 when i == 2 then
  1777.                     p2()
  1778.                 otherwise
  1779.                 endwhen
  1780.                 p3()
  1781.             endrep
  1782.         end
  1783.  
  1784. In this example, the phrase between otherwise and endwhen is nonexistent.  That
  1785. means that on the first and third times through, the complete  phrase  will  be
  1786. equivalent  to  p1();  p3().    On  the second time through, the phrase will be
  1787. equivalent to p1(); p2(); p3().
  1788.  
  1789. 8.7. Parameters
  1790.   It's time to confess:  there is really no difference between mainscore, note,
  1791. up,  and  down.    They  are  all procedures, and every procedure has a list of
  1792. parameters, which  can  serve  to  modify  its  behavior.    For  example,  the
  1793. parameters to note tell the note procedure what pitch and duration to use.  You
  1794. can easily write your own procedures that have  (more  than  zero)  parameters.
  1795. Study  the  newup  procedure below, which plays C4 D4 E4 F4.  The procedure has
  1796. one parameter, called dur, which determines the duration of each note:
  1797.  
  1798.     #include "cmtprog.h"
  1799.  
  1800.     mainscore()
  1801.         begin
  1802.             newup(25);
  1803.             newup(50)
  1804.         end;
  1805.  
  1806.     newup(dur)
  1807.         begin
  1808.             note(48, dur);
  1809.             note(50, dur);
  1810.             note(52, dur);
  1811.             note(53, dur);
  1812.         end
  1813.  
  1814. When mainscore is played, it first calls newup with  the  parameter  25.    The
  1815. computer  will  then find the definition of newup and notice that the parameter
  1816. is to be named dur.  Now, whenever the  computer  finds  the  name  dur  within
  1817. newup,  it  will substitute dur's value (25).  Thus, the duration specified for
  1818. all of the calls to note will be 25, or one quarter second.
  1819.  
  1820.   After the fourth note is played, the computer returns to mainscore, where the
  1821. next  thing  in  the  sequence  is  another  call to newup.  But this time, the
  1822. parameter is 50.  The computer goes through the same steps as before: it  finds
  1823. the  definition  of newup, associates the value of 50 with dur, and substitutes
  1824. 50 for dur throughout the definition of newup.  The result  is  that  the  four
  1825. notes (C4 D4 E4 F4) are now played with durations of 50, or one half second.
  1826.  
  1827.   Parameters may be named with any string of letters, just like procedures.  It
  1828. is a good idea to use mnemonic names, that is, names that remind you  of  their
  1829. purpose.    It  makes no difference to the computer, but when you start writing
  1830. large programs, you will find that it is important to  make  programs  readable
  1831. and understandable.
  1832.  
  1833.   Important:    When  you  use  parameters,  the  number  of  parameters in the
  1834. definition must match the number of parameters in  the  call.    The  order  of
  1835. parameters in the call determines which parameter gets which value.  Neither of
  1836. these properties are checked by the C compiler, so  very  strange  things  will
  1837. happen if you make a mistake here.
  1838.  
  1839. 8.8. Producing Chords
  1840.   The  C language is called a sequential language because programs are executed
  1841. in sequence, performing only one operation at a time.  This is a big limitation
  1842. for  music, and the next chapter will present some solutions to the problems of
  1843. using C. In the meantime, there is  a  fairly  simple  way  to  get  two  notes
  1844. sounding at once.  The procedure pnote is just like note except that pnote does
  1845. not wait for the specified duration.  Instead, it schedules the end of the note
  1846. to happen in the future but returns immediately without waiting.  The following
  1847. procedure plays a minor chord with the specified tonic and duration:
  1848.  
  1849.     minor(tonic, duration)
  1850.         begin
  1851.             pnote(tonic, duration);
  1852.             pnote(tonic + 3, duration);
  1853.             note(tonic + 7, duration)
  1854.         end
  1855.  
  1856. The first two notes of the chord are played using pnote.  Since  pnote  returns
  1857. immediately, all three notes start very close to the same time.  The third note
  1858. uses the note routine, which will delay for duration before  returning.    Thus
  1859. the minor procedure will also take duration before returning.
  1860.  
  1861. 8.9. Low-level Procedures
  1862.   Up  until now, we have concentrated on writing programs that control the high
  1863. level structure of your music.  By now, I hope you are beginning to enjoy  some
  1864. of  the  power  available  to you as a computer programmer.  Now, it is time to
  1865. learn about the lower levels of control, which concern direct control over  the
  1866. synthesizer.  I mentioned earlier that note is just a procedure.  Here it is:
  1867.  
  1868.     note(pitch, duration)
  1869.         begin
  1870.             midi note(1, pitch, 100);
  1871.             rest(duration);
  1872.             midi note(1, pitch, 0);
  1873.         end
  1874.  
  1875. The  note  procedure  first  uses the procedure midi note to start a note.  The
  1876. parameters are the MIDI channel number (1), the pitch,  and  the  key  velocity
  1877. (100).
  1878.  
  1879.   The  rest  procedure  stops  the  program for the length of time specified by
  1880. duration.  This sustains the note.
  1881.  
  1882.   The third procedure call is another call on midi note.  The key  velocity  of
  1883. zero (the third parameter) indicates to turn the note off.
  1884.  
  1885.   Incidentally, the Adagio program also uses the same midi note procedure.  You
  1886. can find the C programs that make up Adagio in the directory ``\cmt''.
  1887.  
  1888.  
  1889.  
  1890. 8.9.1. Other Procedures and Functions
  1891.   A complete list of music functions and procedures  are  listed  in  the  file
  1892. \cmt\mpu.c  and  in Appendix I.  A summary of some useful ones, as well as some
  1893. useful C procedures are given below.  Italicized parameters stand  for  numbers
  1894. that you supply when you call the function.
  1895.  
  1896. printf("this is a string\n");
  1897.                 writes "this is a string" on the screen when called.   The  two
  1898.                 characters  \n  should  be  included  after  the  text you want
  1899.                 written.  This tells the computer to ``write'' a newline  after
  1900.                 writing the line of text.
  1901.  
  1902. rest(duration); does nothing for duration (expressed in hundredths of seconds).
  1903.  
  1904. getkey(waitflag);
  1905.                 gets a keyboard event.  Returns  a  the  key  number  (numbered
  1906.                 starting  at  0) when a key is pressed, and the key number plus
  1907.                 128 when a key is released.  If waitflag is  not  zero,  getkey
  1908.                 will  wait  for  a key to be pressed.  If waitflag is 0, getkey
  1909.                 may return -1 to indicate no key has  been  pressed.    Example
  1910.                 return values and their meaning are -1: no key was pressed, 48:
  1911.                 middle C was pressed, 176: middle C was released (176 =  128  +
  1912.                 48).
  1913.  
  1914. midi note(channel, pitch, velocity);
  1915.                 sends a MIDI note-on command.   The  parameters  are  the  MIDI
  1916.                 channel  (from  1 to 16), the key number (from -12 to 115), and
  1917.                 the key velocity (from 0 to 127).  If the velocity is  0,  then
  1918.                 the note is turned off.
  1919.  
  1920. midi program(channel, program);
  1921.                 changes the synthesizer program (preset) to the  one  indicated
  1922.                 in  the  second  parameter.    The  first parameter is the MIDI
  1923.                 channel.
  1924.  
  1925. random(low, high);
  1926.                 a  function whose value is a random number between low and high
  1927.                 inclusive.
  1928.  
  1929. 8.10. Command Line Options
  1930.  
  1931.    - -debug (or -d): turn on debugging code.
  1932.  
  1933.    - -help: print a list of command line options.
  1934.  
  1935.    - -miditrace (or -m): turn on MIDI byte trace.
  1936.  
  1937.    - -trace (or -t): turn on music operation trace.
  1938.  
  1939.    - -block: turns off the MPU-401 MIDI THRU function so that the input is
  1940.      not passed to the output.
  1941.  
  1942.    - -tune filename: tells Adagio to use filename to specify tuning.
  1943.  
  1944.  
  1945.  
  1946. 8.10.1. Examples
  1947.   Assuming you have compiled a program named foo,
  1948.  
  1949.     foo -help
  1950.  
  1951. will print a list of command line options.
  1952.  
  1953.   To  run  foo with a tuning specified in myscale.tun, with a printout of music
  1954. operations as they are performed:
  1955.  
  1956.     foo -tune myscale -t
  1957.  
  1958. 8.11. Conclusions
  1959.   Becoming a master programmer is like mastering an instrument; it takes  years
  1960. of hard work.  Fortunately, you can make a lot of good computer music without a
  1961. degree in computer science[Of course, you can make a lot of bad computer  music
  1962. with  a  degree in computer science.].  If you are confused about some point or
  1963. about how to implement an idea, ask someone for help.  It is  often  useful  to
  1964. write  small  programs to test out ideas before you write a magnum opus.  Write
  1965. small procedures and test them before  putting  them  into  a  large  confusing
  1966. program.
  1967.  
  1968.   If  you  want  to  learn  more  about programming, consider taking a computer
  1969. science course if you haven't already.  Your instructors can suggest  textbooks
  1970. if  you  want to study more independently.  There are many programming concepts
  1971. that I have not even touched in this quick introduction.
  1972.  
  1973.   I designed this system so  that  students  could  have  all  the  flexibility
  1974. offered by programming in order to create new music.  Phil Miller showed me how
  1975. to distill the important concepts to the point where basic  programming  skills
  1976. can be developed in a few weeks.  Now it's up to you:  let there be music!
  1977.  
  1978.  
  1979.  
  1980. 9. Moxc: real-time programming package
  1981.  
  1982.      It is the cause, it is the cause, my soul:
  1983.      Let me not name it to you, you chaste stars!
  1984.      It is the cause.
  1985.                          Othello V.2
  1986.  
  1987. 9.1. What is Moxc?
  1988.   Moxc  is  a  set  of  C procedures to help the programmer write programs that
  1989. perform many tasks simultaneously.  The  most  important  procedure  is  called
  1990. cause, which allows you to make things happen not now, but in the future.  Moxc
  1991. is a compatible extension of all the programming constructs you learned in  the
  1992. last chapter.
  1993.  
  1994.   Moxc  is  derived  from a system called Moxie, written by Douglas Collinge of
  1995. the University of Victoria.  The original Moxie runs on  a  Synclavier  I,  and
  1996. another version exists as an extension to the Forth language.
  1997.  
  1998. 9.2. An example
  1999.   The following example uses Moxc to implement a simple performance instrument.
  2000. A blow-by-blow commentary follows the example:
  2001.  
  2002.     /* an example program using moxc */
  2003.  
  2004.     #include <\cmt\musiprog.h>
  2005.  
  2006.     keydown(c, k, v)
  2007.         begin
  2008.             pnote(k+12, 100);
  2009.         end
  2010.  
  2011.     asciievent(c)
  2012.         begin
  2013.             when c == 'q' then quit()
  2014.             endwhen
  2015.         end
  2016.  
  2017.     hello()
  2018.         begin
  2019.             printf("hello\n");
  2020.             cause(300, hello);
  2021.         end
  2022.  
  2023.     mainscore()
  2024.         begin
  2025.             hello();
  2026.         end
  2027.  
  2028.   The first line is an optional comment which is ignored by the compiler.   The
  2029. next  line  of  text tells the compiler to include some definitions from a file
  2030. called \cmt\musiprog.h as described in the last chapter.
  2031.  
  2032.   The procedure keydown is called automatically by Moxc whenever a keyboard key
  2033. is  pressed.    Three parameters, the MIDI channel, the key number, and the key
  2034. velocity are passed to keydown.  When a key is pressed, k  will  have  a  value
  2035. where 48 corresponds to middle C, 49 is C-sharp, and so on.
  2036.  
  2037.   The  procedure  pnote takes two parameters: pitch and duration, and it is the
  2038. same procedure described in the last chapter (see Section 8.8.   Notice  how  I
  2039. added  12  to  k  in  the first parameter position to make the pitch always one
  2040. octave higher than the key that was pressed.  The second  parameter  is  always
  2041. 100, for a duration of one second.
  2042.  
  2043.   The  next  procedure  definition is for asciievent.  This procedure is called
  2044. whenever a character is typed at the computer.  The character typed  is  passed
  2045. as  a  parameter  to asciievent.  To denote a character value in C, you enclose
  2046. the character in single quotes as shown in the example.  The asciievent in  the
  2047. example  only  responds  to one letter, 'q', which results in a call to quit, a
  2048. built-in procedure that tells Moxc to halt  execution.    Notice  that  'q'  is
  2049. written  in  single quotes to denote the letter ``q''.  Without quotes, q would
  2050. refer to a parameter or procedure name.  The exact same asciievent procedure is
  2051. provided by default if you do not provide your own.
  2052.  
  2053.   With  just  these  two  procedures,  a simple instrument has been implemented
  2054. which doubles every note up one octave, and holds the octave  for  one  second.
  2055. When  using  the  DX7  and  TX816,  everything you play on the DX7 will be sent
  2056. directly to the TX816 as well as to Moxc.  Thus, you always hear what is  being
  2057. played on the DX7 combined with any notes played by your Moxc program.  (Unless
  2058. you use the -block option in the command line.)
  2059.  
  2060.   Moxc provides a few more features.  Look at the  next  procedure  definition,
  2061. for  hello.    The  hello  procedure  prints ``hello\n'' on the terminal.  (The
  2062. ``\n'' code at the end  means  type  a  newline,  putting  the  cursor  at  the
  2063. beginning  of the next line.) The next line is the interesting one:  cause(300,
  2064. hello); means that Moxc should, after 300 time units, cause the procedure hello
  2065. to  be  called.   In other words, travel 3 seconds into the future, call hello,
  2066. and return to the present.  In effect, we have  realized  time  travel  in  the
  2067. computer!    If  this makes you uncomfortable, what really happens is that Moxc
  2068. saves a record of the procedure to be called, the time  to  call  it,  and  any
  2069. parameters  that should be passed to it.  When the time comes, the call is made
  2070. automatically by Moxc.  In the case of  hello,  the  effect  is  that  every  3
  2071. seconds,  ``hello''  is  printed  on  the  screen,  and  the  performer  may be
  2072. simultaneously  playing  the  keyboard.    Why  does  hello   print   ``hello''
  2073. repeatedly?   Because after each printing, hello uses cause to schedule another
  2074. call to hello in the future.  This call will schedule yet another call, and  so
  2075. on.
  2076.  
  2077.   How  does  hello ever get started?  It won't, unless someone calls it for the
  2078. first time.  This is done in mainscore, which is  always  called  once  at  the
  2079. beginning of the program, and therefore must be present in your program.
  2080.  
  2081. 9.3. Compiling
  2082.   There  are  three simple steps to take you from a text file (created with the
  2083. editor) to a running program.  Let us assume your file is called test.c:
  2084.  
  2085.    1. Compile your program by typing cmtc test.c.    Any  detected  errors
  2086.       will  be  listed on the screen and must be corrected before the next
  2087.       step.
  2088.  
  2089.    2. Link your program by typing cmtl test, without the ``.c''!
  2090.  
  2091.    3. Run your program by typing test.
  2092.  
  2093.   That's all there is to it.  You must repeat all three  steps  each  time  you
  2094. edit your file.
  2095.  
  2096. 9.4. More about cause
  2097.   What  would have happened if mainscore (above) would have called hello twice?
  2098. Would the characters ``h e l l o'' get scrambled together?  Would ``hello''  be
  2099. printed once or twice every three seconds?  Would the computer get confused and
  2100. blow up?  In fact, what happens  in  Moxc  is  that  every  procedure  runs  to
  2101. completion  before any other procedure is called.  If a procedure calls another
  2102. directly, such as mainscore calling hello, then  the  caller  is  suspended  as
  2103. usual until the callee completes.  Thus, if there were two calls to hello, they
  2104. would execute in sequence, and letters would not be scrambled.
  2105.  
  2106.   Now, each of the calls to hello would also issue a call  to  cause,  so  Moxc
  2107. would  have  two  records telling it to call hello again at time 300.  The Moxc
  2108. system picks one of the two records at time 300 and calls  hello.    When  this
  2109. instance  of  hello  completes, Moxc notices that there is another record for a
  2110. call to hello at time 300 and makes that call too.   By  this  time,  Moxc  has
  2111. probably fallen behind schedule.  In general, Moxc will call procedures as soon
  2112. after the indicated time as possible.  This time will be quite accurate  unless
  2113. something is keeping the computer very busy.
  2114.  
  2115.   The  current  version  of  Moxc  will  quit automatically when it has nothing
  2116. scheduled to do.  It will then prompt you to  see  if  you  want  to  run  your
  2117. program again.  This can be rather annoying if you plan to give it something to
  2118. do in the future, say by playing a note on a keyboard.    The  program  example
  2119. shows  how  a  hello  procedure  can  be  used to make sure that Moxc is always
  2120. waiting to do something (call hello), thus being content to run forever.  Also,
  2121. I find it helpful when debugging to be able to look at the screen and know Moxc
  2122. is running normally, as indicated by the hello messages.  The other way to halt
  2123. Moxc is to call the quit procedure[You can also type CONTROL-C or CONTROL-BREAK
  2124. to kill almost any process.].  This will abort any requests to cause  procedure
  2125. calls.
  2126.  
  2127.   You  can  pass parameters through cause to a future procedure call by listing
  2128. up to 8 of them after the procedure name.  Here is  a  version  of  hello  that
  2129. prints the number of times it has been called:
  2130.  
  2131.     hello(i)
  2132.         begin
  2133.             printf("hello: %d\n", i);
  2134.             cause(300, hello, i+1);
  2135.         end
  2136.  
  2137. On  each call to hello, i is created anew with a value that is one greater than
  2138. the value of i in the previous call to hello.  To print the  value  of  i,  the
  2139. characters  "%d"  are  placed  anywhere  within  the first (string) argument to
  2140. printf, and the number to be printed is passed as the  second  argument.    The
  2141. procedure  printf  will replace %d by a decimal representation of the number as
  2142. it prints the string.  If you do not understand this last example  (it  is  not
  2143. simple!),  you  will probably have trouble writing Moxc programs, so please ask
  2144. your instructor for a more detailed explanation.
  2145.  
  2146.   The cause procedure does not use  a  fast  algorithm  for  scheduling  future
  2147. events.    In  fact,  cause  does  not really schedule anything; it merely puts
  2148. events on a list of events to be scheduled at  some  later  time.    For  every
  2149. waiting  event Moxc runs, Moxc takes at least one event from the list of events
  2150. created by cause and inserts it into another list of events that are waiting to
  2151. run.    This  waiting  list is ordered by event time.  If there are hundreds of
  2152. events in the list and Moxc has to insert an event  at  the  end  (because  the
  2153. event  happens  later  than  the others), Moxc may delay a noticeable amount of
  2154. time.  So far, this behavior has been rather interesting, so no  attempts  have
  2155. been made to make Moxc faster or more accurate under heavy loads.
  2156.  
  2157. 9.5. Event Handlers
  2158.   Event  handling  procedures  were  described  in the example above, including
  2159. keydown and asciievent.  A complete list of these is  given  below.    If  your
  2160. program  does  not  provide an event handler, the cmtl (link) step of preparing
  2161. your program will provide a default  handler  which  does  nothing  except  for
  2162. asciievent, which is given in the example above.
  2163.  
  2164. asciievent(k)   action for terminal input, k is the ascii key code.
  2165.  
  2166. bendchange(ch, val)
  2167.                 pitch bend handler; ch is the  channel,  and  val  is  the  new
  2168.                 value.
  2169.  
  2170. ctrlchange(ch, c, val)
  2171.                 control change handler; ch is the channel,  c  is  the  control
  2172.                 number, and val is the new value.
  2173.  
  2174. keydown(ch, p, v)
  2175.                 MIDI note on handler; ch is the channel, p is  the  pitch  code
  2176.                 (48 = middle C), and v is the velocity.
  2177.  
  2178. keyup(ch, p)    MIDI  note  off  handler; ch is the channel, and p is the pitch
  2179.                 code..
  2180.  
  2181. mainscore()     first  action(s).    This  ``event''  is  called  once  at  the
  2182.                 beginning of execution.
  2183.  
  2184. peddown(ch)     sustain pedal down handler; ch is the channel.
  2185.  
  2186. pedup(ch)       sustain pedal up handler; ch is the channel.
  2187.  
  2188. touchchange(ch, val)
  2189.                 aftertouch handler; ch is the channel, and val is the value.
  2190.  
  2191. 9.6. Command Line Options
  2192.   The following options can be specified in the command line:
  2193.  
  2194.    - -debug (or -d): turn on debugging code.
  2195.  
  2196.    - -help: print a list of command line options.
  2197.  
  2198.    - -miditrace (or -m): turn on MIDI byte trace.
  2199.  
  2200.    - -trace (or -t): turn on music operation trace.
  2201.  
  2202.    - -block: turns off the MPU-401 MIDI THRU function so that the input is
  2203.      not passed to the output.
  2204.  
  2205.    - -tune filename: tells Adagio to use filename to specify tuning.
  2206.  
  2207.  
  2208.  
  2209. 9.6.1. Examples
  2210.   Run  Moxc  program  named  echoes[Note that echo is a special DOS command, so
  2211. that is why I named this program echoes.  The echoes  program  and  its  source
  2212. code are included on the CMT disks.]:
  2213.  
  2214.     echoes
  2215.  
  2216.   Run the echoes program with tuning file scale23.tun:
  2217.  
  2218.     echoes -tune scale23
  2219.  
  2220.  
  2221.  
  2222. 10. System Details
  2223.   For  simple  applications,  you  do  not  have  to  understand much about the
  2224. structure of the CMU MIDI Toolkit in order  to  get  useful  work  done.    The
  2225. preceding  chapters have described the existing application programs as well as
  2226. Moxc, a system that helps you write  real-time  music  programs  of  your  own.
  2227. Details  of  the available calls to send and receive MIDI are given in Appendix
  2228. I.
  2229.  
  2230.   However, you may wish to write more ambitious  programs  or  modify  existing
  2231. programs.  To do this effectively, you must understand how the CMT programs are
  2232. put together.  This chapter describes the various components of  the  CMU  MIDI
  2233. Toolkit from a system programmer's perspective.
  2234.  
  2235. 10.1. Introduction
  2236.   In  general, CMT programs are assembled from a collection of modules, where a
  2237. module is a piece of software that performs a set of related  functions.    For
  2238. example,  there  is  a  module for parsing command lines and another module for
  2239. recording MIDI data.  Modules usually consist of a single  ``.c''  file  and  a
  2240. related  ``.h'' file.  In the following sections, each module is described, and
  2241. references to example uses of the modules are given.
  2242.  
  2243. 10.2. Basic MIDI interface
  2244.   All programs in CMT that send or receive MIDI use  the  module  mpu.c,  which
  2245. provides  an interface between C programs and the MPU-401 MIDI Processing Unit.
  2246. In theory, mpu.c could be replaced by  another  software  module  designed  for
  2247. another hardware MIDI interface.
  2248.  
  2249.  
  2250.  
  2251. 10.2.1. Interface design issues
  2252.   A  few  words  about  the  overall design of this interface are in order.  To
  2253. begin with, mpu.c is neither a complete interface to the MPU-401 nor  to  MIDI.
  2254. Instead,  mpu.c is an attempt at providing the intended community of users with
  2255. a rational interface  that  supports  experimental,  real-time  computer  music
  2256. functions.    One  of  the reasons CMT comes with source code is so that if you
  2257. disagree with these design decisions, you are free  to  modify  or  extend  the
  2258. system to meet your requirements.
  2259.  
  2260.   The  main  areas  in  which  mpu.c deviates from the ``conventional'' are the
  2261. absence of ``tracks'', the way in which time is handled,  pitch  specification,
  2262. and  the lack of external synchronization.  Tracks are a concept implemented in
  2263. the MPU-401 whereby several sequences of MIDI data can be merged in  real-time.
  2264. In  some commercial sequencers, the use of tracks allows the sequencer to avoid
  2265. a lot of bookkeeping and sorting when several sequences are to be played at the
  2266. same  time.    In  CMT,  the  Adagio compiler sorts its data, so tracks are not
  2267. needed to play multiple sequences together.  For example, to  play  two  Adagio
  2268. scores simultaneously, one can normally just concatenate the files together and
  2269. run Adagio on the new file.  This approach has the advantages that an arbitrary
  2270. number  of  sequences  can be merged, and the resulting system is more portable
  2271. (not all MIDI interfaces implement the notion of tracks).
  2272.  
  2273.   Timing in CMT is probably the most radical departure from MIDI.  Whereas MIDI
  2274. sequencers  normally  tend  to  talk about time in terms of beats, CMT measures
  2275. time in units of 0.01 seconds.  This is  roughly  the  smallest  rhythmic  time
  2276. deviation  we can perceive.  The rationale behind this decision is that not all
  2277. music  is  measured  in  beats,  and  some  music  has  several   tempi   going
  2278. simultaneously.    If  everything is converted to time in seconds, then one can
  2279. freely combine scores with different tempi and meters as well  as  scores  with
  2280. timing  notated  directly in seconds.  Another timing issue is that the MPU-401
  2281. was designed to allow the host computer to send data in advance of  its  actual
  2282. use.    MIDI commands can be sent to the MPU-401 with a ``time tag'' that tells
  2283. the MPU-401 when to send the data to MIDI OUT.  This is a nice feature in  that
  2284. it  can  help  a  slow  computer achieve tighter real-time performance.  On the
  2285. other hand, it is not very suitable for interactive real-time programs in which
  2286. one  normally  wants  output  to  occur  immediately  after data is sent to the
  2287. MPU-401.  Time tags also have the problem that it is hard to stop a performance
  2288. immediately,  because  several  seconds  of  data  buffered in the MPU-401 will
  2289. continue to play after the host computer stops sending data.  CMT does not  use
  2290. time tags; MIDI commands are send immediately.
  2291.  
  2292.   Pitch  in CMT is based on earlier computer music systems in which middle C is
  2293. represented by the number 48.  Therefore, CMT pitch numbers are  12  less  than
  2294. the  corresponding  MIDI  pitch numbers.  CMT also allows users to redefine the
  2295. interpretation of pitch numbers.  Within mpu.c,  there  is  a  table  with  two
  2296. entries  for each pitch number.  One of these entries specifies a pitch and the
  2297. other specifies pitch bend.  When the midi note routine is called, it uses  the
  2298. table  to  translate  the  pitch parameter into a MIDI pitch number and a pitch
  2299. bend.  This translation is  normally  only  enabled  if  the  ``-tune''  option
  2300. followed by a file name is specified in the command line.
  2301.  
  2302.   Finally,  CMT at present has no means for external synchronization and cannot
  2303. now be used with other sequencers or drum machines to  achieve  a  synchronized
  2304. performance.    This  is  partly  a  consequence  of the fact that CMT does not
  2305. measure time in beats, while sequencers synchronize by sending MIDI messages to
  2306. mark beats and their subdivisions.
  2307.  
  2308.  
  2309.  
  2310. 10.2.2. Interface implementation
  2311.   The  mpu.c module is primarily responsible for MIDI output.  For example, the
  2312. midi note routine sends commands and data to the MPU-401 to cause it to send  a
  2313. MIDI  note-on  command.   In contrast, mpu.c never reads data directly from the
  2314. MPU-401.  Input is handled by the interrupt handler in aintr.asm.
  2315.  
  2316.   The interrupt handler (aintr.asm) is invoked whenever the  MPU-401  has  data
  2317. ready.   The data is read and decoded to determine what kind of data it is.  If
  2318. the data is a MIDI message (e.g. MIDI Note-on), the message is inserted into  a
  2319. circular  buffer,  which can be read by either the getbuf or getkey routines in
  2320. mpu.c.  The buffer provides a communication path between the interrupt  handler
  2321. and  the  non-interrupt  level  of  CMT  programs;  it  also helps prevent lost
  2322. messages when a burst of MIDI  events  arrives.    The  aintr.asm  module  also
  2323. receives  acknowledgments  for commands sent by mpu.c.  Since mpu.c cannot read
  2324. these acknowledgments directly (it might read a MIDI message), mpu.c waits  for
  2325. a  global  variable  to  be  changed  by  aintr.asm  when  it  wants  to get an
  2326. acknowledgment.
  2327.  
  2328.   A final function of aintr.asm is  maintaining  the  time.    In  the  current
  2329. implementation,  time  is  maintained  in  the  MPU-401 by chosing a tempo that
  2330. results in 400 ticks per second.  Whenever the 8-bit  timer  overflows  in  the
  2331. MPU-401,  a  timer  overflow  message  is sent to aintr.asm, which increments a
  2332. 32-bit time accumulator.  The MPU-401 timer value is sent with each MIDI  input
  2333. message and the timer is then cleared.  Therefore, aintr.asm must strip off the
  2334. time from each MIDI input message and add it to the time accumulator  as  well.
  2335. At  all  times,  the current time is the sum of the 32-bit time accumulator and
  2336. the 8-bit timer inside the  MPU-401.    Therefore,  to  get  an  accurate  time
  2337. reading,  one  must  force  the  MPU-401  to  send  the  value  of its counter.
  2338. Fortunately, there is an MPU-401 command for this.  When a user  calls  gettime
  2339. in  mpu.c,  the  command  is sent to the MPU-401, which responds by sending its
  2340. counter value.  This value is added to the time accumulator by aintr.asm.   The
  2341. gettime  routine  can then read the accumulator, which is now up to date, shift
  2342. it right 2 bits to divide by 4, and return the result, which is  absolute  time
  2343. in hundredths of seconds.
  2344.  
  2345.   A  new  timer  has  been implemented using the real-time clock on the IBM-PC.
  2346. The new timer code is not compatible with an IBM-AT.    This  new  code  should
  2347. reduce  some  of  the  load on the MPU-401 when the host computer needs to poll
  2348. gettime.  This timer is included in the first release of the system and can  be
  2349. enabled  by  defining  TIMDIF  in  mpu.c and recompiling it.  You will find the
  2350. definition of TIMDIF commented out in the file  mpu.c.    Notice  that  with  a
  2351. little  coding,  one could get the MPU-401 to synchronize its internal clock to
  2352. an external tape machine.  In the hopes that someone will actually  extend  CMT
  2353. to implement tape synchronization, the code that uses the MPU-401 timer will be
  2354. left in the system even if it is disabled.
  2355.  
  2356.  
  2357.  
  2358. 10.2.3. System exclusive messages
  2359.   In an earlier implementation of CMT, incoming system exclusive messages  were
  2360. put  into  the buffer just like other MIDI messages.  I then discovered that an
  2361. IBM XT could not empty the buffer as fast as the messages came  in.    This  is
  2362. fine  if messages are short, but some system exclusive messages are much longer
  2363. than the buffer.  Making the buffer bigger would penalize programs that are not
  2364. interested   in   system  exclusive  messages  by  taking  up  lots  of  space.
  2365. Consequently, the current system does not put system exclusive messages in  the
  2366. buffer.    Instead, there is a call (midi buffer) through which a user of mpu.c
  2367. can provide a special buffer to be used by system  exclusive  messages.    Most
  2368. programs  use the MPU-401 to filter out these messages, so what to do with them
  2369. is not usually an issue.  If exclusive messages are enabled and  no  buffer  is
  2370. supplied for them, mpu.c throws them away.
  2371.  
  2372. 10.3. Command line parsing
  2373.   The  module  cmdline.c  implements an interface to the command line, that is,
  2374. the line that the user types to the operating system to start a program.  There
  2375. are  several conventions enforced by cmdline.c.  A command line must consist of
  2376. three types of entities which must be separated by one  or  more  blanks.    In
  2377. order  to describe them, I have given the entities names, although they are not
  2378. terribly mnemonic:
  2379.  
  2380.    1. A switch is a sequence of non-space characters that  begins  with  a
  2381.       dash  (``-'').  Normally, a switch is used to enable or disable some
  2382.       function in the program.  An example is the ``-help'' switch,  which
  2383.       causes most CMT programs to print a help message and quit.
  2384.  
  2385.    2. An  option looks just like a switch except it is followed by another
  2386.       sequence of non-space characters that do  not  begin  with  a  dash.
  2387.       Options  are used to give additional information to the program.  An
  2388.       example is ``-tune myscale.tun'', which  tells  mpu.c  to  load  the
  2389.       tuning definition file myscale.tun.
  2390.  
  2391.    3. An  argument is a sequence of non-space characters that do not begin
  2392.       with a dash.   Arguments  are  usually  pieces  of  information  the
  2393.       program expects.  An example is in the command line ``adagio bach'':
  2394.       ``Adagio'' is the command name, and ``bach'' is an  argument,  which
  2395.       in this case specifies a score file.
  2396.  
  2397. Both switches and options are referred to in earlier chapters as ``command line
  2398. options''.  Switches, options, and arguments can be placed in the command  line
  2399. in  any  order,  with the exception that arguments are numbered in the order in
  2400. which they appear from left to right.  An example of  a  command  with  several
  2401. switches and arguments is:
  2402.  
  2403.     transcri -tune myscale -control off -block foo
  2404.  
  2405. Taken one at a time, the entities in this command line are:
  2406.  
  2407.    - transcri is the name of the command.
  2408.  
  2409.    - -tune myscale is an option specifying a tuning definition file.
  2410.  
  2411.    - -control  off  is an option telling transcri to ignore control change
  2412.      data.
  2413.  
  2414.    - -block is a switch which turns off the  internal  MIDI  thru  of  the
  2415.      MPU-401.
  2416.  
  2417.    - foo  is  an  argument  specifying a score file.  Notice that ``-block
  2418.      foo'' has the same syntax as an option, but since -block is a switch,
  2419.      foo must be an argument.
  2420.  
  2421.   This module provides the following functions:
  2422.  
  2423.    - Syntax checking.  The entire line is checked to make sure every token
  2424.      is recognized.
  2425.  
  2426.    - Testing for switches and options.  Functions  are  provided  to  test
  2427.      whether the user typed a switch or option.
  2428.  
  2429.    - Argument  access.  Command line arguments can be retrieved by number.
  2430.      (The first argument after the command is argument number 1.)
  2431.  
  2432.    - Consistency checking.  All legal switches or options must be declared
  2433.      when  the  cmdline.c  module  is  initialized.  Attempts to look up a
  2434.      switch or option that was not part of  the  initial  declaration  are
  2435.      detected and cause an error message.
  2436.  
  2437.   The  only  aspect  of  cmdline.c  that  is  likely  to  be  confusing  is the
  2438. initialization and consistency checking.  Notice that a switch followed  by  an
  2439. argument is syntactically identical to an option.  Thus, cmdline.c must know in
  2440. advance the complete list of switches and options in order to parse the command
  2441. line.    It is illegal for a switch to have the same name as an option, because
  2442. this could lead to an ambiguous parse.  Therefore, cmdlne.c must be initialized
  2443. with a list of switches and a separate list of options.
  2444.  
  2445.   This  is  a  somewhat error-prone operation because cmdline.c can be (and is)
  2446. used by many modules, but there is no convenient way in C for these modules  to
  2447. make  known  what switches and options they look for.  For example, suppose you
  2448. write a program that uses cmdline.c  and  mpu.c.    You  initialize  cmdline.c,
  2449. passing  it  several switches and the ``-aardvark'' option, but you forget that
  2450. mpu.c looks for a ``-tune'' option.   Consequently,  cmdline.c  does  not  have
  2451. enough  information  to  properly  parse  the  command  line.  Even worse, your
  2452. program is booby-trapped!  As soon as some poor sole tries to use the ``-tune''
  2453. option, cmdline.c will report a syntax error.  As far as it knows, ``-tune'' is
  2454. not a valid switch or option.
  2455.  
  2456.   Fortunately, the situation is not as  bad  as  it  looks,  because  cmdline.c
  2457. performs  some  internal consistency checks automatically.  What will happen in
  2458. this example is that as soon as mpu.c is initialized, it will go out  and  look
  2459. for  the  ``-tune''  option by calling the appropriate routine in cmdline.c (cl
  2460. option(), for example).  Before searching the command line, cmdline.c checks to
  2461. see  if  ``-tune''  is  in  its list of valid options.  It is not, so cmdline.c
  2462. prints an error message:
  2463.  
  2464.     internal error detected by cmdline module:
  2465.               '-tune' should be in valid lists
  2466.  
  2467. Thus you, the implementor, will get a clear message that you  made  a  mistake,
  2468. and  you  will  get the message whether or not ``-tune'' appears on the command
  2469. line.  If it is not obvious where the message came from, you can  use  grep  to
  2470. search  the  source  code  of all the modules you use for the string ``-tune''.
  2471. That would tell you that ``-tune'' is an option used by the mpu.c module.
  2472.  
  2473.   In the best of all worlds, it should not be necessary for the implementor  to
  2474. keep  track of options and switches used in other modules, but this is the best
  2475. compromise I could come up with.
  2476.  
  2477. 10.4. The record module
  2478.   Two programs in CMT record data from the keyboard and  write  Adagio  scores.
  2479. These  are  the  transcri  and record programs.  Both programs use the record.c
  2480. module to do most of the work.  The interface to  record.c  is  fairly  simple.
  2481. The  routine  rec  init  is  called to initialize the module.  Then rec poll is
  2482. called (frequently) for the  duration  of  the  recording  ``session''.    This
  2483. routine  reads  data  from  the  input buffer and stores it in a data structure
  2484. along with timing information.  When the recording is finished,  rec  final  is
  2485. called to write the data to a file.
  2486.  
  2487.   Several  tricks  are used to improve the performance of record.c.  First, the
  2488. program does not try to record a time for every input event.  This would  waste
  2489. processor  time  when  bursts  of  data  arrive.   Instead, the current time is
  2490. recorded only when something is found in the input buffer.  Then the buffer  is
  2491. read  until  it  is  empty  and all buffered events are assigned the same time.
  2492. Thus, buffer reading occurs at maximum speed when bursts arrive.
  2493.  
  2494.   A second optimization deals with the form of the output file.   It  has  been
  2495. found  that  a DX7 will send large amounts of control information, particularly
  2496. aftertouch data.  The rec final routine filters the recorded  data  so  that  a
  2497. given control will not change more than once per 0.01 second time period.  This
  2498. reduces the size of the output file, reduces the amount of data to be stored by
  2499. the Adagio program, and has a minimal impact on the accuracy of reproduction.
  2500.  
  2501.  
  2502.  
  2503. 11. What next?
  2504.   A  number  of  improvements  remain  to  be made to the CMU MIDI Toolkit.  To
  2505. encourage others to make these improvements, CMT  is  distributed  with  source
  2506. code  and  documentation.    In  addition, the Center for Art and Technology at
  2507. Carnegie Mellon University will help coordinate and integrate changes  to  this
  2508. software.    If  you  develop  a  new  tool or enhance an existing one, you can
  2509. incorporate it into CMT by sending it to me (Roger B. Dannenberg) at the Center
  2510. for  Art and Technology.  Provided the changes or additions are consistent with
  2511. the goals of CMT, I will integrate them into the next release and  redistribute
  2512. your code to other users.  Thus others will benefit from your efforts as I hope
  2513. you have benefited from mine.
  2514.  
  2515.   The following sections outline changes I would like to see in  the  CMU  MIDI
  2516. Toolkit.  If you decide to tackle one of these, it might be a good idea to call
  2517. me at (412) 268-3827 or write to find out if anyone else is working on the same
  2518. thing.
  2519.  
  2520. 11.1. Microsoft C conversion
  2521.   The  current version of CMT uses the Lattice C compiler.  Work is in progress
  2522. to make CMT compatible with both Lattice and Microsoft C.
  2523.  
  2524. 11.2. Large memory model conversion
  2525.   The most serious problem with CMT at the moment is that it was  designed  for
  2526. use  with the ``small memory model''.  This means that only 16 bits are used to
  2527. address code and data, so not all of the available memory can be used.  This is
  2528. a  problem  that  limits  Adagio to less than 4 thousand notes.  To use another
  2529. memory model,  one  would  have  to  recode  some  of  the  assembler  routines
  2530. (particularly aintr.asm) to get the right values into the segment registers.
  2531.  
  2532. 11.3. Multiple Midi Interfaces
  2533.   Another  limitation  of  CMT is that it supports only one MPU-401.  There are
  2534. two reasons for using more than one.  First, you might want to have  more  than
  2535. one  MIDI  input to the system.  A keyboard like the KX88 will ``mix'' the data
  2536. it generates with its MIDI Input to form the MIDI Output.  Thus,  you  can  get
  2537. input  from  a KX88 and at least one other device by connecting them in series.
  2538. However, most MIDI devices cannot ``mix'' MIDI data, so one might want to  have
  2539. several  MIDI  interfaces  to  get input from several controllers.  Notice that
  2540. input data can be ``mixed'' internally by the IBM PC, and there is no reason to
  2541. distinguish which physical input is the source of a given piece of data.
  2542.  
  2543.   The  second  reason  for multiple interfaces is to overcome the maximum of 16
  2544. MIDI channels or to obtain higher speed.  A reasonable thing to do in this case
  2545. is to implement ``logical'' MIDI channels.  Logical channels 1 through 16 would
  2546. correspond to MIDI channels 1  through  16  on  the  first  MPU-401.    Logical
  2547. channels  17  through  32 would correspond to MIDI channels 1 through 16 on the
  2548. second MPU-401, and so on.  This presents no problems for Adagio, but there  is
  2549. a  lot  of  CMT software that assumes only 4 bits are needed to store a channel
  2550. number.  Implementing logical channels  is  more  work  than  the  mixing  idea
  2551. described in the preceding paragraph.
  2552.  
  2553. 11.4. Improve Adagio compilation (sorting) speed
  2554.   Currently,  Adagio keeps a linked list of notes and control changes sorted by
  2555. start time.  If scores are roughly in time  order,  the  performance  is  good.
  2556. However, if a score is constructed by concatenating several files created using
  2557. transcri or record, then notes are not in order and Adagio  can  spend  several
  2558. minutes  loading a score.  I believe this can be solved by two transformations.
  2559. First, change the insert routines  to  insert  notes  in  forward  rather  than
  2560. reverse  time  order  and  take  out  the  code  that reverses the final score.
  2561. Second, keep a pointer to the last point at which a note was  inserted.    When
  2562. you go to insert a note, try searching forward from the saved pointer.  Only if
  2563. this fails should you search from the beginning of the  list.    The  resulting
  2564. program  will  still  perform  badly  on  perverse  scores,  but  the  expected
  2565. performance should be quite good on normal scores.
  2566.  
  2567. 11.5. Multi-track recording
  2568.   Not everyone has enough equipment to play an entire score, and not all scores
  2569. will  fit  into the available memory.  A solution to these problems is to use a
  2570. multi-track recorder and to record a composition one track at a time.    To  do
  2571. this,  one must be able to enable one Adagio voice at a time.  I suggest adding
  2572. an option to the Adagio (and Record) command line of the form
  2573.  
  2574.     -v 1,5
  2575.  
  2576. which would mean play only voices (MIDI channels) 1 and 5.  Notes  and  control
  2577. events  on  other  channels  would  not be saved in memory for playing, so this
  2578. facility would help get around memory restrictions.
  2579.  
  2580.   For long works and pieces where close synchronization of parts is  important,
  2581. it  is  essential to have some means of synchronizing Adagio output with a tape
  2582. recorder.  The MPU-401 has a tape-sync input and output which could be used for
  2583. this  purpose.    Probably, a command-line switch (``-sync'') should be read by
  2584. mpu.c.   When  the  switch  is  present,  mpu.c  should  tell  the  MPU-401  to
  2585. synchronize  to  the  tape  input.  Notice that CMT has optional code to derive
  2586. time from the internal IBM-PC timer rather than the MPU-401.  If  that  is  the
  2587. case, then the ``-sync'' switch should either cause mpu.c to revert back to the
  2588. MPU-401 or there should be some way  to  cause  MPU-401  clock  input  data  to
  2589. resynchronize the internal IBM-PC timer.
  2590.  
  2591. 11.6. MIDI Continuous Controls
  2592.   Adagio  supports the notion of continuous controls through its control change
  2593. commands, but these are presently very limited.  Three enhancements  should  be
  2594. made.    First, it should be possible to program how control change commands in
  2595. Adagio are mapped into MIDI control change commands.  For  example,  one  might
  2596. want  to  use  the  X  command to send breath-controller values.  This could be
  2597. implemented by having an optional control specification file, just as there  is
  2598. now an optional tuning specification file.  The same file format should be used
  2599. by transcri and record to determine how Adagio scores are  produced  from  MIDI
  2600. input.   One could use this same facility to tell record and transcri to ignore
  2601. certain control information.  For example, if no command is assigned to control
  2602. aftertouch,   then   aftertouch   data   would  be  ignored  in  the  recording
  2603. (transcription) process.
  2604.  
  2605.   A second change would be to add new commands to  Adagio  to  allow  users  to
  2606. specify smooth, continuous changes without a huge amount of typing.  This could
  2607. be done by implementing a new special command.  For example,
  2608.  
  2609.     !ramp x0 x100 q.
  2610.  
  2611. would mean change the X control smoothly from 0 to 100 in the time of a  dotted
  2612. quarter  note.  This command would be translated into a single Adagio event and
  2613. the stream of control change data would be computed from the event data in real
  2614. time.   Thus, in addition to save typing, the scheme would save on memory space
  2615. wherever these special commands could be used in place of many  control  change
  2616. commands.
  2617.  
  2618.   Finally,  it  would be very interesting to look into using control changes to
  2619. modify MIDI programs in real-time.  For example, you can put a DX7  in  a  mode
  2620. where  the  inharmonicity  of  a  tone can be controlled by a slider on the DX7
  2621. control panel.  By  using  system  exclusive  messages,  one  can  control  the
  2622. inharmonicity  by  computer.    The  missing  link  here is to make the control
  2623. specification file flexible enough that one  can  use  Adagio  to  send  system
  2624. exclusive  messages  as well as conventional control change commands.  It might
  2625. be helpful to add yet another  command  to  Adagio  to  send  system  exclusive
  2626. messages directly.
  2627.  
  2628. 11.7. Interacting with Moxc programs
  2629.   Every  Moxc program I write has a big asciievent routine that calls different
  2630. routines and sets values depending upon characters that get typed at run  time.
  2631. It  should be possible to write a routine that could read the map file produced
  2632. by the linker and figure out where variables and procedures are located.  Then,
  2633. a user interface could be designed such that you could type
  2634.  
  2635.     seti foo 2006
  2636.     call bar 100 572
  2637.  
  2638. in  order  to  set  the  integer  foo  to 2006 and then call procedure bar with
  2639. parameters 100 and 572.
  2640.  
  2641. 11.8. Code to play sequences from Moxc
  2642.   It is hard to write Moxc programs that play sequences of notes, and it  would
  2643. be  nice  to be able to write sequences in Adagio and trigger them in real time
  2644. Moxc programs.  I designed a module for this and wrote most of the code, but  I
  2645. have  not  tested  anything  yet.  The idea is to use a modified Adagio to read
  2646. scores and transform them into data files that  can  be  input  easily  without
  2647. resorting  to  a  full-blown  Adagio translator.  Routines are then provided to
  2648. read and play these sequences.  Several parameters including transposition  and
  2649. rate  can  be  changed  in real-time to modify the performance of the sequence.
  2650. The interface is as follows:
  2651.  
  2652. seq read(name, filename);
  2653.                 reads  the  sequence  in  file  filename.   Sequences are named
  2654.                 internally by small  integers,  and  name  is  the  integer  to
  2655.                 associate with this sequence.
  2656.  
  2657. seq play(name); plays sequence associated with the integer name.
  2658.  
  2659. seq transpose(name, transposition);
  2660.                 sets the transposition of the sequence associated with name  to
  2661.                 transposition.
  2662.  
  2663. seq rate(name, rate);
  2664.                 sets the rate of the sequence associated with name to rate.   A
  2665.                 rate  of  100  gives the normal rate as specified in the Adagio
  2666.                 file that generated the sequence.
  2667.  
  2668. seq cycle(name, flag);
  2669.                 sets  the  cycle  flag  of the sequence associated with name to
  2670.                 flag.  If the flag is non-zero, then the sequence  will  repeat
  2671.                 (cycle) indefinitely.
  2672.  
  2673. seq pause(name, flag);
  2674.                 sets the pause flag of the sequence  associated  with  name  to
  2675.                 flag.    If the flag is non-zero, the sequence performance will
  2676.                 be suspended until the flag is set to zero.
  2677.  
  2678. seq at end(name, procedure);
  2679.                 will  cause  the routine named by procedure to be called at the
  2680.                 end of the performance of the sequence associated with name.
  2681.  
  2682.   This implementation of this interface is quite compact.  A drawback  is  that
  2683. there  is  no provision for recording sequences in real-time within the context
  2684. of Moxc, so some more thinking and experimentation is probably in  order.    It
  2685. has  also  been  suggested  that  one should be able to combine rhythm from one
  2686. sequence with pitches from another.
  2687.  
  2688. 11.9. A player module
  2689.   Currently, Adagio and Record are very similar.  The main difference  is  that
  2690. in  phase  2,  in which Adagio plays a score, Record plays a score and calls on
  2691. record.c to record MIDI input.  It would be nice to design  a  module  player.c
  2692. that  both  Adagio  and  Record  could  call  on  to  play a score.  This would
  2693. eliminate a lot of redundant code and would insure consistency  between  Adagio
  2694. and Record when changes are made.
  2695.  
  2696.   For  example,  one  might want to allow users to transpose scores, change the
  2697. playback speed, and make other changes without editing the score.   At  present
  2698. these  sorts  of  changes would have to be made in both phase2.c for Adagio and
  2699. trans2.c for Record.
  2700.  
  2701. 11.10. User-defined note routines for Adagio
  2702.   Not only would it be nice to be able to invoke Adagio-defined sequences  from
  2703. Moxc,  it  would  also  be  nice to be able to invoke Moxc routines from Adagio
  2704. scores.  One way to do this  would  be  to  separate  the  Adagio  note-playing
  2705. routines  into  a  separate  module.    Then  users  could write their own note
  2706. routines that would get parameters from Adagio scores, but that might have some
  2707. complex  behavior.    For example, one could write a routine that produced drum
  2708. rolls consisting of many MIDI notes, but which could be  invoked  by  a  single
  2709. line  in Adagio.  One would have to be careful to smoothly integrate Adagio and
  2710. Moxc; perhaps Adagio should be modified to use Moxc for its own scheduling.
  2711.  
  2712. 11.11. DX7 Program Librarian
  2713.   In Adagio, one specifies timbre by numbers that correspond to MIDI  programs.
  2714. It  is  up  to  the  user  to make sure the proper programs are loaded into the
  2715. synthesizer in the right locations.  It would be nice to be  able  to  write  a
  2716. file like
  2717.  
  2718.     Channels  ProgramNumber  ProgramName
  2719.     1-8       1              marimba
  2720.     1         2              harp
  2721.     2         2              celeste
  2722.     3-8       2              strings
  2723.  
  2724. which would specify a correspondence between program numbers and program names.
  2725. One could write a Program Librarian that could read such a file and use  it  to
  2726. load  up  a  TX816 or whatever with exactly the right programs for a particular
  2727. piece.  The program names would correspond to file names.
  2728.  
  2729. 11.12. An Adagio editor
  2730.   It might be interesting to be able to  extract  sections  of  Adagio  scores,
  2731. stretch  them,  transpose  them, copy them, merge them with other files, and so
  2732. on.   This  can  be  done  with  a  text  editor,  but  a  specialized  editor,
  2733. particularly  one  that  could  play  the files as it edits them, might be more
  2734. effective.  Another idea for an editor is to try to use a combination of  typed
  2735. text  and  MIDI  input  to  speed up the process of entering scores.  This is a
  2736. largely unexplored area that has applications in music  typography  systems  as
  2737. well as CMT.
  2738.  
  2739. 11.13. Interface to XLISP
  2740.   An interpretive language like LISP can be an excellent teaching and composing
  2741. tool.  XLISP is a version of LISP implemented in C and in  the  public  domain.
  2742. It should be fairly simple to provide a LISP interface to mpu.c, allowing XLISP
  2743. programs to make music.
  2744.  
  2745. 11.14. A Sequencer
  2746.   Everyone else writes sequencers.  Why not build one for CMT?  This  would  be
  2747. the  first  MIDI  sequencer  for small machines that users could modify to suit
  2748. their special needs.
  2749.  
  2750. 11.15. Ports
  2751.   There is very little in CMT that is specific to the IBM PC.  It should not be
  2752. too  difficult  to  get  CMT  running on the Macintosh, Amiga, Atari, and other
  2753. small machines.  Work is under way at Brown University and Carnegie  Mellon  to
  2754. port CMT to an IBM RT as well.
  2755.  
  2756.  
  2757.  
  2758. I. The MIDI Interface
  2759.   This  appendix  contains  documentation  for calls in the module mpu.c.  Type
  2760. boolean is an int that takes on values of true or false, and type  byte  is  an
  2761. unsigned char.
  2762.  
  2763.  
  2764. exclusive(onflag)
  2765.   boolean onflag;
  2766.      This  procedure  tells  the  MPU-401  to  read exclusive messages into the
  2767.      buffer provided by a previous call to midi buffer.  onflag is set to  true
  2768.      to receive MIDI exclusive data, otherwise it is set to false.
  2769.  
  2770.  
  2771. boolean getbuf(waitflag, p)
  2772.   boolean waitflag;
  2773.   byte * p;
  2774.      getbuf copies 4 bytes of data from buffer (the MIDI input buffer filled by
  2775.      the interrupt handler in aintr.asm) to *p.  It will  wait  for  buffer  to
  2776.      become  nonempty if and only if waitflag is true.  It returns true if data
  2777.      was written to *p, and false if data was not written to *p.
  2778.  
  2779.  
  2780. int getkey(waitflag)
  2781.   boolean waitflag;
  2782.      getkey tries to read a key.  It returns the key number of  the  key  which
  2783.      has  been  depressed,  or  the key number plus 128 of a key which has been
  2784.      released.  It returns -1 if waitflag is false and no key has been pressed.
  2785.      If waitflag is true this routine will block until a key is pressed.  Since
  2786.      getkey uses getbuf (see above), non-key events (e.g. pitch  bend)  may  be
  2787.      read and discarded by getkey.
  2788.  
  2789.  
  2790. long gettime()
  2791.      Return  the  time in 100ths of seconds since the last call to musicinit or
  2792.      timereset.
  2793.  
  2794.  
  2795. l  rest(time)
  2796.   long time;
  2797.      l rest waits until the amount of time specified by time has elapsed.
  2798.  
  2799.  
  2800. l  restuntil(time)
  2801.   long time;
  2802.      l restuntil waits until the specified time has been reached (absolute time
  2803.      as returned by gettime).
  2804.  
  2805.  
  2806. metronome(onflag)
  2807.   boolean onflag;
  2808.      metronome  enables  (true) or disables (false) MPU-401 metronome function,
  2809.      as indicated by onflag.  This procedure must be called  before  musicinit.
  2810.      The metronome is not started until musicinit is called.
  2811.  
  2812.  
  2813. midi  bend(channel, value)
  2814.   int channel;
  2815.   int value;
  2816.      Sends  a  MIDI pitch bend message; channel is the MIDI channel on which to
  2817.      send data, and value is the pitch bend value from 0 to 16383.   The  value
  2818.      8192  is  the  value representing no pitch bend; smaller values bend pitch
  2819.      down, and higher values bend pitch up.
  2820.  
  2821.  
  2822. int xbuffhead, xbufftail;
  2823.  
  2824. int midi  buffer(buffer, size)
  2825.   byte * buffer;
  2826.   int size;
  2827.      midi buffer tells interrupt routine to store system exclusive messages  in
  2828.      buffer.  The largest power of 2 bytes less than size will be used (a power
  2829.      of 2 is used so that masking can be used to cause wrap-around).  xbuffhead
  2830.      and  xbufftail  will  be  initialized  to  zero, and xbufftail will be one
  2831.      greater than the index of the last system exclusive byte read from mpu401.
  2832.      midi  buffer  returns  false  if  size  is less than 16 or buffer is NULL,
  2833.      otherwise true.
  2834.  
  2835.  
  2836. midi  cont(onflag)
  2837.   boolean onflag;
  2838.      midi cont enables (true) or disables (false) continuous control info  from
  2839.      the MPU-401 to the host, depending on the value of onflag.
  2840.  
  2841.  
  2842. midi  ctrl(channel, control, value)
  2843.   int channel;
  2844.   int control;
  2845.   int value;
  2846.      Sends  a MIDI control change message; channel is the MIDI channel on which
  2847.      to send data, control is the control number,  and  value  is  the  control
  2848.      value.
  2849.  
  2850.  
  2851. midi  exclusive(msg)
  2852.   byte * msg;
  2853.      Sends  a  MIDI  exclusive  message;  msg  is a pointer to a MIDI exclusive
  2854.      message, terminated by 0xF7.
  2855.  
  2856.  
  2857. midi  note(channel, pitch, velocity)
  2858.   int channel;
  2859.   int pitch;
  2860.   int velocity;
  2861.      Sends a MIDI note-on request out; channel is the MIDI channel on which  to
  2862.      send data, pitch is the MIDI pitch code, and velocity is the velocity with
  2863.      which to sound it (0 means release).  If read tuning has  been  called  to
  2864.      define  a  tuning  and  velocity  is not zero, then this procedure sends a
  2865.      pitch bend followed by a note-on message.  The pitch bend and the  note-on
  2866.      pitch are found by table lookup, using pitch as the table index.  For zero
  2867.      velocity, the table lookup is done to get the pitch for a note-on  message
  2868.      with  zero  velocity.    No pitch bend message is sent since zero velocity
  2869.      means note-off.
  2870.  
  2871.  
  2872. midi  program(channel, program)
  2873.   int channel;
  2874.   int program;
  2875.      Sends a program change request; channel is the channel on  which  to  send
  2876.      the MIDI program change request, and program is the program number to send
  2877.      (this number is decremented by 1 before being sent as MIDI data, so values
  2878.      should be in the range of 1 to 128.)
  2879.  
  2880.  
  2881. midi  thru(onflag)
  2882.   boolean onflag;
  2883.      Enables  (true)  or  disables (false) MIDI thru info from MPU-401 to host,
  2884.      depending on the value of onflag.  The default is enabled, but the command
  2885.      line switch -block will cause it to be disabled initially.
  2886.  
  2887.  
  2888. midi  touch(channel, value)
  2889.   int channel;
  2890.   int value;
  2891.      Sends  a MIDI after touch message; channel is the MIDI channel on which to
  2892.      send data, and value is the after touch value.
  2893.  
  2894.  
  2895. mpu  error  check()
  2896.      Reports any errors originating in the interrupt handler by  printing  them
  2897.      on stdout.  If you do not call this routine, you do not find out about the
  2898.      errors.
  2899.  
  2900.  
  2901. mpuexists(flag)
  2902.   boolean flag;
  2903.      If argument is false, this indicates no MPU-401  is  on  the  machine,  so
  2904.      simulate the mpu-401 (for debugging only).
  2905.  
  2906.  
  2907. read  tuning(filename)
  2908.   char *filename;
  2909.      Reads  tuning  information from filename and enables pitch bend to be sent
  2910.      by midi note to effect detuning.
  2911.  
  2912.  
  2913. musicinit()
  2914.      Initializes the MPU-401 device driver and resets the MPU-401.   The  clock
  2915.      (see gettime) is reset to zero.
  2916.  
  2917.  
  2918. musicterm()
  2919.      Cleans  up;  disables  MPU-401 interrupts; resets MIDI devices.  Call this
  2920.      upon finishing execution.
  2921.  
  2922.  
  2923. int random(lo, hi)
  2924.   int lo, hi;
  2925.      Returns a pseudo-random number between lo and hi inclusive (lo  <=  result
  2926.      <=  hi).  This routine is reasonably fast, but it should not be trusted to
  2927.      be very ``random''.
  2928.  
  2929.  
  2930. timereset()
  2931.      Resets the time on the MPU-401.  The time returned by gettime is reset  to
  2932.      0.
  2933.  
  2934.  
  2935. trace(flag)
  2936.   boolean flag;
  2937.      Turns  tracing  on  (if flag is true) or off (if flag is false).  Calls to
  2938.      mpu.c are traced.
  2939.  
  2940.  
  2941. tracemidi(flag)
  2942.   boolean flag;
  2943.      Turns MIDI tracing on (if flag is true) or off (if flag is false).    MIDI
  2944.      output bytes are printed.
  2945.  
  2946.  
  2947.  
  2948. II. List of Files in CMT
  2949.   The  following  files are included in CMT.  (The number following the file is
  2950. its size in bytes.  This data was obtained from the DOS directory command.)
  2951.  
  2952.            Volume in drive A is CMT DISK 1
  2953.            Directory of  A:\
  2954.  
  2955.           README            508
  2956.           TUNING   EXE    21072
  2957.           TRANSCRI EXE    27616
  2958.           MM       EXE    24568
  2959.           RECORD   EXE    36674
  2960.           DXPUT    EXE    25110
  2961.           DXGET    EXE    25834
  2962.           ADAGIO   EXE    33320
  2963.           EXPORT   BAT      709
  2964.           TEST         <DIR>
  2965.           CMTL     BAT       61
  2966.           CMTC     BAT       18
  2967.           BIN          <DIR>
  2968.                  13 File(s)     19456 bytes free
  2969.  
  2970.            Volume in drive A is CMT DISK 1
  2971.            Directory of  A:\bin
  2972.  
  2973.           .            <DIR>
  2974.           ..           <DIR>
  2975.           MAKEEXE  EXE    19200
  2976.           MAKE     MAN     7595
  2977.           MAKE     BAT      128
  2978.           GREP     EXE    22400
  2979.           LS       EXE    18176
  2980.                   7 File(s)     19456 bytes free
  2981.  
  2982.            Volume in drive A is CMT DISK 1
  2983.            Directory of  A:\test
  2984.  
  2985.           .            <DIR>
  2986.           ..           <DIR>
  2987.           WIDE     TUN     1276
  2988.           BACH     GIO     5154
  2989.           STTHOMAS GIO     5143
  2990.           CONTIN   GIO      172
  2991.           SCALE    GIO      128
  2992.           ALL      GIO      110
  2993.           RETUNE   EXE    25974
  2994.           ECHOES   EXE    25974
  2995.                  10 File(s)     19456 bytes free
  2996.  
  2997.            Volume in drive A is CMT DISK 2
  2998.            Directory of  A:\
  2999.  
  3000.           MAKEFILE         5612
  3001.           MOXCPRGM C         95
  3002.           ADASPACE C        417
  3003.           RECMAIN  C       4259
  3004.           RECORD   C      18538
  3005.           TRANS2   C      10610
  3006.           USERIO   C       4804
  3007.           MOXCTOUC C         97
  3008.           MOXCPDUP C         75
  3009.           MOXCPDDN C         79
  3010.           MOXCKYUP C         79
  3011.           MOXCKYDN C         86
  3012.           MOXCCTRL C        102
  3013.           MOXCASCI C        151
  3014.           MOXCBEND C         95
  3015.           CINTR    C       9897
  3016.           NOTEOFF  C       4504
  3017.           TRASPACE C        415
  3018.           MPU      C      33966
  3019.           ADAGIO   C       4236
  3020.           PHASE1   C      34033
  3021.           PHASE2   C      10380
  3022.           MM       C       4485
  3023.           CMDLINE  C      10779
  3024.           MOXC     C      15736
  3025.           TUNING   C      10005
  3026.           TRANSCRI C       5071
  3027.           RECSPACE C        420
  3028.           EXCLDESC C       1437
  3029.           DXGET    C       6766
  3030.           DXPUT    C       7536
  3031.           TIMDIF   H         18
  3032.           CEXT     H        141
  3033.           MOXC     H         80
  3034.           TRANS2   H         16
  3035.           ADAGIO   H       1192
  3036.           ATXT     H         85
  3037.           CMDLINE  H        121
  3038.           MAXSPACE H        280
  3039.           MIDICODE H        553
  3040.           MOXCPROG H        656
  3041.           MPU      H        703
  3042.           MUSIPROG H       1039
  3043.           PHASE1   H         77
  3044.           PHASE2   H         71
  3045.           PITCH    H        112
  3046.           RECORD   H         62
  3047.           USERIO   H         51
  3048.           CINTR    H        149
  3049.           CMTPROG  H       1060
  3050.           TIMDIF   ASM    13318
  3051.           AINTR    ASM    14949
  3052.           BREAK    ASM     8292
  3053.           ATXT     ASM      877
  3054.           CMT      LNK      177
  3055.           MOXC     OBJ     4471
  3056.           TIMDIF   LIB       18
  3057.           MACSYM   LIB     5006
  3058.           PRCSYM   LIB     8399
  3059.           CMT      LIB    27648
  3060.           DOS      MAC     2059
  3061.           TEST         <DIR>
  3062.                  62 File(s)     15360 bytes free
  3063.  
  3064.            Volume in drive A is CMT DISK 2
  3065.            Directory of  A:\test
  3066.  
  3067.           .            <DIR>
  3068.           ..           <DIR>
  3069.           MOXCTEST C       1919
  3070.           ECHOES   C        356
  3071.           PROG     C        758
  3072.           RETUNE   C        491
  3073.                   6 File(s)     15360 bytes free
  3074.  
  3075.  
  3076.  
  3077. Index
  3078.           Accidentals   4
  3079.           Adagio   4
  3080.           Aftertouch   6
  3081.           Alternatives   14
  3082.           Amiga   21
  3083.           Append   11
  3084.           Asciievent   16, 20
  3085.           Asterisk   4
  3086.           Atari   21
  3087.           Attributes   4
  3088.  
  3089.           Backing up files   3
  3090.           Backup   3
  3091.           Bartok   5
  3092.           Begin   13
  3093.           Bendchange   16
  3094.           Blank   4
  3095.           Brown University   21
  3096.  
  3097.           Case   4
  3098.           Cause   16
  3099.           Character value   16
  3100.           Chord   14
  3101.           Clean   3
  3102.           Cleanobjs   3
  3103.           Cmtc   13
  3104.           Cmtl   13
  3105.           Cmusic   4
  3106.           Collinge, Douglas   16
  3107.           Commas   6
  3108.           Comment   4, 13
  3109.           Compiler   13
  3110.           Compiling   16
  3111.           Conditionals   13
  3112.           Copy   3, 11
  3113.           Ctrlchange   16
  3114.  
  3115.           Debug   20
  3116.           Debugging   6, 16
  3117.           Default   5
  3118.           Default durations   5
  3119.           Default time   4
  3120.           Dot   4
  3121.           Drum rolls   21
  3122.           Duration   4
  3123.           DX7   4, 21
  3124.           DXGet   12
  3125.           DXPut   12
  3126.           Dynamic markings   4
  3127.  
  3128.           Editor   21
  3129.           Eighth note   4
  3130.           End   13
  3131.           Endwhen   14
  3132.           Equal temperment   8
  3133.           Equal to   14
  3134.           Errors   1, 13
  3135.           Event handler   16
  3136.           Everything   3
  3137.           Exclamation point   4
  3138.           Exclusive   22
  3139.  
  3140.           F   4
  3141.           FF   4
  3142.           FFF   4
  3143.           Fileopen   3
  3144.           Files   3
  3145.           First ending   14
  3146.           Flat   4
  3147.           Flexible disks   3
  3148.           Floppy disks   3
  3149.           Foot pedal   6
  3150.           Future   16
  3151.  
  3152.           Getbuf   18, 22
  3153.           Getkey   14, 18, 22
  3154.           Gettime   18, 22
  3155.           Greater than   14
  3156.           Grep   3
  3157.  
  3158.           H   4
  3159.           Halt   16
  3160.  
  3161.           I   4
  3162.           IBM RT   21
  3163.           Include   13
  3164.           Insert   11
  3165.           Interrupt handler   18
  3166.  
  3167.           J   6
  3168.  
  3169.           K   6
  3170.           Keydown   16
  3171.           Keyup   17
  3172.  
  3173.           L   4
  3174.           L rest   22
  3175.           L restuntil   22
  3176.           Large memory model   20
  3177.           Lattice C   20
  3178.           Less than   14
  3179.           Link   13
  3180.           LISP   21
  3181.           Loudness   4
  3182.           Loudness, velocity   4
  3183.           Ls   3
  3184.  
  3185.           M   6
  3186.           Macintosh   21
  3187.           Mainscore   13, 17
  3188.           Make   3
  3189.           Makefile   3
  3190.           Memory model   20
  3191.           Merging two scores   11
  3192.           Metronome   22
  3193.           MF   4
  3194.           Microsoft C   20
  3195.           MIDI   1
  3196.           Midi Monitor   10
  3197.           MIDI program   4, 10
  3198.           Midi bend   22
  3199.           Midi buffer   18, 22
  3200.           Midi cont   22
  3201.           Midi ctrl   22
  3202.           Midi exclusive   22
  3203.           Midi note   15, 22
  3204.           Midi program   15, 22
  3205.           Midi thru   22
  3206.           Midi touch   22
  3207.           Mikrokosmos   5
  3208.           Miller, Phil   15
  3209.           Mistake   6
  3210.           MM   10
  3211.           Modulation wheel   6
  3212.           Moxc   16
  3213.           Moxie   16
  3214.           MP   4
  3215.           MPL   4
  3216.           Mpu error check   22
  3217.           Mpuexists   22
  3218.           Multi-track recording   20
  3219.           Multiple commands   6
  3220.           Multiple Midi Interfaces   20
  3221.           Multiple tempi   6
  3222.           MUSIC V   4
  3223.           Musicinit   22
  3224.           Musicterm   22
  3225.           Musiprog.h   13
  3226.  
  3227.           N   4
  3228.           Natural   4
  3229.           Nelson, Gary   4
  3230.           Next   4
  3231.           Not equal   14
  3232.           Note   13
  3233.  
  3234.           O   6
  3235.           Octave specification   4
  3236.           Omissions   1
  3237.           Otherwise   14
  3238.  
  3239.           P   4
  3240.           Parameters   14, 16
  3241.           Peddown   17
  3242.           Pedup   17
  3243.           Pitch   4
  3244.           Pitch bend   6, 8
  3245.           Pnote   14
  3246.           Polyrhythm   6
  3247.           Portamento rate   6
  3248.           Portamento switch   6
  3249.           PP   4
  3250.           PPP   4
  3251.           Preset   4, 22
  3252.           Printf   14
  3253.           Procedure   13
  3254.           Program change   4, 22
  3255.           Program Change Command   10
  3256.           Program Librarian   21
  3257.           Programming   13
  3258.  
  3259.           Q   4
  3260.  
  3261.           R   4
  3262.           Random   15, 22
  3263.           Rate   4, 5
  3264.           Read tuning   22
  3265.           Real-time clock   18
  3266.           Record   10, 11
  3267.           Recording   20
  3268.           Repeats   13
  3269.           Repetition   13
  3270.           Rest   14
  3271.           Rests   4
  3272.  
  3273.           S   4
  3274.           Saving files   3
  3275.           Second ending   14
  3276.           Sections   5
  3277.           Semicolon   6
  3278.           Semicolons   13
  3279.           Sequence   13
  3280.           Sequencer   21
  3281.           Sharp   4
  3282.           Small memory model   20
  3283.           Space bar   6, 11
  3284.           Special command   4
  3285.           Stopping programs   13
  3286.           Suggestions   1
  3287.           Synchronization   20
  3288.           Sys Info Avail   10
  3289.           System exclusive messages   12, 18
  3290.  
  3291.           T   4
  3292.           Tape-sync   20
  3293.           Tempo   4
  3294.           Terry Riley   13
  3295.           Then   14
  3296.           Timbre   4, 10
  3297.           Time   4, 5, 18
  3298.           Time travel   16
  3299.           Timereset   22
  3300.           Touchchange   17
  3301.           Trace   22
  3302.           Tracemidi   22
  3303.           Tracks   18
  3304.           Transcribe   10
  3305.           Triplet   4
  3306.           Tuning   8
  3307.  
  3308.           U   4
  3309.  
  3310.           V   4
  3311.           Voice   4
  3312.  
  3313.           W   4
  3314.           When   14
  3315.  
  3316.           X   6
  3317.           XLISP   21
  3318.  
  3319.           Y   6
  3320.  
  3321.           Z   4, 10
  3322.  
  3323.  
  3324.  
  3325.                                Table of Contents
  3326.  
  3327. 1. Introduction and Overview                                                  2
  3328.  
  3329.    1.1. Installing CMT                                                        2
  3330.  
  3331. 2. DOS Utilities                                                              3
  3332.  
  3333.    2.1. make                                                                  3
  3334.    2.2. ls                                                                    3
  3335.    2.3. grep                                                                  3
  3336.    2.4. Backing up files                                                      3
  3337.  
  3338. 3. The Adagio Language                                                        4
  3339.  
  3340.    3.1. Specifying Attributes                                                 4
  3341.        3.1.1. Time                                                            4
  3342.        3.1.2. Pitch                                                           4
  3343.        3.1.3. Duration                                                        4
  3344.        3.1.4. Next Time                                                       4
  3345.        3.1.5. Rest                                                            4
  3346.        3.1.6. Loudness                                                        4
  3347.        3.1.7. Voice                                                           4
  3348.        3.1.8. Timbre (MIDI program)                                           4
  3349.        3.1.9. Tempo                                                           4
  3350.        3.1.10. Rate                                                           5
  3351.    3.2. Default Attributes                                                    5
  3352.    3.3. Examples                                                              5
  3353.    3.4. Advanced features                                                     6
  3354.        3.4.1. Multiple notes per line                                         6
  3355.        3.4.2. Control change commands                                         6
  3356.        3.4.3. Multiple Tempi                                                  6
  3357.    3.5. Running Adagio                                                        6
  3358.        3.5.1. Debugging Adagio Scores                                         6
  3359.        3.5.2. Command Line Options                                            6
  3360.        3.5.3. Examples                                                        7
  3361.  
  3362. 4. Defining Nonstandard Tunings                                               8
  3363.  
  3364.    4.1. The Tuning Program                                                    8
  3365.        4.1.1. Entering a range of pitches.                                    8
  3366.        4.1.2. Entering an octave                                              8
  3367.        4.1.3. Entering one pitch                                              8
  3368.        4.1.4. Saving a tuning file.                                           8
  3369.    4.2. The Retune Program                                                    8
  3370.  
  3371. 5. The Transcribe Program                                                    10
  3372.  
  3373.    5.1. Overview                                                             10
  3374.    5.2. Tutorial                                                             10
  3375.    5.3. Timbre                                                               10
  3376.    5.4. Command Line Options                                                 10
  3377.        5.4.1. Examples                                                       10
  3378.  
  3379. 6. The Record Program                                                        11
  3380.  
  3381.    6.1. Overview                                                             11
  3382.    6.2. Instructions                                                         11
  3383.    6.3. Merging Adagio Scores                                                11
  3384.        6.3.1. Playing two scores in sequence                                 11
  3385.        6.3.2. Playing two scores at the same time                            11
  3386.    6.4. Command Line Options                                                 11
  3387.        6.4.1. Examples                                                       11
  3388.  
  3389. 7. DXGet and DXPut                                                           12
  3390.  
  3391.    7.1. DXGet                                                                12
  3392.    7.2. DXPut                                                                12
  3393.  
  3394. 8. Programming in C                                                          13
  3395.  
  3396.    8.1. Introduction                                                         13
  3397.    8.2. Writing a Program                                                    13
  3398.    8.3. Stopping a Program                                                   13
  3399.    8.4. Writing a Procedure                                                  13
  3400.    8.5. Repeats                                                              13
  3401.    8.6. Conditions                                                           13
  3402.    8.7. Parameters                                                           14
  3403.    8.8. Producing Chords                                                     14
  3404.    8.9. Low-level Procedures                                                 14
  3405.        8.9.1. Other Procedures and Functions                                 14
  3406.    8.10. Command Line Options                                                15
  3407.        8.10.1. Examples                                                      15
  3408.    8.11. Conclusions                                                         15
  3409.  
  3410. 9. Moxc: real-time programming package                                       16
  3411.  
  3412.    9.1. What is Moxc?                                                        16
  3413.    9.2. An example                                                           16
  3414.    9.3. Compiling                                                            16
  3415.    9.4. More about cause                                                     16
  3416.    9.5. Event Handlers                                                       16
  3417.    9.6. Command Line Options                                                 17
  3418.        9.6.1. Examples                                                       17
  3419.  
  3420. 10. System Details                                                           18
  3421.  
  3422.    10.1. Introduction                                                        18
  3423.    10.2. Basic MIDI interface                                                18
  3424.        10.2.1. Interface design issues                                       18
  3425.        10.2.2. Interface implementation                                      18
  3426.        10.2.3. System exclusive messages                                     18
  3427.    10.3. Command line parsing                                                18
  3428.    10.4. The record module                                                   19
  3429.  
  3430. 11. What next?                                                               20
  3431.  
  3432.    11.1. Microsoft C conversion                                              20
  3433.    11.2. Large memory model conversion                                       20
  3434.    11.3. Multiple Midi Interfaces                                            20
  3435.    11.4. Improve Adagio compilation (sorting) speed                          20
  3436.    11.5. Multi-track recording                                               20
  3437.    11.6. MIDI Continuous Controls                                            20
  3438.    11.7. Interacting with Moxc programs                                      20
  3439.    11.8. Code to play sequences from Moxc                                    20
  3440.    11.9. A player module                                                     20
  3441.    11.10. User-defined note routines for Adagio                              21
  3442.    11.11. DX7 Program Librarian                                              21
  3443.    11.12. An Adagio editor                                                   21
  3444.    11.13. Interface to XLISP                                                 21
  3445.    11.14. A Sequencer                                                        21
  3446.    11.15. Ports                                                              21
  3447.  
  3448. I. The MIDI Interface                                                        22
  3449.  
  3450. II. List of Files in CMT                                                     23
  3451.  
  3452. Index                                                                        24
  3453.