How can I select a Sound to play using an Expression?
Hymloe
Member Posts: 1,653
Hello,
I am working on a virtual instrument, and I want to be able to trigger a sound when tapping keys, for example.
I want to choose the sound to play using an expression. How can I do this?
If it's not supported now, will it be supported soon?
Has anyone found a way to do this somehow?
Thanks.
- Murray
I am working on a virtual instrument, and I want to be able to trigger a sound when tapping keys, for example.
I want to choose the sound to play using an expression. How can I do this?
If it's not supported now, will it be supported soon?
Has anyone found a way to do this somehow?
Thanks.
- Murray
Comments
@Hymloe
Hi Murray, here's no expression editor linked with the sounds themselves in a Play Sound behaviour apart from those for Volume and Pitch, as you know.
So one workaround to your problem would be to have several integer attributes, one for each soundset.
Put into the Rules of an actor for one of your keys (in the Inspector): When touch is pressed
---this next rule nested in the above
When attribute SoundPlay = Piano
Play Sound Piano
---this next rule also nested in the first rule
When attribute SoundPlay = Flute
Play Sound Flute
etc, for each type of sound you have.
Providing this is done in the actor's Prototype, you can then drag the rest out for the other keys and adjust the sound values in the Play Sound behaviours accordingly.
Hope that gives you a start.
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
I want to build, say a piano keyboard, with 12 keys.
A, A#, B, C, C#, D, D#, E, F, F#, G, G#
And ideally, every key is just the one actor, with a rule that says "When pressed, play Sound with name (derived from Expression) MyInstrument_MyOctave_MyNote", and I can manipulate those attributes for each key, so that the user can manipulate the interface to choose a different instrument, choose a different octave, and press the keys to derive the appropriate note.
I can use the behaviour "Change Attribute" and set an Image for an actor using this approach (combining Attributes to give the file name for the image).
So to do the same for sound, I assume, would simply involve Game Salad allowing for the Expression Editor to select the sound's filename, in that same way.
@SaladStraightShooter
Will we be seeing this feature in future?
It would be very empowering to be able to specify a sound filename with an expression, not just for things like virtual instruments, although especially for that.
- Murray
If you tried my suggestion, it certainly would do what you want.... just not the way you want it done. Yes, I understood what you wanted and I explained it can't be done with using the expression editor to pick/change sounds directly.
If you don't get a reply from @saladstraightshooter I can give you my guess – that there won't ever be an expression editor linked with the sound value area in a Play Sound behaviour because: any attribute selected would still have to be linked with whatever sound you wanted via a Change Attribute Behavior anyway.
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
I guess my question is two parts.
One is about my immediate goals, and whether there is an elegant and powerful way to implement it. The other part is perhaps more of a feature request / suggestion... that the Play Sound behaviour be improved, so that people can more intelligently select which sound to play, based on expressions that define the filename, not just a simple "dumb" dropdown box.
The suggestion of a more powerful Play Sound behaviour seems relatively modest to me, (at least far from the impossibility you seem to be suggesting in your last paragraph).
Personally, here's hoping it gets added into the Play Sound behaviour, so the project I have in mind becomes a reasonable proposition that can be implemented elegantly and powerfully.
I have not outlined above all that my project is intended to do. But the desire would be to have a single actor (or "key on a piano") for example, which I can have many instances of on the screen, and go into each actor and give it a unique set of attribute (without breaking them off from the prototype actor itself), so that each key has it's own "note" (in terms of what note it triggers), and the user could also toggle various modifiers for each key, such as what effect is applied, which instrument it is, etc. So the user can change what all the keys do, and I store those attributes for each key, and as they tap the keys, it plays the appropriate sound for that key, which would be an amalgam of the various settings they have assigned, thus defining a sound from a series of perhaps 100 or 200 sounds, using a naming convention that aligns with the various attributes strung together to make that filename.
I am not going to make some big list of IF statements to choose a sound, it would be a nightmare, and breaking off each "key" instance to be a unique instance would disallow me from updating the prototype actor as I go along.
Now, I know my project is very sound specific. But allowing the user to use an expression editor to select the Play Sound file would allow for other common uses in games...
While finishing my last game, upon completing a mission, I wanted to play a random Win_Voiceover file. I had 30 to choose from.
I had to generate a random number (all good so far), then nest 30 "IF" statements to then define which one is played! It was a bit ridiculous, and could have been collapsed into a single Play Sound behaviour, if it allowed for the use of the expression editor to select the filename.
I could have just gone...
1. Change Attribute: VONumber = random(1,30)
2. PlaySound: WonGame .. VONumber
Easy! Done!
And it could choose and play whichever file was relevant... whether it be...
WonGame1
WonGame2
WonGame3
...
WonGame30
As it was, I actually had to cut VO out of my game, because after nesting the original 60 VO lines I had intended to include, my project simply crashed and wouldn't load. So I had to cut it back to 30 just so I could ship my game.
It has many other purposes, and allows people to implement the playing of random sounds in a fraction of the time (say if you want 6 different shotgun sounds, or something), and generally do sound more elegantly and programatically.
- Murray
:P
Hi again Martin
I, for one, applaud your efforts in trying to make GS easier to use and more elegant.
Unfortunately though I still can't see how your suggestion for the Play Sound Behaviour could help.... sorry about that.... and the reason is:
with your example:
1. Change Attribute: VONumber = random(1,30)
2. keyboard key pressed
2. PlaySound: WonGame .. VONumber
you would still need to input - somewhere, somehow - a list, i.e which Sound belongs to which number,
VONNumber =1 is SoundType Flute
VONNumber =2 is SoundType Piano
etc.
So, to my mind, that is as much "work" as what you'd need at the moment:
When touch is pressed
When VONnumber = 1
Play Sound Flute
When VON number = 2
PlaySound Piano
etc.
Do you see what I'm saying? Or perhaps I'm missing the point...
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
Well, let's break it down.
I just want sounds to work the same way images do.
I can specify an image using an expression, which lets me create systems.
So, if I have a profile headshot of the character at the bottom of the screen, and I want it to show your character, whether male or female, and their health status, I can do this by using two attributes, which, when combined, specify the name of the graphic I want shown.
For example, I might have these 8 graphics.
Male4.png (full)
Male3.png (3/4)
Male2.png (half)
Male1.png (1/4)
Female4.png (full)
Female3.png (3/4)
Female2.png (1/2)
Female1.png (1/4)
So, I now have 2 game attributes.
PlayerGender (text)
PlayerHealthStatus (integer)
The player chooses a character gender at the beginning of the game, male or female. This is stored as PlayerGender (text).
Then, as they keep playing the game, as their health goes up and down, it updates PlayerHealthStatus, to indicate whether the player has full health, 3/4 health, 1/2 health, or 1/4 health.
Now, I have an actor which shows the player portrait. It has a rule... very simple...
Timer > Every 1 second...
Change Attribute > self.Image > Expression (PlayerGender..PlayerHealthStatus)
That's it. Every second, it will load the appropriate image using that expression.
So it will load in an image Male3.png, if you are playing as a Male character, and your health is 78/100, for example.
This, you can do now, in Game Salad. Very cool. Powerful. Elegant.
For my virtual instrument (for example), I would like to do this...
Have an actor, which is basically this...
If Press > Play Sound > Expression (Instrument..Octave..Note..FX)
Where the attributes could be...
Instrument (Piano, Kalimba, Guitar)
Octave (1, 2, 3, 4, 5, 6)
Note (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12) (A through G#)
FX (None, Dist, Fuzz)
And my files for distorted piano would be named:
Piano11Dist
Piano12Dist
Piano13Dist
Piano14Dist
Piano15Dist
Piano16Dist
Piano17Dist
Piano18Dist
Piano19Dist
Piano110Dist
Piano111Dist
Piano112Dist
Piano21Dist
Piano22Dist
Piano23Dist
Piano24Dist
Piano25Dist
Piano26Dist
Piano27Dist
Piano28Dist
Piano29Dist
Piano210Dist
Piano211Dist
Piano212Dist
Piano31Dist
Piano32Dist
Piano33Dist
Piano34Dist
Piano35Dist
Piano36Dist
Piano37Dist
Piano38Dist
Piano39Dist
Piano310Dist
Piano311Dist
Piano312Dist
Piano41Dist
Piano42Dist
Piano43Dist
Piano44Dist
Piano45Dist
Piano46Dist
Piano47Dist
Piano48Dist
Piano49Dist
Piano410Dist
Piano411Dist
Piano412Dist
Piano51Dist
Piano52Dist
Piano53Dist
Piano54Dist
Piano55Dist
Piano56Dist
Piano57Dist
Piano58Dist
Piano59Dist
Piano510Dist
Piano511Dist
Piano512Dist
Piano61Dist
Piano62Dist
Piano63Dist
Piano64Dist
Piano65Dist
Piano66Dist
Piano67Dist
Piano68Dist
Piano69Dist
Piano610Dist
Piano611Dist
Piano612Dist
So that's one instrument with one effect (piano with distortion).
There's be 9 times that many files, if you went off that examples I've given of 3 instruments (piano, kalimba, guitar).
And that one single rule above would cover every single one of them. If I could use an expression to choose a sound filename in the Play Sound behaviour.
I would place 12 of these "piano key" actors on the stage. Leave them all as prototypes. I'd go into each one and change it's "Note" attributes to a number from 1 to 12 (but still leave them as prototypes, so I can continue editing the one actor for all of them as I go).
And the rest would just work.
I can't really see how you'd make a manageable project of any sort of sanity or order without the use of expressions to choose the sound file.
But if you can see a way, it'd be cool to hear it.
- Murray
I think they could support the drop down box, as the default, but let you use an expression if you want. As you do often just want to play a single sound.
But the expression editor would allow for much more, that is currently not really do-able.
I think the ability to call sounds from tables would be useful too!
Although still not getting the multiple sound parameters via just one expression thing.... I must be getting slow-brained or something.... So an example, if press > Play Sound (Piano..3..7..Fuzz)
Even if expressions in the Play Sound behaviour was there, there isn't an ability to make the sound "Fuzz" or "Distorted", nor change it's pitch without affecting the length of time it plays, or change it's pitch depending on its octave. So you'd still need each sound as separate, i.e not only Piano11Dist, Piano12Dist, Piano13Dist, Piano14Dist, etc., but also Piano11Fuzz, Piano12Fuzz, Piano13Fuzz, Piano14Fuzz, not to mention Piano11DistOct1Note1, Piano11DistOct1Note2, etc, etc, etc.
Just to say I think if a sound file could be altered with fuzz, distortion or timing and octave elements built into the sound behaviour file, that'd be terrific, and all these parameters could be "controlled" with simple attributes , (OK, via the expression editor, but individual editors, one for each).
I'm not being stubborn on purpose or anything, that's just how I see it...
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
I'm not expecting Game Salad to introduce some way to actually apply effects to the sounds in real time, just a way for me to specify a filename using an expression (like you can do with images).
In everything I've said above, I didn't mention anything about volume and pitch, because you CAN use an expression to alter those. Which is all good and well. But we really need to be able to use an expression to choose the filename, making Play Sound much more powerful, and allowing us to do things that are not currently possible (in any practical way).
I'm getting it, Murray, thanks. :-)
Yes, it would be excellent to have more aspects to Play Sounds behaviour as you say, for sure; as well as Play Music Behaviour as well; hopefully one day soon.
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
I understand they can't go into great depth on every feature, but it would be nice to be able to CROSSFADE a new track in. Perhaps being able to define the duration of the crossfade.
Full-on dynamic music systems get rather complex, and I think they might be outside the scope of Game Salad. But yes, a few more basic controls would be nice.
I'm really just interested in being able to define a Play Sound filename using the expression editor.
Thanks
I'm still really hanging for this feature to make it into Game Salad.
Seems like kind of an easy one, and one well overdue.
And one that would be helpful for many users.
The ability to reference variables using variable would be amazing. If you could say, for example, game.Touches. Active.Touch[game.nextTouch] or something, that would save hundreds of lines of logic in some cases.
Going back a couple of posts, it's possible to crossfade tracks with a little juggling of logic. Can be done quite smoothly.
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
Sounds like good think to put in the public bug data base as feature request.
This was on the road map at one point last year.
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
Great idea! It's in the Public Bug Database as #205. Would love to see it done...
http://bugs.gamesalad.com/show_bug.cgi?id=205
Still no sign of this feature, but an approximation can be had by:
make a global variable: soundrequired
make a prototype actor: soundplayer
put the 80 (or so) rules into the soundplayer actor (tedious, but you only have to do it once):
if game.soundrequired = 1
play sound1
if game.soundrequired = 2
play sound2
etc...
Then place a copy of the soundplayer actor in any scene where you want sound to occur.
Now any actor in the scene can call a sound from a table, or at random, or by some expression, by changing the global variable game.soundrequired.
If you need to be able to trigger the same sound over and over, without playing a different sound in between, you need a slightly more complicated version, that zeroes game.soundrequired in between calls, or that uses a separate trigger variable. Where I also wanted a convincing legato, in a basic piano/synth app, I have also tried using 4 almost identical soundrequired actors, which a midi controller actor uses in rotation, and zeros after an adjustable overlap.
Check out play-my-note.com for a working example - not the whole synth solution Hymloe (and I) would love to see, but a reasonable approximation for smallish music apps.
The biggest issue is still scene loading times, but this seems to be affecting all kinds of GS projects, not just ones with many-rule actors.
Thanks Marion,
That sounds like a fairly good work around for some cases, even though it's quite complicated and painstaking to set up, and has limited functionality.
I think your rather groovy workaround goes to show just how much we need Game Salad to implement this feature properly, so that users don't have to do awkward things like that to get the results we're after.
The main limitation I see of your approach is that it doesn't lend itself very well to positional audio, because the sound is always coming from your SoundPlayer actor. (You could of course pass an X,Y position to the sound player as well, and it jumps to that position before playing the sound - which would work in many cases)... BUT!
You can't play multiple sounds from the SoundPlayer all at once, from different locations in the scene, for example.
And I can see the logic getting a bit crazy if you were trying to play many sounds from it from different places, etc.
For many game project, if you had lots of sounds to play, but only one at a time, and it's OK for them to be in 2D space, then your system sounds like a great solution.
But it wouldn't work for what I need it to do, so I still urgently need GS to support a proper system for selecting which sound to play using an expression to get the sound name.
I am still waiting on this feature to be implemented properly, so the Play Sound behaviour allows the use of an expression to define the sound name, whether that is grabbing it from a table cell, or concatenating a string to get, say "Hurt_1" or "Hurt_2" or "Hurt_3" by joining ["Hurt_" .. random(1,3)] for example.
I have a single actor which is my Monster.
When it spawns, it looks up tables and expressions to decide which type it is, what it's attributes are, what image it uses, etc.
All works fantastic. But when it comes to sound, I've just not implemented it yet, because I need them to look up their sounds, when hurt, when attack, when die, etc, etc, from a table.
This would be a simple thing, if Play Sound supported the use of expressions. But as it stands, I just can't implement the monster sounds (or a bunch of other sounds) until the feature is done.
Again... VOTE HERE if you want this feature!
http://bugs.gamesalad.com/show_bug.cgi?id=205
It's the 5th highest voted feature in the bugbase, but somehow I feel Game Salad is shy of putting resources onto implementing this feature. I don't know why. It would make a lot of audio implementation much quicker and easier, and even open up whole new possibilities for sorts of games and apps made with Game Salad.
Any updates on this @BlackCloakGS ? Is this feature on the table? Coming down the pipe?
My game is coming to an end, after many years of development, and the lack of this feature is going to cause me big problems with implementing my audio in a rad / sane / effective / good way.
Would love to see it in there ASAP.
Any progress, Game Salad?