Skip to content

Commit

Permalink
Working audio mixer, speaker, audio player
Browse files Browse the repository at this point in the history
  • Loading branch information
Rushmead committed Jan 1, 2025
1 parent bb32d41 commit 6236de9
Show file tree
Hide file tree
Showing 95 changed files with 2,847 additions and 765 deletions.
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id "architectury-plugin" version "3.4-SNAPSHOT"
id "dev.architectury.loom" version "1.6-SNAPSHOT" apply false
id "dev.architectury.loom" version "1.7-SNAPSHOT" apply false
id 'io.github.juuxel.loom-quiltflower' version '1.10.0' apply false
id "me.modmuss50.mod-publish-plugin" version "0.4.5" apply false
}
Expand Down Expand Up @@ -55,6 +55,10 @@ allprojects {
maven { url 'https://jitpack.io' }
mavenCentral()
mavenLocal()
// Lavaplayer
maven {
url 'https://m2.dv8tion.net/releases'
}
// Add repositories to retrieve artifacts from in here.
// You should only use this when depending on other mods because
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
Expand Down
3 changes: 3 additions & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ dependencies {
//Opus JNI
implementation rootProject.files("libs/opus-jni-java-1.0.3.jar")
shadowCommon rootProject.files("libs/opus-jni-java-1.0.3.jar")

implementation 'com.sedmelluq:lavaplayer:1.3.77'
shadowCommon 'com.sedmelluq:lavaplayer:1.3.77'
}

publishing {
Expand Down
16 changes: 8 additions & 8 deletions common/src/main/java/dev/imabad/theatrical/Theatrical.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,20 @@
import dev.imabad.theatrical.config.ConfigHandler;
import dev.imabad.theatrical.config.TheatricalConfig;
import dev.imabad.theatrical.dmx.DMXDevice;
import dev.imabad.theatrical.dmx.DMXNetwork;
import dev.imabad.theatrical.dmx.DMXNetworkData;
import dev.imabad.theatrical.networks.AVNetwork;
import dev.imabad.theatrical.fixtures.Fixtures;
import dev.imabad.theatrical.items.Items;
import dev.imabad.theatrical.mixin.ArgumentTypeInfosAccessor;
import dev.imabad.theatrical.net.TheatricalNet;
import dev.imabad.theatrical.net.artnet.ListConsumers;
import dev.imabad.theatrical.networks.AVNetworkData;
import net.minecraft.commands.synchronization.ArgumentTypeInfo;
import net.minecraft.commands.synchronization.SingletonArgumentInfo;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.ItemStack;
Expand Down Expand Up @@ -70,11 +69,11 @@ public static void init() {
argTypes.register();
dev.imabad.theatrical.items.Items.ITEMS.register();
PlayerEvent.PLAYER_JOIN.register((event) -> {
DMXNetworkData instance = DMXNetworkData.getInstance(event.server.overworld());
for (DMXNetwork network : instance.getNetworksForPlayer(event.connection.player.getUUID())) {
for (Integer universe : network.getUniverses()) {
AVNetworkData instance = AVNetworkData.getInstance(event.server.overworld());
for (AVNetwork network : instance.getNetworksForPlayer(event.connection.player.getUUID())) {
for (Integer universe : network.getDmxHandler().getUniverses()) {
List<DMXDevice> devices = new ArrayList<>();
network.getConsumers(universe).forEach(consumer -> {
network.getDmxHandler().getConsumers(universe).forEach(consumer -> {
devices.add(new DMXDevice(consumer.getDeviceId(), consumer.getChannelStart(),
consumer.getChannelCount(), consumer.getDeviceTypeId(), consumer.getActivePersonality(), consumer.getModelName(),
consumer.getFixtureId()));
Expand All @@ -85,7 +84,8 @@ public static void init() {
});
LifecycleEvent.SERVER_LEVEL_UNLOAD.register(world -> {
if(world.dimension().equals(Level.OVERWORLD)){
DMXNetworkData.unloadLevel();
AVNetworkData.unloadLevel();
AVNetworkData.unloadLevel();
}
});
CommandRegistrationEvent.EVENT.register((dispatcher, registry, selection) -> {
Expand Down
21 changes: 17 additions & 4 deletions common/src/main/java/dev/imabad/theatrical/TheatricalClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.math.Axis;
import com.mojang.serialization.Codec;
import dev.architectury.event.events.client.ClientPlayerEvent;
import dev.architectury.platform.Platform;
import dev.architectury.registry.client.rendering.BlockEntityRendererRegistry;
import dev.imabad.theatrical.api.dmx.DMXConsumer;
import dev.imabad.theatrical.api.network.audio.AudioDeviceDefinition;
import dev.imabad.theatrical.api.network.dmx.DMXConsumer;
import dev.imabad.theatrical.blockentities.BlockEntities;
import dev.imabad.theatrical.blockentities.control.BasicLightingDeskBlockEntity;
import dev.imabad.theatrical.blockentities.light.BaseLightBlockEntity;
import dev.imabad.theatrical.blockentities.light.FresnelBlockEntity;
import dev.imabad.theatrical.blockentities.sound.MixerBlockEntity;
import dev.imabad.theatrical.blocks.light.MovingLightBlock;
import dev.imabad.theatrical.client.LazyRenderers;
import dev.imabad.theatrical.client.blockentities.BasicLightingConsoleRenderer;
Expand All @@ -23,6 +26,7 @@
import dev.imabad.theatrical.client.gui.screen.BasicLightingDeskScreen;
import dev.imabad.theatrical.client.gui.screen.FresnelScreen;
import dev.imabad.theatrical.client.gui.screen.GenericDMXConfigurationScreen;
import dev.imabad.theatrical.client.gui.screen.audio.MixerScreen;
import dev.imabad.theatrical.client.sound.SpeakerManager;
import dev.imabad.theatrical.config.TheatricalConfig;
import dev.imabad.theatrical.config.UniverseConfig;
Expand All @@ -33,6 +37,7 @@
import dev.imabad.theatrical.net.artnet.NotifyConsumerChange;
import dev.imabad.theatrical.net.artnet.RequestNetworks;
import dev.imabad.theatrical.client.sound.mic.MicrophoneManager;
import dev.imabad.theatrical.util.DimensionBlockPos;
import net.labymod.opus.OpusCodec;
import net.minecraft.client.Camera;
import net.minecraft.client.Minecraft;
Expand All @@ -42,6 +47,7 @@
import net.minecraft.client.renderer.RenderType;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.NbtOps;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
Expand All @@ -50,9 +56,8 @@

import java.awt.*;
import java.nio.ByteBuffer;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import java.util.*;
import java.util.List;

public class TheatricalClient {

Expand Down Expand Up @@ -239,6 +244,14 @@ public static void handleOpenScreen(OpenScreen openScreen){
Minecraft.getInstance().setScreen(new BasicLightingDeskScreen(bse));
}
}
case MIXER -> {
if(Minecraft.getInstance().level.getBlockEntity(openScreen.getPos()) instanceof MixerBlockEntity bse) {
Map<DimensionBlockPos, AudioDeviceDefinition> knownDevices = AudioDeviceDefinition.POS_MAP_CODEC
.parse(NbtOps.INSTANCE, openScreen.getExtraData())
.getOrThrow(true, (e) -> System.out.println(e));
Minecraft.getInstance().setScreen(new MixerScreen(bse, knownDevices));
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public enum TheatricalScreen {

GENERIC_DMX,
BASIC_LIGHTING_DESK,
FRESNEL
FRESNEL,
MIXER

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dev.imabad.theatrical.api;

import dev.imabad.theatrical.api.dmx.DMXPersonality;
import dev.imabad.theatrical.api.network.dmx.DMXPersonality;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.state.BlockState;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.imabad.theatrical.api.dmx;
package dev.imabad.theatrical.api.network;

import java.util.UUID;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package dev.imabad.theatrical.api.network.audio;

import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;

public record AudioChannelDefinition(String name, int index, AudioChannelType channelType) {
public static final Codec<AudioChannelDefinition> CODEC = RecordCodecBuilder.create(i -> i.group(
Codec.STRING.fieldOf("name").forGetter(AudioChannelDefinition::name),
Codec.INT.fieldOf("index").forGetter(AudioChannelDefinition::index),
AudioChannelType.CODEC.fieldOf("channelType").forGetter(AudioChannelDefinition::channelType)
).apply(i, AudioChannelDefinition::new));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package dev.imabad.theatrical.api.network.audio;

import com.mojang.serialization.Codec;
import net.minecraft.util.StringRepresentable;
import org.jetbrains.annotations.NotNull;

public enum AudioChannelType implements StringRepresentable {

INPUT,
OUTPUT;

public static final Codec<AudioChannelType> CODEC = StringRepresentable.fromEnum(AudioChannelType::values);

@Override
public @NotNull String getSerializedName() {
return name();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package dev.imabad.theatrical.api.network.audio;

import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import dev.imabad.theatrical.util.DimensionBlockPos;

import java.util.List;
import java.util.Map;

public record AudioDeviceDefinition(String name, List<AudioChannelDefinition> channelDefinitions) {
public static final Codec<AudioDeviceDefinition> CODEC = RecordCodecBuilder.create(i -> i.group(
Codec.STRING.fieldOf("name").forGetter(AudioDeviceDefinition::name),
AudioChannelDefinition.CODEC.listOf().fieldOf("channelDefinitions").forGetter(AudioDeviceDefinition::channelDefinitions)
).apply(i, AudioDeviceDefinition::new));
public static final Codec<Map<DimensionBlockPos, AudioDeviceDefinition>> POS_MAP_CODEC =
Codec.unboundedMap(Codec.STRING.xmap(DimensionBlockPos::fromString, DimensionBlockPos::toString), AudioDeviceDefinition.CODEC);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package dev.imabad.theatrical.api.network.audio;

import dev.imabad.theatrical.api.network.BelongsToNetwork;
import dev.imabad.theatrical.audio.AudioSink;
import dev.imabad.theatrical.audio.AudioSource;
import org.jetbrains.annotations.Nullable;

public interface AudioNetworkDevice extends BelongsToNetwork {
AudioDeviceDefinition getDefinition();

@Nullable
AudioSink getSinkForChannel(int channel);

@Nullable
AudioSource getSourceForChannel(int channel);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.imabad.theatrical.api.dmx;
package dev.imabad.theatrical.api.network.dmx;

import ch.bildspur.artnet.rdm.RDMDeviceId;
import dev.imabad.theatrical.api.network.BelongsToNetwork;
import net.minecraft.resources.ResourceLocation;

import java.util.UUID;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.imabad.theatrical.api.dmx;
package dev.imabad.theatrical.api.network.dmx;

import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.imabad.theatrical.api.dmx;
package dev.imabad.theatrical.api.network.dmx;

import ch.bildspur.artnet.rdm.RDMSlotID;
import ch.bildspur.artnet.rdm.RDMSlotType;
Expand Down
38 changes: 38 additions & 0 deletions common/src/main/java/dev/imabad/theatrical/audio/AudioBuffer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package dev.imabad.theatrical.audio;

public class AudioBuffer {

private byte[] samples;
private int sampleRate;
private int channels;

public AudioBuffer(byte[] samples, int sampleRate, int channels) {
this.samples = samples;
this.sampleRate = sampleRate;
this.channels = channels;
}

public byte[] getSamples() {
return samples;
}

public void setSamples(byte[] samples) {
this.samples = samples;
}

public int getSampleRate() {
return sampleRate;
}

public void setSampleRate(int sampleRate) {
this.sampleRate = sampleRate;
}

public int getChannels() {
return channels;
}

public void setChannels(int channels) {
this.channels = channels;
}
}
Loading

0 comments on commit 6236de9

Please sign in to comment.