예제 #1
0
void ofxTLKeyframer::load() {
    ofxXmlSettings savedkeyframes;

    cout << "Loading keyframe file " << xmlFileName << endl;

    if(!savedkeyframes.loadFile(xmlFileName)) {
        ofLog(OF_LOG_ERROR, "ofxTLKeyframer --- couldn't load xml file " + xmlFileName);
        reset();
        return;
    }

    clear();

    savedkeyframes.pushTag("keyframes");
    int numKeyTags = savedkeyframes.getNumTags("key");

    for(int i = 0; i < numKeyTags; i++) {
        savedkeyframes.pushTag("key", i);
        ofxTLKeyframe* key = newKeyframe(ofVec2f(savedkeyframes.getValue("x", 0.0),
                                         savedkeyframes.getValue("y", 0.0)));

        key->easeFunc = easingFunctions[ofClamp(savedkeyframes.getValue("easefunc", 0), 0, easingFunctions.size()-1)];
        key->easeType = easingTypes[ofClamp(savedkeyframes.getValue("easetype", 0), 0, easingTypes.size()-1)];

        savedkeyframes.popTag(); //key

    }

    savedkeyframes.popTag();//keyframes

    updateKeyframeSort();
}
void ofxTLFlags::addFlagAtTime(string key, unsigned long long time){
	ofxTLKeyframe* keyFrame = newKeyframe();
	ofxTLFlag* flag = (ofxTLFlag*)keyFrame;
	setKeyframeTime(keyFrame, time);
	flag->textField.text = key;
	keyframes.push_back(keyFrame);
	updateKeyframeSort();
	timeline->flagTrackModified(this);
}
void ofxTLKeyframes::addKeyframeAtMillis(float value, unsigned long long millis){
	ofxTLKeyframe* key = newKeyframe();
	key->time = key->previousTime = millis;
	key->value = ofMap(value, valueRange.min, valueRange.max, 0, 1.0, true);
	keyframes.push_back(key);
	//smart sort, only sort if not added to end
	if(keyframes.size() > 2 && keyframes[keyframes.size()-2]->time > keyframes[keyframes.size()-1]->time){
		updateKeyframeSort();
	}
	lastKeyframeIndex = 1;
	timeline->flagTrackModified(this);
	shouldRecomputePreviews = true;
}
예제 #4
0
void ofxTLFlags::addFlagAtTime(string key, unsigned long long time){
//	cout << "***ADDING FLAG WITH TIME " << time << endl;
	if(time > 2000000){
		cout << "***UNITITED VAR " << time << endl;
		return;
	}
	ofxTLKeyframe* keyFrame = newKeyframe();
	ofxTLFlag* flag = (ofxTLFlag*)keyFrame;
	setKeyframeTime(keyFrame, time);
	flag->textField.text = key;
	keyframes.push_back(keyFrame);
	updateKeyframeSort();
	timeline->flagTrackModified(this);
}
예제 #5
0
KeyframeModel::KeyframePtr KeyframeModel::createFrame()
{
	KeyframePtr newKeyframe(new motionfile::Keyframe);
	newKeyframe->duration = 0;
	for (unsigned i = 0; i < m_motion.jointList.size(); i++)
	{
		motionfile::FrameJoint newJoint;
		newJoint.effort = 1;
		newJoint.position = 0;
		newKeyframe->joints.push_back(newJoint);
	}

	m_currentFrame = newKeyframe;
	m_jointManager->setFrame(newKeyframe);
	m_ikl->setFrame(newKeyframe);
	m_ikr->setFrame(newKeyframe);
	return newKeyframe;
}
void ofxTLKeyframes::createKeyframesFromXML(ofxXmlSettings xmlStore, vector<ofxTLKeyframe*>& keyContainer){

	int numKeyframeStores = xmlStore.getNumTags("keyframes");
	for(int store = 0; store < numKeyframeStores; store++){
		xmlStore.pushTag("keyframes",store);
		int numKeyTags = xmlStore.getNumTags("key");
		
		for(int i = 0; i < numKeyTags; i++){
			xmlStore.pushTag("key", i);
			//ofxTLKeyframe* key = newKeyframe(ofVec2f(xmlStore.getValue("x", 0.0),xmlStore.getValue("y", 0.0)));
            ofxTLKeyframe* key = newKeyframe();
            
            string legacyX = xmlStore.getValue("x", "");
            //if there is a decimal this is most likely an old save so let's 
            //convert it based on the current duration
            if(legacyX != ""){
                ofLogNotice() << "ofxTLKeyframes::createKeyframesFromXML -- Found legacy time " + legacyX << endl;
                float normalizedTime = ofToFloat(legacyX);
                key->time = key->previousTime =  normalizedTime*timeline->getDurationInMilliseconds();
            }
            else {
                string timecode = xmlStore.getValue("time", "00:00:00:000");
	            key->time = key->previousTime = timeline->getTimecode().millisForTimecode(timecode);
            }
            
            float legacyYValue = xmlStore.getValue("y", 0.0);
            if(legacyYValue != 0.0){
                ofLogNotice() << "ofxTLKeyframes::createKeyframesFromXML -- Found legacy value " << legacyYValue << endl;
                key->value = legacyYValue;
            }
            else{
	            key->value = xmlStore.getValue("value", 0.0f);
            }
			restoreKeyframe(key, xmlStore);			
			xmlStore.popTag(); //key
			keyContainer.push_back( key );
		}
		
		xmlStore.popTag(); //keyframes
	}
	sort(keyContainer.begin(), keyContainer.end(), keyframesort);
}
예제 #7
0
void ofxTLNotes::addKeyframeAtMillis(int pitch, float velocity, unsigned long millis, bool isGrowing){
	ofxTLNote* key = (ofxTLNote*)newKeyframe();
	key->time = key->previousTime = millis;
    key->timeRange.min = millis;
    key->timeRange.max = millis + 100;
    key->pitch = pitch;
    key->velocity = velocity;
    cout << "added keyframe with velocity " << key->velocity << endl;
	key->value = ofMap(pitch, valueRange.min, valueRange.max, 0, 1, true);
    key->growing = isGrowing;
	keyframes.push_back(key);
	//smart sort, only sort if not added to end
	if(keyframes.size() > 2 && keyframes[keyframes.size()-2]->time > keyframes[keyframes.size()-1]->time){
		updateKeyframeSort();
	}
    trimToPitches();
	lastKeyframeIndex = 1;
	timeline->flagTrackModified(this);
	shouldRecomputePreviews = true;
}
void ofxTLKeyframes::mouseReleased(ofMouseEventArgs& args, long millis){
	keysAreDraggable = false;
    if(keysDidDrag){
		//reset these caches because they may no longer be valid
		lastKeyframeIndex = 1;
		lastSampleTime = 0;
        timeline->flagTrackModified(this);
    }
	
	if(createNewOnMouseup){
		//add a new one
		selectedKeyframe = newKeyframe();
		setKeyframeTime(selectedKeyframe,millis);
		selectedKeyframe->value = screenYToValue(args.y);
		keyframes.push_back(selectedKeyframe);
		selectedKeyframes.push_back(selectedKeyframe);
		updateKeyframeSort();
		timeline->flagTrackModified(this);
	}
	createNewOnMouseup = false;
}
void ofxTLKeyframes::loadFromBinaryFile(){
	
	string filePath = ofFilePath::removeExt(xmlFileName) + ".bin";
	
	if(!ofFile(filePath).exists()){
		cout << "binary file doesn't exist " << filePath << endl;
		return;
	}
	cout << " found file " << filePath << endl;
	keyframes.clear();
	ofFile infile(ofToDataPath(filePath), ofFile::ReadOnly, true);
	int numKeys, keyBytes;
	infile.read( (char*)&numKeys, sizeof(int) );
	infile.read( (char*)&keyBytes, sizeof(int) );
	cout << "# keys " << numKeys << " of size " << keyBytes << endl;
	for(int i = 0; i < numKeys; i++){
		ofxTLKeyframe* k = newKeyframe();
		infile.read( (char*)&k->time, sizeof(unsigned long long) );
		infile.read( (char*)&k->value, sizeof(float) );
		keyframes.push_back(k);
	}
	shouldRecomputePreviews = true;
}
예제 #10
0
void ofxTLKeyframer::mousePressed(ofMouseEventArgs& args) {
    if(!enabled) return;

    ofVec2f screenpoint = ofVec2f(args.x, args.y);
    if(drawingEasingWindow) {
        //see if we clicked on an
        drawingEasingWindow = false;

        for(int i = 0; i < easingFunctions.size(); i++) {
            if(easingFunctions[i]->bounds.inside(screenpoint-easingWindowPosition)) {
                selectedKeyframe->easeFunc = easingFunctions[i];
                if(autosave) save();
                return;
            }
        }
        for(int i = 0; i < easingTypes.size(); i++) {
            if(easingTypes[i]->bounds.inside(screenpoint-easingWindowPosition)) {
                selectedKeyframe->easeType = easingTypes[i];
                if(autosave) save();
                return;
            }
        }
    }

    bool clickIsInRect = screenpointIsInBounds(screenpoint);
    if(!focused) {
        focused = clickIsInRect;
        if(!focused) {
            selectedKeyframe = NULL;
            drawingEasingWindow = false;
        }
        return;
    }

    if(!clickIsInRect) {
        focused = false;
        selectedKeyframe = NULL;
        drawingEasingWindow = false;
        return;
    }

    selectedKeyframe = keyframeAtScreenpoint(screenpoint, selectedKeyframeIndex);
    //cout << "selected index is " << selectedKeyframeIndex << endl;
    if(selectedKeyframe == NULL) {
        //add a new one
        selectedKeyframe = newKeyframe( keyframePointForCoord(screenpoint) );

        grabOffset = ofVec2f(0,0);
        updateKeyframeSort();
        //find bounds
        for(int i = 0; i < keyframes.size(); i++) {
            if(keyframes[i] == selectedKeyframe) {
                selectedKeyframeIndex = i;
            }
        }
    }

    //grabbed a keyframe
    if(selectedKeyframe != NULL) {
        timeline->setPercentComplete(selectedKeyframe->position.x);

        if(args.button == 0) {
            grabOffset = screenpoint - coordForKeyframePoint(selectedKeyframe->position);
            if(keyframes.size() == 1) {
                minBound = 0.0;
                maxBound = 1.0;
            }
            else if(selectedKeyframeIndex == 0) {
                minBound = 0.0;
                maxBound = keyframes[selectedKeyframeIndex+1]->position.x;
            }
            else if(selectedKeyframeIndex == keyframes.size()-1) {
                minBound = keyframes[selectedKeyframeIndex-1]->position.x;
                maxBound = 1.0;
            }
            else {
                minBound = keyframes[selectedKeyframeIndex-1]->position.x;
                maxBound = keyframes[selectedKeyframeIndex+1]->position.x;
                //cout << "keyframe point is " << selectedKeyframe->position.x << " min bound is " << minBound << " max bound is " << maxBound << endl;
            }
        }
        else if(args.button == 2) {
            easingWindowPosition = screenpoint;
            drawingEasingWindow = true;
        }
    }
}