Join us in Outworldz at www.outworldz.com:9000 or follow us:

Search dozens of selected web sites for OpenSim and LSL script

New! Script Meta-Search will search thousands of scripts here and at other sites for LSL or Opensim scripts.
Loading

Want to add a script or a project? Upload it and a half million people will see it and your name here this year.

Home   Show All
Category: Contributor: Creator
Music Psykes_Music_Script  

Psykes_Music_Script

Psyke's Music Script.lsl

Category: Music
By : Psyke Phaeton
Created: 2010-01-10 Edited: 2010-01-10
Worlds: Second Life

the Zip file

Download all files for Psykes_Music_Script
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Psykes_Music_Script_1.lsl
1
2 //Psyke's Music Script v4.15.1
3 //Song Player
4
5 //Modified by Psyke Phaeton... this script is free for anyone to use or copy.. please make it copyable from your "CD"
6 //Drop 9 second song clips in reverse order into the Inv of the obect, and touch to play.
7
8 //user variables
9
10 integer waves_to_preload = 3; //wave files to Preload ahead of the wav being played.
11 float preload_load_time = 0.5; // seconds pause between each preloaded wave file attempt b4 play comnences
12 //vector set_text_colour = <,0,0>; // colour of floating text label
13 float set_text_alpha = 1; //no idea what this is LOL
14 float timer_interval = 8.9; //time interval between requesting server to play the next 9 second wave
15 // times just below 9 seconds are suitable as we use sound queueing
16 integer timer_started;
17
18 // program variables
19 list invlist;
20 integer total_wave_files; //number of wave files
21 integer last_wave_file_number; //final wave sequence number (note: sequence starts at zero
22 //- so this is 1 less than total wave files)
23 integer i; //used by timer() player
24 integer c; //user by sound() bufferer
25 string preloading_wave_name; //the name of the wave file being preloaded
26 string playing_wave_name; //the name of the wave being played
27 integer play = FALSE; //toggle for music playing or stopped
28
29 sound()
30 {
31 total_wave_files = llGetInventoryNumber(INVENTORY_SOUND);
32 last_wave_file_number = total_wave_files - 1; // because wav files are numbered from zero
33 float length = total_wave_files*9.0;
34 //llSay(0, "preloading " + (string)tottrack + " wavs. Play length " + (string)llFloor(length) + "secs");
35 integer c = 0;
36 //do full preload of sound
37 llSetSoundQueueing(TRUE); //ONLY WORKS ON llPlaySound not llTriggerSound
38 /////////////////
39 //integer x = waves_to_preload;
40 //if( total_wave_files < waves_to_preload ) { x = total_wave_files; }
41 ////////////////
42 integer x = total_wave_files;
43 llSay(0, "(" + llGetScriptName() + ") " + llGetSubString((string)(x * preload_load_time),0,3) + " sec buffering..");
44 timer_started = FALSE;
45 for (c = 0 ; c <= (x - 1) ; c++) { //preload X wave files b4 we play
46 //since wavs are numbered from 0 we minus 1
47 preloading_wave_name = llGetInventoryName(INVENTORY_SOUND, c);
49 "\n(preloading " + llGetSubString((string)((x - c)*preload_load_time),0,3) + " secs)"
50 //////debug lines
51 //+ "\n--debug--\n"
52 //+ "Preload wav: " + (string)c
53 //+ "\nkey: " + (string)llGetInventoryKey(preloading_wave_name)
54 //////end debug line
55 +"\n.", <1,0,0>, set_text_alpha);
56
57 //Attempt to preload first x wave files to local machines cache!
58 llTriggerSound(preloading_wave_name, 0.0);
59 llPreloadSound(preloading_wave_name);
60 //llWhisper(0, (string)c + " of " + (string)tottrack);
61 //llWhisper(0,"Preloading wav: " + (string)c + (string)llGetInventoryKey(preloading_wave_name));
62
63 //start play sound timer in 'timer_interval' seconds when we are less than 'timer_interval' seconds from
64 // finishing preloading.
65 if( ((total_wave_files - c) * preload_load_time) < timer_interval && !timer_started) {
66 //llWhisper(0, "Starting timer:" + (string)timer_interval);
67 llSetTimerEvent(timer_interval);
68 timer_started = TRUE;
69 }
70
71 llSleep(preload_load_time);
72 }
73 i=0; c=0;
74 llSay(0, "Done! Playing.. (" + (string)llFloor(length) + " secs) Click to stop.");
75 //llSetTimerEvent(8.85);
76 }
77
78 default
79 {
80 on_rez(integer start_param)
81 {
82 //set text above object to the name of the object
83 llSetText(llGetObjectName() + "\n.", <0,1,0>, set_text_alpha);
84 //llSetSoundQueueing(FALSE); //ONLY WORKS ON llPlaySound not llTriggerSound
85 }
86 touch_start(integer total_number)
87 {
88 if(!play) {
89 //llTargetOmega(<0,0,1>,PI,1.0) ;
90 sound();
91 } else {
92 //llTargetOmega(<0,0,1>,0,0);
93 llSetTimerEvent(0.0);
95 //llSetSoundQueueing(FALSE); //ONLY WORKS ON llPlaySound not llTriggerSound
96 llSay(0, "Stopping..");
97 llSetText(llGetObjectName() + "\n.", <0,1,0>, set_text_alpha);
98 }
99
100 play = !play;
101 }
102
103 timer()
104 {
105 if( i > last_wave_file_number )
106 {
107 //llSay(0, "finished.");
108 play = FALSE;
109 //llSetSoundQueueing(FALSE); //ONLY WORKS ON llPlaySound not llTriggerSound
110 llSetText(llGetObjectName() + "\n.", <0,1,0>, set_text_alpha);
111 //llResetScript();
113 }
114 else
115 {
116 playing_wave_name = llGetInventoryName(INVENTORY_SOUND, i);
117 //llWhisper(0, "llPlaySound wav: " + (string)i + " " + (string)llGetInventoryKey(playing_wave_name) );
118 llPlaySound(playing_wave_name, 0.7);
120 "\n(playing " + (string)i +" of "+ (string)last_wave_file_number +")\n."
121 , <0,1,1>, set_text_alpha);
122
123 if(i + waves_to_preload <= last_wave_file_number)
124 {
125 preloading_wave_name = llGetInventoryName(INVENTORY_SOUND, i + waves_to_preload);
127 // "\n(playing " + (string)i +" of "+ (string)last_wave_file_number +")"
128 //////debug line
129 //+ "\n--debug--\n"
130 //+ "Playing key: " + (string)llGetInventoryKey(playing_wave_name) + "\n"
131 //+ "Preloading sequence: " + (string)(i + waves_to_preload)
132 //+ "\nPreloading key: " + (string)llGetInventoryKey(preloading_wave_name)
133 //////end debig line
134 // , set_text_colour, set_text_alpha);
135
136 //llWhisper(0, "Preloading wav:" + (string)(i + waves_to_preload) + " " +
137 // (string)llGetInventoryKey(preloading_wave_name) +" last = " + (string)last_wave_file_number);
138 llTriggerSound(llGetInventoryName(INVENTORY_SOUND, i + waves_to_preload), 0.0);
140 }
141 }
142
143 i++; //increment for next wave file in sequence!
144 }
145 }
146
147 // END //

Back to the Best Free Tools in Second Life and OpenSim.