Example #1
0
void ofxTLTicker::updateTimelinePosition(){
	if(timeline->getIsFrameBased()){
		timeline->setCurrentFrame(indexForScreenX(ofGetMouseX()));
	}
	else{
		timeline->setCurrentTime(timeForScreenX(ofGetMouseX()));
	}
	
}
Example #2
0
float ofxTLElement::timeForScreenX(float screenX){
	return timeForScreenX(screenX, timeline->getDurationInSeconds());
}
Example #3
0
void ofxTLTicker::updateTimelinePosition(){
	timeline->setCurrentTimeSeconds(timeForScreenX(ofGetMouseX()));
}
Example #4
0
void ofxTLTicker::draw(){
	
	ofPushStyle();
	
	int textH, textW;
	string text;
	if(timeline->getIsFrameBased()){
		
		int curStartFrame = ofMap(zoomBounds.min, 0, 1.0, 0, timeline->getDurationInFrames());
		int curEndFrame = ofMap(zoomBounds.max, 0, 1.0, 0, timeline->getDurationInFrames());
		int framesInView = curEndFrame-curStartFrame;
	
		float framesPerPixel = framesInView / bounds.width;
		int frameStepSize = 1;
		
		//TODO make adaptive if we are way zoomed in don't draw so many
		//draw ticker marks
		for(int i = curStartFrame; i <= curEndFrame; i++){
			float x = ofMap(i, curStartFrame, curEndFrame, totalDrawRect.x, totalDrawRect.x+totalDrawRect.width, true);
			ofSetColor(200, 180, 40);
			float heightMultiplier = 0.0;
			if(i % 10 == 0){
				ofSetLineWidth(3);
				heightMultiplier = .5;
			}
			else {
				ofSetLineWidth(1);
				heightMultiplier = .75;
			}
			
			ofLine(x, bounds.y+bounds.height*heightMultiplier, x, bounds.y+bounds.height);
		}
		
		
	}
	//Time based
	else {
		//draw tickers with time
		float startTime = zoomBounds.min * timeline->getDurationInSeconds();
		float endTime = zoomBounds.max * timeline->getDurationInSeconds();
		float durationInview = endTime-startTime;
		float secondsPerPixel = durationInview / bounds.width;
		
		//draw ticker marks
		ofSetLineWidth(1);
		ofSetColor(200, 180, 40);
		float heightMultiplier = .75;
		for(float i = startTime; i <= endTime; i += secondsPerPixel*5){
			//float x = ofMap(i, curStartFrame, curEndFrame, totalDrawRect.x, totalDrawRect.x+totalDrawRect.width, true);
			float x = screenXForTime(i);
			ofLine(x, bounds.y+bounds.height*heightMultiplier, x, bounds.y+bounds.height);
		}
		
		//draw regular increments
		int bigTickStep;
		if(durationInview < 1){ //draw big tick every 100 millis
			bigTickStep = .1;
		}
		else if(durationInview < 60){ // draw big tick every second
			bigTickStep = 1;
		}
		else {
			bigTickStep = 60;
		}
		ofSetLineWidth(3);
		heightMultiplier = .5;		
		for(float i = startTime-fmod(startTime, bigTickStep); i <= endTime; i+=bigTickStep){
			float x = screenXForTime(i);
			ofLine(x, bounds.y+bounds.height*heightMultiplier, x, bounds.y+bounds.height);
		}
		
		if(drawBPMGrid){
			updateBPMPoints();
			ofPushStyle();
			ofSetColor(255, 255, 255, 50);
			for(int i = 0; i < bpmScreenPoints.size(); i++){
				ofSetLineWidth(bpmScreenPoints[i].weight);
				ofLine(bpmScreenPoints[i].screenX, totalDrawRect.y, bpmScreenPoints[i].screenX, totalDrawRect.y+totalDrawRect.height-20);
			}
			ofPopStyle();
		}
	}

	//highlite current mouse position
	if(hover){
		//draw background rect
		ofSetColor(timeline->getColors().backgroundColor);
		if (timeline->getIsFrameBased()) {
			text = ofToString(indexForScreenX(ofGetMouseX()));
		}
		else{
			//text = ofToString();
			text = timeline->formatTime(timeForScreenX(ofGetMouseX()));
		}
		
		textH = 10;
		textW = (text.size()+1)*7;
		ofRect(ofGetMouseX(), bounds.y+textH, textW, textH);
		
		//draw playhead line
		ofSetColor(timeline->getColors().textColor);
		ofDrawBitmapString(text, ofGetMouseX()+5, bounds.y+textH*2);
		
		ofSetColor(timeline->getColors().highlightColor);
		ofSetLineWidth(1);
		ofLine(ofGetMouseX(), totalDrawRect.y, ofGetMouseX(), totalDrawRect.y+totalDrawRect.height);
	}
	
	//draw current frame
	int currentFrameX;
	if (timeline->getIsFrameBased()) {
		text = ofToString(timeline->getCurrentFrame());
		currentFrameX = screenXForIndex(timeline->getCurrentFrame());
	}
	else{
		//text = ofToString();
		text = timeline->formatTime(timeline->getCurrentTime());
		currentFrameX = screenXForTime(timeline->getCurrentTime());
	}
	
	textH = 10;
	textW = (text.size()+1)*7;
	
	ofSetColor(timeline->getColors().backgroundColor);
	ofRect(currentFrameX, bounds.y, textW, textH);
	ofSetColor(timeline->getColors().textColor);
	ofDrawBitmapString(text, currentFrameX+5, bounds.y+textH);
	
	
	if(timeline->getIsPlaying()){
		ofSetColor(timeline->getColors().keyColor);
	}
	else{
		ofSetColor(timeline->getColors().outlineColor);
	}
	
	//draw playhead line
	ofSetLineWidth(1);
	ofLine(currentFrameX, totalDrawRect.y, currentFrameX, totalDrawRect.y+totalDrawRect.height);
	
	//draw in/out point
	float inPointX = normalizedXtoScreenX(timeline->getInOutRange().min, zoomBounds);
	float outPointX = normalizedXtoScreenX(timeline->getInOutRange().max, zoomBounds);
	
	if(bounds.x < inPointX){
		ofSetColor(timeline->getColors().disabledColor,120);
		ofRect(bounds.x, bounds.y, inPointX - bounds.x, totalDrawRect.height);
		ofSetColor(timeline->getColors().highlightColor);
		ofLine(inPointX, bounds.y, inPointX, bounds.y+totalDrawRect.height);
	}
	
	if(bounds.x+bounds.width > outPointX){
		ofSetColor(timeline->getColors().disabledColor,120);
		ofRect(outPointX, bounds.y, (bounds.x+bounds.width) - outPointX, totalDrawRect.height);	
		ofSetColor(timeline->getColors().highlightColor);
		ofLine(outPointX, bounds.y, outPointX, bounds.y+totalDrawRect.height);
	}
	
	//draw bounds 
	ofNoFill();
	ofSetColor(200, 180, 40);
	ofRect(bounds);
		
	ofPopStyle();
}