aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/org/openrndr/Preload.kt
blob: 0fd1656ff0bd050a2c0b0fc2337dd10613920469 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package org.openrndr

import org.openrndr.draw.*
import org.openrndr.extensions.SingleScreenshot
import org.openrndr.extra.olive.*
import org.openrndr.ffmpeg.ScreenRecorder
import phenax.utils.*

class Preload : ApplicationPreload() {
  override fun onProgramSetup(program: Program) {
    println("Program: ${program.name}")
    val fileSuffix =
            if (System.getenv("PHENAX_FILE_SUFFIX").isNullOrEmpty()) {
              ""
            } else {
              ".${System.getenv("PHENAX_FILE_SUFFIX") ?: ""}"
            }
    if (recordingEnabled) {
      program.extend(ScreenRecorder()) {
        outputToVideo = true
        outputFile = "video/${program.name}${fileSuffix}.mp4"
        frameRate = 60
        maximumDuration = recordDuration()
        quitAfterMaximum = true
        multisample = BufferMultisample.SampleCount(16)
      }
    } else if (screenshotEnabled) {
      program.extend(SingleScreenshot()) {
        outputFile = "screenshot/${program.name}${fileSuffix}.png"
        async = false
        quitAfterScreenshot = true
      }
    }
  }
}