Reputation: 21
In many versions of Basic, Music can be played with the statement PLAY. It accepts as its arguments, notes, octaves, etc, but also substrings.
as an example, A$="BCD": B$="FDE": PLAY "XA$;O3XB$;"
is equivalent to PLAY "BCDO3FDE"
I want to do the same in C++. I know that is is difficult, as BASIC is interpreted and C++ compiled, but is there a way ?
To be more precise, I already have a function PlayString(AnsiString ss)
, that is able to play a string made of notes (e.g. "BCD"), octaves (prefix O plus a digit, e.g."O2"), note length (prefix L plus a number, e.g."L4"), so a string to play could be "BCDO3FDE" (the same as above).
I want to add to it the necessary code to play a substring, say with prefix X, so that code as in the line below would work :
AnsiString aa="BCD", bb="FDE";PlayString("Xaa;O3Xbb;");
and be equivalent to
PlayString("BCDO3FDE");
Idea(s), anyone ?
Upvotes: 0
Views: 44
Reputation: 180185
As written, this cannot work. The reason is exactly what you suspected: C++ is compiled. Variable names do not exist at run time. But PlayString
interprets its argument only at run time. You need
PlayString(aa+"O3"+bb);
Upvotes: 0