MUV601 - Robin Le Couteur - Assignment 3, blog 3 - 2018


Assignment 3 Progress - Blog 3 - 

Scripting the keys

Over the last couple of weeks I've been making some progress on my scripting for the piano keys.
I've done some other progress on other elements of the build, but I'll just talk about what I've done in the week 11(May 21).

So into the key scripting! 
Right, so my first idea for scripting the keys was to place the audio file for each note into each individual key, and have a script for each key that would play the note and perform additional effects for the key. The script that each key had looked something like this:
--------------------------------------------------------------
string note = "note_00";

playsound()  
    {
        llPlaySound(note,1.0);
    }       

default
    touch_start(integer total_number)
    {
        playsound();
    }
    collision_start(integer num)
    {
        playsound();
    }
   
}
--------------------------------------------------------------

The basics of this script is that it detects user input from either touch or collision(if they stand on the key), then calls a function to play the note. in this initial design I had to modify every script to have a different value in 'string note'. In this example it was note_00 for the first note, then it would be note_01, note_02 etc.

To resolve this so that there was only one script that was copied to each key, I made it so that each key had an object name of its number, so 00, 01, 02 etc. this was combined with the string "note_" to form the name of the corresponding sound file.

I found that as I made each new version of the script, I needed to replace the script in every single key which was quite time consuming. To get around this I thought it would be a good idea to put all the sounds and a sound playing script into one single object, and have the keys send a message to the main object telling it what note it is. This meant that any new sounds or added features that did not involve direct manipulation of the keys could be much more easily added. 
The way I implemented this was using the llMessageLinked function. Each key would send a message with the key number to the root object which would then play the sound.

Unfortunately I found a flaw with this system. It could only play one sound at a time meaning that the keyboard was much less responsive and couldn't play more than one note at a time.

I decided to go back to the old method of each sound being played by its own key. It just meant that I have to make the script on one key and when I am happy with it, copy it to all the other keys.

I did retain the main object, however, except it communicates in the opposite direction. It has now been implemented as a sound selector that tells all the keys what sound set to use. The idea of this is that each key has sounds like piano_note_00 or synth_note_00, then the user selects "synth" so the object tells all the keys to use the "synth" note.

All that's left to really is add all the effects and key movement when a key is pressed, and to add different sound sets then the keys are done! After that it's setting up the user selection of sounds, then I can finish other parts of the build like the environment that the keyboard will be in




Comments

Popular posts from this blog

MUV601 - Robin Le Couteur - Assignment 3, blog 1 planning - 2018

MUV601 - Robin Le Couteur - Assignment 3, blog 6 - 2018