How do I use a CSV/XML for music ?

Get help using Construct 2

Post » Wed Mar 23, 2016 3:02 am

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.
Using R243 for all examples
B
69
S
20
G
6
Posts: 379
Reputation: 9,699

Post » Wed Mar 23, 2016 8:41 pm

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.
B
92
S
32
G
106
Posts: 5,272
Reputation: 69,455

Post » Thu Mar 24, 2016 11:37 am

Wow ! Just wow !

That is a perfect execution of how I wanted the sound to play.
Using R243 for all examples
B
69
S
20
G
6
Posts: 379
Reputation: 9,699

Post » Tue Mar 29, 2016 12:58 am

@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 :(
Using R243 for all examples
B
69
S
20
G
6
Posts: 379
Reputation: 9,699

Post » Thu Mar 31, 2016 8:27 pm

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.
B
92
S
32
G
106
Posts: 5,272
Reputation: 69,455

Post » Fri Apr 01, 2016 10:57 pm

Yeah, that's where I was struggling, but will give it another shot this weekend :)
Using R243 for all examples
B
69
S
20
G
6
Posts: 379
Reputation: 9,699

Post » Wed Apr 06, 2016 1:45 am

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. :(
Using R243 for all examples
B
69
S
20
G
6
Posts: 379
Reputation: 9,699

Post » Wed Apr 06, 2016 6:47 pm

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.
B
92
S
32
G
106
Posts: 5,272
Reputation: 69,455

Post » Thu Apr 07, 2016 6:54 pm

@R0J0hound,

Not even ninjas can beat you in C2. You are the master!
B
116
S
48
G
24
Posts: 401
Reputation: 22,207


Return to How do I....?

Who is online

Users browsing this forum: guannstar, nahima and 22 guests