Skip to content

Commit

Permalink
Daily Commit 11-1-2021
Browse files Browse the repository at this point in the history
Some temp stuff for class and updated Consumers.
  • Loading branch information
Rusettsten committed Nov 1, 2021
1 parent 04ab7b5 commit feda7cf
Show file tree
Hide file tree
Showing 5 changed files with 342 additions and 1 deletion.
4 changes: 3 additions & 1 deletion photon/src/main/java/com/strikete/photon/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.io.IOException;
import java.util.Scanner;

import com.strikete.photon.temp.BeatProcessor;

public class Main {

/*
Expand All @@ -11,14 +13,14 @@ public class Main {
public static void main(String[] args) throws IOException {

Photon photon = new Photon();
Scanner scanner = new Scanner(System.in);

String targetIp = "192.168.10.111";
int targetPort = 3032;
int listeningPort = 3033;

photon.initializeOsc(targetIp, targetPort, listeningPort);

BeatProcessor beatProcessor = new BeatProcessor(photon);

while(true) {
photon.updateOscObjects();
Expand Down
178 changes: 178 additions & 0 deletions photon/src/main/java/com/strikete/photon/PhotonDataUtilities.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.strikete.photon;

import com.strikete.photon.exceptions.ObjectNotFoundException;

public class PhotonDataUtilities {

/*
Expand Down Expand Up @@ -141,6 +143,182 @@ public boolean doesSubExist(String uid) {
return false;
}

/*
* METHODS - FIND OBJECT ARRAY INDEX VIA PK
*/
public int findBeamPalette(float paletteNum, int index, String uid) throws ObjectNotFoundException {
for(int x = 0; x < photon.beamPalettes.size(); x++) {
if(photon.beamPalettes.get(x).getPaletteNumber() == paletteNum &&
photon.beamPalettes.get(x).getIndex() == index &&
photon.beamPalettes.get(x).getUid().equals(uid)) {
return x;
}
}
throw new ObjectNotFoundException("Could not find Beam Palette #" + paletteNum + " !");
}
public int findChannel(int channelNum, int part, int index, String uid) throws ObjectNotFoundException {
for(int x = 0; x < photon.channels.size(); x++) {
if(photon.channels.get(x).getChannelNumber() == channelNum &&
photon.channels.get(x).getPart() == part &&
photon.channels.get(x).getIndex() == index &&
photon.channels.get(x).getUid().equals(uid)) {
return x;
}
}
throw new ObjectNotFoundException("Could not find Channel #" + channelNum + " !");
}
public int findColorPalette(float paletteNum, int index, String uid) throws ObjectNotFoundException {
for(int x = 0; x < photon.colorPalettes.size(); x++) {
if(photon.colorPalettes.get(x).getPaletteNumber() == paletteNum &&
photon.colorPalettes.get(x).getIndex() == index &&
photon.colorPalettes.get(x).getUid().equals(uid)) {
return x;
}
}
throw new ObjectNotFoundException("Could not find Color Palette #" + paletteNum + " !");
}
public int findCue(int cueNum, int index, String uid, int cuelistNum, int cuePart) throws ObjectNotFoundException {
for(int x = 0; x < photon.cues.size(); x++) {
if(photon.cues.get(x).getCueNumber() == cueNum &&
photon.cues.get(x).getIndex() == index &&
photon.cues.get(x).getUid().equals(uid) &&
photon.cues.get(x).getCuelistNumber() == cuelistNum &&
photon.cues.get(x).getPart() == cuePart) {
return x;
}
}
throw new ObjectNotFoundException("Could not find Cue #" + cueNum + " from Cuelist #" + cuelistNum + " !");
}
public int findCuelist(int cuelistNum, int index, String uid) throws ObjectNotFoundException {
for(int x = 0; x < photon.cuelists.size(); x++) {
if(photon.cuelists.get(x).getCuelistNumber() == cuelistNum &&
photon.cuelists.get(x).getIndex() == index &&
photon.cuelists.get(x).getUid().equals(uid)) {
return x;
}
}
throw new ObjectNotFoundException("Could not find Cuelist #" + cuelistNum + " !");
}
public int findCurve(int curveNum, int index, String uid) {
for(int x = 0; x < photon.curves.size(); x++) {
if(photon.curves.get(x).getCurveNumber() == curveNum &&
photon.beamPalettes.get(x).getIndex() == index &&
photon.beamPalettes.get(x).getUid().equals(uid)) {
return x;
}
}
throw new ObjectNotFoundException("Could not find Curve #" + curveNum + " !");
}
public int findEffect(float effectNum, int index, String uid) throws ObjectNotFoundException {
for(int x = 0; x < photon.effects.size(); x++) {
if(photon.effects.get(x).getEffectNumber() == effectNum &&
photon.beamPalettes.get(x).getIndex() == index &&
photon.beamPalettes.get(x).getUid().equals(uid)) {
return x;
}
}
throw new ObjectNotFoundException("Could not find Effect #" + effectNum + " !");
}
public int findFixture(String fixtureName, String manufacturerName) throws ObjectNotFoundException {
for(int x = 0; x < photon.fixtures.size(); x++) {
if(photon.fixtures.get(x).getFixtureName().equals(fixtureName) &&
photon.fixtures.get(x).getManufacturerName().equals(manufacturerName)) {
return x;
}
}
throw new ObjectNotFoundException("Could not find Fixture: " + fixtureName + " !");
}
public int findFocusPalette(float paletteNum, int index, String uid) throws ObjectNotFoundException {
for(int x = 0; x < photon.focusPalettes.size(); x++) {
if(photon.focusPalettes.get(x).getPaletteNumber() == paletteNum &&
photon.focusPalettes.get(x).getIndex() == index &&
photon.focusPalettes.get(x).getUid().equals(uid)) {
return x;
}
}
throw new ObjectNotFoundException("Could not find Focus Palette #" + paletteNum + " !");
}
public int findGroup(float groupNum, int index, String uid) throws ObjectNotFoundException {
for(int x = 0; x < photon.groups.size(); x++) {
if(photon.groups.get(x).getGroupNumber() == groupNum &&
photon.groups.get(x).getIndex() == index &&
photon.groups.get(x).getUid().equals(uid)) {
return x;
}
}
throw new ObjectNotFoundException("Could not find Group #" + groupNum + " !");
}
public int findIntensityPalette(float paletteNum, int index, String uid) throws ObjectNotFoundException {
for(int x = 0; x < photon.intensityPalettes.size(); x++) {
if(photon.intensityPalettes.get(x).getPaletteNumber() == paletteNum &&
photon.intensityPalettes.get(x).getIndex() == index &&
photon.intensityPalettes.get(x).getUid().equals(uid)) {
return x;
}
}
throw new ObjectNotFoundException("Could not find Intensity Palette #" + paletteNum + " !");
}
public int findMacro(int macroNum, int index, String uid) throws ObjectNotFoundException {
for(int x = 0; x < photon.macros.size(); x++) {
if(photon.macros.get(x).getMacroNumber() == macroNum &&
photon.macros.get(x).getIndex() == index &&
photon.macros.get(x).getUid().equals(uid)) {
return x;
}
}
throw new ObjectNotFoundException("Could not find Macro #" + macroNum + " !");
}
public int findMagicSheet(int magicSheetNum, int index, String uid) throws ObjectNotFoundException {
for(int x = 0; x < photon.magicSheets.size(); x++) {
if(photon.magicSheets.get(x).getMagicSheetNumber() == magicSheetNum &&
photon.beamPalettes.get(x).getIndex() == index &&
photon.beamPalettes.get(x).getUid().equals(uid)) {
return x;
}
}
throw new ObjectNotFoundException("Could not find Magic Sheet #" + magicSheetNum + " !");
}
public int findPixelmap(int pixelmapNum, int index, String uid) throws ObjectNotFoundException {
for(int x = 0; x < photon.pixelmaps.size(); x++) {
if(photon.pixelmaps.get(x).getPixelmapNumber() == pixelmapNum &&
photon.beamPalettes.get(x).getIndex() == index &&
photon.beamPalettes.get(x).getUid().equals(uid)) {
return x;
}
}
throw new ObjectNotFoundException("Could not find Pixelmap #" + pixelmapNum + " !");
}
public int findPreset(float presetNum, int index, String uid) throws ObjectNotFoundException {
for(int x = 0; x < photon.presets.size(); x++) {
if(photon.presets.get(x).getPresetNumber() == presetNum &&
photon.presets.get(x).getIndex() == index &&
photon.presets.get(x).getUid().equals(uid)) {
return x;
}
}
throw new ObjectNotFoundException("Could not find Preset #" + presetNum + " !");
}
public int findSnapshot(int snapshotNum, int index, String uid) throws ObjectNotFoundException {
for(int x = 0; x < photon.snapshots.size(); x++) {
if(photon.snapshots.get(x).getSnapshotNumber() == snapshotNum &&
photon.beamPalettes.get(x).getIndex() == index &&
photon.beamPalettes.get(x).getUid().equals(uid)) {
return x;
}
}
throw new ObjectNotFoundException("Could not find Snapshot #" + snapshotNum + " !");
}
public int findSub(int subNum, int index, String uid) throws ObjectNotFoundException {
for(int x = 0; x < photon.subs.size(); x++) {
if(photon.subs.get(x).getSubNumber() == subNum &&
photon.subs.get(x).getIndex() == index &&
photon.subs.get(x).getUid().equals(uid)) {
return x;
}
}
throw new ObjectNotFoundException("Could not find Sub #" + subNum + " !");
}


/*
* CONSTRUCTOR
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.strikete.photon.exceptions;

public class ObjectNotFoundException extends RuntimeException {

/**
* VARIABLES
*/
private static final long serialVersionUID = 7112843241263143043L;


/*
* CONSTRUCTOR
*/
public ObjectNotFoundException(String message) {
super(message);
}
}
122 changes: 122 additions & 0 deletions photon/src/main/java/com/strikete/photon/temp/BeatProcessor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package com.strikete.photon.temp;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

import com.strikete.photon.Photon;

public class BeatProcessor {

/*
* VARIABLES
*/
private static ArrayList<BeatTime> beatTimes = new ArrayList<BeatTime>();
private Photon photon;

/*
* METHODS
*/

public static void readFile() throws IOException {
String path = "C:\\Users\\Rusettsten\\Desktop\\sample-data.txt";

//Open File
FileInputStream fstream = new FileInputStream(path);
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));

String strLine;
int currentSample = 0;
float amplitudeThreshold = (float) -7.000;
float amplitudeFloor = (float) -40.000;
boolean activeBeat = false;
int activeBeatStartingSample = 0;

while((strLine = br.readLine()) != null) {
currentSample++;

float lineAmplitude = Float.parseFloat(strLine);
if(activeBeat) {
if(lineAmplitude < amplitudeFloor) {
beatTimes.add(new BeatTime(activeBeatStartingSample, currentSample));
activeBeat = false;
}
}else {
if(lineAmplitude >= amplitudeThreshold) {
activeBeatStartingSample = currentSample;
activeBeat = true;
}
}
}
System.out.println(beatTimes.size());
}


public void setupCueRecording() {
photon.sender.sendOscMessage("/eos/key/blind");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

public void recordCues() {
photon.sender.sendOscMessage("/eos/cmd","Cue 1 ##");
photon.sender.sendOscMessage("/eos/newcmd", "Chan 1 Thru 3 @ 0 #");
photon.sender.sendOscMessage("/eos/newcmd","Cue 1 Time 0 #");

int cueCount = 1;
float oldCueTime = 0;

for(int x = 0; x < beatTimes.size(); x++) {
String oldCueNum = Integer.toString(cueCount);
cueCount++;
double oldFollowTime = (beatTimes.get(x).startSeconds-oldCueTime);
String senderMessageOldFollow = "Cue " + oldCueNum + " Follow " + Double.toString(oldFollowTime) + " #";

String cueNum = Integer.toString(cueCount); //New Cue Creation
String senderMessage = "Cue " + cueNum + " ##";
photon.sender.sendOscMessage("/eos/newcmd",senderMessage);
photon.sender.sendOscMessage("/eos/newcmd","Chan 1 Thru 3 @ 100 #");
String senderMessage2 = "Cue " + cueNum + " Time 0.1 #";
photon.sender.sendOscMessage("/eos/newcmd", senderMessage2);
double followTime = (beatTimes.get(x).endSeconds - beatTimes.get(x).startSeconds);
String senderMessage3 = "Cue " + cueNum + " Follow " + Double.toString(followTime) + " #";
photon.sender.sendOscMessage("/eos/newcmd", senderMessage3);

cueCount++;
cueNum = Integer.toString(cueCount); //New Cue Creation
senderMessage = "Cue " + cueNum + " ##";
photon.sender.sendOscMessage("/eos/newcmd",senderMessage);
photon.sender.sendOscMessage("/eos/newcmd","");
photon.sender.sendOscMessage("/eos/newcmd","Chan 1 Thru 3 @ 0 #");
senderMessage2 = "Cue " + cueNum + " Time 0.6 #";
oldCueTime = beatTimes.get(x).endSeconds;

}

}

/*
* CONSTRUCTOR
*/
public BeatProcessor(Photon photonIn) {
this.photon = photonIn;
try {
readFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

setupCueRecording();
recordCues();

}

}
22 changes: 22 additions & 0 deletions photon/src/main/java/com/strikete/photon/temp/BeatTime.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.strikete.photon.temp;

public class BeatTime {

/*
* VARIABLES
*/
public int startSampleNumber;
public int endSampleNumber;
public float startSeconds;
public float endSeconds;

/*
* CONSTRUCTOR
*/
public BeatTime(int startSampleNumIn, int endSampleNumIn) {
this.startSampleNumber = startSampleNumIn;
this.endSampleNumber = endSampleNumIn;
this.startSeconds = startSampleNumIn / 8000;
this.endSeconds = endSampleNumIn / 8000;
}
}

0 comments on commit feda7cf

Please sign in to comment.