Skip to content

Commit

Permalink
Code cleanup, minor bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
will2dye4 committed Oct 26, 2023
1 parent c7de348 commit 3813d58
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
8 changes: 4 additions & 4 deletions unmixer/ui/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@

class SongImportSettings(QWidget):

AUDIO_FORMAT_LABEL = 'Isolated Track Output Format'
OTHER_TRACK_LABEL = '"Other" Track Name'
AUDIO_FORMAT_LABEL = 'Isolated track output format'
OTHER_TRACK_LABEL = '"Other" track name'

OTHER_SETTINGS_BUTTON_TEXT = '⚙️ Other Settings...'
OTHER_SETTINGS_BUTTON_TEXT = '⚙️ More settings...'
OTHER_SETTINGS_BUTTON_WIDTH = 200

LABEL_SPACING = 20
Expand Down Expand Up @@ -175,7 +175,7 @@ class SongImporter(QWidget):
DEFAULT_SUBTITLE_TEXT = 'You can also drop a song here from your computer.'
IMPORTING_SUBTITLE_TEXT = (
'Please wait; this may take some time.\n'
'The time required is roughly equal to the length of the song itself.'
'The time required depends on the length of the song and the current prediction model.'
)
SONG_SELECTED_SUBTITLE_TEXT = f'Press [{START_BUTTON_TEXT}] to begin unmixing the song into isolated tracks.'

Expand Down
14 changes: 13 additions & 1 deletion unmixer/ui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from unmixer.remix import merge_audio_files
from unmixer.ui.constants import (
APP_NAME,
ERROR_MESSAGE_TITLE,
ORGANIZATION_NAME,
PROJECT_README_URL,
SUCCESS_MESSAGE_TITLE,
Expand Down Expand Up @@ -112,13 +113,20 @@ def create_file_menu(self) -> QMenu:

# File > Open Recent > [Song Title]
recently_opened = self.app.settings.value(settings.open.RECENTLY_OPENED, [], 'QStringList')
removed = False
for recent_dir_path in recently_opened:
# TODO - ensure path still exists before adding it to the menu (if not, update settings)
if not os.path.exists(recent_dir_path):
recently_opened.remove(recent_dir_path)
removed = True
continue
song_title = os.path.basename(recent_dir_path.rstrip(os.path.sep))
open_action = recent_menu.addAction(song_title)
open_action.setStatusTip(recent_dir_path)
open_action.setToolTip(recent_dir_path)
open_action.triggered.connect(self.open_recent_menu_action(recent_dir_path))

if removed:
self.app.update_setting(settings.open.RECENTLY_OPENED, recently_opened)

return file_menu

Expand Down Expand Up @@ -633,6 +641,10 @@ def show_track_explorer_window(self, input_dir_path: str, source_file_path: Opti
self.track_windows[dir_path].bring_to_front()
return

if not os.path.exists(dir_path):
QMessageBox.warning(self.active_window, ERROR_MESSAGE_TITLE, f'Could not locate directory {dir_path}!')
return

window = UnmixerTrackExplorerWindow(self, input_dir_path=dir_path, source_file_path=source_file_path)
window.show()
self.track_windows[dir_path] = window
Expand Down
16 changes: 3 additions & 13 deletions unmixer/ui/multitrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
)
from soundfile import SoundFile

from unmixer.constants import MAX_VOLUME, MIN_VOLUME, OTHER_TRACK_NAME, settings
from unmixer.constants import MAX_VOLUME, MIN_VOLUME, settings
from unmixer.ui.constants import (
ERROR_MESSAGE_TITLE,
FONT_WEIGHT_BOLD,
Expand Down Expand Up @@ -428,12 +428,7 @@ def __init__(self, parent: QWidget, song_title: str, file_paths: list[str]) -> N
for i, file_path in enumerate(file_paths):
with SoundFile(file_path, 'rb') as sound_file:
colors = WAVEFORM_BACKGROUND_COLORS[i % len(WAVEFORM_BACKGROUND_COLORS)]
name = (
self.parent().app.other_track_name.capitalize()
if os.path.basename(sound_file.name).lower().startswith(f'{OTHER_TRACK_NAME}.')
else None
)
self.tracks.append(Track(sound_file, colors, name=name))
self.tracks.append(Track(sound_file, colors))

self.controls = PlaybackControls(self) # This needs to be initialized AFTER self.tracks is populated!

Expand Down Expand Up @@ -571,12 +566,7 @@ def export_selected_tracks(self) -> None:
_, extension = os.path.splitext(temp_file_path)
export_dir = os.path.dirname(self.selected_tracks[0].file_path)

names = []
for name in sorted(os.path.splitext(os.path.basename(track.file_path))[0] for track in self.selected_tracks):
if name.lower() == OTHER_TRACK_NAME:
name = self.parent().app.other_track_name
names.append(name)

names = sorted(os.path.splitext(os.path.basename(track.file_path))[0] for track in self.selected_tracks)
export_name = '+'.join(names) + extension
default_export_path = os.path.join(export_dir, export_name)
export_path, _ = QFileDialog.getSaveFileName(self, self.EXPORT_DIALOG_TITLE, default_export_path)
Expand Down

0 comments on commit 3813d58

Please sign in to comment.