Skip to content

Commit

Permalink
Set default channel values for fixtures that aren't included in the c…
Browse files Browse the repository at this point in the history
…urrent scene.
  • Loading branch information
spensbot committed Jun 22, 2024
1 parent 0e60eca commit abb831c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 33 deletions.
44 changes: 13 additions & 31 deletions src/main/engine/dmxEngine.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import {
DMX_MAX_VALUE,
DMX_DEFAULT_VALUE,
DMX_NUM_CHANNELS,
FlattenedFixture,
} from '../../shared/dmxFixtures'
import { Params } from '../../shared/params'
import { RandomizerState } from '../../shared/randomizer'
import { CleanReduxState } from '../../renderer/redux/store'
import {
getDmxValue,
getFixturesInGroups,
flatten_fixtures,
forEachChannel,
getDefaultDmxValue,
} from '../../shared/dmxUtil'
import { indexArray, zip } from '../../shared/util'
import { TimeState } from '../../shared/TimeState'
Expand All @@ -24,38 +22,18 @@ export function calculateDmx(
const universe = state.dmx.universe
const all_fixtures = flatten_fixtures(universe, state.dmx.fixtureTypesByID)

// All channels start at 0
let channels = Array(DMX_NUM_CHANNELS).fill(0)

if (timeState.isPlaying) {
// Set each channel to it's default value
forEachChannel(all_fixtures, (_fixtureIdx, _fixture, channelIdx, channel) => {
channels[channelIdx] = getDefaultDmxValue(channel)
})

const scenes = state.control.light
const activeScene = scenes.byId[scenes.active]

const applyFixtures = (
fixtures: FlattenedFixture[],
outputParams: Params,
randomizerState: RandomizerState
) => {
fixtures.forEach((fixture, i) => {
fixture.channels.forEach(([outputChannel, channelType]) => {
let new_channel_value = DMX_DEFAULT_VALUE
let current_channel_value = channels[outputChannel - 1]
if (fixture.intensity <= (outputParams.intensity ?? 1)) {
new_channel_value = getDmxValue(
channelType,
outputParams,
fixture,
state.control.master,
randomizerState[i]?.level ?? 1
)
}
channels[outputChannel - 1] = Math.max(
new_channel_value,
current_channel_value
)
})
})
}

for (const [{ outputParams, randomizer }, splitScene] of zip(
splitStates,
activeScene.splitScenes
Expand All @@ -64,7 +42,11 @@ export function calculateDmx(

const splitSceneFixtures = getFixturesInGroups(all_fixtures, splitGroups)

applyFixtures(splitSceneFixtures, outputParams, randomizer)
// Set each channel based on active scene fixtures
forEachChannel(splitSceneFixtures, (fixtureIdx, fixture, channelIdx, channel) => {
const randomizerLevel = randomizer[fixtureIdx]?.level ?? 1
channels[channelIdx] = getDmxValue(channel, outputParams, fixture, state.control.master, randomizerLevel)
})
}

// Apply any overwrites
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/pages/Mixer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import StatusBar from '../menu/StatusBar'
import React from 'react'
import useHover from 'renderer/hooks/useHover'
import {
DMX_MAX_VALUE,
DMX_NUM_CHANNELS,
FixtureChannel,
FixtureType,
Expand Down Expand Up @@ -68,7 +67,8 @@ function Header() {
(state) => state.mixer.overwrites.length > 0
)
const canGoBack = _s.pageIndex > 0
const canGoForward = (_s.pageIndex + 1) * _s.channelsPerPage < DMX_MAX_VALUE
const canGoForward =
(_s.pageIndex + 1) * _s.channelsPerPage < DMX_NUM_CHANNELS

return (
<HeaderRoot>
Expand Down
23 changes: 23 additions & 0 deletions src/shared/dmxUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,29 @@ export function applyMirror(
return (mirroredDoubleNorm + 1) / 2
}

export function forEachChannel(fixtures: FlattenedFixture[], cb: (fixtureIdx: number, fixture: FlattenedFixture, channelIdx: number, channel: FixtureChannel) => void) {
fixtures.forEach((fixture, fixtureIdx) => {
fixture.channels.forEach(([channelNumber, channel]) => {
cb(fixtureIdx, fixture, channelNumber - 1, channel)
})
})
}

export function getDefaultDmxValue(
ch: FixtureChannel,
): DmxValue {
switch (ch.type) {
case 'master':
return ch.min
case 'axis':
return lerp(ch.min, ch.max, 0.5)
case 'custom':
return ch.default
default: // 'color' | 'strobe' | 'colorMap'
return DMX_DEFAULT_VALUE
}
}

export function getDmxValue(
ch: FixtureChannel,
params: Params,
Expand Down

0 comments on commit abb831c

Please sign in to comment.