'==============
'SNDRAWPLAY.BAS v1.00
'==============
'Attempting a PLAY-like song format using _SNDRAW
'Plays notes and allows more than one note to sound at the same time.
'Can play notes in the background.
'Coded By Dav, JAN/2021
'For now, there only 15 notes playable, about 2 octaves.
' e1 f1 g1 a1 b1 | c2 d2 e2 f2 g2 a2 b2 | c3 d3 e3
'You can play a chord of notes by grouping inside ()
' (c2 e2 g2)
'Assign current note/rest length values like this...
'WN = Whole note, HN = Half note, DQ = Dotted quarter note
'QN = Quarter note, EN = Eighth note, SN = Sixteenth note
'Rests - nothing played, but time continues
'RN = Rest note. Uses current note length value set.
'For example, to rest a quarter note, do this:
'QN RN
'Assign Tempos like this (always must be in 4 characters):
'T120 ... or T060 ... or T100
'Assign current meter (for whole length value to work)
'M3 (thats for 3/4).... M4 (Thats for 4/4)
'========================================================
'=== Playing all notes...
'Set tempo 120, meter 4/4, set sixteen note value
SPLAY "t120 m4 sn e1f1g1a1b1c2d2e2f2g2a2b2c3d3e3"
PRINT "Testing all notes...e1 to e3..."
'=== Playing some chords...
'Set tempo 120, meter 4/4, set sixteen note value, play all notes
'Note: You don't have to include spaces, but I did here...
SPLAY "qn (c2 e2 g2) (f2a2c3) (g2b2d3) (f2a2c3) (c2 e2 g2)"
PRINT "Playing chords..."
'=== Playing a song.... part of Silent Night.,,,
Song$ = ""
Song$ = Song$ + "t100m3dq(c2e2g2)en(c2f2a2)qn(c2e2g2)wn(g1c2e2)"
Song$ = Song$ + "dq(c2e2g2)en(c2f2a2)qn(c2e2g2)wn(g1c2e2)"
Song$ = Song$ + "hn(d3b2g2)qnd3(g2b2)c3(d3g2f2)"
Song$ = Song$ + "dq(c2e2g2)en(c2f2a2)qn(c2e2g2)wn(g1c2e2)"
SPLAY Song$
'Set Defaults, just in case empty
IF NoteValue
= 0 THEN NoteValue
= 1
cur = 1
'skip any spaces
'Check for tempo
cur = cur + 1
Tempo
= VAL(MID$(Music$
, cur
, 3)): cur
= cur
+ 3
'Check for Meter
cur = cur + 1
Meter
= VAL(MID$(Music$
, cur
, 1)): cur
= cur
+ 1
'Get notevalue
CASE IS = "DQ": cur
= cur
+ 2: NoteValue
= 1.5 CASE IS = "EN": cur
= cur
+ 2: NoteValue
= .5 CASE IS = "QN": cur
= cur
+ 2: NoteValue
= 1 CASE IS = "HN": cur
= cur
+ 2: NoteValue
= 2 IF Meter
= 3 THEN NoteValue
= 3 ELSE NoteValue
= 4 CASE IS = "SN": cur
= cur
+ 2: NoteValue
= .25
'If regular note/rest found (not a group)
CASE IS = "E1": note
= 329.63: cur
= cur
+ 2:
GOSUB LoadNote
CASE IS = "F1": note
= 349.23: cur
= cur
+ 2:
GOSUB LoadNote
CASE IS = "G1": note
= 392.00: cur
= cur
+ 2:
GOSUB LoadNote
CASE IS = "A1": note
= 440.00: cur
= cur
+ 2:
GOSUB LoadNote
CASE IS = "B1": note
= 493.88: cur
= cur
+ 2:
GOSUB LoadNote
CASE IS = "C2": note
= 523.25: cur
= cur
+ 2:
GOSUB LoadNote
CASE IS = "D2": note
= 587.33: cur
= cur
+ 2:
GOSUB LoadNote
CASE IS = "E2": note
= 659.25: cur
= cur
+ 2:
GOSUB LoadNote
CASE IS = "F2": note
= 698.46: cur
= cur
+ 2:
GOSUB LoadNote
CASE IS = "G2": note
= 783.99: cur
= cur
+ 2:
GOSUB LoadNote
CASE IS = "A2": note
= 880.00: cur
= cur
+ 2:
GOSUB LoadNote
CASE IS = "B2": note
= 987.77: cur
= cur
+ 2:
GOSUB LoadNote
CASE IS = "C3": note
= 1046.50: cur
= cur
+ 2:
GOSUB LoadNote
CASE IS = "D3": note
= 1174.66: cur
= cur
+ 2:
GOSUB LoadNote
CASE IS = "E3": note
= 1318.51: cur
= cur
+ 2:
GOSUB LoadNote
CASE IS = "RN": note
= 0: cur
= cur
+ 2:
GOSUB LoadNote
'if group of notes found
cur = cur + 1
'Grab up until ')' found
Group$ = ""
a$
= MID$(Music$
, cur
, 1): cur
= cur
+ 1 IF a$
<> " " THEN Group$
= Group$
+ a$
NumOfNotes
= LEN(Group$
) / 2 Length = (60 * NoteValue / Tempo)
'fade = EXP(-L / rate * 8)
note$
= MID$(Group$
, N
, 2)
'IF INKEY$ <> "" THEN EXIT SUB
'=========================================================
LoadNote:
'========
Length = (60 * NoteValue / Tempo)
FOR L
= 0 TO Length
* rate
'fade = EXP(-l / rate * 8)