From 836690ff5d3777cb9593be0e0cb7565df0d39e8c Mon Sep 17 00:00:00 2001 From: ShmayaR Date: Fri, 14 Feb 2025 06:11:40 +0200 Subject: [PATCH 01/47] added orchestra stuff --- .../phoenix6/talonfx/TalonFXMotor.java | 5 +++ .../org/trigon/utilities/TrigonOrchestra.java | 44 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 src/main/java/org/trigon/utilities/TrigonOrchestra.java diff --git a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java index 5a351b01..1f5a02a9 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java +++ b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java @@ -10,6 +10,7 @@ import org.trigon.hardware.phoenix6.talonfx.io.RealTalonFXIO; import org.trigon.hardware.phoenix6.talonfx.io.SimulationTalonFXIO; import org.trigon.hardware.simulation.MotorPhysicsSimulation; +import org.trigon.utilities.TrigonOrchestra; /** * A class that represents a TalonFX motor controller. @@ -191,6 +192,10 @@ public void setBrake(boolean brake) { motorIO.setBrake(brake); } + public void addToTrigonOrchestra(int trackNumber) { + TrigonOrchestra.addMotor(motorIO.getTalonFX(), trackNumber); + } + private BaseStatusSignal motorSignalToStatusSignal(TalonFXSignal signal) { final TalonFX talonFX = motorIO.getTalonFX(); if (RobotHardwareStats.isReplay() || talonFX == null) diff --git a/src/main/java/org/trigon/utilities/TrigonOrchestra.java b/src/main/java/org/trigon/utilities/TrigonOrchestra.java new file mode 100644 index 00000000..3a4f02e1 --- /dev/null +++ b/src/main/java/org/trigon/utilities/TrigonOrchestra.java @@ -0,0 +1,44 @@ +package org.trigon.utilities; + +import com.ctre.phoenix6.Orchestra; +import com.ctre.phoenix6.hardware.TalonFX; + +public class TrigonOrchestra { + private static final Orchestra ORCHESTRA = new Orchestra(); + + public static void addMotor(TalonFX motor, int trackNumber) { + ORCHESTRA.addInstrument(motor, trackNumber); + } + + public static void addTrack(String trackFile) { + ORCHESTRA.loadMusic(trackFile); + } + + public static void clearAllMotors() { + ORCHESTRA.clearInstruments(); + } + + public static void playTrack() { + ORCHESTRA.play(); + } + + public static void pauseTrack() { + ORCHESTRA.pause(); + } + + public static void stopTrack() { + ORCHESTRA.stop(); + } + + public static void closeTrack() { + ORCHESTRA.close(); + } + + public static boolean isTrackPlaying() { + return ORCHESTRA.isPlaying(); + } + + public static double getCurrentTrackTime() { + return ORCHESTRA.getCurrentTime(); + } +} From 51bd0c6acaeb652b893aefd2c118bc6a82a7d14d Mon Sep 17 00:00:00 2001 From: ShmayaR Date: Fri, 14 Feb 2025 06:38:25 +0200 Subject: [PATCH 02/47] changed name from TrigonOrchestra to Orchestra --- .../org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java | 4 ++-- .../utilities/{TrigonOrchestra.java => Orchestra.java} | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) rename src/main/java/org/trigon/utilities/{TrigonOrchestra.java => Orchestra.java} (86%) diff --git a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java index 1f5a02a9..8275b470 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java +++ b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java @@ -10,7 +10,7 @@ import org.trigon.hardware.phoenix6.talonfx.io.RealTalonFXIO; import org.trigon.hardware.phoenix6.talonfx.io.SimulationTalonFXIO; import org.trigon.hardware.simulation.MotorPhysicsSimulation; -import org.trigon.utilities.TrigonOrchestra; +import org.trigon.utilities.Orchestra; /** * A class that represents a TalonFX motor controller. @@ -193,7 +193,7 @@ public void setBrake(boolean brake) { } public void addToTrigonOrchestra(int trackNumber) { - TrigonOrchestra.addMotor(motorIO.getTalonFX(), trackNumber); + Orchestra.addMotor(motorIO.getTalonFX(), trackNumber); } private BaseStatusSignal motorSignalToStatusSignal(TalonFXSignal signal) { diff --git a/src/main/java/org/trigon/utilities/TrigonOrchestra.java b/src/main/java/org/trigon/utilities/Orchestra.java similarity index 86% rename from src/main/java/org/trigon/utilities/TrigonOrchestra.java rename to src/main/java/org/trigon/utilities/Orchestra.java index 3a4f02e1..d93680da 100644 --- a/src/main/java/org/trigon/utilities/TrigonOrchestra.java +++ b/src/main/java/org/trigon/utilities/Orchestra.java @@ -1,10 +1,9 @@ package org.trigon.utilities; -import com.ctre.phoenix6.Orchestra; import com.ctre.phoenix6.hardware.TalonFX; -public class TrigonOrchestra { - private static final Orchestra ORCHESTRA = new Orchestra(); +public class Orchestra { + private static final com.ctre.phoenix6.Orchestra ORCHESTRA = new com.ctre.phoenix6.Orchestra(); public static void addMotor(TalonFX motor, int trackNumber) { ORCHESTRA.addInstrument(motor, trackNumber); From ae0cd14ef0ed15e69ebbae8f7f88867926233d39 Mon Sep 17 00:00:00 2001 From: Strflightmight09 <148347057+Strflightmight09@users.noreply.github.com> Date: Sun, 16 Feb 2025 09:11:56 +0200 Subject: [PATCH 03/47] Ugliness so @ShmayaR can clean :) --- .../phoenix6/talonfx/TalonFXMotor.java | 4 +- .../java/org/trigon/utilities/Orchestra.java | 40 ++++++++++++++++--- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java index 8275b470..64a0b9f4 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java +++ b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java @@ -192,8 +192,8 @@ public void setBrake(boolean brake) { motorIO.setBrake(brake); } - public void addToTrigonOrchestra(int trackNumber) { - Orchestra.addMotor(motorIO.getTalonFX(), trackNumber); + public void addToOrchestra() { + Orchestra.addMotor(motorIO.getTalonFX()); } private BaseStatusSignal motorSignalToStatusSignal(TalonFXSignal signal) { diff --git a/src/main/java/org/trigon/utilities/Orchestra.java b/src/main/java/org/trigon/utilities/Orchestra.java index d93680da..7ce4fc42 100644 --- a/src/main/java/org/trigon/utilities/Orchestra.java +++ b/src/main/java/org/trigon/utilities/Orchestra.java @@ -2,11 +2,43 @@ import com.ctre.phoenix6.hardware.TalonFX; +import java.util.ArrayList; + public class Orchestra { private static final com.ctre.phoenix6.Orchestra ORCHESTRA = new com.ctre.phoenix6.Orchestra(); + private static final ArrayList MOTORS = new ArrayList<>(); + + public static void addMotor(TalonFX motor) { + MOTORS.add(motor); + } + + public static void playTrack(String trackFile, int tracks) { + for (int i = 0; i < MOTORS.size(); i++) { + ORCHESTRA.addInstrument(MOTORS.get(i), i % tracks + 1); + } + addTrack(trackFile); + playTrack(); + } + + public static void playTrack(String trackFile, int... perTrack) throws IllegalStateException { + int total = 0, + index = 0; + for (int i = 0; i < perTrack.length; i++) { + total += perTrack[i]; + if (total > MOTORS.size()) + throw new IllegalStateException("Not enough motors"); + for (int j = 0; j < perTrack[i]; i++) { + ORCHESTRA.addInstrument(MOTORS.get(index++), i + 1); + } + } + + addTrack(trackFile); + playTrack(); + } - public static void addMotor(TalonFX motor, int trackNumber) { - ORCHESTRA.addInstrument(motor, trackNumber); + public static void stopTrack() { + ORCHESTRA.stop(); + clearAllMotors(); } public static void addTrack(String trackFile) { @@ -25,10 +57,6 @@ public static void pauseTrack() { ORCHESTRA.pause(); } - public static void stopTrack() { - ORCHESTRA.stop(); - } - public static void closeTrack() { ORCHESTRA.close(); } From 38060abc22e4311c14085af24172dfc533815d2f Mon Sep 17 00:00:00 2001 From: Strflightmight09 <148347057+Strflightmight09@users.noreply.github.com> Date: Sun, 16 Feb 2025 09:13:54 +0200 Subject: [PATCH 04/47] =?UTF-8?q?Hard=20code=20=F0=9F=92=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trigon/hardware/phoenix6/talonfx/io/RealTalonFXIO.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/org/trigon/hardware/phoenix6/talonfx/io/RealTalonFXIO.java b/src/main/java/org/trigon/hardware/phoenix6/talonfx/io/RealTalonFXIO.java index b465e437..385f76d2 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/talonfx/io/RealTalonFXIO.java +++ b/src/main/java/org/trigon/hardware/phoenix6/talonfx/io/RealTalonFXIO.java @@ -25,6 +25,10 @@ protected void setPosition(double positionRotations) { @Override public void applyConfiguration(TalonFXConfiguration configuration) { + configuration.Audio.BeepOnBoot = false; + configuration.Audio.BeepOnConfig = false; + configuration.Audio.AllowMusicDurDisable = true; + talonFX.getConfigurator().apply(configuration); } From 4f06706691ff229565571565173c494ea9740f3f Mon Sep 17 00:00:00 2001 From: ShmayaR Date: Sun, 16 Feb 2025 11:34:32 +0200 Subject: [PATCH 05/47] added java docs --- .../phoenix6/talonfx/TalonFXMotor.java | 3 + .../java/org/trigon/utilities/Orchestra.java | 57 +++++++++++++++++-- 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java index 64a0b9f4..01a8c3c9 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java +++ b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java @@ -192,6 +192,9 @@ public void setBrake(boolean brake) { motorIO.setBrake(brake); } + /** + * Adds the motor to the Orchestra. + */ public void addToOrchestra() { Orchestra.addMotor(motorIO.getTalonFX()); } diff --git a/src/main/java/org/trigon/utilities/Orchestra.java b/src/main/java/org/trigon/utilities/Orchestra.java index 7ce4fc42..cc8c7dc9 100644 --- a/src/main/java/org/trigon/utilities/Orchestra.java +++ b/src/main/java/org/trigon/utilities/Orchestra.java @@ -8,18 +8,37 @@ public class Orchestra { private static final com.ctre.phoenix6.Orchestra ORCHESTRA = new com.ctre.phoenix6.Orchestra(); private static final ArrayList MOTORS = new ArrayList<>(); + /** + * adds a motor to the array list MOTORS. + * + * @param motor the motor to be added to MOTORS + */ public static void addMotor(TalonFX motor) { MOTORS.add(motor); } + /** + * sets a track file to the Orchestra and assigns a track to each motor added to the Orchestra. + * if the number of motors exceeds the amount of tracks then the extra motors will be assigned used tracks. + * + * @param trackFile the track file to be added to the Orchestra + * @param tracks how many tracks should be assigned to the motors + */ public static void playTrack(String trackFile, int tracks) { - for (int i = 0; i < MOTORS.size(); i++) { + for (int i = 0; i < MOTORS.size(); i++) ORCHESTRA.addInstrument(MOTORS.get(i), i % tracks + 1); - } addTrack(trackFile); playTrack(); } + /** + * sets a track file to the Orchestra and assigns one or multiple motors in the Orchestra a single track. + * works with multiple tracks + * + * @param trackFile the track file to be added to the Orchestra + * @param perTrack how many motors should get assigned to a track + * @throws IllegalStateException if the amount of motors is below the amount of tracks to be assigned + */ public static void playTrack(String trackFile, int... perTrack) throws IllegalStateException { int total = 0, index = 0; @@ -27,44 +46,74 @@ public static void playTrack(String trackFile, int... perTrack) throws IllegalSt total += perTrack[i]; if (total > MOTORS.size()) throw new IllegalStateException("Not enough motors"); - for (int j = 0; j < perTrack[i]; i++) { + for (int j = 0; j < perTrack[i]; i++) ORCHESTRA.addInstrument(MOTORS.get(index++), i + 1); - } + } addTrack(trackFile); playTrack(); } + /** + * stops the Orchestra from playing and clears all the motors from it. + */ public static void stopTrack() { ORCHESTRA.stop(); clearAllMotors(); } + /** + * adds a track file to the Orchestra. + * + * @param trackFile the file to be added to the Orchestra + */ public static void addTrack(String trackFile) { ORCHESTRA.loadMusic(trackFile); } + /** + * clears all the motors from the Orchestra + */ public static void clearAllMotors() { ORCHESTRA.clearInstruments(); } + /** + * plays the track in the Orchestra. + */ public static void playTrack() { ORCHESTRA.play(); } + /** + * pauses the track in the Orchestra. + */ public static void pauseTrack() { ORCHESTRA.pause(); } + /** + * closes the Orchestra. + */ public static void closeTrack() { ORCHESTRA.close(); } + /** + * a function to determine whether the track is playing. + * + * @return if the track is playing + */ public static boolean isTrackPlaying() { return ORCHESTRA.isPlaying(); } + /** + * a function to get how much time the Orchestra has been playing. + * + * @return how long the Orchestra has been playing + */ public static double getCurrentTrackTime() { return ORCHESTRA.getCurrentTime(); } From c6169f9f787ef7afca40243398f7bc99828b8b71 Mon Sep 17 00:00:00 2001 From: ShmayaR Date: Sun, 16 Feb 2025 13:18:00 +0200 Subject: [PATCH 06/47] rewrote java docs --- .../phoenix6/talonfx/TalonFXMotor.java | 6 +- .../java/org/trigon/utilities/Orchestra.java | 87 ++++++++++--------- 2 files changed, 52 insertions(+), 41 deletions(-) diff --git a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java index 01a8c3c9..f21a7bb3 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java +++ b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java @@ -32,6 +32,7 @@ public class TalonFXMotor { */ public TalonFXMotor(int id, String motorName) { this(id, motorName, ""); + addToOrchestra(); } /** @@ -193,9 +194,10 @@ public void setBrake(boolean brake) { } /** - * Adds the motor to the Orchestra. + * Adds the TalonFX to the Orchestra. + * Orchestra plays a track of music in one or more motors. */ - public void addToOrchestra() { + private void addToOrchestra() { Orchestra.addMotor(motorIO.getTalonFX()); } diff --git a/src/main/java/org/trigon/utilities/Orchestra.java b/src/main/java/org/trigon/utilities/Orchestra.java index cc8c7dc9..206b0518 100644 --- a/src/main/java/org/trigon/utilities/Orchestra.java +++ b/src/main/java/org/trigon/utilities/Orchestra.java @@ -6,57 +6,66 @@ public class Orchestra { private static final com.ctre.phoenix6.Orchestra ORCHESTRA = new com.ctre.phoenix6.Orchestra(); - private static final ArrayList MOTORS = new ArrayList<>(); + private static final ArrayList TALON_FXES = new ArrayList<>(); /** - * adds a motor to the array list MOTORS. + * Adds a motor to the array list TALON_FXES to then be added to the Orchestra. * * @param motor the motor to be added to MOTORS */ public static void addMotor(TalonFX motor) { - MOTORS.add(motor); + TALON_FXES.add(motor); } /** - * sets a track file to the Orchestra and assigns a track to each motor added to the Orchestra. + * sets a music file to the Orchestra and assigns a track to each motor added to the Orchestra. * if the number of motors exceeds the amount of tracks then the extra motors will be assigned used tracks. + * can only assign one track to each motor * - * @param trackFile the track file to be added to the Orchestra - * @param tracks how many tracks should be assigned to the motors + * @param musicFile the music file to be added to the Orchestra + * @param tracks number of tracks to be assigned to the motors */ - public static void playTrack(String trackFile, int tracks) { - for (int i = 0; i < MOTORS.size(); i++) - ORCHESTRA.addInstrument(MOTORS.get(i), i % tracks + 1); - addTrack(trackFile); - playTrack(); + public static void playTrack(String musicFile, int tracks) { + for (int i = 0; i < TALON_FXES.size(); i++) + ORCHESTRA.addInstrument(TALON_FXES.get(i), i % tracks + 1); + addAndPlayTrack(musicFile); } /** - * sets a track file to the Orchestra and assigns one or multiple motors in the Orchestra a single track. - * works with multiple tracks + * Sets a music file to the Orchestra and assigns one or multiple motors in the Orchestra a single track. + * Works with multiple tracks. + * can assign a single track to more than one motor. * - * @param trackFile the track file to be added to the Orchestra + * @param musicFile the music file to be added to the Orchestra * @param perTrack how many motors should get assigned to a track - * @throws IllegalStateException if the amount of motors is below the amount of tracks to be assigned */ - public static void playTrack(String trackFile, int... perTrack) throws IllegalStateException { - int total = 0, - index = 0; + public static void playTrack(String musicFile, int... perTrack) throws IllegalStateException { + int totalTracks = 0; + int motorsAssignedTracks = 0; for (int i = 0; i < perTrack.length; i++) { - total += perTrack[i]; - if (total > MOTORS.size()) + totalTracks += perTrack[i]; + if (totalTracks > TALON_FXES.size()) throw new IllegalStateException("Not enough motors"); for (int j = 0; j < perTrack[i]; i++) - ORCHESTRA.addInstrument(MOTORS.get(index++), i + 1); + ORCHESTRA.addInstrument(TALON_FXES.get(motorsAssignedTracks++), i + 1); } + addAndPlayTrack(musicFile); + } - addTrack(trackFile); + /** + * Adds a music file to the Orchestra and then plays it. + * + * @param musicFile the music file to be added to the Orchestra + */ + public static void addAndPlayTrack(String musicFile) { + addTrack(musicFile); playTrack(); } /** - * stops the Orchestra from playing and clears all the motors from it. + * Stops the Orchestra from playing and resets the music file to the start + * removes all the motors from the Orchestra. */ public static void stopTrack() { ORCHESTRA.stop(); @@ -64,44 +73,44 @@ public static void stopTrack() { } /** - * adds a track file to the Orchestra. - * - * @param trackFile the file to be added to the Orchestra - */ - public static void addTrack(String trackFile) { - ORCHESTRA.loadMusic(trackFile); - } - - /** - * clears all the motors from the Orchestra + * Removes all the motors from the Orchestra meaning there is no hardware to play the music. */ public static void clearAllMotors() { ORCHESTRA.clearInstruments(); } /** - * plays the track in the Orchestra. + * Plays the music file in the Orchestra. */ public static void playTrack() { ORCHESTRA.play(); } /** - * pauses the track in the Orchestra. + * add a music file to the Orchestra. + * + * @param musicFile the music file to be added to the Orchestra + */ + public static void addTrack(String musicFile) { + ORCHESTRA.loadMusic(musicFile); + } + + /** + * Pauses the music file in the Orchestra. */ public static void pauseTrack() { ORCHESTRA.pause(); } /** - * closes the Orchestra. + * Closes the current Orchestra instance. */ public static void closeTrack() { ORCHESTRA.close(); } /** - * a function to determine whether the track is playing. + * Determines whether or not the music file is playing. * * @return if the track is playing */ @@ -110,9 +119,9 @@ public static boolean isTrackPlaying() { } /** - * a function to get how much time the Orchestra has been playing. + * Gets the current time stamp of the music file. * - * @return how long the Orchestra has been playing + * @return the current time stamp of the music file in seconds */ public static double getCurrentTrackTime() { return ORCHESTRA.getCurrentTime(); From 8c7f53a5882c9b0ae9c4ab7de86720b57bb07704 Mon Sep 17 00:00:00 2001 From: ShmayaR Date: Sun, 16 Feb 2025 14:18:32 +0200 Subject: [PATCH 07/47] rewrote java docs again --- .../phoenix6/talonfx/TalonFXMotor.java | 5 +- .../java/org/trigon/utilities/Orchestra.java | 91 ++++++++++--------- 2 files changed, 49 insertions(+), 47 deletions(-) diff --git a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java index f21a7bb3..f85b2895 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java +++ b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java @@ -32,7 +32,7 @@ public class TalonFXMotor { */ public TalonFXMotor(int id, String motorName) { this(id, motorName, ""); - addToOrchestra(); + Orchestra.addMotor(motorIO.getTalonFX()); } /** @@ -197,9 +197,6 @@ public void setBrake(boolean brake) { * Adds the TalonFX to the Orchestra. * Orchestra plays a track of music in one or more motors. */ - private void addToOrchestra() { - Orchestra.addMotor(motorIO.getTalonFX()); - } private BaseStatusSignal motorSignalToStatusSignal(TalonFXSignal signal) { final TalonFX talonFX = motorIO.getTalonFX(); diff --git a/src/main/java/org/trigon/utilities/Orchestra.java b/src/main/java/org/trigon/utilities/Orchestra.java index 206b0518..1a29f517 100644 --- a/src/main/java/org/trigon/utilities/Orchestra.java +++ b/src/main/java/org/trigon/utilities/Orchestra.java @@ -4,53 +4,59 @@ import java.util.ArrayList; +/** + * Software that plays music through motors. + */ public class Orchestra { private static final com.ctre.phoenix6.Orchestra ORCHESTRA = new com.ctre.phoenix6.Orchestra(); - private static final ArrayList TALON_FXES = new ArrayList<>(); + private static final ArrayList INSTRUMENTS = new ArrayList<>(); /** - * Adds a motor to the array list TALON_FXES to then be added to the Orchestra. + * Adds a motor to the array list INSTRUMENTS to then be added to the Orchestra. * - * @param motor the motor to be added to MOTORS + * @param motor the motor to be added to the Orchestra through INSTRUMENTS */ public static void addMotor(TalonFX motor) { - TALON_FXES.add(motor); + INSTRUMENTS.add(motor); } /** - * sets a music file to the Orchestra and assigns a track to each motor added to the Orchestra. - * if the number of motors exceeds the amount of tracks then the extra motors will be assigned used tracks. - * can only assign one track to each motor + * Gives a music file to the Orchestra and assigns a track to each motor added to the Orchestra. + * Each track plays a different part of the music file; bass, harmonys, etc.... + * If the number of motors exceeds the amount of total tracks then the extra motors will be assigned used tracks. + * The extra motors will receive the track number equivalent to by how much exceeded the total amount of tracks. + * Only one track can be assigned to each motor. * - * @param musicFile the music file to be added to the Orchestra - * @param tracks number of tracks to be assigned to the motors + * @param musicFile the music file to be added to the Orchestra + * @param totalTracks number of totalTracks to be assigned to the motors */ - public static void playTrack(String musicFile, int tracks) { - for (int i = 0; i < TALON_FXES.size(); i++) - ORCHESTRA.addInstrument(TALON_FXES.get(i), i % tracks + 1); - addAndPlayTrack(musicFile); + public static void playTracks(String musicFile, int totalTracks) { + for (int i = 0; i < INSTRUMENTS.size(); i++) + ORCHESTRA.addInstrument(INSTRUMENTS.get(i), i % totalTracks + 1); + addAndPlayTracks(musicFile); } /** - * Sets a music file to the Orchestra and assigns one or multiple motors in the Orchestra a single track. + * Sets a music file to the Orchestra and assigns each track to one or more motors. + * Each track plays a different part of the music file; bass, harmonys, etc.... * Works with multiple tracks. - * can assign a single track to more than one motor. + * Can assign a single track to more than one motor. * - * @param musicFile the music file to be added to the Orchestra - * @param perTrack how many motors should get assigned to a track + * @param musicFile the music file to be added to the Orchestra + * @param motorsPerTrack number of motors that get assigned to a track */ - public static void playTrack(String musicFile, int... perTrack) throws IllegalStateException { + public static void playTracks(String musicFile, int... motorsPerTrack) throws IllegalStateException { int totalTracks = 0; int motorsAssignedTracks = 0; - for (int i = 0; i < perTrack.length; i++) { - totalTracks += perTrack[i]; - if (totalTracks > TALON_FXES.size()) + for (int i = 0; i < motorsPerTrack.length; i++) { + totalTracks += motorsPerTrack[i]; + if (totalTracks > INSTRUMENTS.size()) throw new IllegalStateException("Not enough motors"); - for (int j = 0; j < perTrack[i]; i++) - ORCHESTRA.addInstrument(TALON_FXES.get(motorsAssignedTracks++), i + 1); + for (int j = 0; j < motorsPerTrack[i]; i++) + ORCHESTRA.addInstrument(INSTRUMENTS.get(motorsAssignedTracks++), i + 1); } - addAndPlayTrack(musicFile); + addAndPlayTracks(musicFile); } /** @@ -58,22 +64,21 @@ public static void playTrack(String musicFile, int... perTrack) throws IllegalSt * * @param musicFile the music file to be added to the Orchestra */ - public static void addAndPlayTrack(String musicFile) { - addTrack(musicFile); - playTrack(); + public static void addAndPlayTracks(String musicFile) { + addTracks(musicFile); + playTracks(); } /** - * Stops the Orchestra from playing and resets the music file to the start - * removes all the motors from the Orchestra. + * Resets the Orchestra. */ - public static void stopTrack() { + public static void stopTracks() { ORCHESTRA.stop(); clearAllMotors(); } /** - * Removes all the motors from the Orchestra meaning there is no hardware to play the music. + * Removes all the motors from the Orchestra and returns the status code of clearing all the motors. */ public static void clearAllMotors() { ORCHESTRA.clearInstruments(); @@ -82,48 +87,48 @@ public static void clearAllMotors() { /** * Plays the music file in the Orchestra. */ - public static void playTrack() { + public static void playTracks() { ORCHESTRA.play(); } /** - * add a music file to the Orchestra. + * Assigns a music file to the Orchestra. * * @param musicFile the music file to be added to the Orchestra */ - public static void addTrack(String musicFile) { + public static void addTracks(String musicFile) { ORCHESTRA.loadMusic(musicFile); } /** - * Pauses the music file in the Orchestra. + * Stops the music file in the Orchestra until resumed. */ - public static void pauseTrack() { + public static void pauseTracks() { ORCHESTRA.pause(); } /** - * Closes the current Orchestra instance. + * Stops playing the music file and resets the Orchestra. */ - public static void closeTrack() { + public static void closeTracks() { ORCHESTRA.close(); } /** - * Determines whether or not the music file is playing. + * returns whether or not the music file is playing. * * @return if the track is playing */ - public static boolean isTrackPlaying() { + public static boolean areTracksPlaying() { return ORCHESTRA.isPlaying(); } /** - * Gets the current time stamp of the music file. + * Gets the current time location of the music file. * - * @return the current time stamp of the music file in seconds + * @return the current time location of the music file in seconds */ - public static double getCurrentTrackTime() { + public static double getCurrentMusicFileTimeLocation() { return ORCHESTRA.getCurrentTime(); } } From 567a2109f17969e27da1ed34c2a32103a531fd1c Mon Sep 17 00:00:00 2001 From: ShmayaR Date: Tue, 18 Feb 2025 21:59:01 +0200 Subject: [PATCH 08/47] Update Orchestra.java --- .../java/org/trigon/utilities/Orchestra.java | 121 +++++++----------- 1 file changed, 49 insertions(+), 72 deletions(-) diff --git a/src/main/java/org/trigon/utilities/Orchestra.java b/src/main/java/org/trigon/utilities/Orchestra.java index 1a29f517..41a1148e 100644 --- a/src/main/java/org/trigon/utilities/Orchestra.java +++ b/src/main/java/org/trigon/utilities/Orchestra.java @@ -5,130 +5,107 @@ import java.util.ArrayList; /** - * Software that plays music through motors. + * A class that uses the {@link com.ctre.phoenix6.Orchestra} library in Phoenix 6 to play a .chrp file. */ public class Orchestra { private static final com.ctre.phoenix6.Orchestra ORCHESTRA = new com.ctre.phoenix6.Orchestra(); - private static final ArrayList INSTRUMENTS = new ArrayList<>(); + private static final ArrayList MOTORS = new ArrayList<>(); /** - * Adds a motor to the array list INSTRUMENTS to then be added to the Orchestra. + * Adds a motor to the Orchestra. + * The Orchestra can then play the music from those motors. * - * @param motor the motor to be added to the Orchestra through INSTRUMENTS + * @param motor the motor to be added to the Orchestra */ public static void addMotor(TalonFX motor) { - INSTRUMENTS.add(motor); + MOTORS.add(motor); } /** - * Gives a music file to the Orchestra and assigns a track to each motor added to the Orchestra. - * Each track plays a different part of the music file; bass, harmonys, etc.... - * If the number of motors exceeds the amount of total tracks then the extra motors will be assigned used tracks. - * The extra motors will receive the track number equivalent to by how much exceeded the total amount of tracks. - * Only one track can be assigned to each motor. + * Plays a .chrp file and assigns a track to each motor. + * A .chrp file stores music as tracks that can be played separately. + * The tracks are assigned linearly and loop back if there are extra motors. * - * @param musicFile the music file to be added to the Orchestra - * @param totalTracks number of totalTracks to be assigned to the motors + * @param fileName the .chrp file to be played by the Orchestra + * @param totalTracks the number of tracks in the .chrp file. */ - public static void playTracks(String musicFile, int totalTracks) { - for (int i = 0; i < INSTRUMENTS.size(); i++) - ORCHESTRA.addInstrument(INSTRUMENTS.get(i), i % totalTracks + 1); - addAndPlayTracks(musicFile); + public static void playFile(String fileName, int totalTracks) { + for (int i = 0; i < MOTORS.size(); i++) + ORCHESTRA.addInstrument(MOTORS.get(i), i % totalTracks + 1); + addAndPlayFile(fileName); } /** - * Sets a music file to the Orchestra and assigns each track to one or more motors. - * Each track plays a different part of the music file; bass, harmonys, etc.... - * Works with multiple tracks. - * Can assign a single track to more than one motor. + * plays a .chrp file and assigns a track to each motor. + * A .chrp file stores music as tracks that can be played separately. + * The tracks are assigned by the {@code motorsPerTrack}. + * Each slot represents a track. + * Each value in the slot represents the number of motors that will be assigned that track. * - * @param musicFile the music file to be added to the Orchestra - * @param motorsPerTrack number of motors that get assigned to a track + * @param fileName the .chrp file to be added to the Orchestra + * @param motorsPerTrack number of motors that should be assigned to each track */ - public static void playTracks(String musicFile, int... motorsPerTrack) throws IllegalStateException { - int totalTracks = 0; + public static void playFile(String fileName, int... motorsPerTrack) throws IllegalStateException { + int totalUsedMotors = 0; int motorsAssignedTracks = 0; for (int i = 0; i < motorsPerTrack.length; i++) { - totalTracks += motorsPerTrack[i]; - if (totalTracks > INSTRUMENTS.size()) - throw new IllegalStateException("Not enough motors"); + totalUsedMotors += motorsPerTrack[i]; + if (totalUsedMotors > MOTORS.size()) + throw new IllegalStateException("Not enough motors added to the Orchestra."); for (int j = 0; j < motorsPerTrack[i]; i++) - ORCHESTRA.addInstrument(INSTRUMENTS.get(motorsAssignedTracks++), i + 1); + ORCHESTRA.addInstrument(MOTORS.get(motorsAssignedTracks++), i + 1); } - addAndPlayTracks(musicFile); + addAndPlayFile(fileName); } /** - * Adds a music file to the Orchestra and then plays it. - * - * @param musicFile the music file to be added to the Orchestra - */ - public static void addAndPlayTracks(String musicFile) { - addTracks(musicFile); - playTracks(); - } - - /** - * Resets the Orchestra. + * Stops the music and removes all tracks assigned to motors. */ - public static void stopTracks() { + public static void stop() { ORCHESTRA.stop(); - clearAllMotors(); - } - - /** - * Removes all the motors from the Orchestra and returns the status code of clearing all the motors. - */ - public static void clearAllMotors() { ORCHESTRA.clearInstruments(); } /** - * Plays the music file in the Orchestra. + * Plays the stored .chrp file. */ - public static void playTracks() { + public static void play() { ORCHESTRA.play(); } /** - * Assigns a music file to the Orchestra. - * - * @param musicFile the music file to be added to the Orchestra + * Pauses the music. */ - public static void addTracks(String musicFile) { - ORCHESTRA.loadMusic(musicFile); - } - - /** - * Stops the music file in the Orchestra until resumed. - */ - public static void pauseTracks() { + public static void pause() { ORCHESTRA.pause(); } /** - * Stops playing the music file and resets the Orchestra. + * Returns whether the Orchestra is playing music. + * + * @return if music is playing */ - public static void closeTracks() { - ORCHESTRA.close(); + public static boolean isOrchestraCurrentlyPlayingMusic() { + return ORCHESTRA.isPlaying(); } /** - * returns whether or not the music file is playing. + * Gets the play time of the .chrp file being played in seconds. * - * @return if the track is playing + * @return the play time */ - public static boolean areTracksPlaying() { - return ORCHESTRA.isPlaying(); + public static double getPlayTimeSeconds() { + return ORCHESTRA.getCurrentTime(); } /** - * Gets the current time location of the music file. + * Adds a .chrp file to the Orchestra and plays it. * - * @return the current time location of the music file in seconds + * @param fileName the .chrp file to be added to the Orchestra */ - public static double getCurrentMusicFileTimeLocation() { - return ORCHESTRA.getCurrentTime(); + private static void addAndPlayFile(String fileName) { + ORCHESTRA.loadMusic(fileName); + play(); } } From 9ae124b84f868164b414f77dd65d6da907b4f050 Mon Sep 17 00:00:00 2001 From: ShmayaR Date: Tue, 25 Feb 2025 11:37:38 +0200 Subject: [PATCH 09/47] fixed up java doc --- .../org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java | 6 +++--- src/main/java/org/trigon/utilities/Orchestra.java | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java index f85b2895..b9b9e159 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java +++ b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java @@ -194,10 +194,10 @@ public void setBrake(boolean brake) { } /** - * Adds the TalonFX to the Orchestra. - * Orchestra plays a track of music in one or more motors. + * Allows access to the TalonFX. + * + * @param signal the TalonFX signal */ - private BaseStatusSignal motorSignalToStatusSignal(TalonFXSignal signal) { final TalonFX talonFX = motorIO.getTalonFX(); if (RobotHardwareStats.isReplay() || talonFX == null) diff --git a/src/main/java/org/trigon/utilities/Orchestra.java b/src/main/java/org/trigon/utilities/Orchestra.java index 41a1148e..1426cc3c 100644 --- a/src/main/java/org/trigon/utilities/Orchestra.java +++ b/src/main/java/org/trigon/utilities/Orchestra.java @@ -32,6 +32,7 @@ public static void addMotor(TalonFX motor) { public static void playFile(String fileName, int totalTracks) { for (int i = 0; i < MOTORS.size(); i++) ORCHESTRA.addInstrument(MOTORS.get(i), i % totalTracks + 1); + addAndPlayFile(fileName); } From 52dd81421b4fa746318bb2763d046d5b82b13805 Mon Sep 17 00:00:00 2001 From: ShmayaR Date: Tue, 25 Feb 2025 17:15:55 +0200 Subject: [PATCH 10/47] Update Orchestra.java --- src/main/java/org/trigon/utilities/Orchestra.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/org/trigon/utilities/Orchestra.java b/src/main/java/org/trigon/utilities/Orchestra.java index 1426cc3c..5c939ecc 100644 --- a/src/main/java/org/trigon/utilities/Orchestra.java +++ b/src/main/java/org/trigon/utilities/Orchestra.java @@ -52,10 +52,9 @@ public static void playFile(String fileName, int... motorsPerTrack) throws Illeg for (int i = 0; i < motorsPerTrack.length; i++) { totalUsedMotors += motorsPerTrack[i]; if (totalUsedMotors > MOTORS.size()) - throw new IllegalStateException("Not enough motors added to the Orchestra."); + System.out.println("Not enough motors added to the Orchestra."); for (int j = 0; j < motorsPerTrack[i]; i++) ORCHESTRA.addInstrument(MOTORS.get(motorsAssignedTracks++), i + 1); - } addAndPlayFile(fileName); } @@ -83,8 +82,6 @@ public static void pause() { } /** - * Returns whether the Orchestra is playing music. - * * @return if music is playing */ public static boolean isOrchestraCurrentlyPlayingMusic() { From 4488b3e29da5c101d66112cd237e2809d7420ad5 Mon Sep 17 00:00:00 2001 From: ShmayaR Date: Sun, 2 Mar 2025 10:53:39 +0200 Subject: [PATCH 11/47] Update TalonFXMotor.java --- .../org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java index b9b9e159..b8bf8d7b 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java +++ b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java @@ -192,12 +192,7 @@ public void setPosition(double positionRotations) { public void setBrake(boolean brake) { motorIO.setBrake(brake); } - - /** - * Allows access to the TalonFX. - * - * @param signal the TalonFX signal - */ + private BaseStatusSignal motorSignalToStatusSignal(TalonFXSignal signal) { final TalonFX talonFX = motorIO.getTalonFX(); if (RobotHardwareStats.isReplay() || talonFX == null) From b01545713b52e96064e8d2c1b0d1e719f729be0c Mon Sep 17 00:00:00 2001 From: ShmayaR Date: Tue, 4 Mar 2025 16:38:18 +0200 Subject: [PATCH 12/47] Update Orchestra.java --- .../java/org/trigon/utilities/Orchestra.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/trigon/utilities/Orchestra.java b/src/main/java/org/trigon/utilities/Orchestra.java index 5c939ecc..54a7317e 100644 --- a/src/main/java/org/trigon/utilities/Orchestra.java +++ b/src/main/java/org/trigon/utilities/Orchestra.java @@ -26,14 +26,14 @@ public static void addMotor(TalonFX motor) { * A .chrp file stores music as tracks that can be played separately. * The tracks are assigned linearly and loop back if there are extra motors. * - * @param fileName the .chrp file to be played by the Orchestra + * @param filePath the path of the .chrp file to be played by the Orchestra * @param totalTracks the number of tracks in the .chrp file. */ - public static void playFile(String fileName, int totalTracks) { + public static void playFile(String filePath, int totalTracks) { for (int i = 0; i < MOTORS.size(); i++) ORCHESTRA.addInstrument(MOTORS.get(i), i % totalTracks + 1); - addAndPlayFile(fileName); + addAndPlayFile(filePath); } /** @@ -43,10 +43,10 @@ public static void playFile(String fileName, int totalTracks) { * Each slot represents a track. * Each value in the slot represents the number of motors that will be assigned that track. * - * @param fileName the .chrp file to be added to the Orchestra + * @param filePath the path of the .chrp file to be added to the Orchestra * @param motorsPerTrack number of motors that should be assigned to each track */ - public static void playFile(String fileName, int... motorsPerTrack) throws IllegalStateException { + public static void playFile(String filePath, int... motorsPerTrack) throws IllegalStateException { int totalUsedMotors = 0; int motorsAssignedTracks = 0; for (int i = 0; i < motorsPerTrack.length; i++) { @@ -56,7 +56,7 @@ public static void playFile(String fileName, int... motorsPerTrack) throws Illeg for (int j = 0; j < motorsPerTrack[i]; i++) ORCHESTRA.addInstrument(MOTORS.get(motorsAssignedTracks++), i + 1); } - addAndPlayFile(fileName); + addAndPlayFile(filePath); } /** @@ -100,10 +100,10 @@ public static double getPlayTimeSeconds() { /** * Adds a .chrp file to the Orchestra and plays it. * - * @param fileName the .chrp file to be added to the Orchestra + * @param filePath the path of the .chrp file to be added to the Orchestra */ - private static void addAndPlayFile(String fileName) { - ORCHESTRA.loadMusic(fileName); + private static void addAndPlayFile(String filePath) { + ORCHESTRA.loadMusic(filePath); play(); } } From ac914260a3d1a61c56bbe55fb9e7e2a4f9ed4d8d Mon Sep 17 00:00:00 2001 From: ShmayaR Date: Wed, 5 Mar 2025 23:43:20 +0200 Subject: [PATCH 13/47] shortened a java doc into one @return --- src/main/java/org/trigon/utilities/Orchestra.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/org/trigon/utilities/Orchestra.java b/src/main/java/org/trigon/utilities/Orchestra.java index 54a7317e..282e6b34 100644 --- a/src/main/java/org/trigon/utilities/Orchestra.java +++ b/src/main/java/org/trigon/utilities/Orchestra.java @@ -89,9 +89,7 @@ public static boolean isOrchestraCurrentlyPlayingMusic() { } /** - * Gets the play time of the .chrp file being played in seconds. - * - * @return the play time + * @return the play time of the .chrp file in seconds */ public static double getPlayTimeSeconds() { return ORCHESTRA.getCurrentTime(); From d6da94002790d2a4d59ef72efaca1d407b281318 Mon Sep 17 00:00:00 2001 From: Strflightmight09 <148347057+Strflightmight09@users.noreply.github.com> Date: Thu, 6 Mar 2025 17:28:36 +0200 Subject: [PATCH 14/47] Fix error message --- src/main/java/org/trigon/utilities/Orchestra.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/trigon/utilities/Orchestra.java b/src/main/java/org/trigon/utilities/Orchestra.java index 282e6b34..cf46ce61 100644 --- a/src/main/java/org/trigon/utilities/Orchestra.java +++ b/src/main/java/org/trigon/utilities/Orchestra.java @@ -51,8 +51,11 @@ public static void playFile(String filePath, int... motorsPerTrack) throws Illeg int motorsAssignedTracks = 0; for (int i = 0; i < motorsPerTrack.length; i++) { totalUsedMotors += motorsPerTrack[i]; - if (totalUsedMotors > MOTORS.size()) - System.out.println("Not enough motors added to the Orchestra."); + if (totalUsedMotors > MOTORS.size()) { + System.out.println("Orchestra: Fewer motors than requested tracks, can't play requested file."); + ORCHESTRA.clearInstruments(); + return; + } for (int j = 0; j < motorsPerTrack[i]; i++) ORCHESTRA.addInstrument(MOTORS.get(motorsAssignedTracks++), i + 1); } From f621f70cf8092a0a2a138030e88a53eb266a8081 Mon Sep 17 00:00:00 2001 From: Strflightmight09 <148347057+Strflightmight09@users.noreply.github.com> Date: Tue, 24 Jun 2025 22:34:08 +0300 Subject: [PATCH 15/47] No more throwing --- src/main/java/org/trigon/utilities/Orchestra.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/trigon/utilities/Orchestra.java b/src/main/java/org/trigon/utilities/Orchestra.java index cf46ce61..c145c0d6 100644 --- a/src/main/java/org/trigon/utilities/Orchestra.java +++ b/src/main/java/org/trigon/utilities/Orchestra.java @@ -46,9 +46,10 @@ public static void playFile(String filePath, int totalTracks) { * @param filePath the path of the .chrp file to be added to the Orchestra * @param motorsPerTrack number of motors that should be assigned to each track */ - public static void playFile(String filePath, int... motorsPerTrack) throws IllegalStateException { + public static void playFile(String filePath, int... motorsPerTrack) { int totalUsedMotors = 0; int motorsAssignedTracks = 0; + for (int i = 0; i < motorsPerTrack.length; i++) { totalUsedMotors += motorsPerTrack[i]; if (totalUsedMotors > MOTORS.size()) { @@ -85,7 +86,7 @@ public static void pause() { } /** - * @return if music is playing + * @return whether music is playing or not */ public static boolean isOrchestraCurrentlyPlayingMusic() { return ORCHESTRA.isPlaying(); From 3012beba380de185bab146dcb96c5de9d138a6c6 Mon Sep 17 00:00:00 2001 From: Strflightmight09 <148347057+Strflightmight09@users.noreply.github.com> Date: Thu, 3 Jul 2025 15:22:41 +0300 Subject: [PATCH 16/47] Quick fix --- .../phoenix6/talonfx/TalonFXMotor.java | 5 ++-- .../java/org/trigon/utilities/Orchestra.java | 27 ++++++++++++++----- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java index b8bf8d7b..abf9994a 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java +++ b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java @@ -32,7 +32,6 @@ public class TalonFXMotor { */ public TalonFXMotor(int id, String motorName) { this(id, motorName, ""); - Orchestra.addMotor(motorIO.getTalonFX()); } /** @@ -48,6 +47,8 @@ public TalonFXMotor(int id, String motorName, String canbus) { this.motorInputs = new Phoenix6Inputs(motorName, !canbus.isEmpty()); this.id = id; motorIO.optimizeBusUsage(); + + Orchestra.addMotor(motorIO.getTalonFX()); } /** @@ -192,7 +193,7 @@ public void setPosition(double positionRotations) { public void setBrake(boolean brake) { motorIO.setBrake(brake); } - + private BaseStatusSignal motorSignalToStatusSignal(TalonFXSignal signal) { final TalonFX talonFX = motorIO.getTalonFX(); if (RobotHardwareStats.isReplay() || talonFX == null) diff --git a/src/main/java/org/trigon/utilities/Orchestra.java b/src/main/java/org/trigon/utilities/Orchestra.java index c145c0d6..62985ebd 100644 --- a/src/main/java/org/trigon/utilities/Orchestra.java +++ b/src/main/java/org/trigon/utilities/Orchestra.java @@ -27,11 +27,14 @@ public static void addMotor(TalonFX motor) { * The tracks are assigned linearly and loop back if there are extra motors. * * @param filePath the path of the .chrp file to be played by the Orchestra - * @param totalTracks the number of tracks in the .chrp file. + * @param totalTracks the number of tracks in the .chrp file + * @param skippedIDs the IDs of motors that should not be assigned a track */ - public static void playFile(String filePath, int totalTracks) { - for (int i = 0; i < MOTORS.size(); i++) - ORCHESTRA.addInstrument(MOTORS.get(i), i % totalTracks + 1); + public static void playFile(String filePath, int totalTracks, int... skippedIDs) { + for (int i = 0; i < MOTORS.size(); i++) { + if (!shouldSkipMotor(i, skippedIDs)) + ORCHESTRA.addInstrument(MOTORS.get(i), i % totalTracks + 1); + } addAndPlayFile(filePath); } @@ -45,8 +48,9 @@ public static void playFile(String filePath, int totalTracks) { * * @param filePath the path of the .chrp file to be added to the Orchestra * @param motorsPerTrack number of motors that should be assigned to each track + * @param skippedIDs the IDs of motors that should not be assigned a track */ - public static void playFile(String filePath, int... motorsPerTrack) { + public static void playFile(String filePath, int[] motorsPerTrack, int... skippedIDs) { int totalUsedMotors = 0; int motorsAssignedTracks = 0; @@ -58,7 +62,9 @@ public static void playFile(String filePath, int... motorsPerTrack) { return; } for (int j = 0; j < motorsPerTrack[i]; i++) - ORCHESTRA.addInstrument(MOTORS.get(motorsAssignedTracks++), i + 1); + if (!shouldSkipMotor(motorsAssignedTracks, skippedIDs)) + ORCHESTRA.addInstrument(MOTORS.get(motorsAssignedTracks), i + 1); + motorsAssignedTracks++; } addAndPlayFile(filePath); } @@ -108,4 +114,13 @@ private static void addAndPlayFile(String filePath) { ORCHESTRA.loadMusic(filePath); play(); } + + private static boolean shouldSkipMotor(int id, int[] skippedIDs) { + for (int skippedID : skippedIDs) { + if (id == skippedID) { + return true; + } + } + return false; + } } From 5289a526f7962beea1bfbc3736bf511d6a9e9dbd Mon Sep 17 00:00:00 2001 From: Strflightmight09 <148347057+Strflightmight09@users.noreply.github.com> Date: Thu, 3 Jul 2025 15:33:33 +0300 Subject: [PATCH 17/47] WOW --- src/main/java/org/trigon/utilities/Orchestra.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/trigon/utilities/Orchestra.java b/src/main/java/org/trigon/utilities/Orchestra.java index 62985ebd..99d1b58e 100644 --- a/src/main/java/org/trigon/utilities/Orchestra.java +++ b/src/main/java/org/trigon/utilities/Orchestra.java @@ -61,7 +61,7 @@ public static void playFile(String filePath, int[] motorsPerTrack, int... skippe ORCHESTRA.clearInstruments(); return; } - for (int j = 0; j < motorsPerTrack[i]; i++) + for (int j = 0; j < motorsPerTrack[i]; j++) if (!shouldSkipMotor(motorsAssignedTracks, skippedIDs)) ORCHESTRA.addInstrument(MOTORS.get(motorsAssignedTracks), i + 1); motorsAssignedTracks++; From 32e3df00aeb5f3f8734d917952f8bb992eab28c0 Mon Sep 17 00:00:00 2001 From: Strflightmight09 <148347057+Strflightmight09@users.noreply.github.com> Date: Thu, 3 Jul 2025 15:53:55 +0300 Subject: [PATCH 18/47] Try this --- src/main/java/org/trigon/utilities/Orchestra.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/trigon/utilities/Orchestra.java b/src/main/java/org/trigon/utilities/Orchestra.java index 99d1b58e..2f626bbd 100644 --- a/src/main/java/org/trigon/utilities/Orchestra.java +++ b/src/main/java/org/trigon/utilities/Orchestra.java @@ -32,8 +32,8 @@ public static void addMotor(TalonFX motor) { */ public static void playFile(String filePath, int totalTracks, int... skippedIDs) { for (int i = 0; i < MOTORS.size(); i++) { - if (!shouldSkipMotor(i, skippedIDs)) - ORCHESTRA.addInstrument(MOTORS.get(i), i % totalTracks + 1); + if (!shouldSkipMotor(MOTORS.get(i).getDeviceID(), skippedIDs)) + ORCHESTRA.addInstrument(MOTORS.get(i), (i % totalTracks) + 1); } addAndPlayFile(filePath); @@ -62,7 +62,7 @@ public static void playFile(String filePath, int[] motorsPerTrack, int... skippe return; } for (int j = 0; j < motorsPerTrack[i]; j++) - if (!shouldSkipMotor(motorsAssignedTracks, skippedIDs)) + if (!shouldSkipMotor(MOTORS.get(motorsAssignedTracks).getDeviceID(), skippedIDs)) ORCHESTRA.addInstrument(MOTORS.get(motorsAssignedTracks), i + 1); motorsAssignedTracks++; } From 9048ec259d3d038b39156dd61cfcca6cd655ebde Mon Sep 17 00:00:00 2001 From: Strflightmight09 <148347057+Strflightmight09@users.noreply.github.com> Date: Thu, 3 Jul 2025 16:14:23 +0300 Subject: [PATCH 19/47] ok sure --- src/main/java/org/trigon/utilities/Orchestra.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/trigon/utilities/Orchestra.java b/src/main/java/org/trigon/utilities/Orchestra.java index 2f626bbd..1ab7eb61 100644 --- a/src/main/java/org/trigon/utilities/Orchestra.java +++ b/src/main/java/org/trigon/utilities/Orchestra.java @@ -33,7 +33,7 @@ public static void addMotor(TalonFX motor) { public static void playFile(String filePath, int totalTracks, int... skippedIDs) { for (int i = 0; i < MOTORS.size(); i++) { if (!shouldSkipMotor(MOTORS.get(i).getDeviceID(), skippedIDs)) - ORCHESTRA.addInstrument(MOTORS.get(i), (i % totalTracks) + 1); + ORCHESTRA.addInstrument(MOTORS.get(i), i % totalTracks); } addAndPlayFile(filePath); @@ -63,7 +63,7 @@ public static void playFile(String filePath, int[] motorsPerTrack, int... skippe } for (int j = 0; j < motorsPerTrack[i]; j++) if (!shouldSkipMotor(MOTORS.get(motorsAssignedTracks).getDeviceID(), skippedIDs)) - ORCHESTRA.addInstrument(MOTORS.get(motorsAssignedTracks), i + 1); + ORCHESTRA.addInstrument(MOTORS.get(motorsAssignedTracks), i); motorsAssignedTracks++; } addAndPlayFile(filePath); From cc95c54bc0a0a364ae2195a5542172eb95017d79 Mon Sep 17 00:00:00 2001 From: Strflightmight09 <148347057+Strflightmight09@users.noreply.github.com> Date: Thu, 3 Jul 2025 16:25:23 +0300 Subject: [PATCH 20/47] tets --- src/main/java/org/trigon/utilities/Orchestra.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/trigon/utilities/Orchestra.java b/src/main/java/org/trigon/utilities/Orchestra.java index 1ab7eb61..68d40c8a 100644 --- a/src/main/java/org/trigon/utilities/Orchestra.java +++ b/src/main/java/org/trigon/utilities/Orchestra.java @@ -32,8 +32,8 @@ public static void addMotor(TalonFX motor) { */ public static void playFile(String filePath, int totalTracks, int... skippedIDs) { for (int i = 0; i < MOTORS.size(); i++) { - if (!shouldSkipMotor(MOTORS.get(i).getDeviceID(), skippedIDs)) - ORCHESTRA.addInstrument(MOTORS.get(i), i % totalTracks); +// if (!shouldSkipMotor(MOTORS.get(i).getDeviceID(), skippedIDs)) + ORCHESTRA.addInstrument(MOTORS.get(i), i % totalTracks); } addAndPlayFile(filePath); @@ -62,8 +62,8 @@ public static void playFile(String filePath, int[] motorsPerTrack, int... skippe return; } for (int j = 0; j < motorsPerTrack[i]; j++) - if (!shouldSkipMotor(MOTORS.get(motorsAssignedTracks).getDeviceID(), skippedIDs)) - ORCHESTRA.addInstrument(MOTORS.get(motorsAssignedTracks), i); +// if (!shouldSkipMotor(MOTORS.get(motorsAssignedTracks).getDeviceID(), skippedIDs)) + ORCHESTRA.addInstrument(MOTORS.get(motorsAssignedTracks), i); motorsAssignedTracks++; } addAndPlayFile(filePath); From 33c5a010103385aef485a2bd70487318af28eac1 Mon Sep 17 00:00:00 2001 From: Strflightmight09 <148347057+Strflightmight09@users.noreply.github.com> Date: Thu, 3 Jul 2025 16:32:10 +0300 Subject: [PATCH 21/47] NOw tis goinna work trust --- src/main/java/org/trigon/utilities/Orchestra.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/trigon/utilities/Orchestra.java b/src/main/java/org/trigon/utilities/Orchestra.java index 68d40c8a..e9fa5060 100644 --- a/src/main/java/org/trigon/utilities/Orchestra.java +++ b/src/main/java/org/trigon/utilities/Orchestra.java @@ -32,8 +32,8 @@ public static void addMotor(TalonFX motor) { */ public static void playFile(String filePath, int totalTracks, int... skippedIDs) { for (int i = 0; i < MOTORS.size(); i++) { -// if (!shouldSkipMotor(MOTORS.get(i).getDeviceID(), skippedIDs)) - ORCHESTRA.addInstrument(MOTORS.get(i), i % totalTracks); + if (!shouldSkipMotor(MOTORS.get(i).getDeviceID(), skippedIDs)) + ORCHESTRA.addInstrument(MOTORS.get(i), i % totalTracks); } addAndPlayFile(filePath); @@ -61,10 +61,11 @@ public static void playFile(String filePath, int[] motorsPerTrack, int... skippe ORCHESTRA.clearInstruments(); return; } - for (int j = 0; j < motorsPerTrack[i]; j++) -// if (!shouldSkipMotor(MOTORS.get(motorsAssignedTracks).getDeviceID(), skippedIDs)) - ORCHESTRA.addInstrument(MOTORS.get(motorsAssignedTracks), i); - motorsAssignedTracks++; + for (int j = 0; j < motorsPerTrack[i]; j++) { + if (!shouldSkipMotor(MOTORS.get(motorsAssignedTracks).getDeviceID(), skippedIDs)) + ORCHESTRA.addInstrument(MOTORS.get(motorsAssignedTracks), i); + motorsAssignedTracks++; + } } addAndPlayFile(filePath); } From 52c9fe9c699961d5478fc4c319781ab253c9621a Mon Sep 17 00:00:00 2001 From: Strflightmight09 <148347057+Strflightmight09@users.noreply.github.com> Date: Thu, 3 Jul 2025 16:53:02 +0300 Subject: [PATCH 22/47] I thiikn we got it guys --- .../hardware/phoenix6/talonfx/TalonFXMotor.java | 2 +- src/main/java/org/trigon/utilities/Orchestra.java | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java index abf9994a..fae416c6 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java +++ b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java @@ -48,7 +48,7 @@ public TalonFXMotor(int id, String motorName, String canbus) { this.id = id; motorIO.optimizeBusUsage(); - Orchestra.addMotor(motorIO.getTalonFX()); + Orchestra.addMotor(motorIO.getTalonFX(), id); } /** diff --git a/src/main/java/org/trigon/utilities/Orchestra.java b/src/main/java/org/trigon/utilities/Orchestra.java index e9fa5060..f58248eb 100644 --- a/src/main/java/org/trigon/utilities/Orchestra.java +++ b/src/main/java/org/trigon/utilities/Orchestra.java @@ -2,14 +2,14 @@ import com.ctre.phoenix6.hardware.TalonFX; -import java.util.ArrayList; +import java.util.HashMap; /** * A class that uses the {@link com.ctre.phoenix6.Orchestra} library in Phoenix 6 to play a .chrp file. */ public class Orchestra { private static final com.ctre.phoenix6.Orchestra ORCHESTRA = new com.ctre.phoenix6.Orchestra(); - private static final ArrayList MOTORS = new ArrayList<>(); + private static final HashMap MOTORS = new HashMap<>(); /** * Adds a motor to the Orchestra. @@ -17,8 +17,8 @@ public class Orchestra { * * @param motor the motor to be added to the Orchestra */ - public static void addMotor(TalonFX motor) { - MOTORS.add(motor); + public static void addMotor(TalonFX motor, int id) { + MOTORS.put(id, motor); } /** @@ -32,7 +32,7 @@ public static void addMotor(TalonFX motor) { */ public static void playFile(String filePath, int totalTracks, int... skippedIDs) { for (int i = 0; i < MOTORS.size(); i++) { - if (!shouldSkipMotor(MOTORS.get(i).getDeviceID(), skippedIDs)) + if (!shouldSkipMotor(i, skippedIDs)) ORCHESTRA.addInstrument(MOTORS.get(i), i % totalTracks); } @@ -62,7 +62,7 @@ public static void playFile(String filePath, int[] motorsPerTrack, int... skippe return; } for (int j = 0; j < motorsPerTrack[i]; j++) { - if (!shouldSkipMotor(MOTORS.get(motorsAssignedTracks).getDeviceID(), skippedIDs)) + if (!shouldSkipMotor(motorsAssignedTracks, skippedIDs)) ORCHESTRA.addInstrument(MOTORS.get(motorsAssignedTracks), i); motorsAssignedTracks++; } From 4183fa2c994d4c596c2b6d77ae1477ebaa85302f Mon Sep 17 00:00:00 2001 From: Strflightmight09 <148347057+Strflightmight09@users.noreply.github.com> Date: Sat, 5 Jul 2025 22:37:53 +0300 Subject: [PATCH 23/47] A bit of an update --- .../java/org/trigon/utilities/Orchestra.java | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/trigon/utilities/Orchestra.java b/src/main/java/org/trigon/utilities/Orchestra.java index f58248eb..e08efc88 100644 --- a/src/main/java/org/trigon/utilities/Orchestra.java +++ b/src/main/java/org/trigon/utilities/Orchestra.java @@ -51,22 +51,20 @@ public static void playFile(String filePath, int totalTracks, int... skippedIDs) * @param skippedIDs the IDs of motors that should not be assigned a track */ public static void playFile(String filePath, int[] motorsPerTrack, int... skippedIDs) { - int totalUsedMotors = 0; - int motorsAssignedTracks = 0; - - for (int i = 0; i < motorsPerTrack.length; i++) { - totalUsedMotors += motorsPerTrack[i]; - if (totalUsedMotors > MOTORS.size()) { - System.out.println("Orchestra: Fewer motors than requested tracks, can't play requested file."); - ORCHESTRA.clearInstruments(); - return; - } - for (int j = 0; j < motorsPerTrack[i]; j++) { - if (!shouldSkipMotor(motorsAssignedTracks, skippedIDs)) - ORCHESTRA.addInstrument(MOTORS.get(motorsAssignedTracks), i); - motorsAssignedTracks++; + int motorIndex = 0; + + for (int trackIndex = 0; trackIndex < motorsPerTrack.length; trackIndex++) { + for (int motorsInCurrentTrack = 0; motorsInCurrentTrack < motorsPerTrack[trackIndex]; motorsInCurrentTrack++) { + if (motorIndex >= MOTORS.size()) { + System.out.println("Orchestra: Not enough motors"); + return; + } + if (!shouldSkipMotor(motorIndex, skippedIDs)) + ORCHESTRA.addInstrument(MOTORS.get(motorIndex), trackIndex); + motorIndex++; } } + addAndPlayFile(filePath); } From dba95ee55b72752bb3515951ff710adba43ab3cb Mon Sep 17 00:00:00 2001 From: Strflightmight09 <148347057+Strflightmight09@users.noreply.github.com> Date: Sat, 5 Jul 2025 22:48:24 +0300 Subject: [PATCH 24/47] =?UTF-8?q?ID=200=20=F0=9F=98=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/trigon/utilities/Orchestra.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/trigon/utilities/Orchestra.java b/src/main/java/org/trigon/utilities/Orchestra.java index e08efc88..ddb6bb59 100644 --- a/src/main/java/org/trigon/utilities/Orchestra.java +++ b/src/main/java/org/trigon/utilities/Orchestra.java @@ -31,8 +31,8 @@ public static void addMotor(TalonFX motor, int id) { * @param skippedIDs the IDs of motors that should not be assigned a track */ public static void playFile(String filePath, int totalTracks, int... skippedIDs) { - for (int i = 0; i < MOTORS.size(); i++) { - if (!shouldSkipMotor(i, skippedIDs)) + for (int i = 1; i < MOTORS.size(); i++) { + if (!shouldSkipMotor(i, skippedIDs) && MOTORS.containsKey(i)) ORCHESTRA.addInstrument(MOTORS.get(i), i % totalTracks); } @@ -51,7 +51,7 @@ public static void playFile(String filePath, int totalTracks, int... skippedIDs) * @param skippedIDs the IDs of motors that should not be assigned a track */ public static void playFile(String filePath, int[] motorsPerTrack, int... skippedIDs) { - int motorIndex = 0; + int motorIndex = 1; for (int trackIndex = 0; trackIndex < motorsPerTrack.length; trackIndex++) { for (int motorsInCurrentTrack = 0; motorsInCurrentTrack < motorsPerTrack[trackIndex]; motorsInCurrentTrack++) { From 4b50c8a715098aa8a3d4ff5cd49dedbc6acfc102 Mon Sep 17 00:00:00 2001 From: Strflightmight09 <148347057+Strflightmight09@users.noreply.github.com> Date: Sat, 5 Jul 2025 22:49:17 +0300 Subject: [PATCH 25/47] Oops --- src/main/java/org/trigon/utilities/Orchestra.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/trigon/utilities/Orchestra.java b/src/main/java/org/trigon/utilities/Orchestra.java index ddb6bb59..1d5cbe90 100644 --- a/src/main/java/org/trigon/utilities/Orchestra.java +++ b/src/main/java/org/trigon/utilities/Orchestra.java @@ -59,7 +59,7 @@ public static void playFile(String filePath, int[] motorsPerTrack, int... skippe System.out.println("Orchestra: Not enough motors"); return; } - if (!shouldSkipMotor(motorIndex, skippedIDs)) + if (!shouldSkipMotor(motorIndex, skippedIDs) && MOTORS.containsKey(motorIndex)) ORCHESTRA.addInstrument(MOTORS.get(motorIndex), trackIndex); motorIndex++; } From cf18c47d12d9cb1357b38d9a81e52f1db8fc690b Mon Sep 17 00:00:00 2001 From: Strflightmight09 <148347057+Strflightmight09@users.noreply.github.com> Date: Sat, 5 Jul 2025 23:07:40 +0300 Subject: [PATCH 26/47] Fix --- src/main/java/org/trigon/utilities/Orchestra.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/trigon/utilities/Orchestra.java b/src/main/java/org/trigon/utilities/Orchestra.java index 1d5cbe90..9f54916d 100644 --- a/src/main/java/org/trigon/utilities/Orchestra.java +++ b/src/main/java/org/trigon/utilities/Orchestra.java @@ -31,7 +31,7 @@ public static void addMotor(TalonFX motor, int id) { * @param skippedIDs the IDs of motors that should not be assigned a track */ public static void playFile(String filePath, int totalTracks, int... skippedIDs) { - for (int i = 1; i < MOTORS.size(); i++) { + for (int i = 1; i < MOTORS.size() + 1; i++) { if (!shouldSkipMotor(i, skippedIDs) && MOTORS.containsKey(i)) ORCHESTRA.addInstrument(MOTORS.get(i), i % totalTracks); } @@ -55,7 +55,7 @@ public static void playFile(String filePath, int[] motorsPerTrack, int... skippe for (int trackIndex = 0; trackIndex < motorsPerTrack.length; trackIndex++) { for (int motorsInCurrentTrack = 0; motorsInCurrentTrack < motorsPerTrack[trackIndex]; motorsInCurrentTrack++) { - if (motorIndex >= MOTORS.size()) { + if (motorIndex > MOTORS.size()) { System.out.println("Orchestra: Not enough motors"); return; } From b8b63f6484a76e3f1a6e85c8d499163e55b08c6c Mon Sep 17 00:00:00 2001 From: Strflightmight09 <148347057+Strflightmight09@users.noreply.github.com> Date: Sat, 5 Jul 2025 23:38:44 +0300 Subject: [PATCH 27/47] Test idk --- .../java/org/trigon/utilities/Orchestra.java | 126 +++++++++++++++--- 1 file changed, 104 insertions(+), 22 deletions(-) diff --git a/src/main/java/org/trigon/utilities/Orchestra.java b/src/main/java/org/trigon/utilities/Orchestra.java index 9f54916d..1682a37d 100644 --- a/src/main/java/org/trigon/utilities/Orchestra.java +++ b/src/main/java/org/trigon/utilities/Orchestra.java @@ -1,13 +1,19 @@ package org.trigon.utilities; import com.ctre.phoenix6.hardware.TalonFX; +import edu.wpi.first.wpilibj2.command.Command; +import edu.wpi.first.wpilibj2.command.FunctionalCommand; +import edu.wpi.first.wpilibj2.command.InstantCommand; +import edu.wpi.first.wpilibj2.command.SubsystemBase; import java.util.HashMap; +import java.util.function.Supplier; /** * A class that uses the {@link com.ctre.phoenix6.Orchestra} library in Phoenix 6 to play a .chrp file. */ -public class Orchestra { +public class Orchestra extends SubsystemBase { + private static final Orchestra INSTANCE = new Orchestra(); private static final com.ctre.phoenix6.Orchestra ORCHESTRA = new com.ctre.phoenix6.Orchestra(); private static final HashMap MOTORS = new HashMap<>(); @@ -21,6 +27,61 @@ public static void addMotor(TalonFX motor, int id) { MOTORS.put(id, motor); } + public static Command getPlayFileCommand(String filePath, int totalTracks, Supplier... skippedIDs) { + return new FunctionalCommand( + () -> playFile(filePath, totalTracks, integerSupplierArrayToIntegerArray(skippedIDs)), + () -> updateMotors(totalTracks, skippedIDs), + (interrupted) -> stop(), + () -> false, + INSTANCE + ); + } + + public static Command getPlayFileCommand(String filePath, int[] motorsPerTrack, Supplier... skippedIDs) { + return new FunctionalCommand( + () -> playFile(filePath, motorsPerTrack, integerSupplierArrayToIntegerArray(skippedIDs)), + () -> updateMotors(motorsPerTrack, skippedIDs), + (interrupted) -> stop(), + () -> false, + INSTANCE + ); + } + + public static Command getStopCommand() { + return new InstantCommand( + Orchestra::stop, + INSTANCE + ); + } + + public static Command getPauseCommand() { + return new InstantCommand( + Orchestra::pause, + INSTANCE + ); + } + + public static Command getPlayCommand() { + return new InstantCommand( + Orchestra::play, + INSTANCE + ); + } + + /** + * @return whether music is playing or not + */ + public static boolean isOrchestraCurrentlyPlayingMusic() { + return ORCHESTRA.isPlaying(); + } + + /** + * @return the play time of the .chrp file in seconds + */ + public static double getPlayTimeSeconds() { + return ORCHESTRA.getCurrentTime(); + } + /** * Plays a .chrp file and assigns a track to each motor. * A .chrp file stores music as tracks that can be played separately. @@ -30,7 +91,7 @@ public static void addMotor(TalonFX motor, int id) { * @param totalTracks the number of tracks in the .chrp file * @param skippedIDs the IDs of motors that should not be assigned a track */ - public static void playFile(String filePath, int totalTracks, int... skippedIDs) { + private static void playFile(String filePath, int totalTracks, int... skippedIDs) { for (int i = 1; i < MOTORS.size() + 1; i++) { if (!shouldSkipMotor(i, skippedIDs) && MOTORS.containsKey(i)) ORCHESTRA.addInstrument(MOTORS.get(i), i % totalTracks); @@ -50,7 +111,7 @@ public static void playFile(String filePath, int totalTracks, int... skippedIDs) * @param motorsPerTrack number of motors that should be assigned to each track * @param skippedIDs the IDs of motors that should not be assigned a track */ - public static void playFile(String filePath, int[] motorsPerTrack, int... skippedIDs) { + private static void playFile(String filePath, int[] motorsPerTrack, int... skippedIDs) { int motorIndex = 1; for (int trackIndex = 0; trackIndex < motorsPerTrack.length; trackIndex++) { @@ -68,40 +129,53 @@ public static void playFile(String filePath, int[] motorsPerTrack, int... skippe addAndPlayFile(filePath); } - /** - * Stops the music and removes all tracks assigned to motors. - */ - public static void stop() { - ORCHESTRA.stop(); + private static void updateMotors(int totalTracks, Supplier[] skippedIDs) { ORCHESTRA.clearInstruments(); + int[] skippedIDsIntegerArray = integerSupplierArrayToIntegerArray(skippedIDs); + + for (int i = 1; i < MOTORS.size() + 1; i++) + if (!shouldSkipMotor(i, skippedIDsIntegerArray) && MOTORS.containsKey(i)) + ORCHESTRA.addInstrument(MOTORS.get(i), i % totalTracks); } - /** - * Plays the stored .chrp file. - */ - public static void play() { - ORCHESTRA.play(); + private static void updateMotors(int[] motorsPerTrack, Supplier[] skippedIDs) { + ORCHESTRA.clearInstruments(); + int[] skippedIDsIntegerArray = integerSupplierArrayToIntegerArray(skippedIDs); + int motorIndex = 1; + + for (int trackIndex = 0; trackIndex < motorsPerTrack.length; trackIndex++) { + for (int motorsInCurrentTrack = 0; motorsInCurrentTrack < motorsPerTrack[trackIndex]; motorsInCurrentTrack++) { + if (motorIndex > MOTORS.size()) { + System.out.println("Orchestra: Not enough motors"); + return; + } + if (!shouldSkipMotor(motorIndex, skippedIDsIntegerArray) && MOTORS.containsKey(motorIndex)) + ORCHESTRA.addInstrument(MOTORS.get(motorIndex), trackIndex); + motorIndex++; + } + } } /** - * Pauses the music. + * Stops the music and removes all tracks assigned to motors. */ - public static void pause() { - ORCHESTRA.pause(); + private static void stop() { + ORCHESTRA.stop(); + ORCHESTRA.clearInstruments(); } /** - * @return whether music is playing or not + * Pauses the music. */ - public static boolean isOrchestraCurrentlyPlayingMusic() { - return ORCHESTRA.isPlaying(); + private static void pause() { + ORCHESTRA.pause(); } /** - * @return the play time of the .chrp file in seconds + * Plays the stored .chrp file. */ - public static double getPlayTimeSeconds() { - return ORCHESTRA.getCurrentTime(); + private static void play() { + ORCHESTRA.play(); } /** @@ -122,4 +196,12 @@ private static boolean shouldSkipMotor(int id, int[] skippedIDs) { } return false; } + + private static int[] integerSupplierArrayToIntegerArray(Supplier[] supplierArray) { + int[] array = new int[supplierArray.length]; + for (int i = 0; i < supplierArray.length; i++) + array[i] = supplierArray[i].get(); + + return array; + } } From 9e42192da62130814bb5db149f13f47b0c9f53fe Mon Sep 17 00:00:00 2001 From: Strflightmight09 <148347057+Strflightmight09@users.noreply.github.com> Date: Sat, 5 Jul 2025 23:46:26 +0300 Subject: [PATCH 28/47] oops --- .../java/org/trigon/utilities/Orchestra.java | 50 ++++++++----------- 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/src/main/java/org/trigon/utilities/Orchestra.java b/src/main/java/org/trigon/utilities/Orchestra.java index 1682a37d..79e804ad 100644 --- a/src/main/java/org/trigon/utilities/Orchestra.java +++ b/src/main/java/org/trigon/utilities/Orchestra.java @@ -27,45 +27,45 @@ public static void addMotor(TalonFX motor, int id) { MOTORS.put(id, motor); } - public static Command getPlayFileCommand(String filePath, int totalTracks, Supplier... skippedIDs) { + public static Command getPlayFileCommand(String filePath, int totalTracks, Supplier skippedIDs) { return new FunctionalCommand( - () -> playFile(filePath, totalTracks, integerSupplierArrayToIntegerArray(skippedIDs)), + () -> playFile(filePath, totalTracks, skippedIDs.get()), () -> updateMotors(totalTracks, skippedIDs), (interrupted) -> stop(), () -> false, INSTANCE - ); + ).ignoringDisable(true); } - public static Command getPlayFileCommand(String filePath, int[] motorsPerTrack, Supplier... skippedIDs) { + public static Command getPlayFileCommand(String filePath, int[] motorsPerTrack, Supplier skippedIDs) { return new FunctionalCommand( - () -> playFile(filePath, motorsPerTrack, integerSupplierArrayToIntegerArray(skippedIDs)), + () -> playFile(filePath, motorsPerTrack, skippedIDs.get()), () -> updateMotors(motorsPerTrack, skippedIDs), (interrupted) -> stop(), () -> false, INSTANCE - ); + ).ignoringDisable(true); } public static Command getStopCommand() { return new InstantCommand( Orchestra::stop, INSTANCE - ); + ).ignoringDisable(true); } public static Command getPauseCommand() { return new InstantCommand( Orchestra::pause, INSTANCE - ); + ).ignoringDisable(true); } public static Command getPlayCommand() { return new InstantCommand( Orchestra::play, INSTANCE - ); + ).ignoringDisable(true); } /** @@ -91,9 +91,9 @@ public static double getPlayTimeSeconds() { * @param totalTracks the number of tracks in the .chrp file * @param skippedIDs the IDs of motors that should not be assigned a track */ - private static void playFile(String filePath, int totalTracks, int... skippedIDs) { + private static void playFile(String filePath, int totalTracks, int[] skippedIDs) { for (int i = 1; i < MOTORS.size() + 1; i++) { - if (!shouldSkipMotor(i, skippedIDs) && MOTORS.containsKey(i)) + if (shouldUseMotor(i, skippedIDs) && MOTORS.containsKey(i)) ORCHESTRA.addInstrument(MOTORS.get(i), i % totalTracks); } @@ -120,7 +120,7 @@ private static void playFile(String filePath, int[] motorsPerTrack, int... skipp System.out.println("Orchestra: Not enough motors"); return; } - if (!shouldSkipMotor(motorIndex, skippedIDs) && MOTORS.containsKey(motorIndex)) + if (shouldUseMotor(motorIndex, skippedIDs) && MOTORS.containsKey(motorIndex)) ORCHESTRA.addInstrument(MOTORS.get(motorIndex), trackIndex); motorIndex++; } @@ -129,18 +129,18 @@ private static void playFile(String filePath, int[] motorsPerTrack, int... skipp addAndPlayFile(filePath); } - private static void updateMotors(int totalTracks, Supplier[] skippedIDs) { + private static void updateMotors(int totalTracks, Supplier skippedIDs) { ORCHESTRA.clearInstruments(); - int[] skippedIDsIntegerArray = integerSupplierArrayToIntegerArray(skippedIDs); + int[] skippedIDsIntegerArray = skippedIDs.get(); for (int i = 1; i < MOTORS.size() + 1; i++) - if (!shouldSkipMotor(i, skippedIDsIntegerArray) && MOTORS.containsKey(i)) + if (shouldUseMotor(i, skippedIDsIntegerArray) && MOTORS.containsKey(i)) ORCHESTRA.addInstrument(MOTORS.get(i), i % totalTracks); } - private static void updateMotors(int[] motorsPerTrack, Supplier[] skippedIDs) { + private static void updateMotors(int[] motorsPerTrack, Supplier skippedIDs) { ORCHESTRA.clearInstruments(); - int[] skippedIDsIntegerArray = integerSupplierArrayToIntegerArray(skippedIDs); + int[] skippedIDsIntegerArray = skippedIDs.get(); int motorIndex = 1; for (int trackIndex = 0; trackIndex < motorsPerTrack.length; trackIndex++) { @@ -149,7 +149,7 @@ private static void updateMotors(int[] motorsPerTrack, Supplier[] skipp System.out.println("Orchestra: Not enough motors"); return; } - if (!shouldSkipMotor(motorIndex, skippedIDsIntegerArray) && MOTORS.containsKey(motorIndex)) + if (shouldUseMotor(motorIndex, skippedIDsIntegerArray) && MOTORS.containsKey(motorIndex)) ORCHESTRA.addInstrument(MOTORS.get(motorIndex), trackIndex); motorIndex++; } @@ -188,20 +188,12 @@ private static void addAndPlayFile(String filePath) { play(); } - private static boolean shouldSkipMotor(int id, int[] skippedIDs) { + private static boolean shouldUseMotor(int id, int[] skippedIDs) { for (int skippedID : skippedIDs) { if (id == skippedID) { - return true; + return false; } } - return false; - } - - private static int[] integerSupplierArrayToIntegerArray(Supplier[] supplierArray) { - int[] array = new int[supplierArray.length]; - for (int i = 0; i < supplierArray.length; i++) - array[i] = supplierArray[i].get(); - - return array; + return true; } } From e5669f221e5a25473ebaac388752287164c5bcdd Mon Sep 17 00:00:00 2001 From: Strflightmight09 <148347057+Strflightmight09@users.noreply.github.com> Date: Sun, 6 Jul 2025 20:41:38 +0300 Subject: [PATCH 29/47] Optimization --- src/main/java/org/trigon/utilities/Orchestra.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/trigon/utilities/Orchestra.java b/src/main/java/org/trigon/utilities/Orchestra.java index 79e804ad..0087100b 100644 --- a/src/main/java/org/trigon/utilities/Orchestra.java +++ b/src/main/java/org/trigon/utilities/Orchestra.java @@ -16,6 +16,7 @@ public class Orchestra extends SubsystemBase { private static final Orchestra INSTANCE = new Orchestra(); private static final com.ctre.phoenix6.Orchestra ORCHESTRA = new com.ctre.phoenix6.Orchestra(); private static final HashMap MOTORS = new HashMap<>(); + private static int[] SKIPPED_IDS = new int[0]; /** * Adds a motor to the Orchestra. @@ -130,19 +131,27 @@ private static void playFile(String filePath, int[] motorsPerTrack, int... skipp } private static void updateMotors(int totalTracks, Supplier skippedIDs) { + if (skippedIDs.get() == SKIPPED_IDS) + return; + + SKIPPED_IDS = skippedIDs.get(); ORCHESTRA.clearInstruments(); - int[] skippedIDsIntegerArray = skippedIDs.get(); + int[] skippedIDsIntegerArray = skippedIDs.get(); for (int i = 1; i < MOTORS.size() + 1; i++) if (shouldUseMotor(i, skippedIDsIntegerArray) && MOTORS.containsKey(i)) ORCHESTRA.addInstrument(MOTORS.get(i), i % totalTracks); } private static void updateMotors(int[] motorsPerTrack, Supplier skippedIDs) { + if (skippedIDs.get() == SKIPPED_IDS) + return; + + SKIPPED_IDS = skippedIDs.get(); ORCHESTRA.clearInstruments(); + int[] skippedIDsIntegerArray = skippedIDs.get(); int motorIndex = 1; - for (int trackIndex = 0; trackIndex < motorsPerTrack.length; trackIndex++) { for (int motorsInCurrentTrack = 0; motorsInCurrentTrack < motorsPerTrack[trackIndex]; motorsInCurrentTrack++) { if (motorIndex > MOTORS.size()) { From 4dccd5bdabd1bd60da469fbf2468b80cb6affe08 Mon Sep 17 00:00:00 2001 From: Strflightmight09 <148347057+Strflightmight09@users.noreply.github.com> Date: Mon, 7 Jul 2025 17:25:34 +0300 Subject: [PATCH 30/47] test --- src/main/java/org/trigon/utilities/Orchestra.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/org/trigon/utilities/Orchestra.java b/src/main/java/org/trigon/utilities/Orchestra.java index 0087100b..1bfd67df 100644 --- a/src/main/java/org/trigon/utilities/Orchestra.java +++ b/src/main/java/org/trigon/utilities/Orchestra.java @@ -6,6 +6,7 @@ import edu.wpi.first.wpilibj2.command.InstantCommand; import edu.wpi.first.wpilibj2.command.SubsystemBase; +import java.util.Arrays; import java.util.HashMap; import java.util.function.Supplier; @@ -131,6 +132,7 @@ private static void playFile(String filePath, int[] motorsPerTrack, int... skipp } private static void updateMotors(int totalTracks, Supplier skippedIDs) { + System.out.println(Arrays.toString(skippedIDs.get())); if (skippedIDs.get() == SKIPPED_IDS) return; From ed478c8e9192fff0e28fd9d8726a48a56363096e Mon Sep 17 00:00:00 2001 From: Strflightmight09 <148347057+Strflightmight09@users.noreply.github.com> Date: Mon, 7 Jul 2025 17:32:33 +0300 Subject: [PATCH 31/47] more test --- src/main/java/org/trigon/utilities/Orchestra.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/trigon/utilities/Orchestra.java b/src/main/java/org/trigon/utilities/Orchestra.java index 1bfd67df..845f8b04 100644 --- a/src/main/java/org/trigon/utilities/Orchestra.java +++ b/src/main/java/org/trigon/utilities/Orchestra.java @@ -32,7 +32,10 @@ public static void addMotor(TalonFX motor, int id) { public static Command getPlayFileCommand(String filePath, int totalTracks, Supplier skippedIDs) { return new FunctionalCommand( () -> playFile(filePath, totalTracks, skippedIDs.get()), - () -> updateMotors(totalTracks, skippedIDs), + () -> { + updateMotors(totalTracks, skippedIDs); + System.out.println(Arrays.toString(skippedIDs.get())); + }, (interrupted) -> stop(), () -> false, INSTANCE @@ -132,7 +135,6 @@ private static void playFile(String filePath, int[] motorsPerTrack, int... skipp } private static void updateMotors(int totalTracks, Supplier skippedIDs) { - System.out.println(Arrays.toString(skippedIDs.get())); if (skippedIDs.get() == SKIPPED_IDS) return; From bee510a2e81b0f38f276bb2c518bb62b14777b1e Mon Sep 17 00:00:00 2001 From: Strflightmight09 <148347057+Strflightmight09@users.noreply.github.com> Date: Wed, 16 Jul 2025 18:12:59 +0300 Subject: [PATCH 32/47] Smth idek --- .../java/org/trigon/utilities/Orchestra.java | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/trigon/utilities/Orchestra.java b/src/main/java/org/trigon/utilities/Orchestra.java index 845f8b04..b585a2f6 100644 --- a/src/main/java/org/trigon/utilities/Orchestra.java +++ b/src/main/java/org/trigon/utilities/Orchestra.java @@ -32,10 +32,7 @@ public static void addMotor(TalonFX motor, int id) { public static Command getPlayFileCommand(String filePath, int totalTracks, Supplier skippedIDs) { return new FunctionalCommand( () -> playFile(filePath, totalTracks, skippedIDs.get()), - () -> { - updateMotors(totalTracks, skippedIDs); - System.out.println(Arrays.toString(skippedIDs.get())); - }, + () -> updateMotors(totalTracks, skippedIDs), (interrupted) -> stop(), () -> false, INSTANCE @@ -135,26 +132,26 @@ private static void playFile(String filePath, int[] motorsPerTrack, int... skipp } private static void updateMotors(int totalTracks, Supplier skippedIDs) { - if (skippedIDs.get() == SKIPPED_IDS) + int[] currentSkippedIDs = skippedIDs.get(); + if (Arrays.equals(currentSkippedIDs, SKIPPED_IDS)) return; - SKIPPED_IDS = skippedIDs.get(); + SKIPPED_IDS = currentSkippedIDs; ORCHESTRA.clearInstruments(); - int[] skippedIDsIntegerArray = skippedIDs.get(); for (int i = 1; i < MOTORS.size() + 1; i++) - if (shouldUseMotor(i, skippedIDsIntegerArray) && MOTORS.containsKey(i)) + if (shouldUseMotor(i, SKIPPED_IDS) && MOTORS.containsKey(i)) ORCHESTRA.addInstrument(MOTORS.get(i), i % totalTracks); } private static void updateMotors(int[] motorsPerTrack, Supplier skippedIDs) { - if (skippedIDs.get() == SKIPPED_IDS) + int[] currentSkippedIDs = skippedIDs.get(); + if (Arrays.equals(currentSkippedIDs, SKIPPED_IDS)) return; - SKIPPED_IDS = skippedIDs.get(); + SKIPPED_IDS = currentSkippedIDs; ORCHESTRA.clearInstruments(); - int[] skippedIDsIntegerArray = skippedIDs.get(); int motorIndex = 1; for (int trackIndex = 0; trackIndex < motorsPerTrack.length; trackIndex++) { for (int motorsInCurrentTrack = 0; motorsInCurrentTrack < motorsPerTrack[trackIndex]; motorsInCurrentTrack++) { @@ -162,7 +159,7 @@ private static void updateMotors(int[] motorsPerTrack, Supplier skippedID System.out.println("Orchestra: Not enough motors"); return; } - if (shouldUseMotor(motorIndex, skippedIDsIntegerArray) && MOTORS.containsKey(motorIndex)) + if (shouldUseMotor(motorIndex, SKIPPED_IDS) && MOTORS.containsKey(motorIndex)) ORCHESTRA.addInstrument(MOTORS.get(motorIndex), trackIndex); motorIndex++; } From 4091b2ca1190248090b2e67b56b40793fff84a84 Mon Sep 17 00:00:00 2001 From: Strflightmight09 <148347057+Strflightmight09@users.noreply.github.com> Date: Wed, 16 Jul 2025 18:13:32 +0300 Subject: [PATCH 33/47] For testing purposes --- src/main/java/org/trigon/utilities/Orchestra.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/trigon/utilities/Orchestra.java b/src/main/java/org/trigon/utilities/Orchestra.java index b585a2f6..78eb938e 100644 --- a/src/main/java/org/trigon/utilities/Orchestra.java +++ b/src/main/java/org/trigon/utilities/Orchestra.java @@ -32,7 +32,10 @@ public static void addMotor(TalonFX motor, int id) { public static Command getPlayFileCommand(String filePath, int totalTracks, Supplier skippedIDs) { return new FunctionalCommand( () -> playFile(filePath, totalTracks, skippedIDs.get()), - () -> updateMotors(totalTracks, skippedIDs), + () -> { + updateMotors(totalTracks, skippedIDs); + System.out.println(Arrays.toString(skippedIDs.get())); + }, (interrupted) -> stop(), () -> false, INSTANCE From 5ab23723a42cea122ad092828c5a057806b445ea Mon Sep 17 00:00:00 2001 From: Strflightmight09 <148347057+Strflightmight09@users.noreply.github.com> Date: Wed, 16 Jul 2025 18:22:26 +0300 Subject: [PATCH 34/47] test --- src/main/java/org/trigon/utilities/Orchestra.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/trigon/utilities/Orchestra.java b/src/main/java/org/trigon/utilities/Orchestra.java index 78eb938e..471da06d 100644 --- a/src/main/java/org/trigon/utilities/Orchestra.java +++ b/src/main/java/org/trigon/utilities/Orchestra.java @@ -31,12 +31,18 @@ public static void addMotor(TalonFX motor, int id) { public static Command getPlayFileCommand(String filePath, int totalTracks, Supplier skippedIDs) { return new FunctionalCommand( - () -> playFile(filePath, totalTracks, skippedIDs.get()), + () -> { + playFile(filePath, totalTracks, skippedIDs.get()); + System.out.println("init" + Arrays.toString(skippedIDs.get())); + }, () -> { updateMotors(totalTracks, skippedIDs); System.out.println(Arrays.toString(skippedIDs.get())); }, - (interrupted) -> stop(), + (interrupted) -> { + stop(); + System.out.println("ended"); + }, () -> false, INSTANCE ).ignoringDisable(true); From 533042a3ee6ca2645fc73f832fe66849ec6b76ba Mon Sep 17 00:00:00 2001 From: Strflightmight09 <148347057+Strflightmight09@users.noreply.github.com> Date: Wed, 16 Jul 2025 18:32:48 +0300 Subject: [PATCH 35/47] wowow --- .../java/org/trigon/utilities/Orchestra.java | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/trigon/utilities/Orchestra.java b/src/main/java/org/trigon/utilities/Orchestra.java index 471da06d..b3a19f9a 100644 --- a/src/main/java/org/trigon/utilities/Orchestra.java +++ b/src/main/java/org/trigon/utilities/Orchestra.java @@ -8,7 +8,7 @@ import java.util.Arrays; import java.util.HashMap; -import java.util.function.Supplier; +import java.util.concurrent.atomic.AtomicReference; /** * A class that uses the {@link com.ctre.phoenix6.Orchestra} library in Phoenix 6 to play a .chrp file. @@ -29,26 +29,20 @@ public static void addMotor(TalonFX motor, int id) { MOTORS.put(id, motor); } - public static Command getPlayFileCommand(String filePath, int totalTracks, Supplier skippedIDs) { + public static Command getPlayFileCommand(String filePath, int totalTracks, AtomicReference skippedIDs) { return new FunctionalCommand( - () -> { - playFile(filePath, totalTracks, skippedIDs.get()); - System.out.println("init" + Arrays.toString(skippedIDs.get())); - }, + () -> playFile(filePath, totalTracks, skippedIDs.get()), () -> { updateMotors(totalTracks, skippedIDs); System.out.println(Arrays.toString(skippedIDs.get())); }, - (interrupted) -> { - stop(); - System.out.println("ended"); - }, + (interrupted) -> stop(), () -> false, INSTANCE ).ignoringDisable(true); } - public static Command getPlayFileCommand(String filePath, int[] motorsPerTrack, Supplier skippedIDs) { + public static Command getPlayFileCommand(String filePath, int[] motorsPerTrack, AtomicReference skippedIDs) { return new FunctionalCommand( () -> playFile(filePath, motorsPerTrack, skippedIDs.get()), () -> updateMotors(motorsPerTrack, skippedIDs), @@ -140,7 +134,7 @@ private static void playFile(String filePath, int[] motorsPerTrack, int... skipp addAndPlayFile(filePath); } - private static void updateMotors(int totalTracks, Supplier skippedIDs) { + private static void updateMotors(int totalTracks, AtomicReference skippedIDs) { int[] currentSkippedIDs = skippedIDs.get(); if (Arrays.equals(currentSkippedIDs, SKIPPED_IDS)) return; @@ -153,7 +147,7 @@ private static void updateMotors(int totalTracks, Supplier skippedIDs) { ORCHESTRA.addInstrument(MOTORS.get(i), i % totalTracks); } - private static void updateMotors(int[] motorsPerTrack, Supplier skippedIDs) { + private static void updateMotors(int[] motorsPerTrack, AtomicReference skippedIDs) { int[] currentSkippedIDs = skippedIDs.get(); if (Arrays.equals(currentSkippedIDs, SKIPPED_IDS)) return; From 4a2c57240f58fe6d0d94e01bdd0ae85f0c5c9199 Mon Sep 17 00:00:00 2001 From: Strflightmight09 <148347057+Strflightmight09@users.noreply.github.com> Date: Wed, 16 Jul 2025 19:20:08 +0300 Subject: [PATCH 36/47] ArrayList is goated --- .../java/org/trigon/utilities/Orchestra.java | 77 +++++++++++-------- 1 file changed, 44 insertions(+), 33 deletions(-) diff --git a/src/main/java/org/trigon/utilities/Orchestra.java b/src/main/java/org/trigon/utilities/Orchestra.java index b3a19f9a..5668d267 100644 --- a/src/main/java/org/trigon/utilities/Orchestra.java +++ b/src/main/java/org/trigon/utilities/Orchestra.java @@ -6,6 +6,7 @@ import edu.wpi.first.wpilibj2.command.InstantCommand; import edu.wpi.first.wpilibj2.command.SubsystemBase; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.concurrent.atomic.AtomicReference; @@ -17,7 +18,8 @@ public class Orchestra extends SubsystemBase { private static final Orchestra INSTANCE = new Orchestra(); private static final com.ctre.phoenix6.Orchestra ORCHESTRA = new com.ctre.phoenix6.Orchestra(); private static final HashMap MOTORS = new HashMap<>(); - private static int[] SKIPPED_IDS = new int[0]; + private static final AtomicReference> SKIPPED_IDS = new AtomicReference<>(new ArrayList<>()); + private static ArrayList LAST_SKIPPED_IDS = new ArrayList<>(); /** * Adds a motor to the Orchestra. @@ -29,23 +31,20 @@ public static void addMotor(TalonFX motor, int id) { MOTORS.put(id, motor); } - public static Command getPlayFileCommand(String filePath, int totalTracks, AtomicReference skippedIDs) { + public static Command getPlayFileCommand(String filePath, int totalTracks) { return new FunctionalCommand( - () -> playFile(filePath, totalTracks, skippedIDs.get()), - () -> { - updateMotors(totalTracks, skippedIDs); - System.out.println(Arrays.toString(skippedIDs.get())); - }, + () -> playFile(filePath, totalTracks), + () -> updateMotors(totalTracks), (interrupted) -> stop(), () -> false, INSTANCE ).ignoringDisable(true); } - public static Command getPlayFileCommand(String filePath, int[] motorsPerTrack, AtomicReference skippedIDs) { + public static Command getPlayFileCommand(String filePath, int[] motorsPerTrack) { return new FunctionalCommand( - () -> playFile(filePath, motorsPerTrack, skippedIDs.get()), - () -> updateMotors(motorsPerTrack, skippedIDs), + () -> playFile(filePath, motorsPerTrack), + () -> updateMotors(motorsPerTrack), (interrupted) -> stop(), () -> false, INSTANCE @@ -87,6 +86,24 @@ public static double getPlayTimeSeconds() { return ORCHESTRA.getCurrentTime(); } + public static void addSkippedIDs(Integer... newIDs) { + ArrayList currentIDs = SKIPPED_IDS.get(); + currentIDs.addAll(Arrays.asList(newIDs)); + + SKIPPED_IDS.set(currentIDs); + } + + public static void removeSkippedIDs(Integer... idsToRemove) { + ArrayList currentIDs = SKIPPED_IDS.get(); + currentIDs.removeAll(Arrays.asList(idsToRemove)); + + SKIPPED_IDS.set(currentIDs); + } + + public static void clearSkippedIDs() { + SKIPPED_IDS.set(new ArrayList<>()); + } + /** * Plays a .chrp file and assigns a track to each motor. * A .chrp file stores music as tracks that can be played separately. @@ -94,11 +111,10 @@ public static double getPlayTimeSeconds() { * * @param filePath the path of the .chrp file to be played by the Orchestra * @param totalTracks the number of tracks in the .chrp file - * @param skippedIDs the IDs of motors that should not be assigned a track */ - private static void playFile(String filePath, int totalTracks, int[] skippedIDs) { + private static void playFile(String filePath, int totalTracks) { for (int i = 1; i < MOTORS.size() + 1; i++) { - if (shouldUseMotor(i, skippedIDs) && MOTORS.containsKey(i)) + if (shouldUseMotor(i) && MOTORS.containsKey(i)) ORCHESTRA.addInstrument(MOTORS.get(i), i % totalTracks); } @@ -114,9 +130,8 @@ private static void playFile(String filePath, int totalTracks, int[] skippedIDs) * * @param filePath the path of the .chrp file to be added to the Orchestra * @param motorsPerTrack number of motors that should be assigned to each track - * @param skippedIDs the IDs of motors that should not be assigned a track */ - private static void playFile(String filePath, int[] motorsPerTrack, int... skippedIDs) { + private static void playFile(String filePath, int[] motorsPerTrack) { int motorIndex = 1; for (int trackIndex = 0; trackIndex < motorsPerTrack.length; trackIndex++) { @@ -125,7 +140,7 @@ private static void playFile(String filePath, int[] motorsPerTrack, int... skipp System.out.println("Orchestra: Not enough motors"); return; } - if (shouldUseMotor(motorIndex, skippedIDs) && MOTORS.containsKey(motorIndex)) + if (shouldUseMotor(motorIndex) && MOTORS.containsKey(motorIndex)) ORCHESTRA.addInstrument(MOTORS.get(motorIndex), trackIndex); motorIndex++; } @@ -134,25 +149,24 @@ private static void playFile(String filePath, int[] motorsPerTrack, int... skipp addAndPlayFile(filePath); } - private static void updateMotors(int totalTracks, AtomicReference skippedIDs) { - int[] currentSkippedIDs = skippedIDs.get(); - if (Arrays.equals(currentSkippedIDs, SKIPPED_IDS)) + private static void updateMotors(int totalTracks) { + ArrayList currentSkippedIDs = SKIPPED_IDS.get(); + if (currentSkippedIDs.equals(LAST_SKIPPED_IDS)) return; - SKIPPED_IDS = currentSkippedIDs; + LAST_SKIPPED_IDS = currentSkippedIDs; ORCHESTRA.clearInstruments(); for (int i = 1; i < MOTORS.size() + 1; i++) - if (shouldUseMotor(i, SKIPPED_IDS) && MOTORS.containsKey(i)) + if (shouldUseMotor(i) && MOTORS.containsKey(i)) ORCHESTRA.addInstrument(MOTORS.get(i), i % totalTracks); } - private static void updateMotors(int[] motorsPerTrack, AtomicReference skippedIDs) { - int[] currentSkippedIDs = skippedIDs.get(); - if (Arrays.equals(currentSkippedIDs, SKIPPED_IDS)) + private static void updateMotors(int[] motorsPerTrack) { + ArrayList currentSkippedIDs = SKIPPED_IDS.get(); + if (currentSkippedIDs.equals(LAST_SKIPPED_IDS)) return; - SKIPPED_IDS = currentSkippedIDs; ORCHESTRA.clearInstruments(); int motorIndex = 1; @@ -162,11 +176,13 @@ private static void updateMotors(int[] motorsPerTrack, AtomicReference sk System.out.println("Orchestra: Not enough motors"); return; } - if (shouldUseMotor(motorIndex, SKIPPED_IDS) && MOTORS.containsKey(motorIndex)) + if (shouldUseMotor(motorIndex) && MOTORS.containsKey(motorIndex)) ORCHESTRA.addInstrument(MOTORS.get(motorIndex), trackIndex); motorIndex++; } } + + LAST_SKIPPED_IDS = currentSkippedIDs; } /** @@ -201,12 +217,7 @@ private static void addAndPlayFile(String filePath) { play(); } - private static boolean shouldUseMotor(int id, int[] skippedIDs) { - for (int skippedID : skippedIDs) { - if (id == skippedID) { - return false; - } - } - return true; + private static boolean shouldUseMotor(int id) { + return !SKIPPED_IDS.get().contains(id); } } From 58286318163552d2e2fec5bb8b0c9eafea7a72fb Mon Sep 17 00:00:00 2001 From: Strflightmight09 <148347057+Strflightmight09@users.noreply.github.com> Date: Wed, 16 Jul 2025 19:28:17 +0300 Subject: [PATCH 37/47] ? --- src/main/java/org/trigon/utilities/Orchestra.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/trigon/utilities/Orchestra.java b/src/main/java/org/trigon/utilities/Orchestra.java index 5668d267..a4f20b8a 100644 --- a/src/main/java/org/trigon/utilities/Orchestra.java +++ b/src/main/java/org/trigon/utilities/Orchestra.java @@ -95,7 +95,8 @@ public static void addSkippedIDs(Integer... newIDs) { public static void removeSkippedIDs(Integer... idsToRemove) { ArrayList currentIDs = SKIPPED_IDS.get(); - currentIDs.removeAll(Arrays.asList(idsToRemove)); + for (Integer id : idsToRemove) + currentIDs.remove(id); SKIPPED_IDS.set(currentIDs); } From 06bd78db91d19aabe67337a34a187ce5912d949c Mon Sep 17 00:00:00 2001 From: Strflightmight09 <148347057+Strflightmight09@users.noreply.github.com> Date: Wed, 16 Jul 2025 19:32:24 +0300 Subject: [PATCH 38/47] Ughhhhh --- src/main/java/org/trigon/utilities/Orchestra.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/trigon/utilities/Orchestra.java b/src/main/java/org/trigon/utilities/Orchestra.java index a4f20b8a..a1376dbb 100644 --- a/src/main/java/org/trigon/utilities/Orchestra.java +++ b/src/main/java/org/trigon/utilities/Orchestra.java @@ -95,8 +95,7 @@ public static void addSkippedIDs(Integer... newIDs) { public static void removeSkippedIDs(Integer... idsToRemove) { ArrayList currentIDs = SKIPPED_IDS.get(); - for (Integer id : idsToRemove) - currentIDs.remove(id); + currentIDs.removeAll(Arrays.asList(idsToRemove)); SKIPPED_IDS.set(currentIDs); } @@ -151,6 +150,7 @@ private static void playFile(String filePath, int[] motorsPerTrack) { } private static void updateMotors(int totalTracks) { + System.out.println(SKIPPED_IDS.get()); ArrayList currentSkippedIDs = SKIPPED_IDS.get(); if (currentSkippedIDs.equals(LAST_SKIPPED_IDS)) return; From 8ce853fb8c01d98e3b4aa04b872b3e62f6fa0ecf Mon Sep 17 00:00:00 2001 From: Strflightmight09 <148347057+Strflightmight09@users.noreply.github.com> Date: Wed, 16 Jul 2025 19:38:37 +0300 Subject: [PATCH 39/47] O --- src/main/java/org/trigon/utilities/Orchestra.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/trigon/utilities/Orchestra.java b/src/main/java/org/trigon/utilities/Orchestra.java index a1376dbb..813850f5 100644 --- a/src/main/java/org/trigon/utilities/Orchestra.java +++ b/src/main/java/org/trigon/utilities/Orchestra.java @@ -155,12 +155,13 @@ private static void updateMotors(int totalTracks) { if (currentSkippedIDs.equals(LAST_SKIPPED_IDS)) return; - LAST_SKIPPED_IDS = currentSkippedIDs; ORCHESTRA.clearInstruments(); for (int i = 1; i < MOTORS.size() + 1; i++) if (shouldUseMotor(i) && MOTORS.containsKey(i)) ORCHESTRA.addInstrument(MOTORS.get(i), i % totalTracks); + + LAST_SKIPPED_IDS = currentSkippedIDs; } private static void updateMotors(int[] motorsPerTrack) { @@ -218,7 +219,7 @@ private static void addAndPlayFile(String filePath) { play(); } - private static boolean shouldUseMotor(int id) { + private static boolean shouldUseMotor(Integer id) { return !SKIPPED_IDS.get().contains(id); } } From f4753824208ac0864de0547aa1b2b57d2263bc69 Mon Sep 17 00:00:00 2001 From: Strflightmight09 <148347057+Strflightmight09@users.noreply.github.com> Date: Wed, 16 Jul 2025 19:46:32 +0300 Subject: [PATCH 40/47] WTHELLYYYYYYYYYYYYY --- src/main/java/org/trigon/utilities/Orchestra.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/trigon/utilities/Orchestra.java b/src/main/java/org/trigon/utilities/Orchestra.java index 813850f5..89ac5d6b 100644 --- a/src/main/java/org/trigon/utilities/Orchestra.java +++ b/src/main/java/org/trigon/utilities/Orchestra.java @@ -158,7 +158,7 @@ private static void updateMotors(int totalTracks) { ORCHESTRA.clearInstruments(); for (int i = 1; i < MOTORS.size() + 1; i++) - if (shouldUseMotor(i) && MOTORS.containsKey(i)) + if (!currentSkippedIDs.contains(i) && MOTORS.containsKey(i)) ORCHESTRA.addInstrument(MOTORS.get(i), i % totalTracks); LAST_SKIPPED_IDS = currentSkippedIDs; From 0da6572a4c062bea0677fcb8ee8bf0db3560d6e5 Mon Sep 17 00:00:00 2001 From: Strflightmight09 <148347057+Strflightmight09@users.noreply.github.com> Date: Wed, 16 Jul 2025 19:50:30 +0300 Subject: [PATCH 41/47] whatttttttttttt --- src/main/java/org/trigon/utilities/Orchestra.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/trigon/utilities/Orchestra.java b/src/main/java/org/trigon/utilities/Orchestra.java index 89ac5d6b..647780be 100644 --- a/src/main/java/org/trigon/utilities/Orchestra.java +++ b/src/main/java/org/trigon/utilities/Orchestra.java @@ -150,12 +150,12 @@ private static void playFile(String filePath, int[] motorsPerTrack) { } private static void updateMotors(int totalTracks) { - System.out.println(SKIPPED_IDS.get()); ArrayList currentSkippedIDs = SKIPPED_IDS.get(); if (currentSkippedIDs.equals(LAST_SKIPPED_IDS)) return; ORCHESTRA.clearInstruments(); + System.out.println(currentSkippedIDs.contains(1)); for (int i = 1; i < MOTORS.size() + 1; i++) if (!currentSkippedIDs.contains(i) && MOTORS.containsKey(i)) From b0e0a2ca9b26e6867449c8bfcb28fed8f7baad48 Mon Sep 17 00:00:00 2001 From: Strflightmight09 <148347057+Strflightmight09@users.noreply.github.com> Date: Wed, 16 Jul 2025 19:59:46 +0300 Subject: [PATCH 42/47] JIOHSEF"DS --- src/main/java/org/trigon/utilities/Orchestra.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/trigon/utilities/Orchestra.java b/src/main/java/org/trigon/utilities/Orchestra.java index 647780be..94a2df60 100644 --- a/src/main/java/org/trigon/utilities/Orchestra.java +++ b/src/main/java/org/trigon/utilities/Orchestra.java @@ -151,14 +151,13 @@ private static void playFile(String filePath, int[] motorsPerTrack) { private static void updateMotors(int totalTracks) { ArrayList currentSkippedIDs = SKIPPED_IDS.get(); - if (currentSkippedIDs.equals(LAST_SKIPPED_IDS)) + if (currentSkippedIDs == LAST_SKIPPED_IDS) return; ORCHESTRA.clearInstruments(); - System.out.println(currentSkippedIDs.contains(1)); for (int i = 1; i < MOTORS.size() + 1; i++) - if (!currentSkippedIDs.contains(i) && MOTORS.containsKey(i)) + if (shouldUseMotor(i) && MOTORS.containsKey(i)) ORCHESTRA.addInstrument(MOTORS.get(i), i % totalTracks); LAST_SKIPPED_IDS = currentSkippedIDs; @@ -166,7 +165,7 @@ private static void updateMotors(int totalTracks) { private static void updateMotors(int[] motorsPerTrack) { ArrayList currentSkippedIDs = SKIPPED_IDS.get(); - if (currentSkippedIDs.equals(LAST_SKIPPED_IDS)) + if (currentSkippedIDs == LAST_SKIPPED_IDS) return; ORCHESTRA.clearInstruments(); From ee67c54106fd201eb345724cec77b7215e50c0b2 Mon Sep 17 00:00:00 2001 From: Strflightmight09 <148347057+Strflightmight09@users.noreply.github.com> Date: Wed, 16 Jul 2025 20:14:57 +0300 Subject: [PATCH 43/47] test ig --- src/main/java/org/trigon/utilities/Orchestra.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/trigon/utilities/Orchestra.java b/src/main/java/org/trigon/utilities/Orchestra.java index 94a2df60..06697d08 100644 --- a/src/main/java/org/trigon/utilities/Orchestra.java +++ b/src/main/java/org/trigon/utilities/Orchestra.java @@ -151,7 +151,8 @@ private static void playFile(String filePath, int[] motorsPerTrack) { private static void updateMotors(int totalTracks) { ArrayList currentSkippedIDs = SKIPPED_IDS.get(); - if (currentSkippedIDs == LAST_SKIPPED_IDS) + System.out.println(currentSkippedIDs + " " + LAST_SKIPPED_IDS); + if (currentSkippedIDs.size() == LAST_SKIPPED_IDS.size()) return; ORCHESTRA.clearInstruments(); @@ -165,7 +166,7 @@ private static void updateMotors(int totalTracks) { private static void updateMotors(int[] motorsPerTrack) { ArrayList currentSkippedIDs = SKIPPED_IDS.get(); - if (currentSkippedIDs == LAST_SKIPPED_IDS) + if (currentSkippedIDs.size() == LAST_SKIPPED_IDS.size()) return; ORCHESTRA.clearInstruments(); From c4a0c2f90f1edc90a39d1e032e291b8cbab75104 Mon Sep 17 00:00:00 2001 From: Strflightmight09 <148347057+Strflightmight09@users.noreply.github.com> Date: Wed, 16 Jul 2025 20:27:35 +0300 Subject: [PATCH 44/47] Fine --- .../java/org/trigon/utilities/Orchestra.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/trigon/utilities/Orchestra.java b/src/main/java/org/trigon/utilities/Orchestra.java index 06697d08..a83fe4ee 100644 --- a/src/main/java/org/trigon/utilities/Orchestra.java +++ b/src/main/java/org/trigon/utilities/Orchestra.java @@ -19,7 +19,7 @@ public class Orchestra extends SubsystemBase { private static final com.ctre.phoenix6.Orchestra ORCHESTRA = new com.ctre.phoenix6.Orchestra(); private static final HashMap MOTORS = new HashMap<>(); private static final AtomicReference> SKIPPED_IDS = new AtomicReference<>(new ArrayList<>()); - private static ArrayList LAST_SKIPPED_IDS = new ArrayList<>(); + private static boolean SHOULD_UPDATE_SKIPPED_MOTORS = false; /** * Adds a motor to the Orchestra. @@ -91,6 +91,7 @@ public static void addSkippedIDs(Integer... newIDs) { currentIDs.addAll(Arrays.asList(newIDs)); SKIPPED_IDS.set(currentIDs); + SHOULD_UPDATE_SKIPPED_MOTORS = true; } public static void removeSkippedIDs(Integer... idsToRemove) { @@ -98,10 +99,12 @@ public static void removeSkippedIDs(Integer... idsToRemove) { currentIDs.removeAll(Arrays.asList(idsToRemove)); SKIPPED_IDS.set(currentIDs); + SHOULD_UPDATE_SKIPPED_MOTORS = true; } public static void clearSkippedIDs() { SKIPPED_IDS.set(new ArrayList<>()); + SHOULD_UPDATE_SKIPPED_MOTORS = true; } /** @@ -150,25 +153,20 @@ private static void playFile(String filePath, int[] motorsPerTrack) { } private static void updateMotors(int totalTracks) { - ArrayList currentSkippedIDs = SKIPPED_IDS.get(); - System.out.println(currentSkippedIDs + " " + LAST_SKIPPED_IDS); - if (currentSkippedIDs.size() == LAST_SKIPPED_IDS.size()) + if (!SHOULD_UPDATE_SKIPPED_MOTORS) return; - ORCHESTRA.clearInstruments(); for (int i = 1; i < MOTORS.size() + 1; i++) if (shouldUseMotor(i) && MOTORS.containsKey(i)) ORCHESTRA.addInstrument(MOTORS.get(i), i % totalTracks); - LAST_SKIPPED_IDS = currentSkippedIDs; + SHOULD_UPDATE_SKIPPED_MOTORS = false; } private static void updateMotors(int[] motorsPerTrack) { - ArrayList currentSkippedIDs = SKIPPED_IDS.get(); - if (currentSkippedIDs.size() == LAST_SKIPPED_IDS.size()) + if (!SHOULD_UPDATE_SKIPPED_MOTORS) return; - ORCHESTRA.clearInstruments(); int motorIndex = 1; @@ -184,7 +182,7 @@ private static void updateMotors(int[] motorsPerTrack) { } } - LAST_SKIPPED_IDS = currentSkippedIDs; + SHOULD_UPDATE_SKIPPED_MOTORS = false; } /** From cead20d3e45462d20c1a47bf303f4af0707d9e6d Mon Sep 17 00:00:00 2001 From: Strflightmight09 <148347057+Strflightmight09@users.noreply.github.com> Date: Wed, 16 Jul 2025 20:40:05 +0300 Subject: [PATCH 45/47] Simplify --- .../java/org/trigon/utilities/Orchestra.java | 76 +++++++++++-------- 1 file changed, 43 insertions(+), 33 deletions(-) diff --git a/src/main/java/org/trigon/utilities/Orchestra.java b/src/main/java/org/trigon/utilities/Orchestra.java index a83fe4ee..96c78573 100644 --- a/src/main/java/org/trigon/utilities/Orchestra.java +++ b/src/main/java/org/trigon/utilities/Orchestra.java @@ -73,37 +73,57 @@ public static Command getPlayCommand() { } /** - * @return whether music is playing or not + * @return whether orchestra is currently playing a file */ - public static boolean isOrchestraCurrentlyPlayingMusic() { + public static boolean isOrchestraCurrentlyPlaying() { return ORCHESTRA.isPlaying(); } /** - * @return the play time of the .chrp file in seconds + * @return the play time of the current file in seconds */ public static double getPlayTimeSeconds() { return ORCHESTRA.getCurrentTime(); } + /** + * Adds IDs of motors that should be skipped when playing a file. + * + * @param newIDs the IDs of motors that should be skipped + */ public static void addSkippedIDs(Integer... newIDs) { ArrayList currentIDs = SKIPPED_IDS.get(); currentIDs.addAll(Arrays.asList(newIDs)); - SKIPPED_IDS.set(currentIDs); - SHOULD_UPDATE_SKIPPED_MOTORS = true; + setSkippedIDs(currentIDs); } + /** + * Removes IDs of motors that should no longer be skipped when playing a file. + * + * @param idsToRemove the IDs of motors that should no longer be skipped + */ public static void removeSkippedIDs(Integer... idsToRemove) { ArrayList currentIDs = SKIPPED_IDS.get(); currentIDs.removeAll(Arrays.asList(idsToRemove)); - SKIPPED_IDS.set(currentIDs); - SHOULD_UPDATE_SKIPPED_MOTORS = true; + setSkippedIDs(currentIDs); } + /** + * Clears all skipped motor IDs. + */ public static void clearSkippedIDs() { - SKIPPED_IDS.set(new ArrayList<>()); + setSkippedIDs(new ArrayList<>()); + } + + /** + * Sets the skipped motor IDs to a specific list. + * + * @param skippedIDs the list of motor IDs to be skipped + */ + public static void setSkippedIDs(ArrayList skippedIDs) { + SKIPPED_IDS.set(skippedIDs); SHOULD_UPDATE_SKIPPED_MOTORS = true; } @@ -116,11 +136,7 @@ public static void clearSkippedIDs() { * @param totalTracks the number of tracks in the .chrp file */ private static void playFile(String filePath, int totalTracks) { - for (int i = 1; i < MOTORS.size() + 1; i++) { - if (shouldUseMotor(i) && MOTORS.containsKey(i)) - ORCHESTRA.addInstrument(MOTORS.get(i), i % totalTracks); - } - + applyTracks(totalTracks); addAndPlayFile(filePath); } @@ -135,20 +151,7 @@ private static void playFile(String filePath, int totalTracks) { * @param motorsPerTrack number of motors that should be assigned to each track */ private static void playFile(String filePath, int[] motorsPerTrack) { - int motorIndex = 1; - - for (int trackIndex = 0; trackIndex < motorsPerTrack.length; trackIndex++) { - for (int motorsInCurrentTrack = 0; motorsInCurrentTrack < motorsPerTrack[trackIndex]; motorsInCurrentTrack++) { - if (motorIndex > MOTORS.size()) { - System.out.println("Orchestra: Not enough motors"); - return; - } - if (shouldUseMotor(motorIndex) && MOTORS.containsKey(motorIndex)) - ORCHESTRA.addInstrument(MOTORS.get(motorIndex), trackIndex); - motorIndex++; - } - } - + applyTracks(motorsPerTrack); addAndPlayFile(filePath); } @@ -157,10 +160,7 @@ private static void updateMotors(int totalTracks) { return; ORCHESTRA.clearInstruments(); - for (int i = 1; i < MOTORS.size() + 1; i++) - if (shouldUseMotor(i) && MOTORS.containsKey(i)) - ORCHESTRA.addInstrument(MOTORS.get(i), i % totalTracks); - + applyTracks(totalTracks); SHOULD_UPDATE_SKIPPED_MOTORS = false; } @@ -169,7 +169,19 @@ private static void updateMotors(int[] motorsPerTrack) { return; ORCHESTRA.clearInstruments(); + applyTracks(motorsPerTrack); + SHOULD_UPDATE_SKIPPED_MOTORS = false; + } + + private static void applyTracks(int totalTracks) { + for (int i = 1; i < MOTORS.size() + 1; i++) + if (shouldUseMotor(i) && MOTORS.containsKey(i)) + ORCHESTRA.addInstrument(MOTORS.get(i), i % totalTracks); + } + + private static void applyTracks(int[] motorsPerTrack) { int motorIndex = 1; + for (int trackIndex = 0; trackIndex < motorsPerTrack.length; trackIndex++) { for (int motorsInCurrentTrack = 0; motorsInCurrentTrack < motorsPerTrack[trackIndex]; motorsInCurrentTrack++) { if (motorIndex > MOTORS.size()) { @@ -181,8 +193,6 @@ private static void updateMotors(int[] motorsPerTrack) { motorIndex++; } } - - SHOULD_UPDATE_SKIPPED_MOTORS = false; } /** From 609f6457abe3c4541a5ab754c2aa0a3f2e921a1b Mon Sep 17 00:00:00 2001 From: Strflightmight09 <148347057+Strflightmight09@users.noreply.github.com> Date: Thu, 17 Jul 2025 23:53:21 +0300 Subject: [PATCH 46/47] Small improvement --- src/main/java/org/trigon/utilities/Orchestra.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/trigon/utilities/Orchestra.java b/src/main/java/org/trigon/utilities/Orchestra.java index 96c78573..af8721be 100644 --- a/src/main/java/org/trigon/utilities/Orchestra.java +++ b/src/main/java/org/trigon/utilities/Orchestra.java @@ -93,8 +93,10 @@ public static double getPlayTimeSeconds() { */ public static void addSkippedIDs(Integer... newIDs) { ArrayList currentIDs = SKIPPED_IDS.get(); - currentIDs.addAll(Arrays.asList(newIDs)); + if (currentIDs.containsAll(Arrays.asList(newIDs))) + return; + currentIDs.addAll(Arrays.asList(newIDs)); setSkippedIDs(currentIDs); } @@ -105,8 +107,10 @@ public static void addSkippedIDs(Integer... newIDs) { */ public static void removeSkippedIDs(Integer... idsToRemove) { ArrayList currentIDs = SKIPPED_IDS.get(); - currentIDs.removeAll(Arrays.asList(idsToRemove)); + if (!currentIDs.containsAll(Arrays.asList(idsToRemove))) + return; + currentIDs.removeAll(Arrays.asList(idsToRemove)); setSkippedIDs(currentIDs); } From f0f5c876d785d87880804dbec46198a092bed458 Mon Sep 17 00:00:00 2001 From: Strflightmight09 <148347057+Strflightmight09@users.noreply.github.com> Date: Thu, 7 Aug 2025 20:54:00 +0300 Subject: [PATCH 47/47] Replay protection and used IDs instead of skipped --- .../phoenix6/talonfx/TalonFXMotor.java | 3 +- .../java/org/trigon/utilities/Orchestra.java | 57 +++++++++---------- 2 files changed, 29 insertions(+), 31 deletions(-) diff --git a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java index fae416c6..9c9d3afc 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java +++ b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java @@ -48,7 +48,8 @@ public TalonFXMotor(int id, String motorName, String canbus) { this.id = id; motorIO.optimizeBusUsage(); - Orchestra.addMotor(motorIO.getTalonFX(), id); + if (!RobotHardwareStats.isReplay()) + Orchestra.addMotor(motorIO.getTalonFX(), id); } /** diff --git a/src/main/java/org/trigon/utilities/Orchestra.java b/src/main/java/org/trigon/utilities/Orchestra.java index af8721be..cb29dca4 100644 --- a/src/main/java/org/trigon/utilities/Orchestra.java +++ b/src/main/java/org/trigon/utilities/Orchestra.java @@ -9,7 +9,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; -import java.util.concurrent.atomic.AtomicReference; /** * A class that uses the {@link com.ctre.phoenix6.Orchestra} library in Phoenix 6 to play a .chrp file. @@ -18,8 +17,8 @@ public class Orchestra extends SubsystemBase { private static final Orchestra INSTANCE = new Orchestra(); private static final com.ctre.phoenix6.Orchestra ORCHESTRA = new com.ctre.phoenix6.Orchestra(); private static final HashMap MOTORS = new HashMap<>(); - private static final AtomicReference> SKIPPED_IDS = new AtomicReference<>(new ArrayList<>()); - private static boolean SHOULD_UPDATE_SKIPPED_MOTORS = false; + private static ArrayList USED_MOTOR_IDS = new ArrayList<>(); + private static boolean SHOULD_UPDATE_USED_MOTORS = false; /** * Adds a motor to the Orchestra. @@ -87,48 +86,46 @@ public static double getPlayTimeSeconds() { } /** - * Adds IDs of motors that should be skipped when playing a file. + * Adds IDs of motors that should be used when playing a file. * - * @param newIDs the IDs of motors that should be skipped + * @param newIDs the IDs of the motors that should be used */ - public static void addSkippedIDs(Integer... newIDs) { - ArrayList currentIDs = SKIPPED_IDS.get(); - if (currentIDs.containsAll(Arrays.asList(newIDs))) + public static void addUsedMotorIDs(Integer... newIDs) { + if (USED_MOTOR_IDS.containsAll(Arrays.asList(newIDs))) return; - currentIDs.addAll(Arrays.asList(newIDs)); - setSkippedIDs(currentIDs); + USED_MOTOR_IDS.addAll(Arrays.asList(newIDs)); + setUsedMotorIDs(USED_MOTOR_IDS); } /** - * Removes IDs of motors that should no longer be skipped when playing a file. + * Removes IDs of motors that should no longer be used when playing a file. * - * @param idsToRemove the IDs of motors that should no longer be skipped + * @param idsToRemove the IDs of motors that should no longer be used */ - public static void removeSkippedIDs(Integer... idsToRemove) { - ArrayList currentIDs = SKIPPED_IDS.get(); - if (!currentIDs.containsAll(Arrays.asList(idsToRemove))) + public static void removeUsedMotorIDs(Integer... idsToRemove) { + if (!USED_MOTOR_IDS.containsAll(Arrays.asList(idsToRemove))) return; - currentIDs.removeAll(Arrays.asList(idsToRemove)); - setSkippedIDs(currentIDs); + USED_MOTOR_IDS.removeAll(Arrays.asList(idsToRemove)); + setUsedMotorIDs(USED_MOTOR_IDS); } /** - * Clears all skipped motor IDs. + * Clears all used motor IDs. */ - public static void clearSkippedIDs() { - setSkippedIDs(new ArrayList<>()); + public static void clearUsedMotorIDs() { + setUsedMotorIDs(new ArrayList<>()); } /** - * Sets the skipped motor IDs to a specific list. + * Sets the used motor IDs to a specific list. * - * @param skippedIDs the list of motor IDs to be skipped + * @param usedMotorIDs the list of motor IDs to be used */ - public static void setSkippedIDs(ArrayList skippedIDs) { - SKIPPED_IDS.set(skippedIDs); - SHOULD_UPDATE_SKIPPED_MOTORS = true; + public static void setUsedMotorIDs(ArrayList usedMotorIDs) { + USED_MOTOR_IDS = usedMotorIDs; + SHOULD_UPDATE_USED_MOTORS = true; } /** @@ -160,21 +157,21 @@ private static void playFile(String filePath, int[] motorsPerTrack) { } private static void updateMotors(int totalTracks) { - if (!SHOULD_UPDATE_SKIPPED_MOTORS) + if (!SHOULD_UPDATE_USED_MOTORS) return; ORCHESTRA.clearInstruments(); applyTracks(totalTracks); - SHOULD_UPDATE_SKIPPED_MOTORS = false; + SHOULD_UPDATE_USED_MOTORS = false; } private static void updateMotors(int[] motorsPerTrack) { - if (!SHOULD_UPDATE_SKIPPED_MOTORS) + if (!SHOULD_UPDATE_USED_MOTORS) return; ORCHESTRA.clearInstruments(); applyTracks(motorsPerTrack); - SHOULD_UPDATE_SKIPPED_MOTORS = false; + SHOULD_UPDATE_USED_MOTORS = false; } private static void applyTracks(int totalTracks) { @@ -232,6 +229,6 @@ private static void addAndPlayFile(String filePath) { } private static boolean shouldUseMotor(Integer id) { - return !SKIPPED_IDS.get().contains(id); + return USED_MOTOR_IDS.contains(id); } }