random clip play

Posted by kitchen post 
random clip play
October 27, 2010 12:45PM
does anyone have a script that accomplishes the following: when a single button on a dvd studio pro menu is clicked it will play a random clip. from several, on the dvd (as delineated by chapter markers)? thanks.
Re: random clip play
October 30, 2010 02:49PM
Pretty easy to do... but it involves scripting.

To get it right, you first need to decide whether you want to play a chapter marker, or put them all into stories and play them from there.

I'll assume chapter markers - and that you've got end jumps on each marker to go back to the menu. For the sake of this I'll also assume 10 markers on the track.

Add a script to your project and create the following lines:

Ran GPRM0, 65535
Mod GPRM0, 9
Add GPRM0, 1
Jump Track 1::Chapter 1 if (GPRM0 = 1)
Jump Track 1::Chapter 2 if (GPRM0 = 2)
Jump Track 1::Chapter 3 if (GPRM0 = 3)
Jump Track 1::Chapter 4 if (GPRM0 = 4)
Jump Track 1::Chapter 5 if (GPRM0 = 5)
Jump Track 1::Chapter 6 if (GPRM0 = 6)
Jump Track 1::Chapter 7 if (GPRM0 = 7)
Jump Track 1::Chapter 8 if (GPRM0 = 8)
Jump Track 1::Chapter 9 if (GPRM0 = 9)
Jump Track 1::Chapter 10 if (GPRM0 = 10)
Jump Main Menu

Now, this will randomly create a value from 1 - 10 and jump to the relevant marker accordingly. What it won't do is remember whether it has played that marker before and go to a different one if so. You could, in theory, randomly select the same marker repeatedly. In my experience this is not all that uncommon when there are only a few chapters to choose from.

Your chapter end jumps can either go back to the menu where the button to select random clips is sitting (and that button must point to the script above), or the end jumps could go directly back to the script which would set up a looping playback of random clips.

Adding the logic to prevent repeats requires more scripting, and a little bit of extra logic. Firstly, once a random number has been selected you have to check whether it has been played. If not, mark the clip number as 'used' and play the clip. If the clip has been played before, you go back to the script and run it again. Eventually it will find a clip that has not been used and will play that. However, as the number of unused clips drops, the system could take ages before it finds the last remaining clips. You can add logic to simply add '1' to the random value and then check the clip status if you wish, but then you have to deal with the situation where clip 10 has played... and there is no clip 11! It's quite easy - you simply go to '1' and carry on from there, but it all takes writing out.

So - do you care whether there are repeats or not?

--

lafcpug mod
Re: random clip play
November 01, 2010 03:31PM
sorry i haven't addressed this sooner, been busy. thanks for your answer. since i wrote the first question, i now have more info re what i'm doing. i want a menu button to randomly select one of ultimately 60 (short) tracks. the user will press the menu button on their remote to send them back to the menu button. at the end of each track it jumps to a marker on that track waiting for the user to decide what to do.

so i need a script that will play when the menu button is pressed to randomly select one of the 60 tracks. i've tried two scripts i found online with a trial of 5 tracks and neither one of them works. i keep being sent to the track 1. any help would be appreciated. thanks, david.
Re: random clip play
November 06, 2010 09:34AM
Selecting one of 60 tracks is easy enough, it follows the pattern above, but you'll have larger numbers and more lines of code. You may even need two scripts working together - the last line of script 1 jumping to the first line of script 2.

The bigger question is whether you need to make each selection unique, or whether you are OK with the system repeating tracks that have been previously selected. You didn't answer this crucial bit last time.

The menu button thing is easy enough too - except that you seem to want to pause at the end of each track and not jump to a menu. You can set the menu button to point to a script easily enough, but I'm not quite sure what your end user experience is trying to be... do you want the user to go to a menu whilst you wait for them to make a choice, or do you want to hold them on a track?

--

lafcpug mod
Re: random clip play
November 06, 2010 09:57PM
thanks. what i am trying to accomplish is specifically the following.

when the menu buttom is clicked it will randomly send the user to one of sixty short tracks (which are part of a game). after the track has played, it's end jump is to a marker on that tarck with an infinite pause so the next player may decide if they want to use (repeat) that track or select another in which case the would press the menu button and therefore be able to randomly select another track. it would be best if the tracks didn't repeat after having been selected once.

also the first line of the example above in this thread reads, Ran GPRM0, 65535, it doesn't appear to me how i can enter a number 65535 in any window, is this a typo (i'm using DVDSP4)

it's a lot to ask, i know, thanks. david.
Re: random clip play
November 08, 2010 03:39PM
OK - several things to think about then.

Firstly, 65535 is a value that you enter in the property inspector when setting a GPRM, using the 'immediate' value. Once you select 'Immediate' a text entry area is available and in there you can enter the number. 65535 in decimal is the maximum number a 16bit GPRM will be able to hold.

Secondly, avoiding repeats means you have got to somehow store a value for every track that gets played, and check whether that value is set before a track plays. If it is (meaning if the track has played once already) you have to choose a different track. The challenge you'll face is that you don't have any more than 8 registers, each only 16bit. You'll need four registers just to hold values for 60 tracks (well, 3 3/4 to be precise), leaving you just four registers to do all the math involved.

If this is a game, and you are hoping to total up a score for the players as well, then you're fast going to run out of space in your GPRMs. There may be ways around it by using groups of tracks and first selecting a group, then a single track at random from within the group, until the group is all used up, then selecting a different group to work with. This reduces the number of tracks to remember and gives you more room to do the necessary math, but you have to be OK with the idea of grouping tracks... you can't change the groups later!

The mechanics of playing a track and holding on a marker is ok, but you might be better going to a menu and holding there. How are you going to get the player to say 'use the same track' or 'choose a new track' from a marker position in your track? A menu will allow you to put those questions on the screen and select the one you want to do. It would also be easier to set up the navigation, IMO.

So scripting this... you can be a bit clever if you don't mind doing the math! Things to know are that every track in DVDSP has an internal number, and so rather than referring to the track by name, you can just use the numbers. For example, the first track in your outline view will have an internal number of 49280. They increment by 128 each time, so track 2 will have a value of 49408, and so on. So, by generating a random value you can jump to any track by simply multiplying the random value by 128 and adding 49280. You then put that value into a GPRM and 'jump indirect' to the item with that value:

Ran GPRM0, 65535
Mod GPRM0, 59
Add GPRM0, 1
mul GPRM0, 128
add GPRM0, 49280
Jump Indirect GPRM0

In English, that script reads as follows:

"Get a random number between 0 and 65535 and then do a modulus operation on it (divide by 59 and use the remainder as your value). Add 1 so there is a value between 1 and 60 (not 0 and 59, which modulus will give you). Whatever you get will then need to be multiplied by 128 to get towards a track value, and then add the base amount for tracks (49280). Now, whatever you've got you can jump to - it'll definitely be a track."

Of course, this doesn't do the remembering if a track has played, or checking before it plays. That logic will either need some bit shifting (i.e. put a value into a single bit in a register that represents a track playback status) or you have to use the DVDSP tools to partition four of your GPRMs into 16 bits. Remember that when a track plays you put a value of '1' into the relevant bit slot, but *before* the track plays you check that slot and see if it is less than '1' (i.e. zero... it hasn't played). You can do this by using an XOR operation with one of the four bits left over from the four registers you are using. Make sure one of those is zero, and simply do a comparison against the one you're checking. If it comes back '0' you're good to go ahead and play. ANy other result means it has been played.

This bit gets intense... I'll try to find time to write out some scripts to point you in the right way, but in the mean time have a look here:

[www.dvdstudiopro.co.uk]

To learn more about how this stuff works. It's not the same as your project, but the theory is similar. There are plenty of sample downloads there to help, too... have a look there for 'bit shifting', too.

--

lafcpug mod
Re: random clip play
November 08, 2010 07:22PM
thanks, i'll take a look at the link and await seeing your sample scripts. i can see that it is my intense then i initially thought.

players would use the same track simply by pressing the play button on remote, the track would then play from the marker it had end jumped to and held there. if you want another track the player would press the menu button on remote and be sent to the menu where they would press enter and be sent to another random track.

thanks again. thanks for the heads up re link. david.
Sorry, you do not have permission to post/reply in this forum.
 


Google
  Web lafcpug.org

Web Hosting by HermosawaveHermosawave Internet


Recycle computers and electronics