Skip to content

Commit

Permalink
add: import options
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanTaquet committed Jan 31, 2017
1 parent 27e2b13 commit 051882d
Show file tree
Hide file tree
Showing 2 changed files with 263 additions and 6 deletions.
184 changes: 184 additions & 0 deletions GUI/import_options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
# -*- coding: utf-8 -*-
"""
Copyright (C) 2016 Jonathan Taquet
This file is part of Oe2sSLE (Open e2sSample.all Library Editor).
Oe2sSLE is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Oe2sSLE is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Oe2sSLE. If not, see <http://www.gnu.org/licenses/>
"""

import e2s_sample_all as e2s

import tkinter as tk

from GUI.widgets import ROCombobox


class ImportOptions:
def __init__(self):
self.osc_cat = 'User'
self.loop_type = 0
self.plus_12_db = 0
self.force_osc_cat = 0
self.force_loop_type = 0
self.force_plus_12_db = 0


osc_cat_strs = tuple(
e2s.esli_OSC_cat_to_str[k]
for k in sorted(e2s.esli_OSC_cat_to_str))

loop_type = {
0: '1-shot',
1: 'full loop'
}
loop_type_from_str = {v: k for k, v in loop_type.items()}
loop_type_strs = tuple(loop_type[k] for k in sorted(loop_type))

plus_12_db = {
0: '+0dB',
1: '+12dB'
}
plus_12_db_from_str = {v: k for k, v in plus_12_db.items()}
plus_12_db_strs = tuple(plus_12_db[k] for k in sorted(plus_12_db))


class ImportOptionsDialog(tk.Toplevel):

def __init__(self, parent, options, *args, **kwargs):
super().__init__(parent, *args, **kwargs)
self.transient(parent)
self.title('Import options')

self.parent = parent
self.options = options

self.loop_type = tk.StringVar()
self.plus_12_db = tk.StringVar()
self.osc_cat = tk.StringVar()
self.loop_type.set(loop_type[options.loop_type])
self.plus_12_db.set(plus_12_db[options.plus_12_db])
self.osc_cat.set(options.osc_cat)

self.force_osc_cat = tk.IntVar()
self.force_loop_type = tk.IntVar()
self.force_plus_12_db = tk.IntVar()
self.force_osc_cat.set(options.force_osc_cat)
self.force_loop_type.set(options.force_loop_type)
self.force_plus_12_db.set(options.force_plus_12_db)

fr = tk.Frame(self)

tk.Label(fr, text="OSC Cat.").grid(row=0, column=1)
tk.Label(fr, text="1-shot").grid(row=0, column=2)
tk.Label(fr, text="+12dB").grid(row=0, column=3)

tk.Label(fr, text="Default value :").grid(row=1, column=0, sticky='E')
tk.Label(fr, text="Force to reset :").grid(row=2, column=0, sticky='E')

ROCombobox(
fr,
values=osc_cat_strs,
width=8,
textvariable=self.osc_cat
).grid(row=1, column=1)
ROCombobox(
fr,
values=loop_type_strs,
width=8,
textvariable=self.loop_type
).grid(row=1, column=2)
ROCombobox(
fr,
values=plus_12_db_strs,
width=8,
textvariable=self.plus_12_db
).grid(row=1, column=3)

tk.Checkbutton(
fr,
variable=self.force_osc_cat
).grid(row=2, column=1)
tk.Checkbutton(
fr,
variable=self.force_loop_type
).grid(row=2, column=2)
tk.Checkbutton(
fr,
variable=self.force_plus_12_db
).grid(row=2, column=3)

fr.pack(fill=tk.BOTH, expand=True, padx=5, pady=5)

box = tk.Frame(self)

tk.Button(
box,
text="OK",
width=10,
command=self.ok,
default=tk.ACTIVE
).pack(side=tk.LEFT, padx=5, pady=5)

tk.Button(
box,
text="Cancel",
width=10,
command=self.cancel
).pack(side=tk.LEFT, padx=5, pady=5)

self.bind("<Return>", self.ok)
self.bind("<Escape>", self.cancel)

box.pack()

self.grab_set()

# temporarily hide the window
self.withdraw()
self.update()
width, height = (self.winfo_width(), self.winfo_height())
self.minsize(width, height)
px, py = (parent.winfo_rootx(), parent.winfo_rooty())
pwidth, pheight = (parent.winfo_width(), parent.winfo_height())
x, y = (px+pwidth/2-width/2, py+pheight/2-height/2)
self.geometry("+{}+{}".format(int(x), int(y)))
self.deiconify()

def update_data(self):
self.options.osc_cat = self.osc_cat.get()
self.options.loop_type = loop_type_from_str[self.loop_type.get()]
self.options.plus_12_db = plus_12_db_from_str[self.plus_12_db.get()]
self.options.force_osc_cat = self.force_osc_cat.get()
self.options.force_loop_type = self.force_loop_type.get()
self.options.force_plus_12_db = self.force_plus_12_db.get()

#
# standard button semantics

def ok(self, event=None):
self.withdraw()
self.update_idletasks()

self.apply()

self.cancel()

def cancel(self, event=None):
# put focus back to the parent window
self.parent.focus_set()
self.destroy()

def apply(self):
self.update_data()
85 changes: 79 additions & 6 deletions Oe2sSLE_GUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
from GUI.stereo_to_mono import StereoToMonoDialog
from GUI.wait_dialog import WaitDialog
from GUI.about_dialog import AboutDialog
from GUI.import_options import ImportOptionsDialog, ImportOptions

import utils

Expand Down Expand Up @@ -1730,6 +1731,7 @@ def __init__(self, *args, **kw):
super().__init__(*args, **kw)
GUI.res.init()

self.import_opts = ImportOptions()

# Set the window title
self.wm_title("Open e2sSample.all Library Editor")
Expand Down Expand Up @@ -1786,11 +1788,20 @@ def __init__(self, *args, **kw):
self.buttonRem = tk.Button(self, text="Remove Selected", command=self.sampleList.remove_selected)
self.buttonRem.pack(side=tk.TOP, fill=tk.BOTH)

self.buttonAdd = tk.Button(self, text="Import wav Sample(s)", command=self.import_sample)
fr = tk.Frame(self)
fr2 = tk.Frame(fr)
self.buttonAdd = tk.Button(fr2, text="Import wav Sample(s)", command=self.import_sample)
self.buttonAdd.pack(side=tk.TOP, fill=tk.BOTH)
self.buttonAdd = tk.Button(self, text="Import e2sSample.all", command=self.import_all_sample)

self.buttonAdd = tk.Button(fr2, text="Import e2sSample.all", command=self.import_all_sample)
self.buttonAdd.pack(side=tk.TOP, fill=tk.BOTH)
fr2.pack(side=tk.LEFT, expand=True, fill=tk.BOTH)

fr2 = tk.Frame(fr, borderwidth=2)
self.buttonImportOptions = tk.Button(fr2, text="Import Options", command=self.import_options)
self.buttonImportOptions.pack(fill=None)
fr2.pack(side=tk.LEFT, fill=None)
fr.pack(side=tk.TOP, fill=tk.BOTH)

self.buttonExp = tk.Button(self, text="Export Selected as wav", command=self.export_sample)
self.buttonExp.pack(side=tk.TOP, fill=tk.BOTH)
Expand Down Expand Up @@ -1822,7 +1833,11 @@ def about(self):
def clear(self):
wd = WaitDialog(self)
wd.run(self.sampleList.clear)


def import_options(self):
dialog = ImportOptionsDialog(self, self.import_opts)
self.wait_window(dialog)

def load(self):
filename = tk.filedialog.askopenfilename(parent=self,title="Select e2s Sample.all file to open",filetypes=(('.all Files','*.all'),('All Files','*.*')))
if filename:
Expand Down Expand Up @@ -1940,7 +1955,11 @@ def fct():
esli.useChan1 = True
# by default use maximum volume (not like electribe that computes a good value)
esli.playVolume = 65535


# use options defaults
esli.OSC_category = esli.OSC_category = e2s.esli_str_to_OSC_cat[self.import_opts.osc_cat]
esli.playLevel12dB = self.import_opts.plus_12_db

esli.OSC_importNum = self.import_num
self.import_num += 1
# by default play speed is same as indicated by Frequency
Expand All @@ -1950,6 +1969,7 @@ def fct():

# check if smpl chunk is used
smpl_chunk = sample.RIFF.chunkList.get_chunk(b'smpl')
smpl_used = False
if smpl_chunk:
# use it to initialize loop point
if smpl_chunk.data.numSampleLoops > 0:
Expand All @@ -1963,6 +1983,11 @@ def fct():
esli.OSC_LoopStartPoint_offset = start - esli.OSC_StartPoint_address
esli.OSC_OneShot = 0
esli.OSC_EndPoint_offset = end - esli.OSC_StartPoint_address
smpl_used = True
if not smpl_used and self.import_opts.loop_type == 1:
# loop all
esli.OSC_LoopStartPoint_offset = 0
esli.OSC_OneShot = 0
# check if cue chunk is used
cue_chunk = sample.RIFF.chunkList.get_chunk(b'cue ')
if cue_chunk:
Expand Down Expand Up @@ -1996,6 +2021,30 @@ def fct():
print(e)
continue

#
# Apply forced import options
#

if self.import_opts.force_osc_cat:
esli.OSC_category = e2s.esli_str_to_OSC_cat[self.import_opts.osc_cat]

if self.import_opts.force_loop_type:
if self.import_opts.loop_type == 0:
# force one shot
esli.OSC_LoopStartPoint_offset = esli.OSC_EndPoint_offset
esli.OSC_OneShot = 1
elif self.import_opts.loop_type == 1:
# force loop all
esli.OSC_LoopStartPoint_offset = 0
esli.OSC_OneShot = 0

if self.import_opts.force_plus_12_db:
esli.playLevel12dB = self.import_opts.plus_12_db

#
# Register the sample
#

nextsampleIndex = self.sampleList.get_next_free_sample_index()
if nextsampleIndex is not None:
esli.OSC_0index = esli.OSC_0index1 = nextsampleIndex
Expand Down Expand Up @@ -2045,7 +2094,31 @@ def fct():

for sample in samplesAll.samples:
esli = sample.get_esli()


#
# Apply forced import options
#

if self.import_opts.force_osc_cat:
esli.OSC_category = e2s.esli_str_to_OSC_cat[self.import_opts.osc_cat]

if self.import_opts.force_loop_type:
if self.import_opts.loop_type == 0:
# force one shot
esli.OSC_LoopStartPoint_offset = esli.OSC_EndPoint_offset
esli.OSC_OneShot = 1
elif self.import_opts.loop_type == 1:
# force loop all
esli.OSC_LoopStartPoint_offset = 0
esli.OSC_OneShot = 0

if self.import_opts.force_plus_12_db:
esli.playLevel12dB = self.import_opts.plus_12_db

#
# Register the sample
#

nextsampleIndex = self.sampleList.get_next_free_sample_index()
if nextsampleIndex is not None:
esli.OSC_0index = esli.OSC_0index1 = nextsampleIndex
Expand Down

0 comments on commit 051882d

Please sign in to comment.