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