Skip to content

Commit

Permalink
Minor fixes; add logging; bump version to 1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
will2dye4 committed Oct 6, 2023
1 parent 10754fe commit 2fd2535
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = 'poetry.core.masonry.api'

[tool.poetry]
name = 'unmixer'
version = '1.0.0'
version = '1.0.1'
description = 'Create and explore isolated tracks from music files'
license = 'MIT'
readme = 'README.md'
Expand Down
1 change: 1 addition & 0 deletions unmixer/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def main(args: Optional[list[str]] = None) -> None:
elif config.piano:
other_track_name = PIANO_TRACK_NAME

print('Launching Unmixer UI...')
UnmixerUI(song_path=song_path, input_dir_path=input_dir_path,
output_dir_path=output_dir_path, other_track_name=other_track_name).run()

Expand Down
10 changes: 5 additions & 5 deletions unmixer/remix.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import ffmpeg

from unmixer.constants import OTHER_TRACK_NAME
from unmixer.util import cleanup_intermediate_dir


MIX_FILTER_NAME = 'amix'
Expand Down Expand Up @@ -34,14 +35,13 @@ def create_isolated_tracks_from_audio_file(input_file_path: str, output_dir_path

demucs.separate.main([input_file_path, '--out', output_dir_path])

# demucs creates an intermediate directory for the model name.
# Move the isolated tracks out of this directory.
file_name = os.path.splitext(os.path.basename(input_file_path))[0]
intermediate_dir = os.path.join(output_dir_path, DEFAULT_MODEL)
output_dir = os.path.join(output_dir_path, file_name)
shutil.move(os.path.join(intermediate_dir, file_name), output_dir)
shutil.move(os.path.join(output_dir_path, DEFAULT_MODEL, file_name), output_dir)
print(f'Wrote isolated tracks to "{output_dir}".')

if not os.listdir(intermediate_dir):
shutil.rmtree(intermediate_dir)
cleanup_intermediate_dir(output_dir_path)

if other_track_name and (other_track := next((n for n in os.listdir(output_dir) if n.startswith(OTHER_TRACK_NAME)), None)):
_, extension = os.path.splitext(other_track)
Expand Down
13 changes: 6 additions & 7 deletions unmixer/ui/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
from unmixer.ui.constants import FONT_WEIGHT_BOLD


def import_audio_file(input_file_path: str, output_dir_path: str, other_track_name: Optional[str]) -> None:
create_isolated_tracks_from_audio_file(input_file_path, output_dir_path, other_track_name)


class SongImporter(QWidget):

CHOOSE_BUTTON_TEXT = '📂 Choose...'
Expand Down Expand Up @@ -91,14 +87,17 @@ def import_file(self) -> None:
if not self.input_file_path:
return

if self.parent():
self.parent().setWindowTitle(self.parent().IMPORTING_WINDOW_TITLE)
self.parent().update()

filename = os.path.basename(self.input_file_path)
self.parent().setWindowTitle(self.parent().IMPORTING_WINDOW_TITLE)
self.title.setText(f'Now creating isolated tracks from:\n{filename}')
self.subtitle.setText(self.SUBTITLE_TEXT)
self.subtitle.setHidden(False)
self.choose_file_button.setDisabled(True)
self._import_process = Process(target=import_audio_file,

self._import_process = Process(target=create_isolated_tracks_from_audio_file,
args=(self.input_file_path, self.output_dir_path, self.other_track_name))
self._import_process.start()
self.check_import_status_timer.start()
self.parent().update()
10 changes: 6 additions & 4 deletions unmixer/ui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from unmixer.ui.constants import APP_NAME, SUCCESS_MESSAGE_TITLE
from unmixer.ui.importer import SongImporter
from unmixer.ui.multitrack import MultiTrackDisplay
from unmixer.util import is_isolated_track
from unmixer.util import cleanup_intermediate_dir, is_isolated_track


class UnmixerImportWindow(QMainWindow):
Expand All @@ -26,7 +26,7 @@ def __init__(self, app: 'UnmixerUI', source_file_path: Optional[str] = None, out
self.app = app
self.importer = SongImporter(source_file_path, output_dir_path, other_track_name=other_track_name)
self.setCentralWidget(self.importer)
self.setWindowTitle(self.DEFAULT_WINDOW_TITLE)
self.setWindowTitle(self.IMPORTING_WINDOW_TITLE if source_file_path else self.DEFAULT_WINDOW_TITLE)
self.setMinimumSize(self.MIN_WIDTH, self.MIN_HEIGHT)


Expand Down Expand Up @@ -93,7 +93,9 @@ def temp_file_path(self, input_file_paths: list[str]) -> str:
def create_temp_mix_file(self, input_file_paths: list[str]) -> None:
if not input_file_paths or len(input_file_paths) < 2:
raise ValueError('Not enough input files provided!')
merge_audio_files(input_file_paths, self._output_file_path(input_file_paths))
output_path = self._output_file_path(input_file_paths)
print(f'Creating temporary mix file "{output_path}"...')
merge_audio_files(input_file_paths, output_path)


class UnmixerUI:
Expand Down Expand Up @@ -130,7 +132,7 @@ def run(self) -> None:
def stop_import_process(self) -> None:
if self.import_window and ((import_process := self.import_window.importer.import_process) and import_process.is_alive()):
import_process.terminate()
# TODO - delete intermediate dir (htdemucs) if it exists
cleanup_intermediate_dir(self.output_dir_path)

def show_track_explorer_window(self, source_file_path: Optional[str] = None) -> None:
if self.main_window:
Expand Down
1 change: 1 addition & 0 deletions unmixer/ui/multitrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,3 +415,4 @@ def export_selected_tracks(self) -> None:
# This will overwrite the file if it exists, but the user already confirmed that they want that.
shutil.copy(temp_file_path, export_path)
QMessageBox.information(self, SUCCESS_MESSAGE_TITLE, f'Successfully exported {export_path}.')
print(f'Exported new mix file "{export_path}".')
3 changes: 1 addition & 2 deletions unmixer/ui/waveform.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
import numpy as np


# TODO - experiment with different orderings?
WAVEFORM_BACKGROUND_COLORS = [
(QColor(20, 80, 200), QColor(90, 180, 240)), # blue (bass)
(QColor(5, 175, 30), QColor(100, 240, 120)), # green (drums)
(QColor(230, 30, 15), QColor(240, 110, 100)), # red (other/guitar)
(QColor(230, 30, 15), QColor(240, 110, 100)), # red (other/guitar/piano)
(QColor(245, 225, 10), QColor(235, 240, 150)), # yellow (vocals)
(QColor(245, 90, 10), QColor(250, 150, 100)), # orange
(QColor(100, 5, 175), QColor(155, 55, 245)), # purple
Expand Down
10 changes: 10 additions & 0 deletions unmixer/util.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import os.path
import shutil

from demucs.pretrained import DEFAULT_MODEL

from unmixer.constants import ISOLATED_TRACK_FORMATS


def is_isolated_track(file_path: str) -> bool:
return os.path.splitext(file_path)[1].lower().lstrip('.') in ISOLATED_TRACK_FORMATS


def cleanup_intermediate_dir(output_dir_path: str) -> None:
intermediate_dir = os.path.join(output_dir_path, DEFAULT_MODEL)
if os.path.exists(intermediate_dir) and not os.listdir(intermediate_dir):
print(f'Removing intermediate directory {intermediate_dir}.')
shutil.rmtree(intermediate_dir)

0 comments on commit 2fd2535

Please sign in to comment.