ADSR and mixer devices

This commit is contained in:
りき萌 2023-05-03 17:53:37 +02:00
parent 107119741b
commit 849f12d907
28 changed files with 710 additions and 114 deletions

BIN
proj/block/adsr_front.ase Normal file

Binary file not shown.

BIN
proj/block/adsr_side.ase Normal file

Binary file not shown.

BIN
proj/block/mixer_front.ase Normal file

Binary file not shown.

BIN
proj/block/mixer_side.ase Normal file

Binary file not shown.

View file

@ -1,47 +1,53 @@
// 1.19.2 2023-05-03T14:08:42.976687848 Models
0812a674d14cfc6fbb7c0e2ac1b473bf2afe1965 assets/dawd3/models/item/brown_patch_cable.json
6e01a1aa07f3a36d7950a1b00d1bc6e9045b9995 assets/dawd3/blockstates/knob.json
bf0e322e33123cb6873c2da4e8c6ab85688deb4e assets/dawd3/models/item/gray_patch_cable.json
215b221d48639e96de11914625a770a389d65b81 assets/dawd3/models/item/green_patch_cable.json
6a9fb209d82556f5941422a8d047a0ae2af1dc8f assets/dawd3/models/item/sine_oscillator.json
48ec7ba345d918e9cdd74c026dc5d705f1679a65 assets/dawd3/models/block/amplifier.json
8ba890b28c5ac57c59f19ccc8c72825caac10677 assets/dawd3/models/item/magenta_patch_cable.json
e34001d3c974aecfa347d435beb6bc0b9d325897 assets/dawd3/models/item/cyan_patch_cable.json
// 1.19.2 2023-05-03T17:34:34.425318453 Models
ff88cf4c4547ef552e4ed2f859978e7b875c0b56 assets/dawd3/models/block/amplifier.json
c3ea3e310d8fe7796b5b055d34db712cb8c7ac5a assets/dawd3/blockstates/triangle_oscillator.json
f7b47538f17992177e97e06842c0039ae5096b2b assets/dawd3/blockstates/speaker.json
97f0b7f5e19cd8c92915c4dfdedcee0e0b2a4b7f assets/dawd3/models/item/amplifier.json
9cf2cff42345ec60a944d7399b5047323aa8e88c assets/dawd3/models/item/red_patch_cable.json
0fb5cd695c2a82a2353809529dc8b5086ee2c87d assets/dawd3/blockstates/phase.json
8c6f0307320980a66c70622b0b7c72c8cfe78dc3 assets/dawd3/models/item/light_gray_patch_cable.json
5ed33e9ec3c70e8cc027eea6425951d51487437f assets/dawd3/models/item/blue_patch_cable.json
0d899dc2bd693c95d582231a00faf40bf1d67a47 assets/dawd3/blockstates/saw_oscillator.json
a4e8bc89d39021eb8d56ad7735216cb851d67287 assets/dawd3/models/item/light_blue_patch_cable.json
8c4b8147bfea2bdb8c1d348bc332a60d2cd82d68 assets/dawd3/models/item/phase.json
aa1a1807d2c46f1f25e3d0c507952fefb5b3cd9f assets/dawd3/models/item/knob.json
d65fd7b21da2adf55a0b076103103da7e7bb453a assets/dawd3/models/block/speaker.json
df1b924ee7f1a4f9a6496f52a27d74b449ef05fc assets/dawd3/models/block/triangle_oscillator.json
d1e691559156bd4bf0ec0d488d1a28ac193f4967 assets/dawd3/blockstates/adsr.json
123ed8aa83a77b4714cee4dfc6747832cf72c75c assets/dawd3/blockstates/mixer.json
becb814a10bcf2d3e071a6479e9b2289165d0059 assets/dawd3/models/item/modulator.json
f69a4acfdf715c64f64830ce0a79aa452ad4760a assets/dawd3/models/item/saw_oscillator.json
e289094bba4daa5de7873e6af154a25f4defc16b assets/dawd3/models/block/modulator.json
32bb0e6e3bf75b9005602e8fb1042ad5d41286ad assets/dawd3/models/item/lime_patch_cable.json
bb8b84a5a98c77aaf9ee25760dfc352b760fc2d3 assets/dawd3/models/item/keyboard.json
b5cc6f4b4af952380a1539489f2e406bc6ebe5fa assets/dawd3/blockstates/amplifier.json
2a6b9e841be2ba74ff159488c86d5a569f28798b assets/dawd3/models/block/phase.json
292685c025f28911bca9252da3e4ac72998b3c7a assets/dawd3/blockstates/pulse_oscillator.json
63c9e9521285c0a1041709a42b2232517debee38 assets/dawd3/blockstates/keyboard.json
956d8f117df95cf62c8cac375cff853df96840d6 assets/dawd3/models/item/pink_patch_cable.json
9c18a8292a0c9990cd23bebf5c6191c2114ccc6d assets/dawd3/models/item/black_patch_cable.json
96135c420e211d0cfee4aff9e1ae98484b4603c4 assets/dawd3/models/block/saw_oscillator.json
67ff4ae22c5f716f1aa2b6e2dac31d12be2336d1 assets/dawd3/blockstates/modulator.json
64c9ff6a94721f17a823c9d253559e5b9e73662a assets/dawd3/models/block/sine_oscillator.json
03377aa722945c78e2746f199d558f8338f61c96 assets/dawd3/models/block/mixer.json
0812a674d14cfc6fbb7c0e2ac1b473bf2afe1965 assets/dawd3/models/item/brown_patch_cable.json
6e01a1aa07f3a36d7950a1b00d1bc6e9045b9995 assets/dawd3/blockstates/knob.json
bf0e322e33123cb6873c2da4e8c6ab85688deb4e assets/dawd3/models/item/gray_patch_cable.json
6f8a06858678d53a9e27a2e3e3e5497f6877fee4 assets/dawd3/models/item/mixer.json
215b221d48639e96de11914625a770a389d65b81 assets/dawd3/models/item/green_patch_cable.json
6a9fb209d82556f5941422a8d047a0ae2af1dc8f assets/dawd3/models/item/sine_oscillator.json
8ba890b28c5ac57c59f19ccc8c72825caac10677 assets/dawd3/models/item/magenta_patch_cable.json
e34001d3c974aecfa347d435beb6bc0b9d325897 assets/dawd3/models/item/cyan_patch_cable.json
550c0b15996732cc81c5871290b7fc2e6608c060 assets/dawd3/models/block/adsr.json
f7b47538f17992177e97e06842c0039ae5096b2b assets/dawd3/blockstates/speaker.json
9cf2cff42345ec60a944d7399b5047323aa8e88c assets/dawd3/models/item/red_patch_cable.json
8c6f0307320980a66c70622b0b7c72c8cfe78dc3 assets/dawd3/models/item/light_gray_patch_cable.json
0d899dc2bd693c95d582231a00faf40bf1d67a47 assets/dawd3/blockstates/saw_oscillator.json
8c4b8147bfea2bdb8c1d348bc332a60d2cd82d68 assets/dawd3/models/item/phase.json
8aa966337109315240614d5257eb72f959eba5d8 assets/dawd3/models/item/orange_patch_cable.json
46e362f3f96c54438c29132f76441e6cddb94564 assets/dawd3/models/block/pulse_oscillator.json
12c4bfd825b2476955afcd3bb23c1f736ce68caa assets/dawd3/models/item/yellow_patch_cable.json
aab1bce7ec4e7c7dccd3d33d4242de12b63a981d assets/dawd3/models/item/white_patch_cable.json
6cdda36e539e23acf3db70d761338e88932a6ebb assets/dawd3/models/item/purple_patch_cable.json
e3c6aacd49a6395f37047d3df31f91a18a411267 assets/dawd3/models/item/speaker.json
f69a4acfdf715c64f64830ce0a79aa452ad4760a assets/dawd3/models/item/saw_oscillator.json
e289094bba4daa5de7873e6af154a25f4defc16b assets/dawd3/models/block/modulator.json
32bb0e6e3bf75b9005602e8fb1042ad5d41286ad assets/dawd3/models/item/lime_patch_cable.json
bb8b84a5a98c77aaf9ee25760dfc352b760fc2d3 assets/dawd3/models/item/keyboard.json
b5cc6f4b4af952380a1539489f2e406bc6ebe5fa assets/dawd3/blockstates/amplifier.json
0e38af638352ff27a8ee1e42c72266ce34578db7 assets/dawd3/models/block/phase.json
292685c025f28911bca9252da3e4ac72998b3c7a assets/dawd3/blockstates/pulse_oscillator.json
63c9e9521285c0a1041709a42b2232517debee38 assets/dawd3/blockstates/keyboard.json
5d03886e98a219deed68eecf53a2453916401fc0 assets/dawd3/models/block/keyboard.json
956d8f117df95cf62c8cac375cff853df96840d6 assets/dawd3/models/item/pink_patch_cable.json
49d732a11ba0d66d716dcb6d86718075b6ccf5aa assets/dawd3/models/block/keyboard.json
2adb4f854a9f13090dffaf8ab9dfe0553cc59a80 assets/dawd3/models/item/triangle_oscillator.json
3b1811bab3ba394ba03b67ac2efc72cb35316dc8 assets/dawd3/blockstates/sine_oscillator.json
9c18a8292a0c9990cd23bebf5c6191c2114ccc6d assets/dawd3/models/item/black_patch_cable.json
8688de3eadb6579cac89522683c394f18733e614 assets/dawd3/models/block/knob.json
0afd7ba8d87444961a33cb87bba122fca5ebef8e assets/dawd3/models/block/saw_oscillator.json
67ff4ae22c5f716f1aa2b6e2dac31d12be2336d1 assets/dawd3/blockstates/modulator.json
88b188e4e2b4354de87a0d57bdc0260881438bdd assets/dawd3/models/item/adsr.json
9690e1f7ff13a8ea72a1edb87c8afd6d0a228925 assets/dawd3/models/item/pulse_oscillator.json
50023b9cff64844a4001e3e78d3f0ac828f2724a assets/dawd3/models/block/sine_oscillator.json

View file

@ -0,0 +1,19 @@
{
"variants": {
"facing=east": {
"model": "dawd3:block/adsr",
"y": 90
},
"facing=north": {
"model": "dawd3:block/adsr"
},
"facing=south": {
"model": "dawd3:block/adsr",
"y": 180
},
"facing=west": {
"model": "dawd3:block/adsr",
"y": 270
}
}
}

View file

@ -0,0 +1,19 @@
{
"variants": {
"facing=east": {
"model": "dawd3:block/mixer",
"y": 90
},
"facing=north": {
"model": "dawd3:block/mixer"
},
"facing=south": {
"model": "dawd3:block/mixer",
"y": 180
},
"facing=west": {
"model": "dawd3:block/mixer",
"y": 270
}
}
}

View file

@ -0,0 +1,102 @@
{
"parent": "block/block",
"elements": [
{
"faces": {
"down": {
"cullface": "down",
"texture": "#bottom"
},
"east": {
"cullface": "east",
"texture": "#right"
},
"north": {
"cullface": "north",
"texture": "#front"
},
"south": {
"cullface": "south",
"texture": "#back"
},
"up": {
"cullface": "up",
"rotation": 180,
"texture": "#top"
},
"west": {
"cullface": "west",
"texture": "#left"
}
},
"from": [
0.0,
0.0,
0.0
],
"to": [
16.0,
16.0,
16.0
]
},
{
"faces": {
"north": {
"cullface": "north",
"texture": "#port",
"uv": [
4.0,
0.0,
8.0,
4.0
]
}
},
"from": [
3.0,
6.0,
-0.01
],
"to": [
7.0,
10.0,
0.01
]
},
{
"faces": {
"north": {
"cullface": "north",
"texture": "#port",
"uv": [
0.0,
0.0,
4.0,
4.0
]
}
},
"from": [
9.0,
6.0,
-0.01
],
"to": [
13.0,
10.0,
0.01
]
}
],
"textures": {
"back": "dawd3:block/adsr_side",
"bottom": "dawd3:block/adsr_side",
"front": "dawd3:block/adsr_front",
"left": "dawd3:block/adsr_side",
"particle": "dawd3:block/adsr_side",
"port": "dawd3:device/port",
"right": "dawd3:block/adsr_side",
"top": "dawd3:block/adsr_side"
}
}

View file

@ -64,30 +64,6 @@
0.01
]
},
{
"faces": {
"north": {
"cullface": "north",
"texture": "#port",
"uv": [
4.0,
0.0,
8.0,
4.0
]
}
},
"from": [
3.0,
3.0,
-0.01
],
"to": [
7.0,
7.0,
0.01
]
},
{
"faces": {
"north": {
@ -111,6 +87,30 @@
7.0,
0.01
]
},
{
"faces": {
"north": {
"cullface": "north",
"texture": "#port",
"uv": [
4.0,
0.0,
8.0,
4.0
]
}
},
"from": [
3.0,
3.0,
-0.01
],
"to": [
7.0,
7.0,
0.01
]
}
],
"textures": {

View file

@ -78,13 +78,13 @@
}
},
"from": [
9.0,
9.0,
6.0,
3.0,
-0.01
],
"to": [
13.0,
13.0,
10.0,
7.0,
0.01
]
},
@ -102,13 +102,13 @@
}
},
"from": [
6.0,
3.0,
9.0,
9.0,
-0.01
],
"to": [
10.0,
7.0,
13.0,
13.0,
0.01
]
}

View file

@ -0,0 +1,126 @@
{
"parent": "block/block",
"elements": [
{
"faces": {
"down": {
"cullface": "down",
"texture": "#bottom"
},
"east": {
"cullface": "east",
"texture": "#right"
},
"north": {
"cullface": "north",
"texture": "#front"
},
"south": {
"cullface": "south",
"texture": "#back"
},
"up": {
"cullface": "up",
"rotation": 180,
"texture": "#top"
},
"west": {
"cullface": "west",
"texture": "#left"
}
},
"from": [
0.0,
0.0,
0.0
],
"to": [
16.0,
16.0,
16.0
]
},
{
"faces": {
"north": {
"cullface": "north",
"texture": "#port",
"uv": [
0.0,
0.0,
4.0,
4.0
]
}
},
"from": [
9.0,
3.0,
-0.01
],
"to": [
13.0,
7.0,
0.01
]
},
{
"faces": {
"north": {
"cullface": "north",
"texture": "#port",
"uv": [
4.0,
0.0,
8.0,
4.0
]
}
},
"from": [
3.0,
6.0,
-0.01
],
"to": [
7.0,
10.0,
0.01
]
},
{
"faces": {
"north": {
"cullface": "north",
"texture": "#port",
"uv": [
0.0,
0.0,
4.0,
4.0
]
}
},
"from": [
9.0,
9.0,
-0.01
],
"to": [
13.0,
13.0,
0.01
]
}
],
"textures": {
"back": "dawd3:block/mixer_side",
"bottom": "dawd3:block/mixer_side",
"front": "dawd3:block/mixer_front",
"left": "dawd3:block/mixer_side",
"particle": "dawd3:block/mixer_side",
"port": "dawd3:device/port",
"right": "dawd3:block/mixer_side",
"top": "dawd3:block/mixer_side"
}
}

View file

@ -55,12 +55,12 @@
},
"from": [
9.0,
3.0,
9.0,
-0.01
],
"to": [
13.0,
7.0,
13.0,
0.01
]
},
@ -79,12 +79,12 @@
},
"from": [
9.0,
9.0,
3.0,
-0.01
],
"to": [
13.0,
13.0,
7.0,
0.01
]
},

View file

@ -40,30 +40,6 @@
16.0
]
},
{
"faces": {
"north": {
"cullface": "north",
"texture": "#port",
"uv": [
0.0,
0.0,
4.0,
4.0
]
}
},
"from": [
9.0,
6.0,
-0.01
],
"to": [
13.0,
10.0,
0.01
]
},
{
"faces": {
"north": {
@ -87,6 +63,30 @@
10.0,
0.01
]
},
{
"faces": {
"north": {
"cullface": "north",
"texture": "#port",
"uv": [
0.0,
0.0,
4.0,
4.0
]
}
},
"from": [
9.0,
6.0,
-0.01
],
"to": [
13.0,
10.0,
0.01
]
}
],
"textures": {

View file

@ -40,30 +40,6 @@
16.0
]
},
{
"faces": {
"north": {
"cullface": "north",
"texture": "#port",
"uv": [
0.0,
0.0,
4.0,
4.0
]
}
},
"from": [
9.0,
6.0,
-0.01
],
"to": [
13.0,
10.0,
0.01
]
},
{
"faces": {
"north": {
@ -87,6 +63,30 @@
10.0,
0.01
]
},
{
"faces": {
"north": {
"cullface": "north",
"texture": "#port",
"uv": [
0.0,
0.0,
4.0,
4.0
]
}
},
"from": [
9.0,
6.0,
-0.01
],
"to": [
13.0,
10.0,
0.01
]
}
],
"textures": {

View file

@ -0,0 +1,3 @@
{
"parent": "dawd3:block/adsr"
}

View file

@ -0,0 +1,3 @@
{
"parent": "dawd3:block/mixer"
}

View file

@ -0,0 +1,92 @@
package net.liquidev.dawd3.audio.devices.envelope
import net.liquidev.dawd3.Mod
import net.liquidev.dawd3.audio.Audio
import net.liquidev.dawd3.audio.device.*
import net.liquidev.dawd3.audio.math.Trigger
import net.minecraft.util.Identifier
import kotlin.math.max
class AdsrDevice : Device<AdsrDevice.Controls> {
companion object : DeviceDescriptor {
override val id = Identifier(Mod.id, "adsr")
val attackControl = ControlDescriptor(id, "attack", 0.02f)
val decayControl = ControlDescriptor(id, "decay", 0.1f)
val sustainControl = ControlDescriptor(id, "sustain", 0.8f)
val releaseControl = ControlDescriptor(id, "release", 0.5f)
val triggerPort = InputPortName(id, "trigger")
val envelopePort = OutputPortName(id, "envelope")
}
class Controls : ControlSet {
val attack = FloatControl(attackControl)
val decay = FloatControl(decayControl)
val sustain = FloatControl(sustainControl)
val release = FloatControl(releaseControl)
override fun visitControls(visit: (ControlName, Control) -> Unit) {
visit(attackControl.name, attack)
visit(decayControl.name, decay)
visit(sustainControl.name, sustain)
visit(releaseControl.name, release)
}
}
private enum class State {
Attack,
Decay,
Release,
}
val trigger = InputPort()
val envelope = OutputPort(bufferCount = 1)
private val triggerDetector = Trigger()
private var envelopeValue = 0f
private var state = State.Release
override fun process(sampleCount: Int, controls: Controls) {
val triggerBuffer = trigger.getConnectedOutputBuffer(0, sampleCount)
val envelopeBuffer = envelope.buffers[0].getOrReallocate(sampleCount)
val attack = controls.attack.value
val decay = controls.decay.value
val sustain = controls.sustain.value
val release = controls.release.value
for (i in 0 until sampleCount) {
when (triggerDetector.stepEdge(triggerBuffer[i])) {
Trigger.Edge.Constant -> {}
Trigger.Edge.Rising -> state = State.Attack
Trigger.Edge.Falling -> state = State.Release
}
val envelopeDelta = when (state) {
State.Attack -> Audio.sampleRateFInv / attack
State.Decay -> Audio.sampleRateFInv / -decay
State.Release -> Audio.sampleRateFInv / -release
}
envelopeValue += envelopeDelta
envelopeValue = when (state) {
State.Attack -> if (envelopeValue >= 1f) {
state = State.Decay
1f
} else {
envelopeValue
}
State.Decay -> max(envelopeValue, sustain)
State.Release -> max(envelopeValue, 0f)
}
envelopeBuffer[i] = envelopeValue
}
}
override fun visitInputPorts(visit: (InputPortName, InputPort) -> Unit) {
visit(triggerPort, trigger)
}
override fun visitOutputPorts(visit: (OutputPortName, OutputPort) -> Unit) {
visit(envelopePort, envelope)
}
}

View file

@ -0,0 +1,54 @@
package net.liquidev.dawd3.audio.devices.math
import net.liquidev.dawd3.Mod
import net.liquidev.dawd3.audio.device.*
import net.minecraft.util.Identifier
class MixDevice : Device<MixDevice.Controls> {
companion object : DeviceDescriptor {
override val id = Identifier(Mod.id, "mix")
val aAmplitudeControl = ControlDescriptor(id, "a_amplitude", 1f)
val bAmplitudeControl = ControlDescriptor(id, "b_amplitude", 1f)
val aPort = InputPortName(id, "a")
val bPort = InputPortName(id, "b")
val outputPort = OutputPortName(id, "output")
}
class Controls : ControlSet {
val aAmplitude = FloatControl(aAmplitudeControl)
val bAmplitude = FloatControl(bAmplitudeControl)
override fun visitControls(visit: (ControlName, Control) -> Unit) {
visit(aAmplitudeControl.name, aAmplitude)
visit(bAmplitudeControl.name, bAmplitude)
}
}
val a = InputPort()
val b = InputPort()
val output = OutputPort(bufferCount = 1)
override fun process(sampleCount: Int, controls: Controls) {
val aAmplitude = controls.aAmplitude.value
val bAmplitude = controls.bAmplitude.value
val aBuffer = a.getConnectedOutputBuffer(0, sampleCount)
val bBuffer = b.getConnectedOutputBuffer(0, sampleCount)
val outputBuffer = output.buffers[0].getOrReallocate(sampleCount)
for (i in 0 until sampleCount) {
outputBuffer[i] = aBuffer[i] * aAmplitude + bBuffer[i] * bAmplitude
}
}
override fun visitInputPorts(visit: (InputPortName, InputPort) -> Unit) {
visit(aPort, a)
visit(bPort, b)
}
override fun visitOutputPorts(visit: (OutputPortName, OutputPort) -> Unit) {
visit(outputPort, output)
}
}

View file

@ -39,7 +39,6 @@ class PhaseDevice : Device<NoControls> {
phase %= 1f
if (resetTrigger.stepEdge(resetBuffer[i]) == Trigger.Edge.Rising) {
println("resetting phase")
phase = 0f
}

View file

@ -11,9 +11,11 @@ import net.liquidev.dawd3.block.device.DeviceBlock
import net.liquidev.dawd3.block.device.DeviceBlockEntity
import net.liquidev.dawd3.block.device.DeviceBlockEntityRenderer
import net.liquidev.dawd3.block.devices.SpeakerBlockDescriptor
import net.liquidev.dawd3.block.devices.envelope.AdsrBlockDescriptor
import net.liquidev.dawd3.block.devices.io.KeyboardBlockDescriptor
import net.liquidev.dawd3.block.devices.io.KnobBlockDescriptor
import net.liquidev.dawd3.block.devices.math.AmplifierBlockDescriptor
import net.liquidev.dawd3.block.devices.math.MixerBlockDescriptor
import net.liquidev.dawd3.block.devices.math.ModulatorBlockDescriptor
import net.liquidev.dawd3.block.devices.oscillator.*
import net.liquidev.dawd3.item.Items
@ -68,6 +70,7 @@ object Blocks {
val keyboard = registerDeviceBlock(KeyboardBlockDescriptor)
val amplifier = registerDeviceBlock(AmplifierBlockDescriptor)
val modulator = registerDeviceBlock(ModulatorBlockDescriptor)
val mixer = registerDeviceBlock(MixerBlockDescriptor)
val phase = registerDeviceBlock(PhaseBlockDescriptor)
val sineOscillator = registerDeviceBlock(SineOscillatorBlockDescriptor)
@ -75,6 +78,8 @@ object Blocks {
val sawOscillator = registerDeviceBlock(SawOscillatorBlockDescriptor)
val triangleOscillator = registerDeviceBlock(TriangleOscillatorBlockDescriptor)
val adsr = registerDeviceBlock(AdsrBlockDescriptor)
fun initialize() {}
fun initializeClient() {

View file

@ -0,0 +1,75 @@
package net.liquidev.dawd3.block.devices.envelope
import net.liquidev.dawd3.Mod
import net.liquidev.dawd3.audio.device.DeviceInstance
import net.liquidev.dawd3.audio.devices.envelope.AdsrDevice
import net.liquidev.dawd3.block.device.DeviceBlockDescriptor
import net.liquidev.dawd3.block.device.PhysicalPort
import net.liquidev.dawd3.ui.units.PercentageValue
import net.liquidev.dawd3.ui.units.SiValue
import net.liquidev.dawd3.ui.widget.Knob
import net.liquidev.dawd3.ui.widget.Window
import net.minecraft.client.world.ClientWorld
import net.minecraft.text.Text
import net.minecraft.util.Identifier
import net.minecraft.util.math.Vec2f
object AdsrBlockDescriptor : DeviceBlockDescriptor<AdsrBlockDescriptor.ClientState, AdsrDevice.Controls> {
override val id = Identifier(Mod.id, "adsr")
override val portLayout = PhysicalPort.layout {
port(AdsrDevice.triggerPort, position = Vec2f(0.25f, 0.5f), PhysicalPort.Side.Front)
port(AdsrDevice.envelopePort, position = Vec2f(0.75f, 0.5f), PhysicalPort.Side.Front)
}
class ClientState(controls: AdsrDevice.Controls) : DeviceBlockDescriptor.ClientState {
override val logicalDevice = DeviceInstance.create(AdsrDevice(), controls)
}
override fun initControls() = AdsrDevice.Controls()
override fun onClientLoad(controls: AdsrDevice.Controls, world: ClientWorld) =
ClientState(controls)
override val ui = object : DeviceBlockDescriptor.UI<AdsrDevice.Controls> {
override fun open(controls: AdsrDevice.Controls, x: Int, y: Int) =
Window(x, y, width = 121, height = 48, Text.translatable("block.dawd3.adsr")).apply {
children.add(
Knob(
x = 8, y = 18,
controls.attack,
min = 0f, max = 8f,
Knob.Color.Yellow,
unit = SiValue.time,
)
)
children.add(
Knob(
x = 36, y = 18,
controls.decay,
min = 0f, max = 8f,
Knob.Color.Orange,
unit = SiValue.time,
)
)
children.add(
Knob(
x = 64, y = 18,
controls.sustain,
min = 0f, max = 1f,
Knob.Color.Red,
unit = PercentageValue
)
)
children.add(
Knob(
x = 92, y = 18,
controls.release,
min = 0f, max = 8f,
Knob.Color.Purple,
unit = SiValue.time,
)
)
}
}
}

View file

@ -0,0 +1,61 @@
package net.liquidev.dawd3.block.devices.math
import net.liquidev.dawd3.Mod
import net.liquidev.dawd3.audio.device.DeviceInstance
import net.liquidev.dawd3.audio.devices.math.MixDevice
import net.liquidev.dawd3.block.device.DeviceBlockDescriptor
import net.liquidev.dawd3.block.device.PhysicalPort
import net.liquidev.dawd3.ui.units.AmplitudeValue
import net.liquidev.dawd3.ui.widget.Knob
import net.liquidev.dawd3.ui.widget.Window
import net.minecraft.client.world.ClientWorld
import net.minecraft.text.Text
import net.minecraft.util.Identifier
import net.minecraft.util.math.Vec2f
object MixerBlockDescriptor : DeviceBlockDescriptor<MixerBlockDescriptor.ClientState, MixDevice.Controls> {
override val id = Identifier(Mod.id, "mixer")
override val portLayout = PhysicalPort.layout {
port(MixDevice.aPort, position = Vec2f(0.25f, 0.25f), PhysicalPort.Side.Front)
port(MixDevice.bPort, position = Vec2f(0.25f, 0.75f), PhysicalPort.Side.Front)
port(MixDevice.outputPort, position = Vec2f(0.75f, 0.5f), PhysicalPort.Side.Front)
}
class ClientState(controls: MixDevice.Controls) : DeviceBlockDescriptor.ClientState {
override val logicalDevice = DeviceInstance.create(MixDevice(), controls)
}
override fun initControls() = MixDevice.Controls()
override fun onClientLoad(controls: MixDevice.Controls, world: ClientWorld) =
ClientState(controls)
override val ui = object : DeviceBlockDescriptor.UI<MixDevice.Controls> {
override fun open(controls: MixDevice.Controls, x: Int, y: Int) =
Window(x, y, width = 78, height = 48, Text.translatable("block.dawd3.mixer")).apply {
children.add(
Knob(
x = 14,
y = 18,
control = controls.aAmplitude,
min = 0f,
max = 1f,
color = Knob.Color.Red,
unit = AmplitudeValue,
)
)
children.add(
Knob(
x = 42,
y = 18,
control = controls.bAmplitude,
min = 0f,
max = 1f,
color = Knob.Color.Red,
unit = AmplitudeValue,
)
)
}
}
}

View file

@ -26,3 +26,27 @@ object PercentageValue : FloatUnit {
override fun display(value: Float) =
String.format("%d%%", (value * 100f).roundToInt())
}
class SiValue(val unit: String) : FloatUnit {
override fun display(value: Float): String {
val divided: Float =
if (value > 1_000_000_000_000) value / 1_000_000_000_000
else if (value > 1_000_000_000) value / 1_000_000_000
else if (value > 1_000_000) value / 1_000_000
else if (value > 1_000) value / 1_000
else if (value < 1) value * 1_000
else value
val prefix =
if (value > 1_000_000_000_000) "T"
else if (value > 1_000_000_000) "G"
else if (value > 1_000_000) "M"
else if (value > 1_000) "k"
else if (value < 1) "m"
else ""
return String.format("%.01f %s%s", divided, prefix, unit)
}
companion object {
val time = SiValue("s")
}
}

View file

@ -16,9 +16,11 @@
"item.dawd3.green_patch_cable": "Green Patch Cable",
"item.dawd3.red_patch_cable": "Red Patch Cable",
"item.dawd3.black_patch_cable": "Black Patch Cable",
"block.dawd3.adsr": "ADSR",
"block.dawd3.amplifier": "Amplifier",
"block.dawd3.keyboard": "Keyboard",
"block.dawd3.knob": "Knob",
"block.dawd3.mixer": "Mixer",
"block.dawd3.modulator": "Modulator",
"block.dawd3.phase": "Phase",
"block.dawd3.pulse_oscillator": "Pulse Oscillator",
@ -27,9 +29,15 @@
"block.dawd3.sine_oscillator": "Sine Oscillator",
"block.dawd3.triangle_oscillator": "Triangle Oscillator",
"screen.dawd3.rack.title": "Rack",
"dawd3.control.dawd3.adsr.attack": "ATT",
"dawd3.control.dawd3.adsr.decay": "DEC",
"dawd3.control.dawd3.adsr.sustain": "SUS",
"dawd3.control.dawd3.adsr.release": "REL",
"dawd3.control.dawd3.amplifier.amplitude": "AMP",
"dawd3.control.dawd3.amplifier.amplitude_cv": "CV",
"dawd3.control.dawd3.constant.value": "",
"dawd3.control.dawd3.fma.add": "ADD",
"dawd3.control.dawd3.fma.multiply": "MUL"
"dawd3.control.dawd3.fma.multiply": "MUL",
"dawd3.control.dawd3.mix.a_amplitude": "A",
"dawd3.control.dawd3.mix.b_amplitude": "B"
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 293 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 256 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 294 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 262 B