Ejemplo n.º 1
0
void ofxTLVideoPlayer::draw(){
	
	if(player == NULL){
		return;
	}
	
	if( autoUpdateTimelineOnDraw )
	{
		updateTimeline();
	}

	
//	cout << "in out is " << inFrame << " " << outFrame << endl;
	
	ofPushStyle();
	
	if(thumbsEnabled && getDrawRect().height > 10){
		ofSetColor(255);
		for(int i = 0; i < videoThumbs.size(); i++){
			if(videoThumbs[i].visible){
				videoThumbs[i].thumb.draw(videoThumbs[i].displayRect);
			}
		}
		
		for(int i = 0; i < videoThumbs.size(); i++){
			if(videoThumbs[i].visible){

				if (!thumbsEnabled) {
					ofFill();
					ofSetColor(0);
					ofRect(videoThumbs[i].displayRect);
				}
				ofNoFill();
				ofSetColor(255, 150, 0);
				ofDrawBitmapString(ofToString(videoThumbs[i].framenum), videoThumbs[i].displayRect.x+5, videoThumbs[i].displayRect.y+15);
				ofRect(videoThumbs[i].displayRect);
			}
		}		
	}
	
	int selectedFrameX = screenXForIndex(selectedFrame);
	ofSetColor(0, 125, 255);
	ofLine(selectedFrameX, bounds.y, selectedFrameX, bounds.y+bounds.height);
	ofDrawBitmapString(ofToString(selectedFrame), selectedFrameX, bounds.y+35);
	
	if(inFrame != -1){
		ofSetLineWidth(2);
		ofSetColor(timeline->getColors().highlightColor);
		int inFrameX  = screenXForIndex(inFrame);
		int outFrameX = screenXForIndex(outFrame);
		ofLine(inFrameX, bounds.y, inFrameX, bounds.y+bounds.height);
		ofLine(outFrameX, bounds.y, outFrameX, bounds.y+bounds.height);
		ofSetColor(timeline->getColors().keyColor);
		ofDrawBitmapString("IN:  " + ofToString(inFrameX),  inFrameX  + 5, bounds.y + 10);
		ofDrawBitmapString("OUT: " + ofToString(outFrameX), outFrameX + 5, bounds.y + bounds.height - 20);
	}
	
	ofPopStyle();
}
Ejemplo n.º 2
0
void ofxTLVideoPlayer::calculateFramePositions(){
	
	if(player == NULL){
		return;
	}
	
	int frameWidth = int( bounds.height * videoThumbs[0].targetWidth / videoThumbs[0].targetHeight );
	int totalPixels = int( bounds.width / zoomBounds.span() );
	int framesToShow = MAX(totalPixels / frameWidth, 1);
	int frameStep = MAX(videoThumbs.size() / framesToShow, 1); 
	int minPixelIndex = -(zoomBounds.min * totalPixels);

	//cout << "bounds are " << bounds.width << " "f  << bounds.height << " frameWidth " << frameWidth << " total pixels " << totalPixels << " frame step " << frameStep << " minpix " << minPixelIndex << endl;
	
	for(int i = 0; i < videoThumbs.size(); i++){
		if(i % frameStep == 0){
			int screenX = screenXForIndex(i);
			videoThumbs[i].displayRect = ofRectangle(screenX, bounds.y, frameWidth, bounds.height);
			videoThumbs[i].visible = videoThumbs[i].displayRect.x+videoThumbs[i].displayRect.width > 0 && videoThumbs[i].displayRect.x < bounds.width;
		}
		else {
			videoThumbs[i].visible = false;
		}
	}
}
Ejemplo n.º 3
0
void ofxTLCameraTrack::draw() {

    ofPushStyle();
    ofSetColor(timeline->getColors().keyColor);
    ofNoFill();

    for(int i = 0; i < track.getSamples().size(); i++) {
        float screenX = screenXForIndex(track.getSamples()[i].frame);
        float screenY = bounds.y;
        ofPoint screenPoint = ofPoint(screenX,screenY);

        if(i == mostRecentlySelected) {
            if(easeInSelected) {
                ofSetColor(timeline->getColors().highlightColor);
                draweEase(track.getSamples()[i].easeIn,  screenPoint, true);
                ofSetColor(timeline->getColors().keyColor);
                draweEase(track.getSamples()[i].easeOut, screenPoint, false);
            }
            else {
                ofSetColor(timeline->getColors().keyColor);
                draweEase(track.getSamples()[i].easeIn,  screenPoint, true);
                ofSetColor(timeline->getColors().highlightColor);
                draweEase(track.getSamples()[i].easeOut, screenPoint, false);
            }
        }
        else {
            ofSetColor(timeline->getColors().keyColor);
            draweEase(track.getSamples()[i].easeIn,  screenPoint, true);
            draweEase(track.getSamples()[i].easeOut, screenPoint, false);
        }
    }

    ofFill();
    ofSetColor(timeline->getColors().highlightColor);
    for(int i = 0; i < selectedTrackPoints.size(); i++) {
        float screenX = screenXForIndex(track.getSamples()[ selectedTrackPoints[i] ].frame);
        float screenY = bounds.y+bounds.height/2;
        ofCircle(screenX, screenY, 4);
    }

    ofPopStyle();
}
Ejemplo n.º 4
0
int ofxTLCameraTrack::trackIndexForScreenX(float screenX) {

    for(int i = 0; i < track.getSamples().size(); i++) {
        float camScreenX = screenXForIndex(track.getSamples()[i].frame);
//		cout << "cam point " << i << " screen index is " << camScreenX << " screen index is " << screenX << endl;
        if(fabs(camScreenX - screenX) < bounds.height/2) {
//			cout << " SELECTED TRACK INDEX " << i << endl;
            return i;
        }
    }
    return -1;
}
Ejemplo n.º 5
0
void ofxTLCameraTrack::mousePressed(ofMouseEventArgs& args) {
    if(bounds.inside(args.x, args.y)) {
        int selectedTrack = trackIndexForScreenX(args.x);
        if(selectedTrack == -1) {
            timeline->unselectAll();
            return;
        }

        bool alreadySelected = isPointSelected(selectedTrack);
        if(!alreadySelected) {
            if(!ofGetModifierKeyShift()) {
                timeline->unselectAll();
            }
            selectedTrackPoints.push_back( selectedTrack );
        }

        mostRecentlySelected = selectedTrack;
        easeInSelected = args.x < screenXForIndex(track.getSamples()[selectedTrack].frame);
        canDrag = !ofGetModifierKeyShift();
        updateDragOffsets(args.x);
    }
}
Ejemplo n.º 6
0
int ofxTLElement::screenXForIndex(int index){
	return screenXForIndex(index, timeline->getDurationInFrames());	
}
Ejemplo n.º 7
0
void ofxTLVideoPlayer::draw(){
	
	if(player == NULL){
		return;
	}
	
	if(player->isPlaying() && player->getSpeed() > 0.0){
		
//		cout << " is playing player frame " << player->getCurrentFrame() << " current frame " << getCurrentFrame() << endl;
		if(timeline->getIsFrameBased()){

			if(player->getCurrentFrame() < inFrame || player->getCurrentFrame() > outFrame){
//				cout << "reset in frame from " << player->getCurrentFrame() << endl;
				player->setFrame(inFrame);
//				cout << "	to: " << player->getCurrentFrame() << endl;
			}
			
			if(lastFrame > player->getCurrentFrame()){
				currentLoop++;
//				cout << "LOOPED! with last frame " << lastFrame << " " << player->getCurrentFrame() << " current loop " << currentLoop << endl;
			}
			
			if(timeline->getOutFrame() < getCurrentFrame() || timeline->getInFrame() > getCurrentFrame() ){				
				if(timeline->getInFrame() > player->getCurrentFrame() && timeline->getLoopType() == OF_LOOP_NONE){
					player->stop();
				}
				else {
					//player->setFrame( timeline->getInFrame() % player->getTotalNumFrames());
					selectFrame(timeline->getInFrame());
				}
			}
						
			timeline->setCurrentFrame(getCurrentFrame());
			lastFrame = player->getCurrentFrame();
		}
		else{
			if(timeline->getOutTime() < player->getPosition()*player->getDuration() || timeline->getInTime() > player->getPosition()*player->getDuration() ){
				player->setFrame(timeline->getInOutRange().min * player->getTotalNumFrames());
			}
			timeline->setCurrentTime( player->getPosition() * player->getDuration());
		}
	}
	
//	cout << "in out is " << inFrame << " " << outFrame << endl;
	
	ofPushStyle();
	
	if(thumbsEnabled && getDrawRect().height > 10){
		ofSetColor(255);
		for(int i = 0; i < videoThumbs.size(); i++){
			if(videoThumbs[i].visible){
				videoThumbs[i].thumb.draw(videoThumbs[i].displayRect);
			}
		}
		
		for(int i = 0; i < videoThumbs.size(); i++){
			if(videoThumbs[i].visible){

				if (!thumbsEnabled) {
					ofFill();
					ofSetColor(0);
					ofRect(videoThumbs[i].displayRect);
				}
				ofNoFill();
				ofSetColor(255, 150, 0);
				ofDrawBitmapString(ofToString(videoThumbs[i].framenum), videoThumbs[i].displayRect.x+5, videoThumbs[i].displayRect.y+15);
				ofRect(videoThumbs[i].displayRect);
			}
		}		
	}
	
	int selectedFrameX = screenXForIndex(selectedFrame);
	ofSetColor(0, 125, 255);
	ofLine(selectedFrameX, bounds.y, selectedFrameX, bounds.y+bounds.height);
	ofDrawBitmapString(ofToString(selectedFrame), selectedFrameX, bounds.y+35);
	
	if(inFrame != -1){
		ofSetLineWidth(2);
		ofSetColor(timeline->getColors().highlightColor);
		int inFrameX  = screenXForIndex(inFrame);
		int outFrameX = screenXForIndex(outFrame);
		ofLine(inFrameX, bounds.y, inFrameX, bounds.y+bounds.height);
		ofLine(outFrameX, bounds.y, outFrameX, bounds.y+bounds.height);
		ofSetColor(timeline->getColors().keyColor);
		ofDrawBitmapString("IN:  " + ofToString(inFrameX),  inFrameX  + 5, bounds.y + 10);
		ofDrawBitmapString("OUT: " + ofToString(outFrameX), outFrameX + 5, bounds.y + bounds.height - 20);
	}
	
	ofPopStyle();
}
Ejemplo n.º 8
0
void ofxTLCameraTrack::updateDragOffsets(float screenX) {
    dragOffsets.clear();
    for(int i = 0; i < selectedTrackPoints.size(); i++) {
        dragOffsets.push_back( screenX - screenXForIndex(track.getSamples()[ selectedTrackPoints[i] ].frame) );
    }
}
Ejemplo n.º 9
0
void ofxTLTicker::draw(){
	
	ofPushStyle();
	
	int textH, textW;
	string text;

    //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;
    
	if(viewIsDirty){
		refreshTickMarks();
	}
	
	tickerMarks.setStrokeColor( ofColor(200, 180, 40) );
	tickerMarks.setStrokeWidth(1);
	tickerMarks.draw(bounds.x, bounds.y);
		
    if(drawBPMGrid){
		if(viewIsDirty){
	        updateBPMPoints();
		}
        ofPushStyle();
        ofSetColor(255, 255, 255, 50);
        for(int i = 0; i < bpmScreenPoints.size(); i++){
            ofSetLineWidth(bpmScreenPoints[i].weight);
            ofLine(bpmScreenPoints[i].screenX, getBottomEdge(), bpmScreenPoints[i].screenX, totalDrawRect.y+totalDrawRect.height);
        }
        ofPopStyle();
    }

	textH = timeline->getFont().getLineHeight();
	textW = 3;

	//highlite current mouse position
	if(hover){
		//draw background rect
		ofSetColor(timeline->getColors().backgroundColor);
        float screenX = millisToScreenX(hoverTime);
		text = timeline->formatTime(hoverTime);
		textW = timeline->getFont().stringWidth(text)+3;
        if(bounds.height > 2){
            int previewTimecodeX = ofClamp(screenX+5, bounds.x, bounds.x+bounds.width-textW-5);
            ofFill();
            ofRect(previewTimecodeX-5, bounds.y+textH, textW, textH);		
            //draw playhead line
            ofSetColor(timeline->getColors().textColor);
            timeline->getFont().drawString(text, previewTimecodeX, bounds.y+textH*2);
        }
		
		ofSetColor(timeline->getColors().highlightColor);
		ofSetLineWidth(1);

        ofLine(screenX, totalDrawRect.y, screenX, totalDrawRect.y+totalDrawRect.height);
	}
	
	//draw current frame
    //TIMECODE
    int currentFrameX;
    if (timeline->getIsFrameBased()) {
        text = ofToString(timeline->getCurrentFrame());
        currentFrameX = screenXForIndex(timeline->getCurrentFrame());
    }
    else{
        text = timeline->formatTime(timeline->getCurrentTime());
        currentFrameX = screenXForTime(timeline->getCurrentTime());
    }
    
    if(bounds.height > 2){
        int timeCodeX = ofClamp(currentFrameX+5, bounds.x, bounds.x+bounds.width-textW-5);
        ofSetColor(timeline->getColors().backgroundColor);
        ofFill();
        ofRect(timeCodeX-5, bounds.y, textW, textH);
        ofSetColor(timeline->getColors().textColor);
        timeline->getFont().drawString(text, timeCodeX, 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 bounds 
	ofNoFill();
	ofSetColor(200, 180, 40);
	ofRect(bounds);
		
	ofPopStyle();
}
Ejemplo n.º 10
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();
}
Ejemplo n.º 11
0
void ofxTLBeatTicker::draw(){
	if (!isSetup || disabled)
		return;

	ofPushStyle();

	int textH, textW;
	string text;

	if(viewIsDirty){
		refreshTickMarks();
	}

	drawBPMGrid = true;
	tickerMarks.setStrokeColor( ofColor(0, 0, 240) );
	tickerMarks.setStrokeWidth(1);
	tickerMarks.draw(bounds.x, bounds.y);

	if(drawBPMGrid){
		if(viewIsDirty){
			updateBPMPoints();
		}
		ofPushStyle();

		ofSetColor(0, 0, 0, 200);
		ofSetLineWidth(1);

		int siz = bpmScreenPoints.size();
		int howmany;
		if (siz > 20)
			howmany = siz / 15;
		else if (siz > 12)
			howmany = 4;
		else howmany = 4;
		for(int i = 0; i < bpmScreenPoints.size(); i++) {
			if (isOnScreen(bpmScreenPoints[i].screenX)) {
				int bi = floor(bpmScreenPoints[i].beat);
				//if ((bi) % 4 == 1) { // draw bpms indices
				if ((bi) % howmany == 1) { // draw bpms indices
#if DRAW_FXCKING_GRID
						ofLine(bpmScreenPoints[i].screenX, getBottomEdge(), bpmScreenPoints[i].screenX, totalDrawRect.y+totalDrawRect.height);
#endif
						text = tostr(bi);
						textW = timeline->getFont().stringWidth(text);
						timeline->getFont().drawString(text, bpmScreenPoints[i].screenX - textW/2, getBottomEdge()-20);
				}
			}
		}
		ofPopStyle();
	}

	textH = timeline->getFont().getLineHeight();
	textW = 3;


	//draw current frame
	int currentFrameX;
	if (timeline->getIsFrameBased()) {
		//text = ofToString(timeline->getCurrentFrame());
		text = tostr(timeline->millisecToBeat(hoverTime));
		currentFrameX = screenXForIndex(timeline->getCurrentFrame());
	} else{
		//text = timeline->formatTime(timeline->getCurrentTime());
		text = tostr(timeline->millisecToBeat(hoverTime));
		currentFrameX = screenXForTime(timeline->getCurrentTime());
		//currenttimeline->normalizedXtoScreenX(timeline->beatToNormalizedX(currentPoint), zoomBounds); //;timeline->millisToScreenX(timeline->beatToMillisec(measures[0].beat));
	}
	currentFrameX = ofClamp(currentFrameX, bounds.getMinX(), bounds.getMaxX());

	//draw playhead line
	ofSetLineWidth(1);
	ofLine(currentFrameX, totalDrawRect.y, currentFrameX, totalDrawRect.y+totalDrawRect.height);
	//text = tostr(timeline->millisecToBeat(hoverTime)+1 - startBeat);
	unsigned long startBeat = timeline->normalizedXToBeat(zoomBounds.min);// * timeline->getDurationInMilliseconds();
	text = tostr( timeline->normalizedXToBeat( screenXtoNormalizedX( millisToScreenX(hoverTime), zoomBounds) ) + 1);
	//cout << "ofxTLBeatTicker: hoverTime: " << hoverTime << " text:"<< text << endl;
	float screenX = ofClamp(millisToScreenX(hoverTime), bounds.getMinX(), bounds.getMaxX());
	timeline->getFont().drawString(text, screenX, bounds.y+textH+25);
	ofPopStyle();

}