コード例 #1
0
ファイル: ofxTLZoomer.cpp プロジェクト: Saihsq/ofxTimeline
void ofxTLZoomer::mouseDragged(ofMouseEventArgs& args) {
    
	if(!enabled) return;
	
    bool notify = false;
	ofRange oldRange = getViewRange();
	if(minSelected || midSelected){
		float originalMin = currentViewRange.min;
		currentViewRange.min = ofClamp( screenXtoNormalizedX(args.x-minGrabOffset, ofRange(0, 1.0)), 0, currentViewRange.max-.01);
		if(minSelected){
			currentViewRange.max = ofClamp( currentViewRange.max + (originalMin-currentViewRange.min), currentViewRange.min+.01, 1.0);
		}
		notify = true;
	}

	if(maxSelected || midSelected){
		float originalMax = currentViewRange.max;
		currentViewRange.max = ofClamp( screenXtoNormalizedX(args.x-maxGrabOffset, ofRange(0, 1.0)), currentViewRange.min+.01, 1.0);
		if(maxSelected){
			currentViewRange.min = ofClamp( currentViewRange.min + (originalMax-currentViewRange.max), 0, currentViewRange.max-.01);
		}
        notify = true;
    }
	
    if(notify){
        notifyZoomDragged(oldRange);
    }
}
コード例 #2
0
void ofxTLInOut::mousePressed(ofMouseEventArgs& args){
    
    if(!bounds.inside(args.x,args.y)) return;
       
    
	float distToIn = normalizedXtoScreenX( timeline->getInOutRange().min ) - args.x;
    if(abs(distToIn) < 7){
        draggingIn = true;
        dragOffset = distToIn;
    }
    
    float distToOut = normalizedXtoScreenX( timeline->getInOutRange().max ) - args.x;
    if(!draggingIn && abs(distToOut) < 7){
        draggingOut = true;
        dragOffset = distToOut;
    }

    if(!draggingIn && !draggingOut){
        if(abs(distToOut) > abs(distToIn)){
            draggingIn = true;
            dragOffset = 0;
            timeline->setInPointAtPercent(screenXtoNormalizedX(args.x));            
        }
        else{
            draggingOut = true;
            dragOffset = 0;
            timeline->setOutPointAtPercent(screenXtoNormalizedX(args.x));
        }
    }
    
    //cout << "dist to in " << abs(distToIn) << " out " << abs(distToOut) << " " << draggingIn << " " << draggingOut << endl;
}
コード例 #3
0
void ofxTLInOut::mouseDragged(ofMouseEventArgs& args){
    if(draggingIn){
        timeline->setInPointAtPercent(screenXtoNormalizedX(args.x - dragOffset));
    }
    if(draggingOut){
        timeline->setOutPointAtPercent(screenXtoNormalizedX(args.x - dragOffset));
    }
}
コード例 #4
0
ファイル: ofxTLZoomer.cpp プロジェクト: alesaccoia/xtrees
void ofxTLZoomer::mousePressed(ofMouseEventArgs& args) {

	if(!enabled) return;

	minSelected = maxSelected = midSelected = focused  = false;
	if (pointInScreenBounds(ofVec2f(args.x, args.y))) {
		mouseIsDown = true;
		focused = true;
		
		//did we click on the min-left handle?
		float minScreenX = normalizedXtoScreenX(currentViewRange.min);
		minGrabOffset = args.x - minScreenX;
		if(fabs(minScreenX - args.x) < 5){
			minSelected = true;
			notifyZoomStarted();
			return;
		}
		
		//did we click on the max-right handle?
		float maxScreenX = normalizedXtoScreenX(currentViewRange.max);
		maxGrabOffset = args.x - maxScreenX;
		if(fabs(maxScreenX - args.x) < 5){
			maxSelected = true;
			notifyZoomStarted();
			return;
		}
		
		//did we click in the middle?
		if(args.x > minScreenX && args.x < maxScreenX){
			notifyZoomStarted();
			midSelected = true;
			return;
		}
		
		//did we click to the right?
		if(args.x > maxScreenX){
			maxSelected = true;
			maxGrabOffset = 0;
			currentViewRange.max = screenXtoNormalizedX(args.x);
			notifyZoomStarted();
			return;
		}
		
		//did we click to the left?
		if(args.x < minScreenX){
			minSelected = true;
			minGrabOffset = 0;
			currentViewRange.min = screenXtoNormalizedX(args.x);
			notifyZoomStarted();
			return;
		}
		
	}
}
コード例 #5
0
ファイル: ofxTLZoomer.cpp プロジェクト: alesaccoia/xtrees
void ofxTLZoomer::mouseDragged(ofMouseEventArgs& args) {
	if(!enabled) return;

	ofRange oldRange = currentViewRange;
	if(minSelected || midSelected){
		currentViewRange.min = ofClamp( screenXtoNormalizedX(args.x-minGrabOffset), 0, currentViewRange.max);
		notifyZoomDragged(oldRange);
	}

	if(maxSelected || midSelected){
		currentViewRange.max = ofClamp( screenXtoNormalizedX(args.x-maxGrabOffset), currentViewRange.min, 1.0);
		notifyZoomDragged(oldRange);
	}	
}
コード例 #6
0
ファイル: ofxTLTrigger.cpp プロジェクト: greenbaum/GAmuza
//main function to get values out of the timeline, operates on the given value range
void ofxTLTrigger::mousePressed(ofMouseEventArgs& args){

	enterText = false;
	selectedTrigger = NULL;

	bool clickIsInRect = bounds.inside(args.x, args.y);
	if(clickIsInRect){
		if(!focused){
			focused = true;
			return;
		}
	}
	else{
		focused = false;
		return;
	}
	
	if(focused){
		selectedTrigger = getTriggerForScreenPosition(args.x, dragOffset);
		if(selectedTrigger == NULL){
			Trigger t;
			t.pt = screenXtoNormalizedX(args.x, zoomBounds);
			t.name = "new trigger";
			triggers.push_back(t);
			selectedTrigger = &triggers[triggers.size()-1];
			dragOffset = 0;
		}
	}
}
コード例 #7
0
void ofxTLKeyframes::recomputePreviews(){
	preview.clear();
	
//	cout << "ofxTLKeyframes::recomputePreviews " << endl;
	
//	if(keyframes.size() == 0 || keyframes.size() == 1){
//		preview.addVertex(ofPoint(bounds.x, bounds.y + bounds.height - sampleAtPercent(.5f)*bounds.height));
//		preview.addVertex(ofPoint(bounds.x+bounds.width, bounds.y + bounds.height - sampleAtPercent(.5f)*bounds.height));
//	}
//	else{
		for(int p = bounds.getMinX(); p <= bounds.getMaxX(); p+=2){
			preview.addVertex(p,  bounds.y + bounds.height - sampleAtPercent(screenXtoNormalizedX(p)) * bounds.height);
		}
//	}
//	int size = preview.getVertices().size();
	preview.simplify();
	//cout << "simplify pre " << size << " post: " << preview.getVertices().size() << " dif: " << (size - preview.getVertices().size()) << endl;

	ofVec2f lastPoint;
	keyPoints.clear();
	for(int i = 0; i < keyframes.size(); i++){
		if(!isKeyframeIsInBounds(keyframes[i])){
			continue;
		}
		ofVec2f screenpoint = screenPositionForKeyframe(keyframes[i]);
		if(lastPoint.squareDistance(screenpoint) > 5*5){
			keyPoints.push_back(screenpoint);
		}
		
		lastPoint = screenpoint;
	}
	
	shouldRecomputePreviews = false;
	
}
コード例 #8
0
void ofxTLVideoDepthAlignmentScrubber::mouseDragged(ofMouseEventArgs& args, long millis){
	if(ready() && bounds.inside(args.x, args.y)){
		selectedPercent = screenXtoNormalizedX(args.x);
		selectedVideoMillis = screenXToMillis(args.x);
		updateSelection();
	}
}
コード例 #9
0
void ofxTLVideoTrack::mouseDragged(ofMouseEventArgs& args, long millis){
	if(isActive()){
		selectFrame( timeline->getTimecode().frameForMillis(millis) );
		if(timeline->getMovePlayheadOnDrag()){
			timeline->setPercentComplete(screenXtoNormalizedX(args.x));
		}
	}
}
コード例 #10
0
void ofxTLVideoPlayer::mouseDragged(ofMouseEventArgs& args, bool snapped){
	if(bounds.inside(args.x, args.y)){
		selectFrame( indexForScreenX(args.x) );
		if(timeline->getMovePlayheadOnDrag()){
//			cout << "setting percent complete " << 
			timeline->setPercentComplete(screenXtoNormalizedX(args.x, zoomBounds));
		}
	}
}
コード例 #11
0
void ofxTLAudioTrack::recomputePreview(){
	
	previews.clear();
	
	//cout << "recomputing view with zoom bounds of " << zoomBounds << endl;
	
	float normalizationRatio = timeline->getDurationInSeconds() / player.getDuration(); //need to figure this out for framebased...but for now we are doing time based
	float trackHeight = bounds.height/(1+player.getNumChannels());
	int numSamples = player.getBuffer().size() / player.getNumChannels();
	int pixelsPerSample = numSamples / bounds.width;
	for(int c = 0; c < player.getNumChannels(); c++){
		ofPolyline preview;
		int lastFrameIndex = 0;
		for(float i = bounds.x; i < bounds.x+bounds.width; i++){
			float pointInTrack = screenXtoNormalizedX( i, zoomBounds ) * normalizationRatio; //will scale the screenX into wave's 0-1.0
			float trackCenter = bounds.y + trackHeight * (c+1);
			if(pointInTrack <= 1.0){
				//draw sample at pointInTrack * waveDuration;
				int frameIndex = pointInTrack * numSamples;					
				float losample = 0;
				float hisample = 0;
				for(int f = lastFrameIndex; f < frameIndex; f++){
					int sampleIndex = f * player.getNumChannels() + c;
					float subpixelSample = player.getBuffer()[sampleIndex]/32565.0;
					if(subpixelSample < losample) {
						losample = subpixelSample;
					}
					if(subpixelSample > hisample) {
						hisample = subpixelSample;
					}
				}
				if(losample == 0 && hisample == 0){
					preview.addVertex(i, trackCenter);
				}
				else {
					if(losample != 0){
						preview.addVertex(i, trackCenter - losample * trackHeight);
					}
					if(hisample != 0){
						//ofVertex(i, trackCenter - hisample * trackHeight);
						preview.addVertex(i, trackCenter - hisample * trackHeight);
					}
				}
				lastFrameIndex = frameIndex;
			}
			else{
				preview.addVertex(i,trackCenter);
			}
		}
		preview.simplify();
		previews.push_back(preview);
	}
	computedZoomBounds = zoomBounds;
	shouldRecomputePreview = false;
}
コード例 #12
0
void ofxTLInOut::mousePressed(ofMouseEventArgs& args)
{
 
    //cout << "TLInout : mouse Press " << endl;
    
    if(!bounds.inside(args.x,args.y)) return;
    
//    void presentedModalContent(ofxTLTrack* modalTrack);
//    void dismissedModalContent();

    // operate in modal content mode !!
    timeline->presentedModalContent(((ofxTLTrack*)this));
    
	float distToIn = normalizedXtoScreenX( timeline->getInOutRange().min ) - args.x;
    if(abs(distToIn) < 7){
        draggingIn = true;
        dragOffset = distToIn;
    }
    
    float distToOut = normalizedXtoScreenX( timeline->getInOutRange().max ) - args.x;
    if(!draggingIn && abs(distToOut) < 7){
        draggingOut = true;
        dragOffset = distToOut;
    }

    if(!draggingIn && !draggingOut){
        if(abs(distToOut) > abs(distToIn)){
            draggingIn = true;
            dragOffset = 0;
            timeline->setInPointAtPercent(screenXtoNormalizedX(args.x));            
        }
        else{
            draggingOut = true;
            dragOffset = 0;
            timeline->setOutPointAtPercent(screenXtoNormalizedX(args.x));
        }
    }
    
   
    
    //cout << "dist to in " << abs(distToIn) << " out " << abs(distToOut) << " " << draggingIn << " " << draggingOut << endl;
}
コード例 #13
0
void ofxTLAudioTrack::mouseMoved(ofMouseEventArgs& args, long millis){
	if (!bounds.inside(args.x, args.y)) return;

	for (vector<AlignMarker>::iterator m = markers.begin(); m != markers.end(); m++) {
		if (m->selected) {
			cout << "ms selected changin from " << m->ms << endl;
			m->ms = screenXToMillis(normalizedXtoScreenX(screenXtoNormalizedX(args.x, zoomBounds)));
			cout << " to: " << m->ms << endl;
		}
	}
}
コード例 #14
0
bool ofxTLVideoTrack::mousePressed(ofMouseEventArgs& args, long millis){
	ofxTLTrack::mousePressed(args, millis);
	if(isActive()){
		timeline->unselectAll();
		selectFrame( timeline->getTimecode().frameForMillis(millis) );

		if(timeline->getMovePlayheadOnDrag()){
			timeline->setPercentComplete(screenXtoNormalizedX(args.x));
		}
	}
	return false;
}
コード例 #15
0
bool ofxTLAudioTrack::mousePressed(ofMouseEventArgs& args, long millis){
	if (!bounds.inside(args.x, args.y)) return false;
	
	for (vector<AlignMarker>::iterator m = markers.begin(); m != markers.end(); m++) {
		if (m->rect.inside(args.x, args.y)) {
			cout << "ms selected:" << m->ms << endl;
			m->selected = true;
			return true;
		}
	}
	// change playhead position
	timeline->setPercentComplete(screenXtoNormalizedX(args.x, zoomBounds));

	return false;
}
コード例 #16
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();

}
コード例 #17
0
void ofxTLAudioTrack::recomputePreview(){
	
	previews.clear();
	
//	cout << "recomputing view with zoom bounds of " << zoomBounds << endl;
	
	float normalizationRatio = timeline->getDurationInSeconds() / player.getDuration(); //need to figure this out for framebased...but for now we are doing time based
	float trackHeight = bounds.height/(1+player.getNumChannels());
	int numSamples = player.getBuffer().size() / player.getNumChannels();
	int pixelsPerSample = numSamples / bounds.width;
	int numChannels = player.getNumChannels();
	vector<short> & buffer  = player.getBuffer();

	for(int c = 0; c < numChannels; c++){
		ofPolyline preview;
		int lastFrameIndex = 0;
		preview.resize(bounds.width*2);  //Why * 2? Because there are two points per pixel, center and outside. 
		for(float i = bounds.x; i < bounds.x+bounds.width; i++){
			float pointInTrack = screenXtoNormalizedX( i ) * normalizationRatio; //will scale the screenX into wave's 0-1.0
			float trackCenter = bounds.y + trackHeight * (c+1);
			
			ofPoint * vertex = & preview.getVertices()[ (i - bounds.x) * 2];
			
			if(pointInTrack >= 0 && pointInTrack <= 1.0){
				//draw sample at pointInTrack * waveDuration;
				int frameIndex = pointInTrack * numSamples;					
				float losample = 0;
				float hisample = 0;
				for(int f = lastFrameIndex; f < frameIndex; f++){
					int sampleIndex = f * numChannels + c;
					float subpixelSample = buffer[sampleIndex]/32565.0;
					if(subpixelSample < losample) {
						losample = subpixelSample;
					}
					if(subpixelSample > hisample) {
						hisample = subpixelSample;
					}
				}
				
				if(losample == 0 && hisample == 0){
					//preview.addVertex(i, trackCenter);
					vertex->x = i;
					vertex->y = trackCenter;
					vertex++;
				}
				else {
					if(losample != 0){
//						preview.addVertex(i, trackCenter - losample * trackHeight);
						vertex->x = i;
						vertex->y = trackCenter - losample * trackHeight*.5;
						vertex++;
					}
					if(hisample != 0){
						//ofVertex(i, trackCenter - hisample * trackHeight);
//						preview.addVertex(i, trackCenter - hisample * trackHeight);
						vertex->x = i;
						vertex->y = trackCenter - hisample * trackHeight*.5;
						vertex++;
					}
				}
				
				while (vertex < & preview.getVertices()[ (i - bounds.x) * 2] + 2) {
					*vertex = *(vertex-1);
					vertex++;
				}

				lastFrameIndex = frameIndex;
			}
			else{
				*vertex++ = ofPoint(i,trackCenter);
				*vertex++ = ofPoint(i,trackCenter);
			}
		}
		preview.simplify();
		previews.push_back(preview);
	}
	computedZoomBounds = zoomBounds;
	shouldRecomputePreview = false;
}
コード例 #18
0
void ofxTLAudioTrack::draw(){
	
	if(!soundLoaded || player.getBuffer().size() == 0){
		ofPushStyle();
		ofSetColor(timeline->getColors().disabledColor);
		ofRectangle(bounds);
		ofPopStyle();
		return;
	}
		
	if(shouldRecomputePreview || viewIsDirty){
		recomputePreview();
	}

	//cout << "ofxTLAudioTrack::draw" << endl;

    ofSetColor(255, 255, 255, 205);
    ofFill();
    ofRect(bounds);
    ofPushStyle();
    //ofSetColor(timeline->getColors().keyColor);
    ofSetColor(0, 0 , 0, 255);
    ofNoFill();
    
    for(int i = 0; i < previews.size(); i++){
        ofPushMatrix();
        ofTranslate( normalizedXtoScreenX(computedZoomBounds.min, zoomBounds)  - normalizedXtoScreenX(zoomBounds.min, zoomBounds), 0, 0);
        ofScale(computedZoomBounds.span()/zoomBounds.span(), 1, 1);
        previews[i].draw();
        ofPopMatrix();
    }
    ofPopStyle();
	
	if(getIsPlaying() || timeline->getIsPlaying()){
		ofPushStyle();
		
		//will refresh fft bins for other calls too
		vector<float>& bins = getFFTSpectrum(defaultFFTBins);
		float binWidth = bounds.width / bins.size();
		//find max
		float averagebin = 0 ;
		for(int i = 0; i < bins.size(); i++){
			maxBinReceived = MAX(maxBinReceived, bins[i]);
			averagebin += bins[i];
		}
		averagebin /= bins.size();
		
		ofFill();
		ofSetColor(timeline->getColors().disabledColor, 120);
		for(int i = 0; i < bins.size(); i++){
			float height = bounds.height * bins[i]/maxBinReceived;
			float y = bounds.y + bounds.height - height;
			ofRect(bounds.x + i*binWidth, y, binWidth, height);
		}
		
		ofPopStyle();
	}

	// playhead 
	ofPushStyle();
	ofSetColor(0, 0, 0, 255);
	float x = normalizedXtoScreenX( oldpos, zoomBounds);
	ofLine(x, bounds.y, x, bounds.y + bounds.height);
	ofSetLineWidth(3);
	ofPopStyle();

	/*
	float pos = player.getPosition();
	if (pos) {
		ofxTLZoomer2D *zoom = (ofxTLZoomer2D*)timeline->getZoomer();
		ofRange z = zoom->getViewRange();
		ofRange oldz = z;
		float c = z.center(); 
		float d = pos - c;

		z.min = ofClamp(z.min + d, 0, 1); z.max = ofClamp(z.max + d, 0, 1);
		if (z.min == .0 && z.span() < oldz.span())
			z.max = oldz.max - oldz.min;
		if (z.max == 1. && z.span() < oldz.span())
			z.min = z.max - oldz.max + oldz.min;
	}*/




	// draw markers:
	for (vector<AlignMarker>::iterator m = markers.begin(); m != markers.end(); m++) {
		float xn = screenXtoNormalizedX(millisToScreenX(m->ms));
		if (zoomBounds.contains(xn)) {
			float x = timeline->normalizedXtoScreenX(xn, zoomBounds);
			if (m->selected)
				ofSetColor(255, 0, 0, 255);
			else 
				ofSetColor(0, 0, 0, 255);
			ofLine(x, bounds.y, x, bounds.y+bounds.height);
			m->rect = ofRectangle(x - 5, bounds.y + bounds.height - 12, 10, 10);
			ofSetColor(10, 0, 200, 100);
			ofFill();
			ofRect(m->rect);

			//cout << "m:" << m->ms << endl;
			ofSetColor(0, 0, 0, 255);
			timeline->getFont().drawString(ofToString(m->ms), x+1, bounds.y + 30);
		}
	}
	
}
コード例 #19
0
ファイル: ofxTLTrigger.cpp プロジェクト: greenbaum/GAmuza
void ofxTLTrigger::mouseDragged(ofMouseEventArgs& args){
	ofxTLElement::mouseDragged(args);
	if(selectedTrigger != NULL){
		selectedTrigger->pt = screenXtoNormalizedX(args.x - dragOffset, zoomBounds);
	}
}