/*

	This file is part of "Interface Fractures III - Silicon".
	Copyright (c) 2015 Luka Prinčič, All rights reserved.
	This program is free software distributed under
	GNU General Public Licence. See COPYING for more info.
	- - - - - - - - - - - - - - - - - - - - - - - - - - - -

  playVideo.pde
    
                                                                             */

void playVideo( boolean render, // should we render or not?
                boolean pausePlay, boolean loop,
                int bank, int id,
                int hue, int saturation, int brightness, int alpha, int jump, int speed
                )
{
  if (render) {

    // protect boundaries of vidPool array
    bank = min(bank, vidPool.length - 1);
    id = min(id, vidPool[bank].length - 1);

    // play/pause/loop
    if(pausePlay == true) {
        vidPool[bank][id].speed(float(speed) / 100);
        //println("speed: " + speed + " " + (float(speed) /  100));
        if (loop == true) {
            vidPool[bank][id].loop();
        } else {
            vidPool[bank][id].play();
        }
    }

    if(pausePlay == false) {
        vidPool[bank][id].pause();
    }


    if (jump != 1000) {
        println("jump: " + jump);
        vidPool[bank][id].jump(vidPool[bank][id].duration() * (float(jump) / 100));
        //vidPool[bank][id].read();
    }


    if (vidPool[bank][id].available()) {
        vidPool[bank][id].read();
    }


    // use/display/texture
    textureMode(NORMAL);
    colorMode(HSB, 127);
    
    beginShape();
    tint(hue, saturation, brightness, alpha);
    texture(vidPool[bank][id]);
    vertex(-3, -3, 1, 1);
    vertex(width+3, -3, 0, 1);
    vertex(width+3, height+3, 0, 0);
    vertex(-3, height+3, 1, 0);
    endShape();

  }
}



void jumpVideo(float position, int bank, int id) {

    // protect boundaries of vidPool array
    bank = min(bank, vidPool.length - 1);
    id = min(id, vidPool[bank].length - 1);

    // jump to position in the video maped from 0-127
    vidPool[bank][id].jump(map(position, 0, 127, 0, vidPool[bank][id].duration()));
    //vidPool[bank][id].read();
}





