Compare commits

...

6 Commits

Author SHA1 Message Date
Thibaud 32d25d9826 Merge branch 'exporting' 2024-05-28 20:16:59 +02:00
Thibaud 21ea707712 Basic circle placement according to beat
this doesn't work because sound_process code seems to break for files other than tetris for me...
2024-05-28 20:13:13 +02:00
Thibaud b1687d5d1c Rename new-process to a more descriptive name 2024-05-28 18:16:22 +02:00
Thibaud f57841a11f Beta place.py that adds circles at (0, 0) 2024-05-28 18:11:36 +02:00
Thibaud a4fb003165 Merge branch 'main' into exporting 2024-05-28 17:46:39 +02:00
Thibaud f545e0df3c Start preparing object placement 2024-05-28 17:46:28 +02:00
3 changed files with 61 additions and 15 deletions

33
main.py Normal file
View File

@ -0,0 +1,33 @@
from tkinter import filedialog as fd
import slider as sl
from datetime import timedelta
import place
import sound_process
def alexandre_process(bpm, offset, filename):
pass
def main():
filename = fd.askopenfilename()
beatmap = sl.Beatmap.from_path(filename)
timing = beatmap.timing_points[0]
bpm = timing.bpm
offset = timing.offset.total_seconds() * 10e3
print(beatmap.audio_filename)
timings, amplitudes, freqs = sound_process.process_song(beatmap.audio_filename, offset, bpm)
beatmap._hit_objects = place.greedy(bpm, offset, timings, amplitudes)
#beatmap._hit_objects = [sl.Slider(sl.Position(0, 0), timedelta(milliseconds=3), timedelta(milliseconds=130), 0, sl.curve.Linear([sl.Position(0, 0), sl.Position(100, 100)], 100), 100, 2, 1, 1, 1, timing.ms_per_beat, [], [],)]
beatmap.write_path("rewrite.osu")
#timings, intensities = alexandre_process(bpm, offset, beatmap.audio_filename)
print(bpm)
if __name__ == "__main__":
main()

View File

@ -1,32 +1,43 @@
import numpy as np import numpy as np
import slider as sl
from datetime import timedelta
""" QUARTER = 1
whle HALF = 2
""" NOTE = 4
def beatify(bpm:float, offset:int, time_ms:timedelta) -> float:
return bpm/60000 * (time_ms - offset)
def debeatify(bpm:float, offset:int, beat:int) -> timedelta:
return timedelta(milliseconds=(beat*60000/bpm) + offset)
def f(intensity): return np.pi/2 - np.arctan(2*intensity - 5) def f(intensity): return np.pi/2 - np.arctan(2*intensity - 5)
def greedy(): def greedy(bpm:int, offset:int, timings:list, amplitudes:list):
""" """
input: takes Alexandre's note selection / intensity data input: takes Alexandre's note selection / intensity data
output: list of object type / position output: list of object type / position
""" """
flow = 1 flow = 1
song_beat = 0 notes = [sl.HitObject(0, timedelta(milliseconds=0), 0) * len(timings)]
notes = [0 * len(rhythms)] beats = np.array(beatify(timings))
for (rhythm, i) in zip(rhythms, range(len(rhythms))): for (delta, note_beat, intensity, i) in zip(timings, beats, amplitudes, range(len(timings))):
song_beat += rhythm.time
try: try:
duration = rhythm.time - rhythms[i + 1].time duration = note_beat - beats[i + 1]
if duration in (1, 2): if duration in (QUARTER, HALF):
note_type = "cercle" notes[i] = sl.Circle(sl.Position(0, 0), delta, 0)
notes[i] = sl.Circle(sl.Position(0, 0), delta, 0)
"""
elif duration % 2 == 0: elif duration % 2 == 0:
rhythms.insert(0, f"slider {duration}") rhythms.insert(0, f"slider {duration}")
else: else:
rhythms.insert(0, f"reverse_slider {duration}") rhythms.insert(0, f"reverse_slider {duration}")
"""
except IndexError: except IndexError:
note_type = "cercle" notes[i] = sl.Circle(sl.Position(0, 0), delta, 0)
# TODO mettre à jour flow # TODO mettre à jour flow
"""
if len(notes) > 2: if len(notes) > 2:
angle = flow * f(rhythm.intensite) angle = flow * f(rhythm.intensite)
x1, y1 = notes[i-2].position x1, y1 = notes[i-2].position
@ -36,6 +47,8 @@ def greedy():
y3 = y2 + (intensity * np.sin(angle + old_angle)) y3 = y2 + (intensity * np.sin(angle + old_angle))
else: else:
pass pass
"""
return notes

View File

@ -11,6 +11,7 @@ import heapq
import scipy import scipy
import os import os
import random import random
from datetime import timedelta
from pathlib import Path from pathlib import Path
from time import sleep from time import sleep
@ -380,16 +381,15 @@ def test_sample(timelist):
#BPM = 140 #BPM = 140
#Length = 32*60/BPM-0.01 #Length = 32*60/BPM-0.01
def convert_tuple(datares, freq): def convert_tuple(datares, freq) -> tuple[timedelta, int, float]:
""" """
Takes datares and converts it to a list of tuples (amplitude, time in ms) Takes datares and converts it to a list of tuples (amplitude, time in ms)
""" """
return [(i, datares[i], freq[i]) for i in range(len(datares)) if datares[i] > 0] return [(timedelta(milliseconds=i), datares[i], freq[i]) for i in range(len(datares)) if datares[i] > 0]
def process_song(filename, offset, bpm, div_len_factor=60, n_iter=48, threshold=0.5, divisor=4): def process_song(filename, offset, bpm, div_len_factor=60, n_iter=48, threshold=0.5, divisor=4):
#zaejzlk
div_len = div_len_factor/bpm-0.01 div_len = div_len_factor/bpm-0.01
filtered_name = f"{filename}_trimmed.wav" filtered_name = f"{filename}_trimmed.wav"
void_freq(filename, offset, offset+div_len*(n_iter+1)+0.01, 4*60/bpm, minfreq=0, maxfreq=330, upperthr=5000, ampthr=60, ampfreq = 1200, ampval = 7.27, leniency = 0.005, write=True, output_file=filtered_name) void_freq(filename, offset, offset+div_len*(n_iter+1)+0.01, 4*60/bpm, minfreq=0, maxfreq=330, upperthr=5000, ampthr=60, ampfreq = 1200, ampval = 7.27, leniency = 0.005, write=True, output_file=filtered_name)