Qbasicnews.com

Full Version: Music
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm making a program that let's you easily make music and play it. But right now all the notes in the users' music is stored in one string, which makes it hard to delete a note if they made a mistake. Z!re told me how to delete something at the end of a string, but there is no way I can delete or insert a note in the middle of the music. So I want to store each note seperately in one array, but what I want to know is, if a user deletes a note somewhere in the middle of the song, how can I move all the rest of the notes back one space so that I don't have an empty space in the array. Can someone please help me with that? Please tell me any other suggestions for the program, or tell me how an array holding all the notes can mess up my program if it can. Thanks!
I think these snippets will help you...
Code:
TYPE NOTETYPE
notename AS STRING * 1
octave AS INTEGER
length AS INTEGER
END TYPE

REDIM Notes(0) AS NOTETYPE
REDIM TEMP(0) AS NOTETYPE

To delete a note, and re-index everything...
Code:
REDIM TEMP(LBOUND(Notes) TO UBOUND(Notes)-1) AS NOTETYPE

delidx% = 5  'The note that has been deleted

start1% = LBOUND(Notes)
end1% = delidx% - 1
start2% = delidx%
end2% = UBOUND(Notes) - 1

FOR i% = start1% to end1%
TEMP(i%) = Notes(i%)
NEXT
FOR i% = start2% to end2%
TEMP(i%) = Notes(i% + 1)
NEXT

REDIM Notes(start1% TO end2%) AS NOTETYPE
Notes = TEMP

I think that should do it...

Oz~
You can get the program here. EDIT: Oops you're going to have to open this with QBasic 4.5, sorry.

The way I've written the program, I need everything to be strings, so some of that code might not work. But I don't know what TYPE and UBOUND and LBOUND do...some notes can also be sharps and flats.
Code:
TYPE <typename>
param AS VariableType
[...]
END TYPE

This allows you to organzie data....

Code:
TYPE Test
a   AS INTEGER
b   AS INTEGER
END TYPE

DIM var AS Test

var.a = 0
var.b = 1

Code:
DIM Array(0 TO 153) AS INTEGER

lb% = LBOUND(Array)
ub% = UBOUND(Array)

PRINT lb%, ub%

Output:
Code:
0   153

LBOUND gives an integer number of the lowest possible index of an array.
UBOUND gives an integer number of the highest possible index of an array.

Oz~