Implement styling of combo box and basic functionality

pull/35/head
James Ball 2021-06-17 19:53:58 +01:00
rodzic 810f9c8771
commit 4c584fb96c
6 zmienionych plików z 112 dodań i 13 usunięć

Wyświetl plik

@ -1,6 +1,8 @@
package sh.ball.audio.engine;
public interface AudioDevice {
String id();
String name();
int sampleRate();

Wyświetl plik

@ -2,16 +2,23 @@ package sh.ball.audio.engine;
public class DefaultAudioDevice implements AudioDevice {
final String id;
final String name;
final int sampleRate;
final AudioSample sample;
public DefaultAudioDevice(String name, int sampleRate, AudioSample sample) {
public DefaultAudioDevice(String id, String name, int sampleRate, AudioSample sample) {
this.id = id;
this.name = name;
this.sampleRate = sampleRate;
this.sample = sample;
}
@Override
public String id() {
return id;
}
@Override
public String name() {
return name;
@ -26,4 +33,9 @@ public class DefaultAudioDevice implements AudioDevice {
public AudioSample sample() {
return sample;
}
@Override
public String toString() {
return name + " @ " + sampleRate + "KHz";
}
}

Wyświetl plik

@ -48,7 +48,7 @@ public class XtAudioEngine implements AudioEngine {
try (XtPlatform platform = XtAudio.init(null, null)) {
XtService service = getService(platform);
try (XtDevice xtDevice = service.openDevice(device.name())) {
try (XtDevice xtDevice = service.openDevice(device.id())) {
// TODO: Make this generic to the type of XtSample of the current device.
Structs.XtMix mix = new Structs.XtMix(xtDevice.getMix().orElseThrow().rate, Enums.XtSample.FLOAT32);
Structs.XtChannels channels = new Structs.XtChannels(0, 0, NUM_OUTPUTS, 0);
@ -88,9 +88,10 @@ public class XtAudioEngine implements AudioEngine {
XtDeviceList xtDevices = service.openDeviceList(EnumSet.of(Enums.XtEnumFlags.OUTPUT));
for (int i = 0; i < xtDevices.getCount(); i++) {
String device = xtDevices.getId(i);
String deviceId = xtDevices.getId(i);
String deviceName = xtDevices.getName(deviceId);
try (XtDevice xtDevice = service.openDevice(device)) {
try (XtDevice xtDevice = service.openDevice(deviceId)) {
Optional<Structs.XtMix> mix = xtDevice.getMix();
if (mix.isEmpty()) {
@ -101,7 +102,7 @@ public class XtAudioEngine implements AudioEngine {
Structs.XtFormat format = new Structs.XtFormat(mix.get(), channels);
if (xtDevice.supportsFormat(format)) {
devices.add(new DefaultAudioDevice(device, mix.get().rate, XtSampleToAudioSample(mix.get().sample)));
devices.add(new DefaultAudioDevice(deviceId, deviceName, mix.get().rate, XtSampleToAudioSample(mix.get().sample)));
}
}
}
@ -114,20 +115,22 @@ public class XtAudioEngine implements AudioEngine {
public AudioDevice getDefaultDevice() {
try (XtPlatform platform = XtAudio.init(null, null)) {
XtService service = getService(platform);
String device = service.getDefaultDeviceId(true);
String deviceId = service.getDefaultDeviceId(true);
try (XtDevice xtDevice = service.openDevice(device)) {
try (XtDevice xtDevice = service.openDevice(deviceId)) {
Optional<Structs.XtMix> mix = xtDevice.getMix();
if (mix.isEmpty()) {
return null;
}
String deviceName = service.openDeviceList(EnumSet.of(Enums.XtEnumFlags.OUTPUT)).getName(deviceId);
Structs.XtChannels channels = new Structs.XtChannels(0, 0, NUM_OUTPUTS, 0);
Structs.XtFormat format = new Structs.XtFormat(mix.get(), channels);
if (xtDevice.supportsFormat(format)) {
return new DefaultAudioDevice(device, mix.get().rate, XtSampleToAudioSample(mix.get().sample));
return new DefaultAudioDevice(deviceId, deviceName, mix.get().rate, XtSampleToAudioSample(mix.get().sample));
} else {
return null;
}

Wyświetl plik

@ -3,6 +3,7 @@ package sh.ball.gui;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.scene.control.*;
import javafx.util.Duration;
import sh.ball.audio.*;
@ -60,7 +61,7 @@ public class Controller implements Initializable, FrequencyListener, Listener {
private final WobbleEffect wobbleEffect;
private final ScaleEffect scaleEffect;
private AudioDevice device;
private AudioDevice defaultDevice;
private FrameProducer<List<Shape>> producer;
private boolean recording = false;
@ -122,14 +123,16 @@ public class Controller implements Initializable, FrequencyListener, Listener {
private CheckBox wobbleCheckBox;
@FXML
private Slider wobbleSlider;
@FXML
private ComboBox<AudioDevice> deviceComboBox;
public Controller(AudioPlayer<List<Shape>> audioPlayer) throws IOException {
this.audioPlayer = audioPlayer;
FrameSet<List<Shape>> frames = new ObjParser(DEFAULT_OBJ).parse();
frames.addListener(this);
this.producer = new FrameProducer<>(audioPlayer, frames);
this.device = audioPlayer.getDefaultDevice();
this.sampleRate = device.sampleRate();
this.defaultDevice = audioPlayer.getDefaultDevice();
this.sampleRate = defaultDevice.sampleRate();
this.rotateEffect = new RotateEffect(sampleRate);
this.translateEffect = new TranslateEffect(sampleRate);
this.wobbleEffect = new WobbleEffect(sampleRate);
@ -246,7 +249,10 @@ public class Controller implements Initializable, FrequencyListener, Listener {
audioPlayer.addEffect(EffectType.TRANSLATE, translateEffect);
executor.submit(producer);
audioPlayer.setDevice(device);
audioPlayer.setDevice(defaultDevice);
System.out.println(audioPlayer.devices());
deviceComboBox.setItems(FXCollections.observableList(audioPlayer.devices()));
deviceComboBox.getSelectionModel().select(defaultDevice);
Thread renderThread = new Thread(audioPlayer);
renderThread.setUncaughtExceptionHandler((thread, throwable) -> throwable.printStackTrace());
renderThread.start();

Wyświetl plik

@ -84,4 +84,80 @@
#control-pane, .titled-pane {
-fx-background-color: darker_color;
-fx-effect: dropshadow(three-pass-box, rgba(0,0,0,0.8), 10, 0, 0, 0);
}
.combo-box .list-cell
{
-fx-background: very_dark;
-fx-background-color: very_dark;
-fx-text-fill: white;
-fx-border-radius: 0;
-fx-border-width: 0.2 0 0.2 1;
-fx-border-color: white;
}
.combo-box-popup .list-view
{
-fx-background-color: dark_color;
-fx-background-insets: 0;
-fx-border-radius: 0;
-fx-background-radius: 0;
-fx-border-width: 0;
-fx-padding: 1 1 0 1;
-fx-max-height: 0;
}
.combo-box-popup .list-view .list-cell
{
-fx-padding: 6 0 6 5;
-fx-background-radius: 0;
-fx-border-radius: 0;
-fx-border-width: 0;
/* No alternate highlighting */
-fx-background-color: dark_color;
}
.combo-box-popup .list-view .list-cell:filled:selected, .combo-box-popup .list-view .list-cell:filled:selected:hover
{
-fx-background: darker_color;
-fx-background-color: darker_color;
-fx-border-radius: 0;
-fx-border-width: 0;
-fx-text-fill: white;
}
.combo-box-popup .list-view .list-cell:filled:hover
{
-fx-background-color: darker_color;
-fx-border-radius: 0;
-fx-border-width: 0;
-fx-text-fill: white;
}
.combo-box-base
{
-fx-background-color: very_dark;
-fx-border-radius: 0;
-fx-border-width: 1 1 1 0;
-fx-border-color: white;
-fx-background-radius: 0;
-fx-background-insets: 0;
-fx-padding: 0;
}
.combo-box-base:hover
{
-fx-color: very_dark;
}
.combo-box-base:showing
{
-fx-color: very_dark;
}
.combo-box-base:focused {
-fx-background-color: very_dark;
-fx-background-radius: 0;
-fx-background-insets: 0;
}

Wyświetl plik

@ -18,7 +18,7 @@
<Button fx:id="recordButton" layoutX="14.0" layoutY="54.0" mnemonicParsing="false" prefHeight="26.0" prefWidth="114.0" text="Record" />
<Label fx:id="recordLabel" layoutX="146.0" layoutY="59.0" maxWidth="270.0" prefHeight="18.0" prefWidth="245.0" />
<Label id="frequency" fx:id="frequencyLabel" layoutX="14.0" layoutY="113.0" prefHeight="58.0" prefWidth="376.0" text="L/R Frequency:&#10; &#10;" />
<ComboBox layoutX="251.0" layoutY="113.0" prefWidth="150.0" />
<ComboBox fx:id="deviceComboBox" layoutX="169.0" layoutY="113.0" prefHeight="26.0" prefWidth="221.0" />
</children>
</AnchorPane>
<TitledPane animated="false" collapsible="false" layoutX="422.0" layoutY="213.0" prefHeight="272.0" prefWidth="402.0" text="Effects">