Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
IoeCmcomc committed Nov 16, 2019
1 parent 9a6bc89 commit 10c77a1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -350,4 +350,5 @@ dist/
main.build/
main.dist/

sounds/block.note.sax.ogg
sounds/block.note.sax.ogg
setup.py
43 changes: 30 additions & 13 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾


import sys, os, operator, webbrowser, copy, traceback, re, json, music21
import sys, os, operator, webbrowser, copy, traceback, re, json

import tkinter as tk
import tkinter.ttk as ttk
Expand All @@ -32,6 +32,7 @@
from random import randrange
from math import floor, log2
from datetime import date
#from collections import deque

from PIL import Image, ImageTk
from pydub import AudioSegment
Expand All @@ -49,10 +50,14 @@ def resource_path(*args):
if len(args) > 1:
relative_path = os.path.join(*args)
else: relative_path = args[0]
try:
r = os.path.join(sys._MEIPASS, relative_path)
except Exception:
r = os.path.join(os.path.abspath("."), relative_path)
if getattr(sys, 'frozen', False):
datadir = os.path.dirname(sys.executable)
r = os.path.join(datadir, relative_path)
else:
try:
r = os.path.join(sys._MEIPASS, relative_path)
except Exception:
r = os.path.join(os.path.abspath("."), relative_path)
#print(r)
return r

Expand All @@ -68,6 +73,10 @@ def __init__(self, parent):
self.pack(fill='both', expand=True)
self.update()
WindowGeo(self.parent, self.parent, 800, 500, 600, 500)
self.lift()
self.focus_force()
self.grab_set()
self.grab_release()

def properties(self):
self.VERSION = '0.7.0'
Expand All @@ -86,7 +95,11 @@ def elements(self):
self.parent.title("NBS Tool")
self.style = ttk.Style()
#self.style.theme_use("default")
self.style.theme_use("vista")
try:
self.style.theme_use("vista")
except Exception as e:
print(repr(e), e.__class__.__name__)
self.style.theme_use("winnative")

#Menu bar
self.menuBar = tk.Menu(self)
Expand Down Expand Up @@ -448,7 +461,7 @@ def popupmenus(self, event):
self.popupMenu.add_command(label="Copy", accelerator="Ctrl+C", command=lambda: w.event_generate("<Control-c>"))
self.popupMenu.add_command(label="Paste", accelerator="Ctrl+V", command=lambda: w.event_generate("<Control-v>"))
self.popupMenu.tk.call("tk_popup", self.popupMenu, event.x_root, event.y_root)

def onClose(self, event=None):
self.parent.quit()
self.parent.destroy()
Expand All @@ -473,9 +486,10 @@ def OnOpenFile(self, fileName, fromEntry=False):
self.inputFileData = data
self.ExpOutputEntry.delete(0, 'end')
self.exportFilePath.set('')
print(type(data))

self.UpdateVar()
self.parent.title("{} – NBS Tool".format(fileName.split('/')[-1]))
self.parent.title('"{}" – NBS Tool'.format(fileName.split('/')[-1]))
self.RaiseFooter('Opened')
self.UpdateProgBar(100)
self.UpdateProgBar(-1)
Expand All @@ -494,7 +508,7 @@ def OnSaveFile(self, saveAsNewFile=False):
self.OpenFileEntry.delete(0,'end')
self.OpenFileEntry.insert(0, self.filePath)

self.parent.title("{} – NBS Tool".format(self.filePath.split('/')[-1]))
self.parent.title('"{}" – NBS Tool'.format(self.filePath.split('/')[-1]))
self.UpdateProgBar(100)
self.RaiseFooter('Saved')
self.UpdateProgBar(-1)
Expand Down Expand Up @@ -617,9 +631,10 @@ def UpdateVar(self):
data = self.inputFileData
if data is not None:
self.ToolsTabButton['state'] = 'normal'
self.ExpSaveButton['state'] = 'normal'
if data != self.last.inputFileData:
self.UpdateProgBar(10)
self.parent.title("*{} – NBS Tool".format(self.filePath.split('/')[-1]))
self.parent.title('*"{}" – NBS Tool'.format(self.filePath.split('/')[-1]))
self.UpdateProgBar(20)
headers = data['headers']
self.UpdateProgBar(30)
Expand Down Expand Up @@ -655,6 +670,7 @@ def UpdateVar(self):
self.UpdateProgBar(-1)
else:
self.ToolsTabButton['state'] = 'disabled'
self.ExpSaveButton['state'] = 'disabled'

self.update_idletasks()

Expand Down Expand Up @@ -1083,8 +1099,8 @@ def exportMIDI(cls, path, byLayer=False):
mid.write()
mid.close()

exper_s = m21.midi.translate.midiFileToStream(mid)
fn = exper_s.write("midi", path+'_test.mid')
#exper_s = m21.midi.translate.midiFileToStream(mid)
#exper_s.write("midi", path+'_test.mid')

def exportMusic(cls, path, ext):
start = time()
Expand Down Expand Up @@ -1339,7 +1355,8 @@ def wnbs():
root = tk.Tk()
app = MainWindow(root)
print('Creating app...')


print(sys.argv)
if len(sys.argv) == 2: app.OnBrowseFile(True, sys.argv[1])

root.iconbitmap(resource_path("icon.ico"))
Expand Down
14 changes: 7 additions & 7 deletions nbsio.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from struct import Struct
from pprint import pprint
from random import shuffle
from collections import deque
import operator

BYTE = Struct('<b')
Expand All @@ -37,12 +38,12 @@ def readString(f):
def readnbs(filename):
IsOldVersion = False
headers = {}
notes = []
notes = deque()
maxLayer = 0
usedInsts = [[], []]
hasPerc = False
layers = []
customInsts = []
layers = deque()
customInsts = deque()

if filename is not '':
with open(filename, "rb") as f:
Expand Down Expand Up @@ -157,8 +158,7 @@ def DataPostprocess(data):
data['headers']['length'] = tick
data['maxLayer'] = maxLayer
data['usedInsts'] = usedInsts
#data['indexByTick'] = 1
data['indexByTick'] = tuple([ (tk, tuple([notes.index(nt) for nt in notes if nt['tick'] == tk]) ) for tk in range(headers['length']+1) ])
data['indexByTick'] = tuple([ (tk, set([notes.index(nt) for nt in notes if nt['tick'] == tk]) ) for tk in range(headers['length']+1) ])
note = tick = inst = layer = duraKey = usedInsts = maxLayer = tk = nt = None
return data

Expand All @@ -172,8 +172,8 @@ def writeString(f, v):
def writenbs(filename, data):
if filename is not '' and data is not None:
data = DataPostprocess(data)
headers, notes, layers, customInsts, IsOldVersion, hasPerc, maxLayer, usedInsts = \
data['headers'], data['notes'], data['layers'], data['customInsts'], data['IsOldVersion'], data['hasPerc'], data['maxLayer'], data['usedInsts']
headers, notes, layers, customInsts, IsOldVersion = \
data['headers'], data['notes'], data['layers'], data['customInsts'], data['IsOldVersion']
with open(filename, "wb") as f:
#Header
if not IsOldVersion:
Expand Down

0 comments on commit 10c77a1

Please sign in to comment.