Skip to content

Instantly share code, notes, and snippets.

@antimodular
Created November 6, 2018 01:05
Show Gist options
  • Save antimodular/0ab4cde706da4f0b440fae37bf2631eb to your computer and use it in GitHub Desktop.
Save antimodular/0ab4cde706da4f0b440fae37bf2631eb to your computer and use it in GitHub Desktop.
#include "ofApp.h"
int SIDE_WIDTH;
int SIDE_HEIGHT;
static int64_t prev_frame = 0;
static int64_t cur_frame = 0;
static uint8_t offset = 1;
//--------------------------------------------------------------
void ofApp::setup()
{
HPV::InitHPVEngine();
dir.allowExt("hpv");
dir.listDir("videos");
ofLog()<<"dir.size() "<<dir.size();
videos.resize(dir.size());
for(int i=0; i<videos.size()-1; i++){
videos[i].init(HPV::NewPlayer());
// videos[i].loadAsync(dir.getPath(i));
videos[i].load(dir.getPath(i));
videos[i].setLoopState(OF_LOOP_NORMAL);
}
for(int i=0; i<videos.size(); i++){
videos[i].play();
videos[i].setPaused(true);
}
ofSetVerticalSync(false);
ofSetFrameRate(25);
SIDE_WIDTH = ofGetWidth() / 2;
SIDE_HEIGHT = ofGetHeight() / 2;
}
//--------------------------------------------------------------
void ofApp::update()
{
ofSetWindowTitle(ofToString(ofGetFrameRate()));
// if (cur_frame != prev_frame)
// {
for(int i=0; i<videos.size(); i++){
videos[i].nextFrame();
}
// prev_frame = cur_frame;
// }
// cur_frame++;
//
// if (cur_frame >= videos.getTotalNumFrames())
// {
// cur_frame = 0;
// }
//
HPV::Update();
}
//--------------------------------------------------------------
void ofApp::draw()
{
ofBackground(255);
int x = 0;
int y = 0;
int w = 64;
int h = 48;
for(int i=0; i<videos.size(); i++){
videos[i].draw(x, y, w, h);
x+=w;
if(x > ofGetWidth()){
x = 0;
y+=h;
}
}
// ofDrawBitmapString(ofToString(top_left.getCurrentFrame()), SIDE_WIDTH-30, SIDE_HEIGHT-10);
ofDrawBitmapStringHighlight("Press 'g' to toggle grid mode, showing each video's individual frame", 50, 50);
}
//--------------------------------------------------------------
void ofApp::exit()
{
HPV::DestroyHPVEngine();
}
//--------------------------------------------------------------
void ofApp::keyPressed(int key)
{
if (key == 'a')
{
cur_frame++;
}
else if (key == 'p')
{
for(int i=0; i<videos.size(); i++){
videos[i].setPaused(true);
}
}
else if (key == 'f')
{
ofToggleFullscreen();
}
else if (key == 'g')
{
(offset > 0) ? (offset = 0) : (offset = 1);
}
}
//--------------------------------------------------------------
void ofApp::windowResized(int w, int h){
SIDE_WIDTH = ofGetWidth() / 2;
SIDE_HEIGHT = ofGetHeight() / 2;
}
#pragma once
#include "ofMain.h"
#include "ofxHPVPlayer.h"
class ofApp : public ofBaseApp
{
public:
void setup();
void update();
void draw();
void exit();
void keyPressed(int key);
void windowResized(int w, int h);
vector<ofxHPVPlayer> videos;
ofDirectory dir;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment