How do I use a CSV/XML for music ?

0 favourites
  • 9 posts
From the Asset Store
6 looping tracks to use in your games and projects. These tracks are in the style of the 1960s detective movie genre.
  • So I've used XMLs for projects before, but I'm not sure if I can use it for the following idea.

    So I'd have the code read an XML/CSV that would have something like this in it

    C,D,E,D,C

    1,0.5,1,2,0.75

    Where the letters would be notes on a piano (which I have as .ogg files in the project) and the numbers are the delays between when each is played. This way I could write new musical scores and have the game play the next note when the delay is up.

    Any help would be greatly appreciated. ^_^

    Here's the musical note if it helps with making an example that would explain/demonstrate the correct methods.

  • I guess one way would be to place a sprite down for every note and play each one as another sprite moves over them.

    you could even use one sound and change the frequencies.

    Here's my experiment on the matter:

    https://dl.dropboxusercontent.com/u/542 ... music.capx

    you could do it in a more programmy way using an array too i suppose.

  • Wow ! Just wow !

    That is a perfect execution of how I wanted the sound to play.

  • R0J0hound, any idea how to generate that from a CSV ? So that I need not place them all, and can auto generate the level ? I've been trying but sadly my knowledge of that isn't great

    I was trying to read in from a CSV but can't quite get the syntax right

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • How far have you got it? The cvs is just a file. You can use the AJAX object to get it into a text variable. You can then use the tokenat expression it get indavidual values from it.

  • Yeah, that's where I was struggling, but will give it another shot this weekend

  • Sorry to bug you again R0J0hound , but would you be able to make a simple CAPX to show me how this could be done ? I'm totally lost.

  • Here's a new capx, but I guess it's not really simple.

    https://dl.dropboxusercontent.com/u/542 ... usic2.capx

    It takes a file and loads it into a text variable with ajax.

    The format of the file is just comma seperated:

    note,duration, note,duration....

    Notes are defined by the note and octave: ex: a4, a4#, etc...

    Rests are defined by "r"

    The meat of it is it uses a number i to define where we at.

    It get's the note from the music with tokenat(music, i, ",")

    It takes that and converts it to a frequency. Here I used an equation and a lookup, but it can all just be a lookup.

    Next it get's the duration with tokenat(music, i+1, ",") and sets a timer and adds 2 to i.

    When the timer finishes it goes again.

    I added little stuff here and there like fading the volume, and stopping if something invalid is in the file.

  • R0J0hound,

    Not even ninjas can beat you in C2. You are the master!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)