Skip to content

Commit

Permalink
mac compatibility and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
acrilique committed Dec 4, 2023
1 parent 020ece9 commit f6b0c24
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 21 deletions.
45 changes: 26 additions & 19 deletions automarker.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@
PREMIERE_PROCESS_NAME = "adobe premiere pro.exe" if WINDOWS_SYSTEM else "Adobe Premiere Pro"
AFTERFX_PROCESS_NAME = "AfterFX.exe" if WINDOWS_SYSTEM else "Adobe After Effects"
RESOLVE_PROCESS_NAME = "Resolve.exe" if WINDOWS_SYSTEM else "Resolve"
BLENDER_PROCESS_NAME = "blender.exe" if WINDOWS_SYSTEM else "blender"
CEPPANEL_PROCESS_NAME = "CEPHtmlEngine.exe" if WINDOWS_SYSTEM else "CEPHtmlEngine"
SAMPLE_RATE = 44100

###############################
###############################
Expand Down Expand Up @@ -151,12 +153,12 @@ def obtain_data_from_file():
info.set("Reading file from source...")
root.update()

data, samplerate = librosa.load(path=path.get(), sr=sample_rate, mono=True)
data, samplerate = librosa.load(path=path.get(), sr=SAMPLE_RATE, mono=True)

info.set("Getting beat positions...")
root.update()

tempo, beatsamples = librosa.beat.beat_track(y=data, units="time", sr=sample_rate)
tempo, beatsamples = librosa.beat.beat_track(y=data, units="time", sr=SAMPLE_RATE)

info.set("Displaying preview")
root.update()
Expand All @@ -174,8 +176,8 @@ def child_window_setup():
playButton = ttk.Button(newWindow, text="Play", command=play_preview)

# Draw the waveform
stepsize = int(len(data[:sample_rate * 10]) / 1000)
buffer = [int(x * 130 + 210) for x in data[:sample_rate * 10:stepsize]]
stepsize = int(len(data[:SAMPLE_RATE * 10]) / 1000)
buffer = [int(x * 130 + 210) for x in data[:SAMPLE_RATE * 10:stepsize]]
for i in range(len(buffer)-1):
canvas.create_line(i, buffer[i], i + 1, buffer[i+1], fill="black")

Expand Down Expand Up @@ -216,13 +218,13 @@ def callback(in_data, frame_count, time_info, status):
global playpos
chunk = data[playpos:playpos+frame_count]
playpos += frame_count
if playpos >= sample_rate*10:
if playpos >= SAMPLE_RATE*10:
return (chunk, pyaudio.paComplete)
return (chunk, pyaudio.paContinue)

def play_preview():
global stream, iid
stream = p.open(format=pyaudio.paFloat32, channels=1, rate=sample_rate, output=True, stream_callback=callback)
stream = p.open(format=pyaudio.paFloat32, channels=1, rate=SAMPLE_RATE, output=True, stream_callback=callback)
thread = Thread(target=track_line)
thread.daemon = True
thread.start()
Expand All @@ -239,9 +241,9 @@ def track_line():
global playpos
global stream
if changepos.get():
playpos = int(playpos_param.get()/999*sample_rate*10)
playpos = int(playpos_param.get()/999*SAMPLE_RATE*10)
changepos.set(False)
position = int(playpos*999/sample_rate/10)
position = int(playpos*999/SAMPLE_RATE/10)
newWindow.children["!canvas"].delete("line")
newWindow.children["!canvas"].create_line(position, 120, position, 300, fill="red", tags="line")
newWindow.update()
Expand Down Expand Up @@ -364,14 +366,20 @@ def __init__(self, aeVersion = "", returnFolder = ""):
if not len(self.aeVersion):
self.aeVersion = str(int(time.strftime("%Y")[2:]) + 1) + ".0"

# Get the AE_ exe path from the registry.
try:
self.aeKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Adobe\\After Effects\\" + self.aeVersion)
except:
print ("ERROR: Unable to find After Effects version " + self.aeVersion + " on this computer\nTo get correct version number please check https://en.wikipedia.org/wiki/Adobe_After_Effects\nFor example, \"After Effect CC 2019\" is version \"16.0\"")
sys.exit()

self.aeApp = _winreg.QueryValueEx(self.aeKey, 'InstallPath')[0] + 'AfterFX.exe'
if WINDOWS_SYSTEM:
# Get the AE_ exe path from the registry.
try:
self.aeKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Adobe\\After Effects\\" + self.aeVersion)
except:
print ("ERROR: Unable to find After Effects version " + self.aeVersion + " on this computer\nTo get correct version number please check https://en.wikipedia.org/wiki/Adobe_After_Effects\nFor example, \"After Effect CC 2019\" is version \"16.0\"")

self.aeApp = _winreg.QueryValueEx(self.aeKey, 'InstallPath')[0] + 'AfterFX.exe'
else:
guess_path = "/Applications/Adobe After Effects" + self.aeVersion + "/Adobe After Effects " + self.aeVersion + ".app/Contents/MacOS/AfterFX"
if os.path.exists(guess_path):
self.aeApp = guess_path
else:
print ("ERROR: Unable to find After Effects version " + self.aeVersion + " on this computer\nTo get correct version number please check https://en.wikipedia.org/wiki/Adobe_After_Effects\nFor example, \"After Effect CC 2019\" is version \"16.0\"")

# Get the path to the return file. Create it if it doesn't exist.
if not len(returnFolder):
Expand Down Expand Up @@ -636,8 +644,6 @@ def clearAllMarkers(self):

###########################################
###########################################

sample_rate = 44100
newWindow = None
playpos = 0
p = pyaudio.PyAudio()
Expand Down Expand Up @@ -718,7 +724,8 @@ def clearAllMarkers(self):
for child in mainframe.winfo_children():
child.grid_configure(padx=5, pady=5)

root.iconbitmap(os.path.join(basedir, "icon.ico"))
icon = tk.PhotoImage(file=os.path.join(basedir, "icon.png"))
root.tk.call('wm', 'iconphoto', root._w, icon)
root.after(0, update_runvar)

root.mainloop()
2 changes: 1 addition & 1 deletion automarker_mac.spec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
block_cipher = None

added_files = [
('icon.ico', '.'),
('icon.png', '.'),
('extension_installer_mac.sh', '.'),
('extension_installer_win.bat', '.'),
('README.md', '.'),
Expand Down
2 changes: 1 addition & 1 deletion automarker_win.spec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
block_cipher = None

added_files = [
('icon.ico', '.'),
('icon.png', '.'),
('extension_installer_mac.sh', '.'),
('extension_installer_win.bat', '.'),
('README.md', '.'),
Expand Down
Binary file removed icon.ico
Binary file not shown.
Binary file added icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f6b0c24

Please sign in to comment.