Skip to content

Commit

Permalink
Rename "Shader Channel" to "Stream".
Browse files Browse the repository at this point in the history
  • Loading branch information
xian committed Jul 5, 2022
1 parent 6224d4b commit 0543ac7
Show file tree
Hide file tree
Showing 39 changed files with 627 additions and 575 deletions.
2 changes: 1 addition & 1 deletion src/commonMain/kotlin/baaahs/app/ui/PlatformIcons.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface PlatformIcons {
val Patch: Icon
val DataSource: Icon
val Layout: Icon
val ShaderChannel: Icon
val Stream: Icon
val Settings: Icon
val None: Icon

Expand Down
4 changes: 2 additions & 2 deletions src/commonMain/kotlin/baaahs/app/ui/editor/LinkOption.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class PortLinkOption(
private val mutablePort: MutablePort,
val isPluginRef: Boolean = false,
val wasPurposeBuilt: Boolean = false,
val isShaderChannel: Boolean = false,
val isStream: Boolean = false,
val isLocalShaderOut: Boolean = false,
val isPluginSuggestion: Boolean = false,
val isExactContentType: Boolean = false,
Expand All @@ -39,7 +39,7 @@ class PortLinkOption(
isPluginRef,
createsFilter && isExactContentType,
wasPurposeBuilt && isExactContentType,
isShaderChannel,
isStream,
isLocalShaderOut,
isPluginSuggestion,
isExactContentType,
Expand Down
20 changes: 10 additions & 10 deletions src/commonMain/kotlin/baaahs/gl/Toolchain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import baaahs.gl.patch.*
import baaahs.gl.shader.OpenShader
import baaahs.plugin.Plugins
import baaahs.show.Shader
import baaahs.show.ShaderChannel
import baaahs.show.Stream
import baaahs.show.mutable.MutablePatch
import baaahs.show.mutable.MutablePort
import baaahs.show.mutable.MutableShow
Expand All @@ -33,14 +33,14 @@ interface Toolchain {
fun autoWire(
shaders: Collection<OpenShader>,
defaultPorts: Map<ContentType, MutablePort> = emptyMap(),
shaderChannel: ShaderChannel = ShaderChannel.Main,
stream: Stream = Stream.Main,
fixtureTypes: Collection<FixtureType> = emptyList()
): UnresolvedPatches

fun autoWire(
openShader: OpenShader,
defaultPorts: Map<ContentType, MutablePort> = emptyMap(),
shaderChannel: ShaderChannel = ShaderChannel.Main,
stream: Stream = Stream.Main,
fixtureTypes: Collection<FixtureType> = emptyList()
): UnresolvedPatch
}
Expand Down Expand Up @@ -92,11 +92,11 @@ class RootToolchain(
parentMutableShow: MutableShow,
mutablePatch: MutablePatch
): PatchOptions = stats.autoWire.time {
val channelsInfo = ChannelsInfo(parentMutableShow, emptyList(), this)
val streamsInfo = StreamsInfo(parentMutableShow, emptyList(), this)
PatchOptions(
currentOpenShader,
ShaderChannel.Main,
channelsInfo,
Stream.Main,
streamsInfo,
currentLinks = mutablePatch.incomingLinks,
plugins = plugins
)
Expand All @@ -105,18 +105,18 @@ class RootToolchain(
override fun autoWire(
shaders: Collection<OpenShader>,
defaultPorts: Map<ContentType, MutablePort>,
shaderChannel: ShaderChannel,
stream: Stream,
fixtureTypes: Collection<FixtureType>
): UnresolvedPatches =
autoWirer.autoWire(shaders, shaderChannel, defaultPorts, fixtureTypes)
autoWirer.autoWire(shaders, stream, defaultPorts, fixtureTypes)

override fun autoWire(
openShader: OpenShader,
defaultPorts: Map<ContentType, MutablePort>,
shaderChannel: ShaderChannel,
stream: Stream,
fixtureTypes: Collection<FixtureType>
): UnresolvedPatch =
autoWirer.autoWire(openShader, shaderChannel, defaultPorts, fixtureTypes)
autoWirer.autoWire(openShader, stream, defaultPorts, fixtureTypes)
}

class CachingToolchain(
Expand Down
14 changes: 7 additions & 7 deletions src/commonMain/kotlin/baaahs/gl/ToolchainExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import baaahs.gl.patch.UnresolvedPatch
import baaahs.gl.patch.UnresolvedPatches
import baaahs.gl.shader.OpenShader
import baaahs.show.Shader
import baaahs.show.ShaderChannel
import baaahs.show.Stream
import baaahs.show.mutable.MutablePort
import baaahs.show.mutable.MutableShader

Expand All @@ -19,29 +19,29 @@ fun Toolchain.openShader(mutableShader: MutableShader): OpenShader =
fun Toolchain.autoWire(
vararg shaders: Shader,
defaultPorts: Map<ContentType, MutablePort> = emptyMap(),
shaderChannel: ShaderChannel = ShaderChannel.Main,
stream: Stream = Stream.Main,
fixtureTypes: Collection<FixtureType> = emptyList()
): UnresolvedPatches {
val openShaders = shaders.map { openShader(it) }
return autoWire(openShaders, defaultPorts, shaderChannel, fixtureTypes)
return autoWire(openShaders, defaultPorts, stream, fixtureTypes)
}

fun Toolchain.autoWire(
shader: Shader,
defaultPorts: Map<ContentType, MutablePort> = emptyMap(),
shaderChannel: ShaderChannel = ShaderChannel.Main,
stream: Stream = Stream.Main,
fixtureTypes: Collection<FixtureType> = emptyList()
): UnresolvedPatch {
val openShader = openShader(shader)
return autoWire(openShader, defaultPorts, shaderChannel, fixtureTypes)
return autoWire(openShader, defaultPorts, stream, fixtureTypes)
}

fun Toolchain.autoWire(
vararg shaders: OpenShader,
defaultPorts: Map<ContentType, MutablePort> = emptyMap(),
shaderChannel: ShaderChannel = ShaderChannel.Main,
stream: Stream = Stream.Main,
fixtureTypes: Collection<FixtureType> = emptyList()
): UnresolvedPatches =
autoWire(shaders.toList(), defaultPorts, shaderChannel, fixtureTypes)
autoWire(shaders.toList(), defaultPorts, stream, fixtureTypes)

fun Toolchain.withCache(name: String) = CachingToolchain(this, name)
24 changes: 12 additions & 12 deletions src/commonMain/kotlin/baaahs/gl/patch/AutoWirer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package baaahs.gl.patch
import baaahs.device.FixtureType
import baaahs.gl.shader.OpenShader
import baaahs.plugin.Plugins
import baaahs.show.ShaderChannel
import baaahs.show.Stream
import baaahs.show.live.OpenPatch
import baaahs.show.live.OpenShow
import baaahs.show.mutable.MutablePort
Expand All @@ -12,56 +12,56 @@ import baaahs.show.mutable.MutableShader
class AutoWirer(private val plugins: Plugins) {
fun autoWire(
shaders: Collection<OpenShader>,
shaderChannel: ShaderChannel = ShaderChannel.Main,
stream: Stream = Stream.Main,
defaultPorts: Map<ContentType, MutablePort> = emptyMap(),
fixtureTypes: Collection<FixtureType> = emptyList()
): UnresolvedPatches {
val siblingPatches = shaders.map {
OpenPatch(it, emptyMap(), shaderChannel, 0f)
OpenPatch(it, emptyMap(), stream, 0f)
}

val parentShow = null as OpenShow? // TODO: test with non-null?
val channelsInfo = ChannelsInfo(
val streamsInfo = StreamsInfo(
parentShow, if (fixtureTypes.isEmpty()) plugins.fixtureTypes.all else fixtureTypes
)

// First pass: gather shader output ports.
val unresolvedPatches =
shaders.associateWith { openShader ->
autoWire(openShader, shaderChannel, channelsInfo, defaultPorts)
autoWire(openShader, stream, streamsInfo, defaultPorts)
}

return UnresolvedPatches(unresolvedPatches.values.toList())
}

fun autoWire(
openShader: OpenShader,
shaderChannel: ShaderChannel = ShaderChannel.Main,
stream: Stream = Stream.Main,
defaultPorts: Map<ContentType, MutablePort> = emptyMap(),
fixtureTypes: Collection<FixtureType> = emptyList()
): UnresolvedPatch {
val parentShow = null as OpenShow? // TODO: test with non-null?
val channelsInfo = ChannelsInfo(
val streamsInfo = StreamsInfo(
parentShow, if (fixtureTypes.isEmpty()) plugins.fixtureTypes.all else fixtureTypes
)

return autoWire(openShader, shaderChannel, channelsInfo, defaultPorts)
return autoWire(openShader, stream, streamsInfo, defaultPorts)
}

private fun autoWire(
openShader: OpenShader,
shaderChannel: ShaderChannel,
channelsInfo: ChannelsInfo,
stream: Stream,
streamsInfo: StreamsInfo,
defaultPorts: Map<ContentType, MutablePort>
): UnresolvedPatch {
val patchOptions =
PatchOptions(openShader, shaderChannel, channelsInfo, defaultPorts, emptyMap(), plugins)
PatchOptions(openShader, stream, streamsInfo, defaultPorts, emptyMap(), plugins)
return UnresolvedPatch(
MutableShader(openShader.shader),
openShader.inputPorts.associateWith { inputPort ->
patchOptions.inputPortLinkOptions[inputPort.id]?.toMutableList() ?: mutableListOf()
},
shaderChannel,
stream,
0f
)
}
Expand Down
56 changes: 28 additions & 28 deletions src/commonMain/kotlin/baaahs/gl/patch/PatchOptions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,36 @@ import baaahs.gl.openShader
import baaahs.gl.shader.InputPort
import baaahs.gl.shader.OpenShader
import baaahs.plugin.Plugins
import baaahs.show.ShaderChannel
import baaahs.show.Stream
import baaahs.show.live.OpenPatch
import baaahs.show.live.OpenShow
import baaahs.show.live.OpenShowVisitor
import baaahs.show.mutable.*
import baaahs.util.Logger

class ChannelsInfo {
internal val shaderChannels: MutableMap<ContentType, MutableSet<MutableShaderChannel>>
class StreamsInfo {
internal val streams: MutableMap<ContentType, MutableSet<MutableStream>>
internal val fixtureTypes: Collection<FixtureType>

constructor(
parentShow: OpenShow? = null,
fixtureTypes: Collection<FixtureType>
) {
val shaderChannels = shaderChannelsFromFixtureTypes(fixtureTypes)
val streams = streamsFromFixtureTypes(fixtureTypes)

parentShow?.let {
object : OpenShowVisitor() {
override fun visitPatch(openPatch: OpenPatch) {
super.visitPatch(openPatch)

val contentType = openPatch.shader.outputPort.contentType
shaderChannels.getOrPut(contentType, ::mutableSetOf)
.add(openPatch.shaderChannel.toMutable())
streams.getOrPut(contentType, ::mutableSetOf)
.add(openPatch.stream.toMutable())
}
}.visitShow(parentShow)
}

this.shaderChannels = shaderChannels
this.streams = streams
this.fixtureTypes = fixtureTypes
}

Expand All @@ -47,49 +47,49 @@ class ChannelsInfo {
fixtureTypes: Collection<FixtureType>,
toolchain: Toolchain
) {
val shaderChannels = shaderChannelsFromFixtureTypes(fixtureTypes)
val streams = streamsFromFixtureTypes(fixtureTypes)

parentMutableShow?.accept(object : MutableShowVisitor {
override fun visit(mutablePatch: MutablePatch) {
try {
val shader = mutablePatch.mutableShader.build()
val contentType = toolchain.openShader(shader).outputPort.contentType
shaderChannels.getOrPut(contentType, ::mutableSetOf)
.add(mutablePatch.shaderChannel)
streams.getOrPut(contentType, ::mutableSetOf)
.add(mutablePatch.stream)
} catch (e: Exception) {
// It's okay, just ignore it.
}
}
})
this.shaderChannels = shaderChannels
this.streams = streams
this.fixtureTypes = fixtureTypes
}

private fun shaderChannelsFromFixtureTypes(fixtureTypes: Collection<FixtureType>): MutableMap<ContentType, MutableSet<MutableShaderChannel>> {
val shaderChannels = mutableMapOf<ContentType, MutableSet<MutableShaderChannel>>()
private fun streamsFromFixtureTypes(fixtureTypes: Collection<FixtureType>): MutableMap<ContentType, MutableSet<MutableStream>> {
val streams = mutableMapOf<ContentType, MutableSet<MutableStream>>()

val likelyPipelineArtifactTypes = fixtureTypes.flatMap { it.likelyPipelines }.map { it.second }
likelyPipelineArtifactTypes.forEach { contentType ->
shaderChannels.getOrPut(contentType, ::mutableSetOf)
.add(ShaderChannel.Main.toMutable())
streams.getOrPut(contentType, ::mutableSetOf)
.add(Stream.Main.toMutable())
}
return shaderChannels
return streams
}

operator fun get(contentType: ContentType): Set<MutableShaderChannel>? {
return shaderChannels[contentType]
operator fun get(contentType: ContentType): Set<MutableStream>? {
return streams[contentType]
}
}

class PatchOptions(
shader: OpenShader,
val shaderChannel: ShaderChannel = ShaderChannel.Main,
channelsInfo: ChannelsInfo,
val stream: Stream = Stream.Main,
streamsInfo: StreamsInfo,
defaultPorts: Map<ContentType, MutablePort> = emptyMap(),
currentLinks: Map<String, MutablePort>,
private val plugins: Plugins
) {
val shaderChannels: List<MutableShaderChannel>
val streams: List<MutableStream>
val inputPortLinkOptions: Map<String, List<LinkOption>>

init {
Expand All @@ -113,19 +113,19 @@ class PatchOptions(
)
} else {
PortLinkOption(
MutableShaderChannel(shaderChannel.id),
MutableStream(stream.id),
isExactContentType = isExactContentType,
isDefaultBinding = true,
)
}
)

channelsInfo[contentType]?.forEach { mutableShaderChannel ->
streamsInfo[contentType]?.forEach { mutableStream ->
options.add(
PortLinkOption(
// TODO: this is dumb and broken.
mutableShaderChannel,
isShaderChannel = true,
mutableStream,
isStream = true,
isExactContentType = isExactContentType
)
)
Expand All @@ -134,9 +134,9 @@ class PatchOptions(
if (contentType == shader.outputPort.contentType) {
options.add(
PortLinkOption(
shaderChannel.toMutable(),
stream.toMutable(),
createsFilter = true,
isShaderChannel = true,
isStream = true,
isExactContentType = isExactContentType
)
)
Expand Down Expand Up @@ -171,7 +171,7 @@ class PatchOptions(
inputPort.id to sortedOptions
}

this.shaderChannels = channelsInfo.shaderChannels.values.flatten().sortedBy { it.title }
this.streams = streamsInfo.streams.values.flatten().sortedBy { it.title }
this.inputPortLinkOptions = map
}

Expand Down
Loading

0 comments on commit 0543ac7

Please sign in to comment.