Page 1 of 1

Playing a note as a string variable

Posted: Sun Feb 10, 2019 9:23 pm
by Ken
If I want to play one note say C2, with instrument 25 in the default instrument bank the following code does it.

notes set "25:c2"
notes play
do !until NOTES_TIME() > NOTES_LENGTH()

However if I want to set the note to a string variable I can't get it to work.

So the code below works and produces the note using the default instrument.
note$="c2"

notes set note$
notes play
do !until NOTES_TIME() > NOTES_LENGTH()

If I want to change to another instrument where do I put the quote marks?
Notes set "25:note$" etc almost works. It plays a note but it is a different high pitched one.

25:note$, "25":note$, produce an error.

I notice in the help documentation that midi should be used for real time note playing so I will start looking at that as well.

Re: Playing a note as a string variable

Posted: Mon Feb 11, 2019 4:41 am
by rbytes
This code will work. Note that you can build a new string by combining the literal quote "25:" with the string variable note$. The ampersand is used to join them. It can join any series of literal quotes or string variables in any order you need.

Code: Select all

note$="c3"
notes set "25:"&note$
notes play
do !until NOTES_TIME() > NOTES_LENGTH()

Re: Playing a note as a string variable

Posted: Mon Feb 11, 2019 5:03 am
by Ken
Thanks that makes sense. I will try it later.