Menu Close

SunnYabc© gives to LiveCode users the possibility to play music written in the language ABC. The next chapter describes the very simple functions available in LiveCode. The language ABC is then explained in detail.

SunnYabc© Interface in LiveCode

sunnyabc.Play( abcTune )

# you have your abc tune in field "ABC"
get sunnyabc.Play( field "ABC" ) # your abc tune can be in a variable
get sunnyabc.Play( abc ) # your abc tune can be in a custom property
get sunnyabc.Play( the mozart of stack "MyMusic" )

This function returns the length time of the tune in milliseconds.

sunnyabc.Stop

Stop the current tune if playing, otherwise has no effect.

sunnyabc.Header abcHeader

# 
sunnyabc.Header field "ABCheader" # and play only notes afterwards
sunnyabc.Play( "cdefgh" ) # and reset the Header
sunnyabc.Header

Using the sunnyabc.Header command gives you the ability to simplify your tunes, which is interesting if you’re calling often sunnyabc.Play in your stack. You only have to set the header once, and can then play the sunnyabc.Play command as many times as you like. It’s up to you.

sunnyabc Errors and warnings

Errors are returned in the result variable with 4 items separated by commas. First item is the line number where the error occured, Second item is the char position in the line Third item is the error information.

Fourth item is the char or string unrecognized or misplaced.

From the stack SunnYabcTutorial, here is part of the code to play ABC music:

on mouseUp
  put sunnyabc.Play(field "Fabc") into tunelength
  put the result into r
  if r is not empty then
    printError r
    enable button "PlayABC"
    disable button "Stop"
    ColorsOfErrors item 1 of r,item 2 of r
  end if
end mouseUp

on printError s
  answer "SunnYabc Error !" &cr& \
  "Line: " & item 1 of s &cr& \
  "Position: " & item 2 of s &cr& \
  "Hint: " & item 3 of s &cr& \
  "Text: " & item 4 of s
end printError

sunnyabc.Version()

This function returns a string with some information and the version of the external.

SunnYabcTutorial – A tutorial Stack

When you download sunnyabc, you’ll get a demo stack with it. This stack called “SunnYabcTutorial”, will help you understand what can be done in ABC. I’ve put nearly 20 differents tunes in it, most of them “cut & paste” from the net.

ABC music

Ok, here you have a simple ABC tune !

X: 1
T: all notes....
M:1/4
L:1/4
Q:180
K:D
cdefgab

This tune consists of a header followed by a body. Each line in the header is a different field starting with a letter immediately followed by ‘:’ and then the text of the field. The body of the tune contains lines of music, though it may also contain certain fields.

The end of the tune is marked by a blank line (so blank lines cannot appear within the tune header or body).

Comments are allowed in both the header and the body. A comment starts with a % sign and continues to the end of the line. A comment may be on a line of its own or at the end of a line of abc. Comments can be embraced by quotes too.

The header should look something like this :

X:1
T: the title
M:4/4
L:1/8
Q:120
K:G

X: is the reference number of the tune. Must be the first field of the header. T: is the title of the tune. M: is the time signature. L: is the unit note length Q: is the tempo

K: is the key signature. Must be the last field of the header.

In the example above, the tempo is given at 120 quarter-notes per minute.

Following the header is the tune. This is a textual notation for the things you might see on a stave, Notes !

Notes

A note consists of a pitch specifier followed by a length. Available pitch specifiers which covers 4 octaves, are:

C, D, E, F, G, A, B,
C  D  E  F  G  A  B
c  d  e  f  g  a  b
c' d' e' f' g' a' b'

some abc utilities allow lower octaves to be reached by adding extra , characters and higher octaves to be reached by adding extra ‘ characters. However, this is not standard abc and is not yet supported by SunnYabc.

You can raise or lower the pitch specifier by a semitone by preceding it with ^ or _ respectively. The key signature and preceding sharps, flats and barlines modify the default pitch in the same way as on a stave. Preceding a note with = generates natural pitch.

The length is in general specified by a fraction following the pitch specifier. However, the notation is made more concise by allowing much of the fraction to be omitted. C – selects a note of 1 unit note length. C2 – selects a note of 2 unit note lengths. C/2 – selects a note of 1/2 unit note length.

C3/4 – selects a note of 3/4 unit note length.

No space is allowed within a note, but space may be used to separate notes in the tune. Rests are written by using ‘z’ as the pitch specifier.

z2 – a rest of 2 unit note lengths.

Placing a dot before a note causes it to be played staccato.
.e

Combining notes

Three notes of the same length can be turned into a triplet by prefixing them with “(3”. This has the effect of multiplying the note lengths by 2/3. A chord can be represented by bracketting the notes together within [ and ] e.g. [a2e2].
An older notation which is not supported is to use “+” symbols e.g. +a2e2+.

The “-“ symbol can be used to tie together notes of the same pitch e.g. a2-a; this is equivalent to a3.

A run of 2 or more different notes may be grouped together in a slur. This usually means that the notes are to be played together as smoothly as possible. In abc, “(” marks the start of a slur and “)” marks the end. e.g. (ABc) . SunnYabc recognizes slurs, but they have no effect yet on the MIDI generated.

Barlines

|        is an ordinary barline
||       is a double barline
:|       is "repeat last section".
|:       is "repeat next section".
::       is "repeat last and next sections".
|1   or
|[1  or
| [1     is "first repeat ending".
:|2  or
:|[2 or
:| [2    is "second repeat ending".
|] and
[|       are variants of ||.

A tune with different ending for the first and second repeats has the general form: |: common body of tune |1 first ending :|2 second ending ||

The notation :: is short for 😐 followed by |: .

Broken Rhythm Notation

a>b is notated as a3/2b/2 but played as a4/3b2/3.
The symbols “>>” and “

Program Number – Instrument name

In the tune header, you can specify the instrument number ( 1..128 ) with the “G:” field. G: 7 for instance,sets the Harpsichord.

Here is the whole list of instruments :

 Prog# Instrument Prog# Instrument PIANO CHROMATIC PERCUSSION
1 Acoustic Grand 9 Celesta
2 Bright Acoustic 10 Glockenspiel
3 Electric Grand 11 Music Box
4 Honky-Tonk 12 Vibraphone
5 Electric Piano 1 13 Marimba
6 Electric Piano 2 14 Xylophone
7 Harpsichord 15 Tubular Bells
8 Clavinet 16 Dulcimer ORGAN GUITAR
17 Drawbar Organ 25 Nylon String Guitar
18 Percussive Organ 26 Steel String Guitar
19 Rock Organ 27 Electric Jazz Guitar
20 Church Organ 28 Electric Clean Guitar
21 Reed Organ 29 Electric Muted Guitar
22 Accoridan 30 Overdriven Guitar
23 Harmonica 31 Distortion Guitar
24 Tango Accordian 32 Guitar Harmonics BASS SOLO STRINGS
33 Acoustic Bass 41 Violin
34 Electric Bass(finger) 42 Viola
35 Electric Bass(pick) 43 Cello
36 Fretless Bass 44 Contrabass
37 Slap Bass 1 45 Tremolo Strings
38 Slap Bass 2 46 Pizzicato Strings
39 Synth Bass 1 47 Orchestral Strings
40 Synth Bass 2 48 Timpani ENSEMBLE BRASS
49 String Ensemble 1 57 Trumpet
50 String Ensemble 2 58 Trombone
51 SynthStrings 1 59 Tuba
52 SynthStrings 2 60 Muted Trumpet
53 Choir Aahs 61 French Horn
54 Voice Oohs 62 Brass Section
55 Synth Voice 63 SynthBrass 1
56 Orchestra Hit 64 SynthBrass 2 REED PIPE
65 Soprano Sax 73 Piccolo
66 Alto Sax 74 Flute
67 Tenor Sax 75 Recorder
68 Baritone Sax 76 Pan Flute
69 Oboe 77 Blown Bottle
70 English Horn 78 Skakuhachi
71 Bassoon 79 Whistle
72 Clarinet 80 Ocarina SYNTH LEAD SYNTH PAD
81 Lead 1 (square) 89 Pad 1 (new age)
82 Lead 2 (sawtooth) 90 Pad 2 (warm)
83 Lead 3 (calliope) 91 Pad 3 (polysynth)
84 Lead 4 (chiff) 92 Pad 4 (choir)
85 Lead 5 (charang) 93 Pad 5 (bowed)
86 Lead 6 (voice) 94 Pad 6 (metallic)
87 Lead 7 (fifths) 95 Pad 7 (halo)
88 Lead 8 (bass+lead) 96 Pad 8 (sweep) SYNTH EFFECTS ETHNIC 97 FX 1 (rain) 105 Sitar 98 FX 2 (soundtrack) 106 Banjo 99 FX 3 (crystal) 107 Shamisen
100 FX 4 (atmosphere) 108 Koto
101 FX 5 (brightness) 109 Kalimba
102 FX 6 (goblins) 110 Bagpipe
103 FX 7 (echoes) 111 Fiddle
104 FX 8 (sci-fi) 112 Shanai PERCUSSIVE SOUND EFFECTS
113 Tinkle Bell 121 Guitar Fret Noise
114 Agogo 122 Breath Noise
115 Steel Drums 123 Seashore
116 Woodblock 124 Bird Tweet
117 Taiko Drum 125 Telephone Ring
118 Melodic Tom 126 Helicopter
119 Synth Drum 127 Applause
120 Reverse Cymbal 128   Gunshot