openFrame Code/ Instructable

#include “testApp.h”

 

//————————————————————–

void testApp::setup()

{

serial.setup(“/dev/tty.usbserial-FTFMV6XM”,9600); //to define the serial connection

 

ofBackground(255,255,255); //to define the background (white)

currentVideo = 0; //0. //to play the video when the program starts working

    

for(int i = 0; i<7; i++)

{

movies[i] = new ofVideoPlayer(); // to define the number of movies (7)

}

movies[0]->loadMovie(“movies/oto.mp4”);

movies[0]->stop();

 

movies[1]->loadMovie(“movies/gida.mp4”);

movies[1]->stop();

 

movies[2]->loadMovie(“movies/seks.mp4”);

movies[2]->stop();

 

movies[3]->loadMovie(“movies/aile.mp4”);

movies[3]->stop();

 

movies[4]->loadMovie(“movies/cocuk.mp4”);

movies[4]->stop();

 

movies[5]->loadMovie(“movies/kirmizi.mp4”);

movies[5]->stop();

 

movies[6]->loadMovie(“movies/animasyon.mp4”);

movies[6]->stop();

 

movies[currentVideo]->play();

randomSecond = int(ofRandom(0,int(movies[currentVideo]->getDuration()/10)))*10; //to generate a random number that is a multiple of 10

movies[currentVideo]->setPosition(randomSecond*movies[currentVideo]->getDuration());  //to go to the random second that is generated randomly

volume = 100;

}

 

//————————————————————–

void testApp::update()

{

movies[currentVideo]->idleMovie();

data = serial.readByte(); //to read the data sent from the remote control

 

if(data != -2) //-2 //if not

{

if(data != 10 && data != 13) //if the information sent is not a new line

command = command+char(data); //add the character

}

else if(command != “”)

{

int commandInt = atoi(command.c_str()); //convert to number – ascii to integer

ofLogWarning() << commandInt;

if(commandInt >= 1 && commandInt <= 7)

{

movies[currentVideo]->stop();

currentVideo = commandInt-1;

 

randomSecond = int(ofRandom(0,int(movies[currentVideo]->getDuration()/10)))*10;

movies[currentVideo]->setPosition(randomSecond*movies[currentVideo]->getDuration());

movies[currentVideo]->play();

 

}

else if(commandInt == 16) //decrease volume

{

if(volume > 0)

{

volume -= 5;

}

 

movies[currentVideo]->setVolume(volume);

 

}

else if(commandInt == 17) //increase volume

{

if(volume < 100)

{

volume += 5;

}

 

movies[currentVideo]->setVolume(volume);

}

else if(commandInt == 12)

{

 

 

}

 

command = “”;

}

 

}

 

//————————————————————–

void testApp::draw()

{

ofSetHexColor(0xFFFFFF);

movies[currentVideo]->draw(0,0,1024,768);

 

if(int(movies[currentVideo]->getPosition()*movies[currentVideo]->getDuration()*100)%1000 > 990)// if it is 9, 19, 29… point a number go to the other random number that is a multiple of 10

{

randomSecond = int(ofRandom(0,int(movies[currentVideo]->getDuration()/10)))*10;

movies[currentVideo]->setPosition(randomSecond/movies[currentVideo]->getDuration());

}

 

if(movies[currentVideo]->getIsMovieDone())

{

randomSecond = int(ofRandom(0,int(movies[currentVideo]->getDuration()/10)))*10;

movies[currentVideo]->setPosition(randomSecond/movies[currentVideo]->getDuration());

}

}

Leave a Reply