Created
August 15, 2018 20:39
-
-
Save Hperigo/c635975c3a4fd7fbc62c782c99341f59 to your computer and use it in GitHub Desktop.
example app for how to get all the items in the timeline
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "cinder/app/App.h" | |
#include "cinder/app/RendererGl.h" | |
#include "cinder/gl/gl.h" | |
#include "cinder/Timeline.h" | |
#include "cinder/Rand.h" | |
using namespace ci; | |
using namespace ci::app; | |
using namespace std; | |
//typedef std::shared_ptr<class CustomTimeline> CustomTimelineRef; | |
//class CustomTimeline : public ci::Timeline{ | |
//public: | |
// | |
// std::multimap<void*, TimelineItemRef> getItems() { return mItems; } | |
//}; | |
class CustomTimelineApp : public App { | |
public: | |
void setup() override; | |
void mouseDrag( MouseEvent event ) override; | |
void keyUp ( KeyEvent event ) override; | |
void update() override; | |
void draw() override; | |
TimelineRef mSequencer; | |
Anim<float> mAnim; | |
ci::Color mCurrentColor { 0.8f, 0.9, 0.1 }; | |
bool up = true; | |
}; | |
void CustomTimelineApp::setup() | |
{ | |
mSequencer = Timeline::create(); | |
mSequencer->setInfinite(false); | |
} | |
void CustomTimelineApp::mouseDrag( MouseEvent event ) | |
{ | |
auto normX = float(event.getX()) / float(getWindowWidth() - 200); | |
mSequencer->stepTo( normX * mSequencer->getDuration()); | |
mSequencer->setLoop(true); | |
} | |
void CustomTimelineApp::keyUp(cinder::app::KeyEvent event){ | |
if( event.getChar() == ' ' ){ | |
if( up ){ | |
mSequencer->appendTo(&mAnim, 1.0f , Rand::randFloat(0.5, 2.0f)).delay(1.0f).autoRemove(false); | |
}else{ | |
mSequencer->appendTo(&mAnim, 0.0f , Rand::randFloat(0.5, 2.0f)).delay(1.0f).autoRemove(false); | |
} | |
up = !up; | |
}else{ | |
mSequencer->add([&]{ | |
static int i = 0; | |
console() << "cue!" << i << endl; | |
mCurrentColor = ColorT<float>(CM_HSV, randFloat(0, 1), 0.75, 0.75); | |
i++; | |
}, mSequencer->getCurrentTime() + 5)->setAutoRemove(false); | |
} | |
} | |
void CustomTimelineApp::update() | |
{ | |
mSequencer->step(1.f/60.f); | |
} | |
void CustomTimelineApp::draw() | |
{ | |
gl::clear( Color::gray(0.3) ); | |
// console() << "--------" << endl; | |
// console() << mSequencer->getCurrentTime() << endl; | |
// console() << mSequencer->getEndTime() << endl; | |
// | |
auto timeToWindow = [&] (float t) { | |
return ( t / mSequencer->getEndTime()) * (getWindowWidth() - 200); | |
}; | |
auto cursor = timeToWindow(mSequencer->getCurrentTime()); | |
gl::color(1.0, .7, 0.7); | |
gl::drawLine( { cursor, 0 }, {cursor, getWindowHeight() }); | |
int i = 0; | |
for(auto item : mSequencer->getItems() ){ | |
float xPos = timeToWindow( item.second->getStartTime() ); | |
float length = timeToWindow( item.second->getDuration() ); | |
float yPos = i * 10 + 10; | |
auto cue = dynamic_pointer_cast<Cue>( item.second ); | |
if( cue ){ | |
gl::drawSolidCircle( {xPos, yPos}, 5.0f); | |
}else{ | |
gl::drawSolidRect({ xPos, yPos, xPos + length, yPos + 10 }); | |
} | |
i++; | |
} | |
gl::color( mCurrentColor ); | |
gl::drawSolidCircle( getWindowCenter(), 100 * mAnim() ); | |
} | |
CINDER_APP( CustomTimelineApp, RendererGl ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment