Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sem002 #52

Merged
merged 18 commits into from
Apr 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ build/
out/
*.iml
local.properties
visuals/data/midi
visuals/data/movies
visuals/data/music
*.log
data/midi/
data/music/
data/videoexport/
*.log
ffmpeg.txt
ffmpeg-audio.txt
7 changes: 4 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm") version "1.4.0"
kotlin("plugin.serialization") version "1.4.0"
kotlin("jvm") version "1.4.31"
kotlin("plugin.serialization") version "1.4.31"
}

group = ProjectSettings.group
Expand All @@ -29,4 +29,5 @@ tasks {
val compileKotlin: KotlinCompile by tasks
compileKotlin.kotlinOptions {
freeCompilerArgs = listOf("-Xinline-classes")
}
useIR = true
}
4 changes: 0 additions & 4 deletions core/src/main/kotlin/dev/matsem/astral/core/di/CoreModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import dev.matsem.astral.core.tools.midi.MidiFileParser
import dev.matsem.astral.core.tools.midi.MidiPlayer
import dev.matsem.astral.core.tools.midi.MidiRecorder
import dev.matsem.astral.core.tools.osc.OscManager
import dev.matsem.astral.core.tools.pixelsort.PixelSorter
import dev.matsem.astral.core.tools.shapes.ExtrusionCache
import dev.matsem.astral.core.tools.videoexport.FFTSerializer
import dev.matsem.astral.core.tools.videoexport.VideoExporter
Expand Down Expand Up @@ -44,9 +43,6 @@ val coreModule = module {
single { extruder.extruder(get()) }
single { ExtrusionCache(get(), get()) }

// Effects
single { PixelSorter() }

// VideoExporter
single { VideoExport(get()) }
single { FFTSerializer(get(), get()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,30 @@ import processing.core.PApplet.min
import processing.core.PConstants
import processing.core.PVector

/**
* Returns horizontal center of this [PApplet]'s window in pixels.
*/
fun PApplet.centerX() = this.width / 2f

/**
* Returns vertical center of this [PApplet]'s window in pixels.
*/
fun PApplet.centerY() = this.height / 2f

/**
* Translates the current transformation matrix to the center
* of this [PApplet]'s window in 2D space (does not translate in Z dimension).
*/
fun PApplet.translateCenter() = translate(centerX(), centerY())

/**
* Returns the smaller pixel dimension of this [PApplet]'s window.
*/
fun PApplet.shorterDimension(): Int = min(width, height)

/**
* Returns the bigger pixel dimension of this [PApplet]'s window.
*/
fun PApplet.longerDimension(): Int = max(width, height)

/**
Expand All @@ -29,6 +45,9 @@ fun PApplet.angularTimeS(periodSeconds: Float) = millis() / 1000f * PConstants.T
@Deprecated("Use AnimationHandler to generate the value")
fun PApplet.angularTimeHz(hz: Float) = millis() / 1000f * PConstants.TWO_PI / (1f / hz)

/**
* Translates the current transformation matrix according to offsets passed in [vector].
*/
fun PApplet.translate(vector: PVector) = translate(vector.x, vector.y, vector.z)

fun PApplet.rotate(vector: PVector) {
Expand All @@ -43,10 +62,10 @@ fun PApplet.pushPop(block: PApplet.() -> Unit) {
pop()
}

fun PApplet.drawShape(closeMode: Int, block: PApplet.() -> Unit) {
beginShape()
fun PApplet.drawShape(kind: Int? = null, closeMode: Int? = null, block: PApplet.() -> Unit) {
kind?.let { beginShape(it) } ?: beginShape()
this.block()
endShape(closeMode)
closeMode?.let { endShape(it) } ?: endShape()
}

fun PApplet.colorModeHsb() = colorMode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ operator fun PVector.minusAssign(anotherVector: PVector) {
sub(anotherVector)
}

operator fun PVector.plus(anotherVector: PVector): PVector = add(anotherVector)

fun PVector.toVec2() = Vec2(x, y)

fun PVector.isInRadius(threshold: Float): Boolean = x.absoluteValue <= threshold && y.absoluteValue <= threshold

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ExtrusionCache(

private val textCache = mutableMapOf<String, Array<PShape>>()

fun getText(text: String, fontSize: Int = 48): Array<PShape> {
fun getText(text: String, fontSize: Int = 48, depth: Int = 20): Array<PShape> {
return textCache.getOrPut(text) {

val rShape = RG.getText(text, Files.Font.FFF_FORWARD, fontSize, PApplet.CENTER)
Expand All @@ -59,9 +59,9 @@ class ExtrusionCache(
RG.setPolygonizerStep(1f)

val letters = rShape.children
val depth = 50

letters
.asSequence()
.map { it.points }
.map { points ->
sketch.createShape().apply {
Expand All @@ -72,8 +72,9 @@ class ExtrusionCache(
endShape(PApplet.CLOSE)
}
}
.flatMap { ex.extrude(it, 20, "box").toList() }
.flatMap { ex.extrude(it, depth, "box").toList() }
.onEach { it.translate(0f, fontSize / 2f, -depth / 2f) }
.toList()
.toTypedArray()
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package dev.matsem.astral.core.tools.videoexport

import com.hamoid.VideoExport
import dev.matsem.astral.core.tools.animations.AnimationHandler
import dev.matsem.astral.core.tools.audio.AudioProcessor
import dev.matsem.astral.core.tools.audio.BeatDetectData
import processing.core.PApplet
import java.io.BufferedReader
import java.io.File
import java.io.IOException
import kotlin.properties.Delegates

Expand All @@ -19,6 +21,11 @@ class VideoExporter(
private val audioProcessor: AudioProcessor
) {

companion object {
const val EXPORT_PATH = "data/videoexport"
const val VIDEO_FILE_EXTENSION = ".mp4"
}

private var frameDuration: Float by Delegates.notNull()
private var dryRun: Boolean by Delegates.notNull()
private var audioGain: Float = 1f
Expand All @@ -30,15 +37,23 @@ class VideoExporter(
/**
* Initialization method. When called, prepares the video exporter for movie export and video
* will be exported starting from the first frame.
*
* Call in the sketch setup() method and move your draw logic to [draw] lambda.
* Note, that you still have to override the parent's [draw] method, but leave it empty in order for this to work
* (super.draw() must not be called).
*
* When using [AnimationHandler], don't forget to provide it with
* exporter's [videoMillis] instead of [PApplet.millis].
*
* Video will be exported in [EXPORT_PATH] = <project-dir>/data/videoexport
* directory using provided [outputVideoFileName].
*/
fun prepare(
audioFilePath: String,
movieFps: Float,
audioGain: Float = 1f,
dryRun: Boolean,
audioGain: Float = 1f,
outputVideoFileName: String = "export.mp4",
draw: PApplet.() -> Unit
) {
this.dryRun = dryRun
Expand All @@ -59,6 +74,8 @@ class VideoExporter(
fileReader = parent.createReader(parent.dataPath("$audioFilePath.txt"))
println("Sound analysis done")

File(EXPORT_PATH).mkdirs()
videoExport.setMovieFileName("$EXPORT_PATH/${outputVideoFileName.withFileExtension()}")
videoExport.startMovie()
}
}
Expand Down Expand Up @@ -139,4 +156,13 @@ class VideoExporter(
* Returns the duration of the movie (so far) in milliseconds.
*/
fun videoMillis(): Int = if (dryRun) parent.millis() else (videoExport.currentTime * 1000).toInt()

/**
* Adds [VIDEO_FILE_EXTENSION] to file name if file name without extension
* was provided.
*/
private fun String.withFileExtension() = when {
this.endsWith(VIDEO_FILE_EXTENSION) -> this
else -> "$this$VIDEO_FILE_EXTENSION"
}
}
Binary file removed data/lenna.png
Binary file not shown.
Binary file removed data/music/proximity-clip.wav
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dev.matsem.astral.playground

import dev.matsem.astral.core.di.coreModule
import dev.matsem.astral.playground.sketches.Proximity
import dev.matsem.astral.playground.sketches.StillJazzy
import org.koin.core.KoinComponent
import org.koin.core.context.startKoin
import org.koin.core.inject
Expand All @@ -27,7 +27,7 @@ class PlaygroundApp : KoinComponent {
fun run(processingArgs: Array<String>) {
startKoin {
printLogger(Level.ERROR)
modules(coreModule + playgroundModule { Proximity() })
modules(coreModule + playgroundModule { StillJazzy() })
}

PApplet.runSketch(processingArgs + arrayOf("ProcessingPlayground"), sketch)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ import processing.core.PApplet
import processing.core.PConstants
import processing.core.PVector

/**
* Visual for SEM001 release: Proximity / 40W by Johney.
* https://semfree.bandcamp.com/album/proximity-40w
*
* Was also used to generate artwork for the first version of Soul Ex Machina slipmats.
*/
class Proximity : PApplet(), KoinComponent, AnimationHandler {

private val ec: ExtrusionCache by inject()
Expand Down
Loading