Squeak Class Documentation category index | class index  
 
MoviePlayerMorph
  category: Morphic-Demo
  superclass: BookMorph
  subclasses:

MoviePlayerMorph plays images from a file using async io. The file format is simple but non-standard (see below).

The heart of the play logic is in the step method. Note that play is driven by a simulated time since start. For a movie with a sound score, this is the millisecondsSinceStart of the score player, whereas a movie by itself gets this from the millisecondClock minus msAtStart.

Movie players are designed to be used in three ways
1. Select a movie in the file list, 'open as movie', and play it.
2. As in (1), but drop thumbnails for various frames into a
MIDI piano roll to synchronize video with music.
3. Open a MoviePlayerMorph as a 'new morph', and choose
'make a new movie' from the menu.

In (1) and (2), a shift-drag is used to 'tear off' a thumbnail reference morph to the currently visible frame of this clips. The thumbnail can then be dropped in a MIDI score player to either syncronize that frame with what point in the music, or to cause that clip to being playing in the shared player of a SqueakMovie plex.

When making a new movie, an empty score and piano roll are linked to the movie player, as a SqueakMovie plex. You can then open another movie as a clip, and drop a thumbnail morph into the score to start that clip playing at that frame in the shared player. If you pause while playing that clip, you can manually play the clip forward and backward in the current clip. if you stop at a given frame, you can choose 'end clip here' from the shared player menu to shorten or lengthen the clip.

Clips can be moved by picking up the starting thumbnail (use halo black handle), and dropping them elsewhere. If you try to place one clip in the middle of another, it will slide to the end. If you position one clip close to the end of another, it will sidle up to make them contiguous.

If you wish a soundtrack to be included with a clip, make sure it has been opened in the source clip player before tearing off the starting thumbnail.

About the .movie file format...
The following code was used to convert 27 files into a movie. They were named
'BalloonDrop10fps003.bmp' through 'BalloonDrop10fps081.bmp'
incrementing by 003. Each was known to be a 320x240 image in 32-bit BMP format.
Note the 27 in the 5th line is the number of frames, = (3 to: 81 by: 3) size.

| ps zps f32 out ff |
out _ FileStream newFileNamed: 'BalloonDrop10fps.movie'.
out binary.
ff _ Form extent: 320@240 depth: 16.
#(22 320 240 16 27 100000) , (7 to: 32)
do: [:i | out nextInt32Put: i].

3 to: 81 by: 3 do:
[:i | ps _ i printString. zps _ ps padded: #left to: 3 with: $0.
f32 _ Form fromFileNamed:
'BalloonDrop10fps' , zps , '.bmp'.
f32 displayOn: ff at: 0@0. "Convert down to 16 bits"
ff display; writeOnMovie: out].
out close.

instance methods
  access
  cueMorph
fileName
frameCount
frameNumber:
frameNumber:msSinceStart:
msPerFrame
msPerFrame:
pageFormForFrame:
relativePosition
scorePlayer
scorePlayer:
setCueMorph:
soundTrackFileName

  controls and layout
  extent:
fullControlSpecs
insertPage
showHideSoundTrack
showPageControls
showPageControls:

  events
  handlesMouseDown:
mouseDown:

  initialization
  duplicate
duplicateMore
openFileNamed:
openFileNamed:withScorePlayer:andPlayFrom:
position:
setInitialState
stopSoundTrackIfAny
wantsRoundedCorners

  menu
  addSoundTrack
endClipHere
invokeBookMenu
makeAMovie
openMovieFile
scanBySlider
thumbnailForThisPage

  movie clip player
  pianoRoll
pianoRoll:

  player control
  firstPage
goToPage:
goToRelativePosition:
lastPage
nextPage
playForward
playReverse
previousPage
stopPlay

  private
  makeMyPage
makeThumbnailInHand:
pvtOpenFileNamed:
tryToShareScoreFor:

  score events
  pauseFrom:
resetFrom:
resumeFrom:

  stepping
  fileByteCountPerFrame
filePosForFrameNo:
startRunning
step
stepSoundTrack
stepTime
stopRunning

class methods
  no messages
 

instance methods
  access top  
 

cueMorph


 

fileName


 

frameCount


 

frameNumber:


 

frameNumber:msSinceStart:

Set the current frame number, and save the scorePlayer's simulated time for synchronization.


 

msPerFrame


 

msPerFrame:

Set a new frame rate, base on, eg, score synchronization info.


 

pageFormForFrame:


 

relativePosition


 

scorePlayer


 

scorePlayer:


 

setCueMorph:


 

soundTrackFileName


  controls and layout top  
 

extent:


 

fullControlSpecs

Note extra spec 'menu' causes mousedown activation -- see makePageControlsFrom:


 

insertPage


 

showHideSoundTrack


 

showPageControls


 

showPageControls:


  events top  
 

handlesMouseDown:

We use shift drag to 'tear off' a thumbnail


 

mouseDown:

We use shift drag to 'tear off' a thumbnail


  initialization top  
 

duplicate

Make and return a duplicate of the receiver


 

duplicateMore

Duplicate dies not replicate Forms, but MoviePlayers need this.


 

openFileNamed:


 

openFileNamed:withScorePlayer:andPlayFrom:

Note: The plan is that the score player (a SampledSound) is already spaced
forward to this frame number so it does not need to be reset as would normally
happen in startRunning.


 

position:

Change the position of this morph and and all of its submorphs.


 

setInitialState


 

stopSoundTrackIfAny


 

wantsRoundedCorners

Default response is simple, fast, and false.
May be overridden to allow almost any morph to be rounded.


  menu top  
 

addSoundTrack


 

endClipHere

Change set the termination time for this clip via the endMorph


 

invokeBookMenu

Invoke the book's control panel menu.


 

makeAMovie


 

openMovieFile


 

scanBySlider


 

thumbnailForThisPage

Overridden to make a MovieFrameSyncMorph


  movie clip player top  
 

pianoRoll


 

pianoRoll:

Provides access also to the score and scorePlayer


  player control top  
 

firstPage


 

goToPage:


 

goToRelativePosition:


 

lastPage


 

nextPage


 

playForward


 

playReverse


 

previousPage


 

stopPlay


  private top  
 

makeMyPage


 

makeThumbnailInHand:


 

pvtOpenFileNamed:

Private - open on the movie file iof the given name


 

tryToShareScoreFor:


  score events top  
 

pauseFrom:

subclasses should take five


 

resetFrom:

subclasses should revert to their initial state


 

resumeFrom:

subclasses should continue from their current position


  stepping top  
 

fileByteCountPerFrame


 

filePosForFrameNo:


 

startRunning


 

step

NOTE: The movie player has two modes of play, depending on whether scorePlayer is nil or not. If scorePlayer is nil, then play runs according to the millisecond clock. If scorePlayer is not nil, then the scorePlayer is consulted for synchronization. If the movie is running ahead, then some calls on step will skip their action until the right time. If the movie is running behind, then the frame may advance by more than one to maintain synchronization.


 

stepSoundTrack


 

stepTime

Answer the desired time between steps in milliseconds. This default implementation requests that the 'step' method be called once every second.


 

stopRunning

Must only be called with no outstanding file read requests...


class methods
  no messages top