Random playback, DVD Studio Pro scripting, random play all no repeat

Over the weekend I regained my broadband connection, having lost it for three to four weeks. Boy! What a lot of posts were on the Apple discussion forums for DVD Studio Pro when I looked there!

One that struck me as worthy of a detailed reply was asking about setting up random playback of all of the stories in the project, not repeating any of them. The user had 16 stories and was using DVDSP v4 (which made life easier).

When you do this kind of scripting, you need to do two things. First off, you’ll have to partition a memory register so that all of your clips can be ‘stored’ in either a played or unplayed state. Secondly, you’ll need to track which have played and/or keep track of how many have played.

I chose to build a system which did all of that.

The way I did it (being one of several methods) was as follows. Firstly, each story needs a pre-script which sets a value into your partitioned register at the appropriate bit slot. Secondly, the pre-script needs to add ‘1’ to another register so that we can track the number of times a story has played.

If the partitioned register has 16 slots in it, they can each be named something unique. For ease, I suggested a system that uses ‘Story1play’, changing the number to reflect the number of the story each time. Now, when story4 plays, the fourth slot in the partitioned register will get a ‘1’ instead of being a ‘0’… and so on. The pre-scripts on the stories look like this:

mov Story1Play, 1
add GPRM2, 1
exit prescript

Now, we are ready to create the random number generator and all of the code to determine if a story has already played. We can also add a line to see if there have been 16 stories played (as a kind of ‘belt and braces’ approach). To start with, you don’t want to get stuck in a loop for too long, so make the first line the one that checks to see if 16 stories have played, if they have, jump out to a menu. If not, generate a random number:

Jump Menu_out If(GPRM2 = 16)
ran GPRM0, 65535
mod GPRM0, 16

OK- those three lines are pretty important – the random number is generated up to the maximum a 16 bit register can hold. You then apply a modulo operation in order to get a number we can use that relates to the 16 possible register slots. Modulo returns values starting at zero – so a mod of 16 should give us 0-15 as a result.

Now we have the random number in GPRM0, and GPRM2 is tracking the number of stories played (so far, none have, so it should be at 0 too). We can now set up the possible operations to take place. The idea here is to create 16 versions of the same thing, so we can simply repeat blocks of code and change the numbers each time.

In order to check to see if the story has already played back we have to first see what value is held in the bit slot. It should be a zero if the story hasn’t played yet, and a ‘1’ if it has. However, in order for this script to work we need to copy the value into a temporary location, otherwise we could break the script. We copy it to GPRM1:

mov GPRM1, Story1Play
Jump Story1 If(GPRM1 = 0)

These two lines move the value into GPRM1, then jump to the story *only* if that value is zero. If it is not zero, the story must already have played (because the pre-script will have changed the value to a 1) and so the jump to the story will not take place. If that’s the case, we need to make a new random number:

goto 1

OK, so far, so good. We now need to repeat that over sixteen times, and then add in the correct number of ‘goto’ commands so that when the script runs from the top, if the random number is 14, you go to the 14th section and do that bit, skipping over all of the other possibilities. Don’t forget that each section is a repeat of the first one, but with the relevant number for the story and the bit slot. Putting all this together, the random script now looks like this:

Jump menu_out If (GPRM2 = 16)
ran GPRM0, 65535
mod GPRM0, 16
goto 20 If(GPRM0 = 0)
goto 23 If(GPRM0 = 1)
goto 26 If(GPRM0 = 2)
goto 29 If(GPRM0 = 3)
goto 32 If(GPRM0 = 4)
goto 35 If(GPRM0 = 5)
goto 38 If(GPRM0 = 6)
goto 41 If(GPRM0 = 7)
goto 44 If(GPRM0 = 8 )
goto 47 If(GPRM0 = 9)
goto 50 If(GPRM0 = 10)
goto 53 If(GPRM0 = 11)
goto 56 If(GPRM0 = 12)
goto 59 If(GPRM0 = 13)
goto 62 If(GPRM0 = 14)
goto 65 If(GPRM0 = 15)
mov GPRM1, Story1Play
Jump Story1 If(GPRM1 = 0)
goto 1
mov GPRM1, Story2Play
Jump Story2 If(GPRM1 = 0)
goto 1
mov GPRM1, Story3Play
Jump Story3 If(GPRM1 = 0)
goto 1
mov GPRM1, Story4Play
Jump Story4 If(GPRM1 = 0)
goto 1
mov GPRM1, Story5Play
Jump Story5 If(GPRM1 = 0)
goto 1
mov GPRM1, Story6Play
Jump Story6 If(GPRM1 = 0)
goto 1
mov GPRM1, Story7Play
Jump Story7 If(GPRM1 = 0)
goto 1
mov GPRM1, Story8Play
Jump Story8 If(GPRM1 = 0)
goto 1
mov GPRM1, Story9Play
Jump Story9 If(GPRM1 = 0)
goto 1
mov GPRM1, Story10Play
Jump Story10 If(GPRM1 = 0)
goto 1
mov GPRM1, Story11Play
Jump Story11 If(GPRM1 = 0)
goto 1
mov GPRM1, Story12Play
Jump Story12 If(GPRM1 = 0)
goto 1
mov GPRM1, Story13Play
Jump Story13 If(GPRM1 = 0)
goto 1
mov GPRM1, Story14Play
Jump Story14 If(GPRM1 = 0)
goto 1
mov GPRM1, Story15Play
Jump Story15 If(GPRM1 = 0)
goto 1
mov GPRM1, Story16Play
Jump Story16 If(GPRM1 = 0)
goto 1

Now, when you get to the ‘menu_out’ menu, the user needs to have an option to play it all over again or return to the main menu. You need to re-set ALL of the registers back to zero whatever happens. If you don’t, then the playback will fail because all of the bit slots will hold a ‘1’ and so nothing will play.

You can either do this as a pre-script to the menu, or a better way (in my opinion) would be to set the ‘play it again’ button to go to a script which clears all registers (all sixteen bit slots in the register you partitioned, GPRM0, 1 and 2) and then goes on to the randomiser script.

The end jump of the stories needs to point to the randomiser script as well, otherwise when the story has played back another won’t follow on. The menu call and title call can go to a menu as normal, except you need to think about why a user would have opted out of the playback. You can either place a ‘resume’ button on the menu they land on or you can exit the random playback by again going to the script to re-set the registers and on to another destination. The resume feature will return you to the track with the stories in, and *should* continue where you left off – all register values will be intact, so it should still work. The only question I have about that is whether the resume will put you back in a story or not. If you are not in a story then you could end up simply moving through the track in sequence. That’ll need to be tested to see what happens… I’ve not done that bit yet!

So there you are – random playback of 16 stories, with no repeats.

There are other ways to do this too – but this seems to be an easy way to visualise what needs to happen. I’ll add this project to my .mac space when I get a chance and link to it from here as well.

Happy scripting!

Ultraversity nominated for ICT Innovators award.

Who’d have thought it… after Matt had spent so long writing the application, we were shortlisted for this award for our work with the Ultraversity degree course, a new take on learning and technology.

The funny thing is that I am the one who will be going along to it – black tie and all!

Read more about it on Matt’s blog.

I’ll let you know how it goes after Thursday… it’s being held at the Grosvenor House Hotel in Park Lane, London. Let’s hope they have some decent parking facilities…What are the chances of that?

Replacing your iPod battery, how to get the case off an iPod, open iPod 3G

All things come to pass – and this weekend it was the passing of my original iPod battery. I’ve been using the iPod pretty constantly for a couple of years now, most recently in my car. Whilst the Alpine KC420i does in fact charge the iPod I have been noticing that the iPod isn’t charging too well, and on occasion the car head unit tells me there is no CD changer attached. Of course, CD changer means iPod in my set-up!

On further inspection I found that the iPod was able to charge, and did in fact reach a full charge after about four hours constant charging. It didn’t stay charged very long though, draining in about an hour or so when playing back.

So, I figured it was about time for a replacement battery and so I bought one from iPodworld.co.uk. It was a little more expensive from them compared to other places, but it did include some tools to help open the case up.

Looking at the iPod case it is hard to see how it all fits together. However, the tools supplied were excellent. Shaped a bit like flat headed screwdrivers with a bend in the end of them, the nylon tools are designed to help you prise open a side of the case and carefully release the catches therein. The instruction book that comes with the battery is small, so expect to get your magnifying glass out to read it. The content of the book is superb mind you and the details are very precise. I liked it so much I have got the .pdf version here! This is somewhat easier to read, and the pics are in colour.

Easing the tools into the crack along one side of the iPod is a bit tricky at first. I chose to get the angled tip of the tool pointing downwards into the silver back of the ipod. This seemed to be the easiest way in, at which point I slid the tool along the length of the iPod, looking for any of the clips holding it together. I then used the other tool the other way up to firmly but very carefully push inwards and lever the front white case off along the side. This was a lot easier than I had anticipated and the side came away fairly quickly, although I was quite surprised at how much force was needed – you don’t need much, but you do need to be firm.

Once one side was released the other edges came away easily. Aware of the ribbon cable connector attaching the two halves together I worked on a flat surface from then on.

The hard drive inside the unit is attached by means of a flat connector. Imagine two flat surfaces joined together by a connector between them – this is how the iPod drive gets fitted to the logic board. Removing this is a little worrying, since there is only a flat copper coloured piece of material indicating where anything is joined. Fortunately for me there was a small rectangle which looked a different colour and so I used the nylon tools to gently lift the connector ribbon and the connector itself just popped out.

Moving the hard drive to one side the battery is then revealed. There is a three pin connector which needs taking off first – this is a bit tricky unless you have got fingernails (I don’t) or tweezers (also, none available). So for me it was a case of looking carefully at the connector and seeing that it was only the top of it I had to hold on to when I pulled. Again, the force required was more than I had anticipated, but if you are looking for some pliers in order to get a better grip then you are trying too hard. Once released the battery could be lifted and then twisted around in order to free the cables which were underneath the logic board edge.

In good old fashioned Haynes manual traditions, reassembly is the reverse of removal. Carefully tuck the new battery wires under the same edge of the logic board as the original and lay the battery itself into the space for it. Re-fit the hard drive… for me there was a small click as the connector joined the logic board again. I was a bit sceptical that I had it all lined up correctly at first, but it went in easily when I had it in the right place.

The last part is to replace the cover – be very sure that the new battery wires are not sticking out at all as you will easily pinch them and damage it if they are. The front cover just snaps on to the base and that’s all there is to it.

Other things to watch out for are really to be very careful of the connector between the front and back of the iPod – this looks very fragile and you don’t want to be playing around with it – don’t try to remove it!

Once back together, cycle the power on the iPod (you know, flick the ‘Hold’ switch across and back then hold the play/pause and menu buttons for about 6 seconds), then put it on to charge. The new battery came with about a quarter charge on it, so now it is in the adaptor getting a full top up.

I reckon that I will fully charge and then fully discharge this battery before I then start the usual abuse of partial charges and discharges that it will receive for the rest of its life.

Replacing an iPod battery is not as scary as you might think. This one cost me ��18.99, but the cost for a service to do it for me would be nearer ��50 all told. I’m happy that I saved ��30 and would feel pretty confident to change an iPod battery in the future.

Thanks to iPod World for the supply of decent instructions and good tools to help make the job easy – and scratch free!

Bruce the Wonder Yak, Final Cut Pro, Easter Egg

Oh yes – he does exist in Final Cut Pro 4 and 5! If you have no idea what I am going on about here, run a few intenet searches for ‘Bruce the Yak’ or ‘Easter Egg in Final Cut Pro’. The guy’s a legend!

I am not going to tell you how to get him in v4 or 5. In an earlier version you have to invoke the tools window and click find a certain spot to control+click in, and ‘Call the Yak’ would appear as an option. Nowadays it’s a tad harder, but suffice to say it isn’t in the tools window – and it isn’t about control+clicking anything.

There could be a custom button for it, though… 😉

(Many, many thanks to Michael Conniff for pointing the way here.)

Creating a quiz on a DVD

Over the weekend I was checking in on the Apple forums for DVD Studio Pro when a particular question caught my eye. The gist of it is that the poster wanted to create a quiz on a DVD where the questions were drawn at random. Easy enough, I hear you say… until we got into doing it and then it turned into a ‘random, but no repeats, please’ situation.

I decided to try to build a short project which did this with just five arbitrary questions. Using DVDSP v4 made things a bit easier since I could manually partition the memory register. I chose to use a very verbose scripting method which repeated sections of code.

In essence, the script first of all added 1 to the first register (I needed to count to five to make sure only five questions were asked) and then generated a random number (using 65,355 then modulo with a value of 5). Next it jumped to various lines depending on what the final random number was.

From there, within each section, I jumped on to the actual question *if* there was no value in the partitioned register which corresponded with that question. If there was a value there it meant the question had already been asked and so it went back to generate a new random number. If there wasn’t a value there I put one in place and then jumped to the question. Cunning, huh? 🙂

Keeping track of the score was easy – I simply had to see if the first register had been filled with a value of five. If it had I needed to jump to the exit screen, where I set up a button to clear all the registers and start again.

This was all pretty good to do, and as a proof of concept worked fine. However, with a lot of questions to ask (say, 50 or more) I would need to re-think the process – for two reasons:

1) first the questions were set into menu tiles, and whilst it is unlikely, it is possible to run out of space in the menu domain, which is limited to 1GB in DVDSP.
2) the scripting in sections would be far too long and unwieldy if there were many more questions to deal with. Also the regeneration of a new random number when a repeat was found could take a long time when you get to the end of a 50 question quiz. It would be better to use a system which generated a number and then altered it (by subtracting or adding ‘1’) until a unique number was arrived at. This would save a lot of time and re-iteration of the script.

The major problem with 2) is that when the random number generated is zero (as can happen with a mod command) you can still subtract ‘1’ from it, and end up with 65535 – which to all intents and purposes is an ‘illegal’ value for the script. It would need to add or subtract within a defined range for this to work securely every time.

Finally, a quiz needs a score. This is something I didn’t build in because I ran out of time. Since I have only used three registers it would be easy enough to do, but again there are things to consider. For example, would you only score a point if you got the answer right first time? The way I set this up was to give the user a repeating chance any time they were wrong. Eventually they would get it right (by process of elimination, if not dawning realisation), and then they could still score top marks… which would be a little misleading to say the least!

Anyway, if you want to have a look at the project file and scripting – or if you just want to play the quiz in your computer’s DVD player, click here to download.

Have fun with it, and remember it was written in a simplistic way – I am always happy to hear of better, shorter methods to do things, of course.