Permalink
Browse files

updates for Duration sending o/c messages

  • Loading branch information...
1 parent f53208d commit 28d48c59aa40173b80da7088c441835cf9406bb7 @obviousjim obviousjim committed Aug 11, 2012
View
@@ -4,20 +4,28 @@
ofxTLBangs::ofxTLBangs(){
lastTimelinePoint = 0;
+ isPlayingBack = false;
}
ofxTLBangs::~ofxTLBangs(){
-
+ disable();
}
void ofxTLBangs::enable(){
- ofxTLKeyframer::enable();
- events().registerPlaybackEvents(this);
+ if(!isEnabled()){
+ ofxTLKeyframer::enable();
+ events().registerPlaybackEvents(this);
+ }
}
void ofxTLBangs::disable(){
- ofxTLKeyframer::disable();
- events().removePlaybackEvents(this);
+ if(isEnabled()){
+ if (isPlayingBack) {
+ ofRemoveListener(ofEvents().update, this, &ofxTLBangs::update);
+ }
+ ofxTLKeyframer::disable();
+ events().removePlaybackEvents(this);
+ }
}
void ofxTLBangs::draw(){
@@ -93,6 +101,7 @@ void ofxTLBangs::bangFired(ofxTLKeyframe* key){
ofxTLBangEventArgs args;
args.sender = timeline;
args.track = this;
+ args.currentMillis = timeline->getCurrentTimeMillis();
args.currentPercent = timeline->getPercentComplete();
args.currentFrame = timeline->getCurrentFrame();
args.currentTime = timeline->getCurrentTime();
@@ -102,10 +111,12 @@ void ofxTLBangs::bangFired(ofxTLKeyframe* key){
void ofxTLBangs::playbackStarted(ofxTLPlaybackEventArgs& args){
lastTimelinePoint = timeline->getCurrentTimeMillis();
ofAddListener(ofEvents().update, this, &ofxTLBangs::update);
+ isPlayingBack = true;
}
void ofxTLBangs::playbackEnded(ofxTLPlaybackEventArgs& args){
ofRemoveListener(ofEvents().update, this, &ofxTLBangs::update);
+ isPlayingBack = true;
}
void ofxTLBangs::playbackLooped(ofxTLPlaybackEventArgs& args){
View
@@ -27,6 +27,7 @@ class ofxTLBangs : public ofxTLKeyframer {
protected:
virtual ofxTLKeyframe* keyframeAtScreenpoint(ofVec2f p, int& selectedIndex);
+ bool isPlayingBack;
void update(ofEventArgs& args);
long lastTimelinePoint;
View
@@ -70,6 +70,7 @@ class ofxTLBangEventArgs : public ofEventArgs {
float currentPercent;
float currentTime;
int currentFrame;
+ long currentMillis;
string flag;
};
View
@@ -188,6 +188,7 @@ void ofxTLFlags::bangFired(ofxTLKeyframe* key){
ofxTLBangEventArgs args;
args.sender = timeline;
args.track = this;
+ args.currentMillis = timeline->getCurrentTimeMillis();
args.currentPercent = timeline->getPercentComplete();
args.currentFrame = timeline->getCurrentFrame();
args.currentTime = timeline->getCurrentTime();
View
@@ -73,12 +73,13 @@ ofxTLPage::~ofxTLPage(){
#pragma mark utility
void ofxTLPage::setup(){
-
- ofAddListener(timeline->events().zoomEnded, this, &ofxTLPage::zoomEnded);
- isSetup = true;
- headerHeight = 12;
- defaultTrackHeight = 30;
- loadTrackPositions(); //name must be set
+ if(!isSetup){
+ isSetup = true;
+ headerHeight = 12;
+ defaultTrackHeight = 30;
+ loadTrackPositions(); //name must be set
+ ofAddListener(timeline->events().zoomEnded, this, &ofxTLPage::zoomEnded);
+ }
}
//given a folder the page will look for xml files to load within that
View
@@ -92,8 +92,7 @@ void ofxTLSwitcher::draw(){
}
-bool ofxTLSwitcher::isOn(float percent){
- unsigned long millis = percent*timeline->getDurationInMilliseconds();
+bool ofxTLSwitcher::isOnAtMillis(long millis){
for(int i = 0; i < keyframes.size(); i++){
ofxTLSwitch* switchKey = (ofxTLSwitch*)keyframes[i];
if(switchKey->timeRange.min > millis){
@@ -103,7 +102,12 @@ bool ofxTLSwitcher::isOn(float percent){
return true;
}
}
- return false;
+ return false;
+}
+
+bool ofxTLSwitcher::isOnAtPercent(float percent){
+ unsigned long millis = percent*timeline->getDurationInMilliseconds();
+ return isOnAtMillis(millis);
}
void ofxTLSwitcher::mousePressed(ofMouseEventArgs& args, long millis){
@@ -319,5 +323,5 @@ ofxTLKeyframe* ofxTLSwitcher::keyframeAtScreenpoint(ofVec2f p, int& selectedInde
}
string ofxTLSwitcher::getTrackType(){
- return "Swtiches";
+ return "Switches";
}
View
@@ -54,8 +54,9 @@ class ofxTLSwitcher : public ofxTLKeyframer {
virtual ~ofxTLSwitcher();
virtual void draw();
-
- virtual bool isOn(float percent);
+
+ virtual bool isOnAtMillis(long millis);
+ virtual bool isOnAtPercent(float percent);
virtual void mousePressed(ofMouseEventArgs& args, long millis);
virtual void mouseDragged(ofMouseEventArgs& args, long millis);
View
@@ -37,17 +37,13 @@
ofxTLTicker::ofxTLTicker() {
dragging = false;
+ hasBPM = false;
+ drawBPMGrid = false;
}
ofxTLTicker::~ofxTLTicker(){
}
-void ofxTLTicker::setup(){
- enable();
- hasBPM = false;
- drawBPMGrid = false;
-}
-
void ofxTLTicker::draw(){
ofPushStyle();
View
@@ -49,7 +49,6 @@ class ofxTLTicker : public ofxTLTrack
ofxTLTicker();
~ofxTLTicker();
- virtual void setup();
virtual void draw();
//set the draw rect for the whole keyframer interface
View
@@ -50,7 +50,9 @@ ofxTLTrack::ofxTLTrack()
}
ofxTLTrack::~ofxTLTrack(){
- disable();
+ if(isEnabled()){
+ disable();
+ }
}
void ofxTLTrack::setup(){
View
@@ -24,13 +24,17 @@ void ofxTLTweener::setValueRange(ofRange range, float newDefaultValue){
defaultValue = newDefaultValue;
}
+ofRange ofxTLTweener::getValueRange(){
+ return valueRange;
+}
+
//main function to get values out of the timeline, operates on the given value range
float ofxTLTweener::getValueAtPercent(float percent){
// return ofMap(sampleAt(percent), 0.0, 1.0, valueRange.min, valueRange.max, false);
- return getValueAtTime(percent*timeline->getDurationInMilliseconds());
+ return getValueAtTimeInMillis(percent*timeline->getDurationInMilliseconds());
}
-float ofxTLTweener::getValueAtTime(long sampleTime){
+float ofxTLTweener::getValueAtTimeInMillis(long sampleTime){
return ofMap(sampleAtTime(sampleTime), 0.0, 1.0, valueRange.min, valueRange.max, false);
}
View
@@ -42,10 +42,12 @@ class ofxTLTweener : public ofxTLKeyframer {
virtual void mouseDragged(ofMouseEventArgs& args, long millis);
virtual void setValueRange(ofRange range, float defaultValue = 0);
+ virtual ofRange getValueRange();
+
//main function to get values out of the timeline, operates on the given value range
virtual float getValueAtPercent(float percent);
- virtual float getValueAtTime(long sampleTime);
-
+ virtual float getValueAtTimeInMillis(long sampleTime);
+
virtual string getTrackType();
protected:
View
@@ -39,7 +39,7 @@ void ofxTLVideoTrack::enable(){
void ofxTLVideoTrack::disable(){
stop();
- ofxTLImageTrack::enable();
+ ofxTLImageTrack::disable();
ofRemoveListener(ofEvents().update, this, &ofxTLVideoTrack::update);
ofRemoveListener(events().playheadScrubbed, this, &ofxTLVideoTrack::playheadScrubbed);
}
View
@@ -503,6 +503,7 @@ void ofxTimeline::clear(){
}
void ofxTimeline::reset(){ //gets rid of everything
+ stop();
for(int i = 0; i < pages.size(); i++){
delete pages[i];
}
@@ -542,7 +543,13 @@ void ofxTimeline::setDurationInMillis(long millis){
}
void ofxTimeline::setDurationInTimecode(string timecodeString){
- durationInSeconds = timecode.secondsForTimecode(timecodeString);
+ float newDuration = timecode.secondsForTimecode(timecodeString);
+ if(newDuration > 0){
+ durationInSeconds = newDuration;
+ }
+ else{
+ ofLogError() << "ofxTimeline::setDurationInTimecode -- " << timecodeString << " is invalid, please use the format HH:MM:SS:MLS";
+ }
}
int ofxTimeline::getDurationInFrames(){
@@ -1106,7 +1113,7 @@ bool ofxTimeline::getSwitcherOn(string trackName, float atTime){
ofLogError("ofxTimeline -- Couldn't find switcher track " + trackName);
return false;
}
- return switcher->isOn(atTime/durationInSeconds);
+ return switcher->isOnAtPercent(atTime/durationInSeconds);
}
bool ofxTimeline::getSwitcherOn(string trackName){

0 comments on commit 28d48c5

Please sign in to comment.