Play Consecutive Notes of a Song with each Screen Touch
floatingwoo
Los Angeles, Calif.Member Posts: 393
I've been looking through the forum archives for info on this one, with no success, maybe I'm not using the right search words...if someone could point me in the right direction that would be great.
I would like the user to be able to play a sound (one note of a song) with a touch of the screen, with each consecutive touch the next note of the song would play.
For instance in the song "Mary had a Little Lamb" theres only four notes. But how do I set it up so the note changes and is played in the right order with each touch, and then looped? Is this something I would do with tables? Thanks
Comments
When game.notes = 1 play Note A
Make an integer attribute called "notes"
Each time an action is completed change "notes" to "notes" +1
When game.notes = 1 play Note Do
When game.notes = 2 play Note Re
When game.notes = 3 play Note Me
When game.notes = 4 play Note Fa
When game.notes = 5 play Note So
When game.notes = 6 play Note La
When game.notes = 7 play Note Ti
When game.notes = 8 play Note Do
@RabidParrot Brilliant! Thank you... And then just drop a change attribute (game.notes=0) in the last note to have it loop?
Just do - when touch is pressed change notes to (notes +1)%8
mod(notes+1,9)
Fortuna Infortuna Forti Una
@Socks Thanks that works... I don't think I have it set up the way you intended though
@Lovejoy This is interesting, it plays them all at once..kinda cool. Perhaps I don't have it set up right again..
In the first example, the parentheses are not optional:
The mod() or % function returns the remainder of a division problem. So mod(9,9) is 0 and mod(6,9) is 6 for example. The problem with using notes+1%8 is that you are adding 1 to the attribute every time but never resetting/looping back to 0. When you use (notes+1)%8, when the value of notes+1 equals 8, it resets back to 0.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
It looks like when you add one to game.notes, you are triggering the validity condition for the next sound to play, and the next, and the next, etc. because it keeps adding one all the way to the end.
Mathtap.com (Android) | Fridgemanager.com (Android) | Breakoutofspace.com (Android)
Yep ! You have notes +1%8, but I wrote (notes +1)%8.
EDIT: what @tatiang said.
P.S
If you want to use a single note instead of having to produce an audio file for each note, import a middle C and multiply the pitch by 105.94631% for each semitone up.
I found some math.
Disclaimer: it's math.
Mathtap.com (Android) | Fridgemanager.com (Android) | Breakoutofspace.com (Android)
There's also Wikipedia: http://en.wikipedia.org/wiki/Modulo_operation.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
@Socks Got it ! Made the change.
I did try just using one tone and changing the pitch with some rather strange results...possibly because it was not the middle C. I was using the open strings G,C ,E,A of a ukulele ,captured with protools ,they may have been a little off to begin with, but I found I had to tweak that 105.94631% a bit to keep it in tune....I created a "find the chord on the fretboard game" with the ability to select the notes on the fret with the corresponding note ...sorry no audio...
http://tinypic.com/m/ivv1mq/2
That wouldn't make any difference really, even if your initial sample was wildly out of tune you can still scale the space between the pitches perfectly ok, it just means all the tuning is equally sharp or flat.
You shouldn't have to unless you have multiple sources / audio files of a questionable pitch ? That is to say you are tuning multiple audio samples ?
Like it !
I've seen (and bought) quite a few guitar apps that could easily be done a lot better in GameSalad.
The probable reason they are playing all at once is because you are using a constrain attribute behavior when you probably want a change attribute behavior instead.