Search in sources :

Example 1 with FlamePreparer

use of org.jwildfire.create.tina.dance.FlamePreparer in project JWildfire by thargor6.

the class PostRecordFlameGenerator method createRecordedFlameFiles.

public void createRecordedFlameFiles(String pAbsolutePath) throws Exception {
    if (recorder.getRecordedActions().size() >= 2) {
        List<Flame> flames = new ArrayList<Flame>();
        int actionIdx = 0;
        StartAction startAction = (StartAction) recorder.getRecordedActions().get(actionIdx++);
        DancingFlameStack flameStack = new DancingFlameStack(prefs);
        flameStack.addFlame(startAction.getFlame(), 0, project.getMotions(startAction.getFlame()));
        RecordedAction nextAction = recorder.getRecordedActions().get(actionIdx++);
        long timeRenderStarted = System.currentTimeMillis();
        long nextFrame = (long) (timeRenderStarted + 1000.0 / (double) thread.getFramesPerSecond() + 0.5);
        while (true) {
            long time = System.currentTimeMillis();
            while (time < nextFrame) {
                try {
                    Thread.sleep(1);
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                time = System.currentTimeMillis();
            }
            nextFrame = (long) (time + 1000.0 / (double) thread.getFramesPerSecond() + 0.5);
            DancingFlame dancingFlame = flameStack.getFlame();
            Flame renderFlame;
            long currTime = time - timeRenderStarted;
            short[] currFFT;
            if (fftData == null) {
                // t.createTransformedFlame() --> motion.computeValue() handles null currFFT values
                // if _using_ fftMotion, currFFT == null will result in no change from base offset
                // if _not_using_ fftMotion, currFFT is ignored
                currFFT = null;
            } else {
                currFFT = fftData.getDataByTimeOffset(currTime);
            }
            Flame transformedFlame = transformer.createTransformedFlame(dancingFlame, currFFT, currTime, thread.getFramesPerSecond());
            renderFlame = new FlamePreparer(prefs).createRenderFlame(transformedFlame);
            flames.add(renderFlame);
            if (time >= timeRenderStarted + nextAction.getTime()) {
                if (nextAction instanceof StopAction) {
                    break;
                } else if (nextAction instanceof FlameChangeAction) {
                    Flame nextFlame = ((FlameChangeAction) nextAction).getFlame();
                    flameStack.addFlame(nextFlame, ((FlameChangeAction) nextAction).getMorphFrameCount(), project.getMotions(nextFlame));
                    nextAction = recorder.getRecordedActions().get(actionIdx++);
                } else {
                    throw new Exception("Unknown action type <" + nextAction.getClass() + ">");
                }
            }
        }
        if (flames.size() > 0) {
            File file = new File(pAbsolutePath);
            String fn = file.getName();
            {
                int p = fn.indexOf(".flame");
                if (p > 0 && p == fn.length() - 6) {
                    fn = fn.substring(0, p);
                }
            }
            int fileIdx = 1;
            for (Flame flame : flames) {
                String hs = String.valueOf(fileIdx++);
                while (hs.length() < 5) {
                    hs = "0" + hs;
                }
                new FlameWriter().writeFlame(flame, new File(file.getParent(), fn + hs + ".flame").getAbsolutePath());
            }
        } else {
            throw new Exception("No flame files where created");
        }
    } else {
        throw new Exception("No valid recording");
    }
}
Also used : ArrayList(java.util.ArrayList) DancingFlameStack(org.jwildfire.create.tina.dance.DancingFlameStack) FlameWriter(org.jwildfire.create.tina.io.FlameWriter) DancingFlame(org.jwildfire.create.tina.dance.DancingFlame) FlamePreparer(org.jwildfire.create.tina.dance.FlamePreparer) File(java.io.File) DancingFlame(org.jwildfire.create.tina.dance.DancingFlame) Flame(org.jwildfire.create.tina.base.Flame)

Aggregations

File (java.io.File)1 ArrayList (java.util.ArrayList)1 Flame (org.jwildfire.create.tina.base.Flame)1 DancingFlame (org.jwildfire.create.tina.dance.DancingFlame)1 DancingFlameStack (org.jwildfire.create.tina.dance.DancingFlameStack)1 FlamePreparer (org.jwildfire.create.tina.dance.FlamePreparer)1 FlameWriter (org.jwildfire.create.tina.io.FlameWriter)1