Skip to content

Commit

Permalink
proj search path + ui update
Browse files Browse the repository at this point in the history
  • Loading branch information
SatyrDiamond committed Oct 1, 2024
1 parent 5065ab5 commit 7434d20
Show file tree
Hide file tree
Showing 17 changed files with 343 additions and 161 deletions.
1 change: 1 addition & 0 deletions dawvert_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
filesearcher.add_basepath('dawvert', scriptfiledir)

filesearcher.add_searchpath_partial('projectfile', '.', 'projectfile')
filesearcher.add_searchpath_full_append('projectfile', os.path.dirname(in_file), None)

filesearcher.add_searchpath_full_filereplace('extracted', dawvert_core.config.path_samples_extracted, None)
filesearcher.add_searchpath_full_filereplace('downloaded', dawvert_core.config.path_samples_downloaded, None)
Expand Down
73 changes: 58 additions & 15 deletions dawvert_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import sys
import traceback

logging.disable(logging.INFO)

from objects.convproj import fileref
filesearcher = fileref.filesearcher

Expand All @@ -31,6 +29,8 @@ class converterstate():
is_converting = False
is_plugscan = False

dragdroploctexts = ['Beside Original', 'In "output" folder', 'Always "out.*"']

globalstore.extplug.load()

dawvert_core = dv_core.core()
Expand All @@ -39,7 +39,9 @@ class converterstate():
dawvert_config__main = {}
dawvert_config__main['songnum'] = dawvert_core.config.songnum
dawvert_config__main['extrafile'] = dawvert_core.config.path_extrafile
dawvert_config__main['drag_drop'] = 0
dawvert_config__main['ui__drag_drop'] = 0
dawvert_config__main['ui__overwrite_out'] = False
dawvert_config__main['ui__auto_convert'] = False

dawvert_config__nopl_splitter = {}
dawvert_config__nopl_splitter['mode'] = dawvert_core.config.splitter_mode
Expand Down Expand Up @@ -101,6 +103,7 @@ def run(self):
filesearcher.add_basepath('dawvert', scriptfiledir)

filesearcher.add_searchpath_partial('projectfile', '.', 'projectfile')
filesearcher.add_searchpath_full_append('projectfile', os.path.dirname(in_file), None)

filesearcher.add_searchpath_full_filereplace('extracted', dawvert_core.config.path_samples_extracted, None)
filesearcher.add_searchpath_full_filereplace('downloaded', dawvert_core.config.path_samples_downloaded, None)
Expand Down Expand Up @@ -255,7 +258,6 @@ def __init__(self, qt_ui, configparts, configlabel, dictdata):
configparts_main = {
'songnum': ['int', 'Song Number'],
'extrafile': ['str', 'Extra File'],
'drag_drop': ['int', 'Drag and Drop Location']
}

configparts_soundfont = {
Expand Down Expand Up @@ -326,6 +328,12 @@ def __init__(self, *args, obj=None, **kwargs):
self.ui.ConfigString.textChanged.connect(configinput.update_value)
self.ui.ConfigBool.stateChanged.connect(configinput.update_value)

for dragdroploctext in dragdroploctexts:
self.ui.DndOutPathSelection.addItem(dragdroploctext)
self.ui.DndOutPathSelection.currentIndexChanged.connect(self.__change_dd_setting)
self.ui.OverwriteOut.stateChanged.connect(self.__change_overwrite_setting)
self.ui.AutoConvert.stateChanged.connect(self.__change_auto_convert_setting)

configdata(self.ui, configparts_main, 'Main', dawvert_config__main)
configdata(self.ui, configparts_soundfont, 'Soundfonts', dawvert_core.config.paths_soundfonts)
configdata(self.ui, configparts_splitter, 'NoPl Splitter', dawvert_config__nopl_splitter)
Expand Down Expand Up @@ -377,19 +385,40 @@ def dragEnterEvent(self, event):
else:
event.ignore()

def set_dd_output(self, f):
self.ui.InputFilePath.setText(f)
if dawvert_config__main['ui__drag_drop'] == 0:
self.ui.OutputFilePath.setText(f.rsplit('.',1)[0])
self.ui.OutputSamplePath.setText(f.rsplit('.',1)[0]+'_samples')
if dawvert_config__main['ui__drag_drop'] == 1:
outfile = os.path.join(globalstore.dawvert_script_path, 'output', os.path.basename(f))
self.ui.OutputFilePath.setText(outfile.rsplit('.',1)[0])
self.ui.OutputSamplePath.setText(outfile.rsplit('.',1)[0]+'_samples')
if dawvert_config__main['ui__drag_drop'] == 2:
outfile = os.path.join(globalstore.dawvert_script_path, 'out')
self.ui.OutputFilePath.setText(outfile.rsplit('.',1)[0])
samplepath = os.path.join(globalstore.dawvert_script_path, '__samples', os.path.basename(f))
self.ui.OutputSamplePath.setText(samplepath)

def dropEvent(self, event):
files = [u.toLocalFile() for u in event.mimeData().urls()]
for f in files:
self.ui.InputFilePath.setText(f)
if dawvert_config__main['drag_drop'] == 0:
self.ui.OutputFilePath.setText(f.rsplit('.',1)[0])
self.ui.OutputSamplePath.setText(f.rsplit('.',1)[0]+'_samples')
if dawvert_config__main['drag_drop'] == 1:
outfile = os.path.join(globalstore.dawvert_script_path, 'output', os.path.basename(f))
self.ui.OutputFilePath.setText(outfile.rsplit('.',1)[0])
self.ui.OutputSamplePath.setText(outfile.rsplit('.',1)[0]+'_samples')
if files:
self.set_dd_output(files[0])
self.__do_auto_detect()
self.__change_output_path()
if dawvert_config__main['ui__auto_convert']:
if self.__can_convert():
self.__do_convert()

def __change_dd_setting(self, num):
dawvert_config__main['ui__drag_drop'] = num

def __change_overwrite_setting(self, val):
dawvert_config__main['ui__overwrite_out'] = val
self.__update_convst()

def __change_auto_convert_setting(self, val):
dawvert_config__main['ui__auto_convert'] = val

def __choose_input(self):
filename, _filter = QFileDialog.getOpenFileName(
Expand Down Expand Up @@ -435,21 +464,33 @@ def __do_auto_detect(self):
except:
pass

def __can_convert(self):
in_file = self.ui.InputFilePath.text().replace('/', '\\')
out_file = self.ui.OutputFilePath.text().replace('/', '\\')
inplug = dawvert_core.input_get_current()
outplug = dawvert_core.output_get_current()
not_same = in_file!=out_file
out_exists = (not os.path.exists(out_file)) or dawvert_config__main['ui__overwrite_out']
in_usable, in_usable_msg = dawvert_core.input_get_usable()
out_usable, out_usable_msg = dawvert_core.output_get_usable()
return bool(inplug and outplug and not_same and out_exists and in_usable and out_usable)

def __update_convst(self):
in_file = self.ui.InputFilePath.text().replace('/', '\\')
out_file = self.ui.OutputFilePath.text().replace('/', '\\')
inplug = dawvert_core.input_get_current()
outplug = dawvert_core.output_get_current()
not_same = in_file!=out_file
out_exists = not os.path.exists(out_file)
out_exists = (not os.path.exists(out_file)) or dawvert_config__main['ui__overwrite_out']
in_usable, in_usable_msg = dawvert_core.input_get_usable()
out_usable, out_usable_msg = dawvert_core.output_get_usable()
outstate = bool(inplug and outplug and not_same and out_exists and in_usable)
outstate = bool(inplug and outplug and not_same and out_exists and in_usable and out_usable)

self.ui.ConvertButton.setEnabled(outstate and not converterstate.is_converting)
if converterstate.is_converting:
self.ui.StatusText.setText('Status: Converting')
self.ui.SubStatusText.setText('')
return False
elif not outstate:
self.ui.StatusText.setText('Status: Not Ready')
if not in_file: self.ui.SubStatusText.setText('No input file.')
Expand All @@ -464,9 +505,11 @@ def __update_convst(self):
elif not out_usable:
self.ui.StatusText.setText('Status: Output Plugin Unusable')
self.ui.SubStatusText.setText(out_usable_msg)
return False
else:
self.ui.StatusText.setText('Status: Ready')
self.ui.SubStatusText.setText('')
return True


def __change_input_plugset(self, num):
Expand Down
2 changes: 1 addition & 1 deletion objects/file_proj/proj_ableton.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def load_from_file(self, input_file):
alsbytes.seek(0)
xmlstring = alsbytes.read().decode()
except:
raise ProjectFileParserException('ableton: file is not GZIP or text')
raise ProjectFileParserException('ableton: file is not GZIP or XML')

try: root = ET.fromstring(xmlstring)
except ET.ParseError as t:
Expand Down
9 changes: 6 additions & 3 deletions objects/file_proj/proj_famistudiotxt.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,11 @@ def __init__(self):
self.DPCMMappings = dpcm_mappings()

def load_from_file(self, input_file):
f_fst = open(input_file, 'r')
famistudiotxt_lines = f_fst.readlines()
try:
f_fst = open(input_file, 'r')
famistudiotxt_lines = f_fst.readlines()
except UnicodeDecodeError:
raise ProjectFileParserException('famistudio_txt: File is not text')

for line in famistudiotxt_lines:
t_cmd = line.split(" ", 1)
Expand Down Expand Up @@ -233,5 +236,5 @@ def load_from_file(self, input_file):
cur_pat.Notes.append(fs_note(cmd_params))

else:
raise ProjectFileParserException('famistudio: unexpected command and/or wrong tabs: '+cmd_name)
raise ProjectFileParserException('famistudio_txt: unexpected command and/or wrong tabs: '+cmd_name)
return True
Loading

0 comments on commit 7434d20

Please sign in to comment.