Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • 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!

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

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Your information in this site is absolutely WONDERFUL. It is the most useful site on the web to me right now. Thank You Thank You..."

Geography

Where in the world do Tek-Tips members come from?

Piano with multiple sound options (Array?)

drboxxr (Programmer)
14 Aug 12 8:09
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.
MelodyRogueAngel (Programmer)
18 Aug 12 14:11
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!!!

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