Play Consecutive Notes of a Song with each Screen Touch

floatingwoofloatingwoo Los Angeles, Calif.Member Posts: 393
edited April 2015 in Working with GS (Mac)

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

  • RabidParrotRabidParrot Formally RabidParrot. Member Posts: 956

    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

  • floatingwoofloatingwoo Los Angeles, Calif.Member Posts: 393
    edited April 2015

    @RabidParrot Brilliant! Thank you... And then just drop a change attribute (game.notes=0) in the last note to have it loop?

  • SocksSocks London, UK.Member Posts: 12,822

    @floatingwoo said:
    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

  • LovejoyLovejoy Member Posts: 2,078

    mod(notes+1,9)

    Fortuna Infortuna Forti Una

  • floatingwoofloatingwoo Los Angeles, Calif.Member Posts: 393

    @Socks Thanks that works... I don't think I have it set up the way you intended though

  • floatingwoofloatingwoo Los Angeles, Calif.Member Posts: 393

    @Lovejoy This is interesting, it plays them all at once..kinda cool. Perhaps I don't have it set up right again..

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited April 2015

    In the first example, the parentheses are not optional:

    @Socks said:
    Just do - when touch is pressed change notes to (notes +1)%8

    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

  • SummationSummation Member, PRO Posts: 476
    edited April 2015

    @floatingwoo said:
    Lovejoy This is interesting, it plays them all at once..kinda cool. Perhaps I don't have it set up right again..
    [image]

    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.

  • SocksSocks London, UK.Member Posts: 12,822
    edited April 2015

    @floatingwoo said:
    Socks Thanks that works... I don't think I have it set up the way you intended though !

    Yep ! You have notes +1%8, but I wrote (notes +1)%8.

    EDIT: what @tatiang said.

  • SocksSocks London, UK.Member Posts: 12,822
    edited April 2015

    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.

  • SummationSummation Member, PRO Posts: 476
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • floatingwoofloatingwoo Los Angeles, Calif.Member Posts: 393

    @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

  • SocksSocks London, UK.Member Posts: 12,822
    edited April 2015

    @floatingwoo said:
    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 . .

    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.

    @floatingwoo said:
    but I found I had to tweak that 105.94631% a bit to keep it in tune....

    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 ?

    @floatingwoo said:
    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

    Like it ! :smile:

    I've seen (and bought) quite a few guitar apps that could easily be done a lot better in GameSalad.

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    @floatingwoo said:
    @Lovejoy This is interesting, it plays them all at once..kinda cool. Perhaps I don't have it set up right again..

    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.

Sign In or Register to comment.