Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.


Piano with multiple sound options (Array?)

Piano with multiple sound options (Array?)

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.

RE: Piano with multiple sound options (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 :
- 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!!!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close