From 73d9a9ea161afd79d4643fd5b7f5c1a95705d90e Mon Sep 17 00:00:00 2001 From: Chrisvenator <55980003+Chrisvenator@users.noreply.github.com> Date: Mon, 7 Aug 2023 18:33:00 +0200 Subject: [PATCH] Major Bugfixes --- OnsetGeneration/SlicesToOnset.ps1 | 52 ------------------------------- src/CreatePatterns.java | 39 +++++++++++++---------- src/UserInterface.java | 31 +++--------------- 3 files changed, 28 insertions(+), 94 deletions(-) delete mode 100644 OnsetGeneration/SlicesToOnset.ps1 diff --git a/OnsetGeneration/SlicesToOnset.ps1 b/OnsetGeneration/SlicesToOnset.ps1 deleted file mode 100644 index 180a233..0000000 --- a/OnsetGeneration/SlicesToOnset.ps1 +++ /dev/null @@ -1,52 +0,0 @@ -$folderPath = "C:\Program Files (x86)\Steam\steamapps\common\Beat Saber\_SongsToTimings\SlicesToOnset\slices" - -# Überprüfen, ob der angegebene Ordner existiert -if (-not (Test-Path -Path $folderPath)) { - Write-Host "Der angegebene Ordner existiert nicht." - exit -} - -# Alle .wav-Dateien im Ordner auflisten -$files = Get-ChildItem -Path $folderPath -Filter "*.wav" - -$onsets = ""; -$onsetLength = 0; -# Über jede Datei iterieren und die Länge ausgeben -foreach ($file in $files) { - $duration = Get-WaveFileDuration -Path $file.FullName - Write-Host "Datei: $($file.Name)" - Write-Host "Länge: $($duration) Sekunden" - Write-Host "-----" - - $onsetLength += $duration; - $onsets += $onsetLength.ToString() + "`r`n" -} - -$onsets = $onsets | ForEach-Object { $_ -replace ",", "." } -Set-Content -Path "C:\Program Files (x86)\Steam\steamapps\common\Beat Saber\_SongsToTimings\SlicesToOnset\onsets.txt" -Value $onsets - -# Funktion zum Abrufen der Länge einer .wav-Datei mit ffprobe -function Get-WaveFileDuration { - param ( - [Parameter(Mandatory = $true, ValueFromPipeline = $true, Position = 0)] - [Alias("FullName")] - [string]$Path - ) - - process { - $duration = 0 - - - - $command = "ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 `"$Path`"" - $output = Invoke-Expression -Command $command - - if ($output -match '\d+(\.\d+)?') { - $duration = [double]$Matches[0] - } - - # ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "C:\Program Files (x86)\Steam\steamapps\common\Beat Saber\_SongsToTimings\SlicesToOnset\slices\YASOBI - Idol_0.wav" - - return $duration - } -} \ No newline at end of file diff --git a/src/CreatePatterns.java b/src/CreatePatterns.java index 856311c..17789d6 100644 --- a/src/CreatePatterns.java +++ b/src/CreatePatterns.java @@ -64,13 +64,25 @@ public static BeatSaberMap createMap(BeatSaberMap map, Pattern p, boolean oneHan List notes = new ArrayList<>(); List timings = Arrays.asList(map._notes); List bookmarks = map.bookmarks == null ? map.calculateBookmarks() : map.bookmarks; - bookmarks.add(new Bookmark(timings.get(timings.size() - 1)._time + 10, "end", new float[]{(float) 0.0, (float) 0.0, (float) 0.0})); + String[] supportedTypes = new String[]{"complex", "linear", "1-2", "2-1", "2-2", "small_jumps", "normal_jumps", "big_jumps", "doubles", "pattern"}; //If the map is one-handed or there are no bookmarks, then there is not that much to do if (oneHanded) return new BeatSaberMap(complexPatternFromTemplate(map._notes, p, true, stacks, null, null), map.originalJSON); - if (bookmarks.size() <= 1) - return new BeatSaberMap(complexPatternFromTemplate(map._notes, p, true, stacks, null, null), map.originalJSON); + if (bookmarks.size() <= 1) { + Random random = new Random(); + int min = 10; + int max = 40; + + int randomNumber = random.nextInt(max - min + 1) + min; + for (int i = 0; i < randomNumber; i++) { + bookmarks.add(new Bookmark(timings.get(i * (int) (timings.size() / randomNumber))._time, supportedTypes[random.nextInt(supportedTypes.length - 1)], null)); + if (bookmarks.get(bookmarks.size() - 1)._name.contains("jumps")) i--; + } +// return new BeatSaberMap(complexPatternFromTemplate(map._notes, p, oneHanded, stacks, null, null), map.originalJSON); + } + bookmarks.add(new Bookmark(timings.get(timings.size() - 1)._time + 10, "end", new float[]{(float) 0.0, (float) 0.0, (float) 0.0})); + Note prevBlue = null; Note prevRed = null; @@ -94,8 +106,7 @@ public static BeatSaberMap createMap(BeatSaberMap map, Pattern p, boolean oneHan Note[] linearNotes = linearSlowPattern(currentNotes.toArray(new Note[0]), false, prevBlue, prevRed); notes.addAll(Arrays.stream(linearNotes).toList()); } - case "1-2" -> - notes.addAll(twoRightOneLeft(currentNotes.toArray(new Note[0]), p, prevBlue, prevRed, stacks)); + case "1-2" -> notes.addAll(twoRightOneLeft(currentNotes.toArray(new Note[0]), p, prevBlue, prevRed, stacks)); case "2-1" -> { //prevRed and prevBlue must be inverted right here because in the next line we invert all the notes again. @@ -105,19 +116,15 @@ public static BeatSaberMap createMap(BeatSaberMap map, Pattern p, boolean oneHan } case "2-2" -> notes.addAll(twoLeftTwoRight(currentNotes.toArray(new Note[0]), prevBlue, prevRed)); - case "small-jumps", "smalljumps", "small jumps" -> - notes.addAll(createSmallJumps(currentNotes, false, prevBlue, prevRed)); - case "jumps", "normal jumps", "normal_jumps", "normal-jumps" -> - notes.addAll(createJumps(currentNotes, false, prevBlue, prevRed)); - case "big-jumps", "bigjumps", "big jumps" -> - notes.addAll(createBigJumps(currentNotes, false, prevBlue, prevRed)); - case "doubles", "double-handed" -> - notes.addAll(createDoubles(currentNotes.toArray(new Note[0]), prevBlue, prevRed)); - case "sequence", "seq", "s", "pattern", "pat", "rand-seq", "random-sequence" -> - notes.addAll(createPatternSequence(currentNotes.toArray(new Note[0]), prevBlue, prevRed, "jumps.txt")); + case "small-jumps", "smalljumps", "small_jumps", "small jumps" -> notes.addAll(createSmallJumps(currentNotes, false, prevBlue, prevRed)); + case "jumps", "normal jumps", "normal_jumps", "normal-jumps" -> notes.addAll(createJumps(currentNotes, false, prevBlue, prevRed)); + case "big-jumps", "bigjumps", "big_jumps", "big jumps" -> notes.addAll(createBigJumps(currentNotes, false, prevBlue, prevRed)); + case "doubles", "double-handed" -> notes.addAll(createDoubles(currentNotes.toArray(new Note[0]), prevBlue, prevRed)); + case "sequence", "seq", "s", "pattern", "pat", "rand-seq", "random-sequence" -> notes.addAll(createPatternSequence(currentNotes.toArray(new Note[0]), prevBlue, prevRed, "jumps.txt")); default -> { - System.err.println("There is no such flag as: \"" + bookmarks.get(i)._name + "\" with " + currentNotes.size() + " notes."); + System.err.println("There is no such flag as: \"" + bookmarks.get(i)._name + "\" with " + currentNotes.size() + " notes. Please have a look at the supported ones in the README"); + System.err.println("Supported types: " + Arrays.toString(supportedTypes)); Note[] complexNotes = complexPatternFromTemplate(currentNotes.toArray(new Note[0]), p, false, stacks, prevBlue, prevRed); notes.addAll(Arrays.stream(complexNotes).toList()); } diff --git a/src/UserInterface.java b/src/UserInterface.java index 25b0f1a..44caea7 100644 --- a/src/UserInterface.java +++ b/src/UserInterface.java @@ -11,7 +11,6 @@ public class UserInterface extends JFrame { private String filePath; private BeatSaberMap map; private Pattern pattern; - private float bpm = 120; //config.txt: private boolean verbose = true; //For debugging purposes. It prints EVERYTHING @@ -71,28 +70,6 @@ public UserInterface() { add(openSongButton); - //BPM Buttons are currently disabled! - JTextField bpmTextField = new JFormattedTextField("BPM"); - bpmTextField.setBounds(50, 70, 100, 30); - bpmTextField.setVisible(false); - add(bpmTextField); - - - // Button erstellen und positionieren - //BPM Buttons are currently disabled! - JButton submitBPM = new JButton("save BPM"); - submitBPM.setBounds(160, 70, 100, 30); - submitBPM.setVisible(false); - submitBPM.addActionListener(e -> { - try { - bpm = Float.parseFloat(bpmTextField.getText()); - } catch (NumberFormatException ex) { - System.err.println("The BPM you typed in is not a number!"); - } - }); - add(submitBPM); - - //Status Bar: statusCheck = new TextArea("config: \nverbose: " + verbose + "\npath: " + DEFAULT_PATH + "\n"); statusCheck.setBounds(50, 235, 1090, 510); @@ -475,9 +452,6 @@ public UserInterface() { new Thread(() -> { while (true) { if (mapSuccessfullyLoaded) { -// bpmTextField.setVisible(true); -// submitBPM.setVisible(true); - labelMapDiff.setText("Successfully loaded difficulty"); labelMapDiff.setBackground(Color.GREEN); @@ -503,10 +477,15 @@ public UserInterface() { private void convertMp3ToMap() { try { + statusCheck.setBackground(Color.GRAY); + openSongButton.setText("In Progress..."); statusCheck.setText(statusCheck.getText() + "\nINFO: Converting all Songs from OnsetGeneration/mp3Files/ to timing maps.\nThis might take a while if there are a lot of songs.\n"); statusCheck.setText(statusCheck.getText() + "You can always check the progress when heading to \"OnsetGeneration/output/\"\n"); + Thread.sleep(1000); BatchWavToMaps.generateOnsets("./OnsetGeneration/mp3Files/", "./OnsetGeneration/output/", true); statusCheck.setText(statusCheck.getText() + "\nSuccessfully created Map. You can find your map in \"OnsetGeneration/output/\"\n\n"); + statusCheck.setBackground(Color.WHITE); + openSongButton.setText("Convert MP3s to timing maps"); } catch (Exception e) { System.err.println("ERROR: Something went wrong during conversion. Is it the right file extension?\n" + e); statusCheck.setText("ERROR: Something went wrong during conversion. Is it the right file extension?\n" + e + "\n\n");