Storyboarder

From Deptford.TV

Jump to: navigation, search

There are 2 files sofar:

storyboard1.php (there is the beginning of some css stuff so some things are superflous, sorry)

<?php
require_once('storyboard_classes.php');

/*

//some settings for the css layout

//initial indent: you may change this to change the borders of your collage
$initialindent=30;
//width of each cell: you may change this to generate larger pictures in the collage
$cellwidth=200;
//cells per row: change this to generate more or less colunms of pictures
$cellsPerRow=4;
//height of each cell. fixed in this case.
$cellheight = 100;


i think that startsource is 0 if not a clip.
so need to show that in the edit list, but without a  note




//create an array of variables that hold the current height of each column, set initially to indent a little
$heights = array_fill(0,  $cellsPerRow, $initialindent);


$heights = array();



$cellcounter = 0;
*/
//load the xml file
$cinexml = simplexml_load_file('xml_versions/clips_2_edits_no_transitions.xml'
);

//make a new cliplist to hold teh clips
$clipList = new clipList();
foreach ($cinexml->CLIP_EDL as $clip_edl)
{
    //only one LOCALSESSION per clip_edl element (i think!) - this should not loop?
    $title = $clip_edl->LOCALSESSION['CLIP_TITLE'];
    $notes = $clip_edl->LOCALSESSION['CLIP_NOTES'];
              //calculate the clip length
              //strip out funny characters near the end... what do they mean?
    $sample_rate = $clip_edl->AUDIO['SAMPLERATE'];

      foreach($clip_edl->TRACK as $track)   {
          foreach($track->EDITS as $edits)      {
              foreach($edits->EDIT as $edit)         {
                  if (isset ($edit->FILE['SRC']))        {
                     // print $title;
                      //print $notes;
                     // print "<br>";
                          //create the clip objects now
                      $clip = new clip((string) $title, (string) $notes, (integer) $sample_rate);
                      $clip->setTrackInfo((string) $track['TYPE'], (string) $track->TITLE);
                      $clip->setEditInfo((integer) $edit['STARTSOURCE'], (integer)$edit['LENGTH'], (string) $edit->FILE['SRC']);
                      
                      
                      
                      $clipList->addClip($clip);
                      }
                   }
              }
             
          }
}

//there are also tracks outside of the clip_edi
//these are the ones for our storyboard, bu tneed to link back ot the cliplist to find the clip info
//print "<hr><hr>NOW tracks outside of clip_edl";
//print "<br>";
foreach($cinexml->TRACK as $track)   {
                                    
                              /*css generattion stuff:
                              
                              //find out what column we are in
                              $column = $cellcounter  % $cellsPerRow;
                               //calculate the number of pixels from the left the image should be placed at
                               $leftindent = $column*$cellwidth + $initialindent;
                               //calculate the number of pixels from the top the image should be placed at: wil be the value held in the hights array
                               $topindent = $heights[$column];
                              
                                 print "<div style=\"position:absolute; top:$topindent; left:$leftindent;\">";         
                             */
    
    
         print "<br>Track Type:  ". $track['TYPE']  . ", ";
          print  " Track Title: " . $track->TITLE . "<br>";
          foreach($track->EDITS as $edits)   {
              //set a counter to give clips a number:
              $i = 1;
                  foreach($edits->EDIT as $edit)   {
                       //in here, need to check the src and startsource against the cliplist to see if we //can get a corresponding title and note
                    
                    $length = (integer) $edit['LENGTH'];
                    //print" length: $length <br>";
                    if (isset ($edit->FILE['SRC']))  {
                      $src_file = (string) $edit->FILE['SRC'] ;
                        $startsource = (integer) $edit['STARTSOURCE'];
                      if ($matchingClip = $clipList->getClipInfo($src_file, $startsource, $length))  {
                            print "Clip $i Title:" . $matchingClip->getTitle() . "<br>";
                              print "Clip $i  Notes:  " . $matchingClip->getNotes() . "<br>";
                              print "Clip $i Duration:  " . $matchingClip->getDuration() . "<br>";
                              //add the image height to the relevant value in the heights array to update the height for this column
                             // $heights[$column] += $cellheight;
                              $i++;
                             // $cellcounter++;
                      }
                     }
                  }
              print "</div>"; 
          }      
                
 }





?>


storyboard_classes.php

<?php
class clip
{
    private $track_type;
    private $track_title;
    private $clipInfo;   //a clipinfo obj
    private $src_file;
    private $startpoint;  //frames from beginning of the asset chis clip starts
    private $frame_rate = 25;
    private $length;
    private $sample_rate;
    private $endpoint;  //frames from the beginning of the asset this clip ends
   
    function __construct($clip_title, $clip_notes, $sample_rate)  {
        $this->clipInfo = new clipInfo($clip_title, $clip_notes);
        $this->sample_rate = $sample_rate;
    }
    
    function setTrackInfo($track_type, $track_title)  {
        $this->track_type = $track_type;
        $this->track_title = $track_title;
    }
    
    function setEditInfo($startsource, $length, $src_file)   {
        $this->src_file = $src_file;
        $this->startpoint = $startsource;
        $this->length = $length;
        $this->endpoint = $this->startpoint + $this->length;
        //set the formatted duration in the clipInfo
        $this->clipInfo->setDuration($this->setDuration());
        
    }
    
    //if this is the clip that matches the  start and end of the timeline clip musstt be inside theie length of th clip
    function isSameClip($src_file, $startsource, $length)  {
        if ($src_file == $this->src_file && 
            $startsource >= $this->startpoint &&
                $startsource+$length <= $this->endpoint)  {
            return $this->clipInfo;
        }
        else  {
            return false;
        }
    }
    
    function getClipTitle()  {
        return $this->clip_title;
    }
    
    function getClipNotes()  {
        return $this->clip_notes;
    }
    
    function setDuration()  {
        if ($this->track_type == "VIDEO")  {
                return $this->formattedDuration($this->frame_rate, 'frames');
        }
          if ($this->track_type == "AUDIO")
             return $this->formattedDuration($this->sample_rate, 'samples');
        else return "unknown type";
    }
    
    private function formattedDuration($rate, $unit)  {
        //convert a number of frames into  hrs mins secs and frames according to framerrrate set
        $frames = $this->length % $rate;
        $totalsecs = (integer) $this->length / $rate;
        $secs = $totalsecs % 60;
        $totalmins = (integer) $secs / 60;
        $mins = $totalmins % 60;
        $hours = (integer) $totalmins / 60;

        $formattedString = "";
        if ($hours)
            $formattedString .= "$hours hrs:";
        if ($mins)
            $formattedString .= "$mins mins:";
        if (!$mins && $hours)
            $formattedString .= "00 mins";
        if ($secs)
            $formattedString .= "$secs secs";
        if (!$secs && $hours || $mins)
            $formattedString .= "00 secs:";
        if ($frames)
            $formattedString .= " $frames $unit";
        
        return $formattedString;
    }   
}

class ClipInfo
{
    private $notes;
    private $title;
       //make this the formatted string version
    private $duration;
    
    function __construct($title, $notes)    {
        $this->notes = $notes;
        $this->title = $title;
    }
    
    function setDuration($duration)  {
        $this->duration = $duration;
    }
    
    function getNotes()    {
        return $this->notes;
    }
    
    function getTitle()    {
        return $this->title;
    }
    
    function getDuration()    {
        return $this->duration;
    }
}

class clipList
{
    private $clips = array();
    
    function __construct()  {
    }
    
    function addClip($clip)   {
        $this->clips[] = $clip;
    }
    
    function getClips()   {
        return $this->clips;
    }
    
    function getClipInfo($src_file, $startsource, $length) {
        foreach ($this->clips as $clip)  {
            if($matchingClip = $clip->isSameClip($src_file, $startsource, $length))  {
                    return $matchingClip;
                    
               }
            }
            return false;
        }
  }

//this one doesn't work yet  
class durationFormatter
{
    private $formattedString;
    
    
    function __construct($length, $rate, $unit)   {
        
    //convert a number of frames into  hrs mins secs and frames according to framerrrate set
        $frames = $length % $rate;
        $totalsecs = (integer) $llength / $rate;
        $secs = $totalsecs % 60;
        $totalmins = (integer) $secs / 60;
        $mins = $totalmins % 60;
        $hours = (integer) $totalmins / 60;

        $formattedString = "";
        if ($hours)
            $formattedString .= "$hours hrs:";
        if ($mins)
            $formattedString .= "$mins mins:";
        if (!$mins && $hours)
            $formattedString .= "00 mins";
        if ($secs)
            $formattedString .= "$secs secs";
        if (!$secs && $hours || $mins)
            $formattedString .= "00 secs:";
        if ($frames)
            $formattedString .= " $frames $unit";
        
        $this->formattedString = $formattedString;    
    }
    
    function getFormattedString()   {
        return $this->formattedString;
    }
}
    
?>