Fix GUI launching, adjust max width for editor
This commit is contained in:
parent
d7291b8a8a
commit
3efa526bab
5 changed files with 62 additions and 73 deletions
12
src/cli.py
12
src/cli.py
|
|
@ -7,8 +7,8 @@ from argparse import ArgumentParser, RawTextHelpFormatter
|
|||
|
||||
from colorama import Fore
|
||||
|
||||
from src.common import MODEL_CHOICES
|
||||
from src.messaging import CliOutput
|
||||
from src.music_file import MODEL_CHOICES
|
||||
from src.processor import FolderProcessor
|
||||
|
||||
|
||||
|
|
@ -21,11 +21,7 @@ def __get_parser() -> ArgumentParser:
|
|||
|
||||
model_choices = "\n • ".join(
|
||||
# Padding in the array so the first entry starts on a newline with bullet
|
||||
[""]
|
||||
+ [
|
||||
f"{Fore.GREEN}{MODEL_CHOICES[desc]}{Fore.RESET} - {desc}"
|
||||
for desc in MODEL_CHOICES
|
||||
]
|
||||
[""] + [f"{Fore.GREEN}{MODEL_CHOICES[desc]}{Fore.RESET} - {desc}" for desc in MODEL_CHOICES]
|
||||
)
|
||||
|
||||
parser = ArgumentParser(
|
||||
|
|
@ -34,9 +30,7 @@ def __get_parser() -> ArgumentParser:
|
|||
formatter_class=RawTextHelpFormatter,
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"input_dir", help="The directory to scan for files. Scans recursively."
|
||||
)
|
||||
parser.add_argument("input_dir", help="The directory to scan for files. Scans recursively.")
|
||||
|
||||
parser.add_argument(
|
||||
"output_dir",
|
||||
|
|
|
|||
11
src/common.py
Normal file
11
src/common.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
SUPPORTED_EXTS = [".mp3", ".m4a", ".wav"]
|
||||
|
||||
MODEL_CHOICES = {
|
||||
"Hybrid Transformer Demucs (Fine-Tuned)": "htdemucs_ft",
|
||||
"Hybrid Transformer Demucs": "htdemucs",
|
||||
"Hybrid Transformer Demucs v3": "hdemucs_mmi",
|
||||
"Model Trained with MusDB HQ": "mdx",
|
||||
"Model Trained with MusDB HQ & Extra Training Data": "mdx_extra",
|
||||
"Model Trained with MusDB HQ (Quantized)": "mdx_q",
|
||||
"Model Trained with MusDB HQ (Extra Quantized)": "mdx_extra_q",
|
||||
}
|
||||
48
src/gui.py
48
src/gui.py
|
|
@ -2,11 +2,12 @@
|
|||
@author: Jose Stovall | github.com/oitsjustjose | bsky||@oitsjustjose.com
|
||||
"""
|
||||
|
||||
import os
|
||||
import platform
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import Callable, List
|
||||
from typing import Callable, List, Union
|
||||
|
||||
from PySide6.QtGui import QIcon
|
||||
from PySide6.QtWidgets import (
|
||||
|
|
@ -21,7 +22,7 @@ from PySide6.QtWidgets import (
|
|||
QWidget,
|
||||
)
|
||||
|
||||
from src.music_file import MODEL_CHOICES
|
||||
from src.common import MODEL_CHOICES
|
||||
|
||||
APP_ID = "com.oitsjustjose.drum-track-converter"
|
||||
|
||||
|
|
@ -86,9 +87,13 @@ class MainWindow(QMainWindow):
|
|||
self.setHidden(True)
|
||||
[x.setEnabled(False) for x in self.interactive_elements]
|
||||
|
||||
cli = get_path("dtc_cli.exe") if platform.system() == "Windows" else ""
|
||||
prefix = "start /wait" if platform.system() == "Windows" else ""
|
||||
command = f"{prefix} {sys.executable} -m src.cli {self.input_dir} {self.output_dir} -m {self.model_name}"
|
||||
self.__child_proc = subprocess.Popen(command.split(" "), shell=True)
|
||||
command = f"{prefix} {cli} {self.input_dir} {self.output_dir} -m {self.model_name}"
|
||||
|
||||
print(f"{command=}")
|
||||
|
||||
self.__child_proc = subprocess.Popen(command.split(" "), shell=True, creationflags=subprocess.CREATE_NEW_CONSOLE)
|
||||
self.__child_proc.wait()
|
||||
|
||||
# Re-enable elements now that everything is done
|
||||
|
|
@ -142,9 +147,7 @@ class MainWindow(QMainWindow):
|
|||
QWidget: The VBox widget created
|
||||
"""
|
||||
|
||||
def create_io_button_group(
|
||||
self: MainWindow, label_text: str, on_click: Callable
|
||||
) -> QWidget:
|
||||
def create_io_button_group(self: MainWindow, label_text: str, on_click: Callable) -> QWidget:
|
||||
"""Re-usable template to create an input or output button group
|
||||
This group contains a label and a clickable button, which calls the
|
||||
on_click callable passed in when clicked.
|
||||
|
|
@ -173,12 +176,8 @@ class MainWindow(QMainWindow):
|
|||
# Input and Output directory items
|
||||
widget = QWidget()
|
||||
layout = QHBoxLayout()
|
||||
layout.addWidget(
|
||||
create_io_button_group(self, "Select Input Folder", self.on_input_clicked)
|
||||
)
|
||||
layout.addWidget(
|
||||
create_io_button_group(self, "Select Output Folder", self.on_output_clicked)
|
||||
)
|
||||
layout.addWidget(create_io_button_group(self, "Select Input Folder", self.on_input_clicked))
|
||||
layout.addWidget(create_io_button_group(self, "Select Output Folder", self.on_output_clicked))
|
||||
widget.setLayout(layout)
|
||||
return widget
|
||||
|
||||
|
|
@ -191,9 +190,7 @@ class MainWindow(QMainWindow):
|
|||
widget = QWidget()
|
||||
layout = QHBoxLayout()
|
||||
|
||||
label = self.__create_label(
|
||||
'Demucs Model <a style="text-decoration: none !important;" href="https://github.com/facebookresearch/demucs?tab=readme-ov-file#separating-tracks">ℹ️</a>'
|
||||
)
|
||||
label = self.__create_label('Demucs Model <a style="text-decoration: none !important;" href="https://github.com/facebookresearch/demucs?tab=readme-ov-file#separating-tracks">ℹ️</a>')
|
||||
label.setOpenExternalLinks(True)
|
||||
|
||||
combo_box = QComboBox()
|
||||
|
|
@ -246,8 +243,8 @@ def main() -> None:
|
|||
app = QApplication(sys.argv)
|
||||
|
||||
icon = QIcon()
|
||||
icon.addFile("assets/icon.png")
|
||||
icon.addFile("assets/icon.ico")
|
||||
icon.addFile(str(get_path("assets/icon.png")))
|
||||
icon.addFile(str(get_path("assets/icon.ico")))
|
||||
|
||||
app.setWindowIcon(icon)
|
||||
window = MainWindow()
|
||||
|
|
@ -257,6 +254,21 @@ def main() -> None:
|
|||
sys.exit(exit_code)
|
||||
|
||||
|
||||
def get_path(path: Union[Path, str]) -> Path:
|
||||
"""Gets the path to a given object, determining its location based on if the application is packed or in-dev.
|
||||
|
||||
Args:
|
||||
path (Union[Path, str]): The path you wish to resolve
|
||||
|
||||
Returns:
|
||||
Path: The resolved path, either in the temp dir or locally on disk.
|
||||
"""
|
||||
|
||||
bundle_dir = Path(sys._MEIPASS if getattr(sys, "frozen", False) else os.path.dirname(os.path.abspath(__file__))).resolve()
|
||||
|
||||
return bundle_dir.joinpath(path).resolve()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Set the AppUserModelId so that the proper taskbar icon renders
|
||||
if platform.system() == "Windows":
|
||||
|
|
|
|||
|
|
@ -11,17 +11,6 @@ from eyed3.id3 import ID3_V2_4, Tag
|
|||
from tinytag import TinyTag
|
||||
from wavinfo import WavInfoReader
|
||||
|
||||
SUPPORTED_EXTS = [".mp3", ".m4a", ".wav"]
|
||||
MODEL_CHOICES = {
|
||||
"Hybrid Transformer Demucs (Fine-Tuned)": "htdemucs_ft",
|
||||
"Hybrid Transformer Demucs": "htdemucs",
|
||||
"Hybrid Transformer Demucs v3": "hdemucs_mmi",
|
||||
"Model Trained with MusDB HQ": "mdx",
|
||||
"Model Trained with MusDB HQ & Extra Training Data": "mdx_extra",
|
||||
"Model Trained with MusDB HQ (Quantized)": "mdx_q",
|
||||
"Model Trained with MusDB HQ (Extra Quantized)": "mdx_extra_q",
|
||||
}
|
||||
|
||||
|
||||
class MusicFile:
|
||||
def __init__(self, path: Path, model_name: str):
|
||||
|
|
@ -128,8 +117,6 @@ class MusicFile:
|
|||
"""
|
||||
audio_file = eyed3.load(str(self.file_path))
|
||||
if not audio_file:
|
||||
print(
|
||||
f"Failed to load tag from file {self.file_path} -- returning empty tag"
|
||||
)
|
||||
print(f"Failed to load tag from file {self.file_path} -- returning empty tag")
|
||||
return Tag(version=ID3_V2_4)
|
||||
return audio_file.tag
|
||||
|
|
|
|||
|
|
@ -5,14 +5,15 @@
|
|||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
from argparse import Namespace as argset
|
||||
from pathlib import Path
|
||||
|
||||
import eyed3
|
||||
from eyed3.id3 import ID3_V2_4, Tag
|
||||
|
||||
from src.messaging import MessageInterface, NoPrintStatements
|
||||
from src.music_file import SUPPORTED_EXTS, MODEL_CHOICES, MusicFile
|
||||
from src.common import MODEL_CHOICES, SUPPORTED_EXTS
|
||||
from src.messaging import CliOutput, NoPrintStatements
|
||||
from src.music_file import MusicFile
|
||||
|
||||
|
||||
class FolderProcessor:
|
||||
|
|
@ -21,7 +22,7 @@ class FolderProcessor:
|
|||
input_dir: str,
|
||||
output_dir: str,
|
||||
model_name: str,
|
||||
msg_interface: MessageInterface,
|
||||
output: CliOutput,
|
||||
verbose: bool = False,
|
||||
):
|
||||
"""
|
||||
|
|
@ -29,25 +30,23 @@ class FolderProcessor:
|
|||
input_dir (str): The source directory to traverse and convert
|
||||
output_dir (str): The destination directory which will mirror the source, but with tracks that have no drums
|
||||
model_name (str): The name of the Demucs model to use for splitting tracks
|
||||
msg_interface (MessageInterface): The handler for displaying output to the user
|
||||
output (CliOutput): The handler for displaying output to the user
|
||||
"""
|
||||
self.input_dir: str = input_dir
|
||||
self.output_dir: str = output_dir
|
||||
self.msg_interface: MessageInterface = msg_interface
|
||||
self.output: CliOutput = output
|
||||
self.model_name = model_name
|
||||
self.verbose: bool = verbose
|
||||
|
||||
@classmethod
|
||||
def from_args(self, args: argset, msg_interface: MessageInterface):
|
||||
def from_args(self, args: argset, output: CliOutput):
|
||||
"""Creates a FolderProcessor instance using an argparse argument set
|
||||
|
||||
Args:
|
||||
args (argset): Arguments from the CLI
|
||||
msg_interface (MessageInterface): The handler for displaying output to the user
|
||||
output (CliOutput): The handler for displaying output to the user
|
||||
"""
|
||||
return FolderProcessor(
|
||||
args.input_dir, args.output_dir, args.model, msg_interface, args.verbose
|
||||
)
|
||||
return FolderProcessor(args.input_dir, args.output_dir, args.model, output, args.verbose)
|
||||
|
||||
def _is_ffmpeg_present(self) -> bool:
|
||||
"""Determines if ffmpeg is installed and accessible
|
||||
|
|
@ -57,9 +56,7 @@ class FolderProcessor:
|
|||
When returning false, no processing should be permitted.
|
||||
"""
|
||||
try:
|
||||
exit_code = subprocess.call(
|
||||
["ffmpeg"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
|
||||
)
|
||||
exit_code = subprocess.call(["ffmpeg"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
return exit_code == 1
|
||||
except FileNotFoundError:
|
||||
return False
|
||||
|
|
@ -73,9 +70,7 @@ class FolderProcessor:
|
|||
"""
|
||||
|
||||
if not self._is_ffmpeg_present():
|
||||
raise Exception(
|
||||
"FFMpeg is not installed! Please install it from here: https://www.ffmpeg.org/download.html"
|
||||
)
|
||||
raise Exception("FFMpeg is not installed! Please install it from here: https://www.ffmpeg.org/download.html")
|
||||
|
||||
src: Path = Path(self.input_dir)
|
||||
dest: Path = Path(self.output_dir)
|
||||
|
|
@ -88,16 +83,12 @@ class FolderProcessor:
|
|||
for file in files:
|
||||
original_path = Path(root).joinpath(file)
|
||||
if original_path.suffix not in SUPPORTED_EXTS:
|
||||
self.msg_interface.warning(
|
||||
f"File {original_path.name} has an unsupported extension and will be skipped!"
|
||||
)
|
||||
self.output.warning(f"File {original_path.name} has an unsupported extension and will be skipped!")
|
||||
continue
|
||||
# Create a "MusicFile" from the full path of the original file
|
||||
original_file = MusicFile(original_path, self.model_name)
|
||||
|
||||
self.msg_interface.info(
|
||||
f"Splitting drum tracks from {original_path.name} using {list(MODEL_CHOICES.keys())[list(MODEL_CHOICES.values()).index(self.model_name)]}:"
|
||||
)
|
||||
self.output.info(f"Splitting drum tracks from {original_path.name} using {list(MODEL_CHOICES.keys())[list(MODEL_CHOICES.values()).index(self.model_name)]}:")
|
||||
|
||||
with NoPrintStatements(self.verbose):
|
||||
no_drums_path = original_file.separate()
|
||||
|
|
@ -116,9 +107,7 @@ class FolderProcessor:
|
|||
os.makedirs(file_output_root, exist_ok=True)
|
||||
shutil.move(no_drums_path, file_dest)
|
||||
|
||||
self.msg_interface.info(
|
||||
f"Done processing {original_path.name} and relocated it to {file_dest.relative_to(cur_dir)}!"
|
||||
)
|
||||
self.output.info(f"Done processing {original_path.name} and relocated it to {file_dest.relative_to(cur_dir)}!")
|
||||
|
||||
# Remove the model output since we don't need it anymore
|
||||
if os.path.exists(self.model_name):
|
||||
|
|
@ -136,9 +125,7 @@ class FolderProcessor:
|
|||
bool: True if the process succeeds, False if get_tag raises an exception
|
||||
"""
|
||||
try:
|
||||
self.msg_interface.info(
|
||||
f"Copying Metadata from {original_file.file_path.name} to {no_drums_path.name}"
|
||||
)
|
||||
self.output.info(f"Copying Metadata from {original_file.file_path.name} to {no_drums_path.name}")
|
||||
|
||||
original_tag: Tag = original_file.get_tag()
|
||||
|
||||
|
|
@ -147,9 +134,7 @@ class FolderProcessor:
|
|||
no_drums_audiofile.tag.title = f"{original_tag.title} (No Drums)"
|
||||
no_drums_audiofile.tag.save(version=ID3_V2_4)
|
||||
except Exception:
|
||||
self.msg_interface.warning(
|
||||
f"Failed to get the tag for {no_drums_path.name} - skipping!"
|
||||
)
|
||||
self.output.warning(f"Failed to get the tag for {no_drums_path.name} - skipping!")
|
||||
no_drums_path.unlink()
|
||||
return False
|
||||
return True
|
||||
|
|
|
|||
Loading…
Reference in a new issue