THIS FILE SHOULD BE READ IN UTF-8
IT CONTAINS A FEW NON_STANDARD ASCII CHARACTERS: 

THE FOLLOWING EXAMPLES BELOW CAN BE CUT AND PASTED INTO SEPARATE FILES
WITH AN .mc EXTENTION SHOULD ONE WANT TO TEST THEM. IF YOU TRY TO PARSE THIS
FILE WITH MICROCSOUND IN ITS ENTIRETY, YOU WILL GET ERRORS!!!

a microcsound example: a scale, covering 3 octaves:

1: i=3 div=53 t=120 gr=5 gv=10 mix=1.0
1: c,d,e,f,g,a,b,cdefgabc'd'e'f'g'a'b'c'' ||

Here above we see the basic syntax.

'1: ' (note the space before we write anything else) means "here's voice
number one".  Anything statement with an equal sign in the middle (=) is a
setup parameter for a given variable.

'i=3' means 'use the 3rd instrument in the Csound orchestra file'

'div=53' means 'set it up so that all symbols are interpreted within the
framework of 53-equal division pitches per octave'

't=120' means 'set tempo to 120 beats per quarter note'

"c," is an octave below middle-C, while "c'" is an octave above.
Simply add commas or apostrophes to go even higher or lower. 

The special variables 'gr' and 'gv' stand for 'Gaussian rhythm' and Gaussian
volume'...they are randomizing functions which add a bit of randomness to
time and volume to humanize things....making these too high can make
everything sound chaotic and drunk, so be aware....there is also a third
variable 'gs', which is not seen here, but deals with variance in staccato
length.

Finally, 'mix' is a floating point amount of general volume, a best practice
would be NOT to set this, it's 1 by default, but then if you don't like your
mix, you should set this to be a value between 0 and 1 (although super soft
instruments might benefit from going above one---but be careful and watch
your ears!!!) You can also design intruments that can be used to 'play'
(using the special case 'div=0' directive, see below) which are in fact
'dummy instruments' that might set up a ZAK mixer or set a global volume
variable, which is useful if you get clipping and would like to normalize
your whole mix.  Using ZAK Csound opcodes for such purposes is beyond the
scope of this document, but you can study the attached 'microcsound.orc' file and
Csound documentation on ZAK for more details....

Here's a scale with ties, and accidentals:

1: i=2 div=19 t=100  1/4 c,2-c,d, | _e,^f,g,_a, | 
1: 1/8 b,a,- a,b,- b,g,=a,b, | 1/4 c4 ||

Above we see a couple of new symbols:
'1/4' means 'set default rhythm to quarter notes' (eight notes are assumed
when there is no indication)

The dash after a note indicates a tie, e.g. c,2-c, means "c below middle c
for 2 beats tied to c below middle c for one beat, for a total of 3 beats"

We also see basic accidentals: "^" is sharp (so "^f" is f-sharp) "_" is flat,
and "=" is natural....you can also do double sharps and double flats 
("^^" and "__") 

We also see that notes can be extended in length by numerical factors, e.g.
"^c,,4" would mean "c-sharp, two octaves below middle-C, held for 4 counts
of the current default length"

###################################
## SETTING INSTRUMENT PARAMETERS ##
###################################

If I have a csound instrument that takes some user parameters in its setup,
microcsound reserves parameters p8-p99 for their setup. p1-p7 are reserved
for internal use by microcsound, the standard being:

p1: instrument #
p2: start time
p3: duration
p4: attack intensity
p5: pitch in hertz
p6: panning value (0.0-1.0; 1.0 being hard right)
p7: mix amount (usually 0-1, but can be higher than 1 to indicate gain)
p8 and up: determined by instrument setup and can be fed by user in a setup
string.

Here's an example. Let's say I have an 'instr 5' in my orchestra file. And
let's say I have four extra user parameters to use, p8-p11. The following
string will set up the parameters before the first note is sounded:

1: i=5 "0.01%0.2%0.5%0.4"

All the values are separated by '%' without whitespace, and surrounded by
double-quotes. THis is how microcsound recognizes instrument setup strings.

You can also change a given slot in the middle of a performance. Let's say
the above 4 values represent an envelope of attack, decay, sustain, and
release on a synth instrument. I can make the attack longer after a couple
of notes like so:

1: i=5 "0.01%0.2%0.5%0.4" c d p8=0.04 e f g r |

The instrument parameter slots above are p8, p9, p10, and p11. Since "p8" is
the first slot, we are changing its value from "0.01" to "0.04".


## EXAMPLE of polyphony ##
 
Here's "mary had a little lamb", with polyphony illustrated:

1: div=31 t=96 i=1 1/4  (e   d  c    d)  |     .e .e e2 |
2: div=31          1/8 c,3 .c, g,,2 g,,2 | 1/4 c, g, 1/8 c,b,,c,2 |    
#
1: 1/4  d  d   d2         |    e g g2  |
2: 1/8 g,2 zg, g,,2a,,b,, |1/4 c,g,c,g,,|
#
1: 1/4  (e   d  c    d)  | .e .e        e2 |
2: 1/8 c,3 .c, g,2 g,,2  | 1/4 c, g, 1/8 c,b,,c,a,, |
#
1: 1/4 d d        e     d      | c3 z &-4 z [f,a,] [e,g,] z || 
2: 1/4 g,,g,, 1/8 g,,a,,b,,g,, | f,,a,,c,z ||

Note at the beginning of each line a voice number, eg '1:' or '2:'
this indicates polyphony, or simultaneous voice strands.
Vertical bars are barlines, and are optional for legibility,
they are ignored. also, '#' is for comments or to keep things visually less
cluttered, and are ignored.

A dot before a note is a staccato example: ".c", and a '(' before a note
(must come before any accidentals, too) means 'legato', and holds until the
next ')', which comes immediately after a note (and must come after any note
lengths and/or tie dashes.

As shown above, one can use 'z2' (or 'r2' as we will see below) for a rest 
of 2 quarters.

Note that one might wish to use 'z' instead of 'r' in this scenario, even
thought both are legal, to be compatible with abcm2ps, you would use 'z', as
it would require less hand massaging should one want to produce a printed score.

Two special features are shown in the last measure of 'mary had a little 
lamb': timestamping and chords. If you look at the symbol '&-4', the '&' 
means 'also play this', and the '-4' means 'four beats earlier than the 
current beat timestamp, meaning 'go back four beats and add the following'
in effect, this allows one to stuff extra counterpoint strands in w/o having 
to write another line of music, convenient for textures where the true
number of simultaneous strands is changing a lot. Chords are indicated by
brackets e.g. [ceg] would be a C major triad, [c2e2g2] would be the same
but twice the length of the current default beat length, [c,2e2g'2] would
be the same, but twice the length, and the c would be an octave lower 
than middle c, and the g would be an octave higher. 

We saw ties in the first two examples. Ties come after the note and any
length alterations. In general, a note event is in the following order:
[articulation][accidental(s)]lettername[octave][length][tie indicator]
the only one in letter-style entry that is not optional is the lettername
some examples to show the trend:
c ^c,2 _e'3 __g- ^^d2-
__ is a double flat      ^^ is a double sharp 
microtonal alterations:
/ is up   a syntonic (81/80) comma
\ is down a syntonic (81/80) comma
> is up a septimal (64/63) comma
< is down a septimal (64/63) comma
! is up an undecimal (33/32) comma
¡ is down an undecimal (33/32) comma ### upside down exclamation point
? is up a tridecimal (1053/1024) comma 
¿ is down a tridecimal (1053/1024) comma

example: 
1: div=53 c\eg\e | g<_bc'<_b | c'4 ||

this would be a passage illustrating a pure 7/4 within 53-equal
b/c the 'b' is altered flat AND is lowered by 64/63 with a '<'
also notice the pure 5/4 b/c of the use f '\' before the 'e'
accidentals can be placed in any order before the letter they alter,
but they must be BEFORE......

a final thing before showing the 2nd style of entering notes...one can use a
"meantone" type tuning like 31-equal and request pure fifths by using a "*"
symbol AFTER the letter for the note you want to make pure, e.g.

    1: div=31 [_c_e_g*] 

....would be a c-flat major chord, and the g-flat would be a pure fifth 
with the c-flat....in this way, one can do adaptive just intonation style
music while staying in the comfort of fewer pitches, for example writing
just intonation from within the structure of 31-equal.

#####################################################
## NOW, AN ENTIRELY DIFFERENT WAY OF DOING THINGS: ##
#####################################################

# "Mary had a little lamb":
1: div=31 t=96 i=1 1/8 5.10 t 5 t   0 t   5 r | 10 t  10 t 10  t t r |
2: div=31               4.0 r r 0 -13 t -13 t |  0 t -13 t  0 -3 0 5 |
# 3rd measure
1:  5 t 5   t  5  t  t t | 10 t .18 r   18  t    t   t |
2: 18 z z -13 18 13 10 5 |  0 t   r 0 .-13 -8 .-13 .-3 |
# 5th measure
1: (10 t 5 t  0) t  .5 t | 10 t  10 t 10 t 10  t |
2:   0 r r 0 -13 t -13 t |  0 t -13 t  0 5 10 13 |
# 7th and 8th measures
1:  5 t   5 t   10   t   5    t | 0 t   t t  0 r r r &-8 r r [-18 t -8 t] [.-21 .-13] r r r ||
2: 18 r -13 r .-13 .-8 .-3 .-13 | 0 t -18 t .0 r r r  ||   

This is the oldest style 'number syntax' I developed. It really is a 
low-level way of doing things, but it's useful for non-diatonic music
in non-diatonic tunings. It's also laid out in a way to be a sort of
'grid'-like in it's representation of time, think of it as a text-based 
sequencer or tracker way of thinking about writing music. (To help the clean
alignment of the text, use an editor with a fixed width font, and one that
has the ability to filter blocks of text through system commands for
processing from withing the editor (e.g. joe, vi, emacs), and use the
attached 'mcs_align.py' script as a system command--it will be installed
with microcsound)

Note the use of '#' as a way to put comments in the score. '#' can of course
occur on its own line (or several of them in a row, or several of them above
one another, or both) as a way of aiding readability. 

Basically, a note is defined by it's index (from 0) in a
division of the octave, from middle C being 5.0, C above Middle-C being 
6.0, etc. So in 31 equal, a Major scale would be:

1: div=31 0 5 10 13 18 23 28 31  

or

1: div=31 5.0 5 10 13 18 23 28 6.0  

coming down from middle C, we could do:

1: div=31 5.0 -3 -8 -13 -18 -21 -26 -31

or

1: div=31 5.0 4.28 23 18 13 10 5 0 

notice that octaves get 'held' by default until they are explicitly 
changed...also notice one can index degrees of an octave below 
the reference 'C' by using negative numbers.
You can even use non-octave based scales (not tested extensively, however,
please report any bugs to me) by using an non-integer 'div' like e.g.
'div=31.1' for instance.

#######################
## RATIONAL NOTATION ##
#######################

Since version 20090813, there is now the added feature of being able to do
free-style rational pitch notation for things like just intonation, and
exploring the overtone and undertone series.

Everything is relative to middle_C = 261 HZ, and one indicates a pitch in
rational form with colons, since the normal '/' is already taken by rhythmic
length default indicators. So, for example:

1: t=60 i=3 1:1 2:1 4:1 1:1 1:2 1:4

this above example would be a series of 'c' octaves....to make them 'd'
octaves, we could do:

1: t=60 i=3 key=9:8 1:1 2:1 4:1 1:1 1:2 1:4

or

1: t=60 i=3 key=1:1 9:8 18:8 36:8 9:8 9:16 9:32

which are exact sonic equivalents, but the use of 'key=' makes
conceptualizing modulation much easier to handle.  So now things are
relative to a 9/8 ratio above middle-C...notice that when the denominator is
greater than the numerator, we are going BELOW middle-C in pitch.

We of course can do traids and chord, from simple to exotic:

1: 1:1 5:4 3:2 2:1 t t

...a major triad arpeggio, w/octave at top held for two extra beats

1: [1:1 5:4 3:2 2:1]

...the same, played as a block chord

1: [33:32 37:32 41:32 45:32]

an isoharmonic sonority, built in reference to the 33rd harmonic (otonal)

1: [76:76 76:66 76:56 76:46]

a similar structure, but using an subharmonic (utonal) sequence.

########################
## ATTACK AND PANNING ##
########################

Another feature to note: panning and attack volume:

1: div=31 pan=0.3 0 pan=0.9 5 pan=0.3 10 pan=0.9 13 pan=0.5 18 t 

1: div=31 @5 0 @55 5 @6 10 @7 13 @85 18 t 

I'm using numbers for notes, but letters work equally well, i.e. attack and
pan are available for either style; just make sure to surround the 'pan=nnn'
and '@nn' statements with whitespace!

(NOTE: '@' notation has evolved a bit. Users who make their own microcsound
orchestras are encouraged to used the Csound convention of "0dbfs = 1", and
scale orchestra input to something like "@0" being equal to -60 db. See the
sample orchestra file "basic.orc" for how to do this.

Also: "@6" is the same as "@60", so one more extra digit is used for finer
gradations. The following is a straight line increase by 2 fine grade steps:
@6 @62 @64 @68 @7)

Since ramping is supported, one can use that in attacks to create 
crescendos (or decrescendos), as long as the ramp has a start and 
ending value:

1: div=19 @7 0 @< 3 6 8 11 14 17 @9 19 t t t r r r

In this example above, we start at volume 0.2, initiate a ramp symbol
indicating a crescendo, and end at volume 0.9.

When using ramping with 'pan', due to the nature of the way microcsound
parses, one has to surround the ramp symbol with double quotes, like so:

	pan="<"

In all other respects, it works in the same way that attack ramping works.

#################################################
## CSOUND SPECIFIC DOCUMENTATION--HOW IT WORKS ##
#################################################

Assuming you know Csound, what's happening is that the score fields p4 and
above are being manipulated by microcsound depending on the
microcsound-score you type in. Remember, in Csound, p1,p2 & p3 are reserved
for instrument number, on time, and duration. So p4 and above are
user-defined and open to the instrument designer. 

However, in order to make you instruments compatible with microcsound, you
need to make p4 correspond to attack/volume, p5 is pitch expressed in
octaves (your instruments should interpret the output of microcsound with
the 'cpsoct' opcode), p6 with pan position, p7 is mix volume (a
floating-point number between 0 & 1) and any other p-field can be freely
accessed by the syntax explained below....

So, if you have a Csound instrument with extra parameters beyond note, volume, 
and spatial panning, (i.e. you want to access p8 and above) you can access 
them within quotes, separated the individual p-fields by '%' characters:

1: div=19 i=6 ".01%.01%3%.3" 0 3 ".8%.02%3%.5" 6 t t t r r r

Here we have an instrument (number 6 because i=6) which has 4 extra 
p-fields; in this case, p8 is attack time, p9 is release time, p10 is 
waveform number, and p11 is pulse width. The "%" characters are necessary
because of the way the parsing of the file is done by microcsound, you can
see in the score-file which is output by microcsound that they are replaced
by spaces.

One could easily then modify things, depending on your instrument design,
like filter frequency, resonance, the sky's the limit!

Finally, one can disable the 'interpretation' of the note number as a 
pitch at all by using 'div=0'; this is useful for instruments which
are percussive on a single note or pitch parameter, like a drum, or a
Csound 'instrument' which is not a conventional instrument at all, but an
effect such as reverb or delay, etc. In other words, one could design
instruments in which p5 was not corresponding with pitch. Likewise, although
p4 is accessed with '@' and p6 with 'pan=' there is no reason one couldn't
use other numbers there for other purposes, should your instrument need it.
But the best practice for the purposes of using non-pitch instruments like 
percussion and effects within orchestras with microcsound would be to make 
these fields 'dummy fields' and use p5 and above for sure. The way it is
designed, in fact, p5 of some sort is necessary for an event to register at
all and for time to progress in the time-counter of the score. So if your
special instrument required only one parameter, make sure it's p5 using
div=0 that is used at the very least--make p4 a 'dummy parameter' by having 
your instrument ignore p4 in that case..

So for example, we might use a drum instrument, like the one supplied, 
which allows bass-drum/snare/symbal patterns from one line:

1: div=0 t=120 i=120 0 1 0 1 | 0 1 0 1 &-8 1/8 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2

Well, that should cover it....

Enjoy microcsound!