Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Piano with multiple sound options (Array?)

Status
Not open for further replies.

drboxxr

Programmer
Aug 14, 2012
1
ZA
Hey All,

I am trying to create a piano, but i want to be able to switch between the sounds the piano makes (eg I want to be able to have the piano sound like a trumpet, then a harp, then a piano with button clicks). I have achieved this using BASS.dll, however i am doing it in a very redundant way.

Here is what I am currently doing:

1) Create stream variables for all the sounds (if I have 25 notes on the piano, ill need 25*3 variables for the three instruments)
2) Assign each of these streams to an audio file (75 duplicated lines of code)
3) Have buttons assign a sound to the OnMouseDown of a piano key.

Here are examples of the code I used:
1)Create stream variables: [Example: HSTREAM;]
2)Assign stream: [Example := BASS_StreamCreateFile(False, pansichar('FileName.wav'), 0, 0, 0);]
3)Play stream: [BASS_ChannelPlay(Example, True);]

Clearly, my method means dozens of Copy/Paste lines of code, and since I am using this for a school project, I cannot expect a very good grade for the method I am using. I was wondering if there was some way that I could create an array to assign sounds and such simply by looping through the array.
 
I thinck it is possible by creating 3 differnt arrays
- 1 for the piano sound (under Type: Piano = Array [1..25]
of string; then under global var: arrPiano : Piano;)
- 1 for the trumpet (under Type: Trumpet = Array
[1..25] of String; then under global var: arrTrumpet :
Trumpet;)
- 1 for the harp (under Type: Harp = Array [1..25] of
String; then under glabal var: arrHarp : Harp)

And assign a variable to declare to which sound file it would be assigned to (I'd use three one for each sound - iPiano, iTrumpet, iHarp : Interger;)

Then for the codes

> iPiano := 0;
> iHarp := 0;
> iTrumpet := 0;
>
> While iPiano < 26
> Do
> arrPiano[iPiano] := (Sound File Name);
>
> While iTrumpet < 26
> Do
> arrTrumpet[iTrumpet] := (Sound File Name);
>
> While iHarp < 26
> Do
> arrPiano[iHarp] := (Sound File Name);

The rest is up to you to try and figure out; GOOD LUCK!!!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top