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
Sound Psykes_Music_Script_Looped  

Psykes_Music_Script_Looped

Psykes_Music_Script_Looped

Category: Sound
By : BACANA
Created: 2010-09-24 Edited: 2010-09-24
Worlds: Second Life

the Zip file

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

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