예제 #1
0
    def __init__(self, master):
        self.current = None
        self.frame = Frame(master)
        self.frame.pack()

        self.midi_controller = MidiController()

        # Voice stack info
        self.chosen_bank = None
        self.chosen_voice = None
        self.voice_list = LoadSave.load()
        self.current_index = -1

        # Voice Display Info
        self.display_holder = LabelFrame(self.frame, padx=5, pady=5)
        self.display_holder.pack(side=RIGHT)
        self.display_voice_stringvar = StringVar()
        self.display_voice_label = Label(self.display_holder, textvariable=self.display_voice_stringvar)
        self.display_voice_label.pack(side=LEFT)

        self.button = Button(self.frame, text="QUIT", fg="red", command=self._exit)
        self.button.pack(side=LEFT)

        self.main_bank_select = Listbox(self.frame, exportselection=0, width=8)
        self.main_bank_select.pack(side=LEFT)

        self.voice_select = Listbox(self.frame, exportselection=0, width=12, height=10)
        self.voice_select.pack(side=LEFT)

        button_frame = Frame(self.frame)
        button_frame.pack(side=LEFT)

        self.name_entry = Entry(button_frame)
        self.name_entry.pack(side=TOP)
        chose_append_button = Button(button_frame, text="At End", bg="black", fg="blue",
                                     command=lambda: self._pick_voice(append=True))
        chose_append_button.pack(side=TOP)
        chose_before_button = Button(button_frame, text="Before",
                                     command=lambda: self._pick_voice(after=False))
        chose_before_button.pack(side=TOP)
        chose_before_button = Button(button_frame, text="After",
                                     command=lambda: self._pick_voice(after=True))
        chose_before_button.pack(side=TOP)
        spacer = Frame(button_frame, height=2)
        spacer.pack(side=TOP, pady=5)
        set_cursor_button = Button(button_frame, text="Set At",
                                   command=lambda: self._set_current_index(int(self.order_listbox.curselection()[0])))
        set_cursor_button.pack()

        self.order_listbox = Listbox(self.frame, exportselection=0, width=30)
        self.order_listbox.pack(side=LEFT)
        self.integrated_tones = IntegratedTones()
        self._update_listbox(self.main_bank_select, self.integrated_tones.groups)

        self.main_bank_select.bind("<<ListboxSelect>>", self._update_voice_listbox)
        self.voice_select.bind("<<ListboxSelect>>", self._choose_voice)
        self._update_order_listbox()
예제 #2
0
    def load():
        all_changes = []
        try:
            saved_file = open("saved.json", "r")
            loaded = json.load(saved_file)
            saved_file.close()
        except Exception as e:
            print e
            return all_changes

        print loaded

        for change in loaded:
            name = change["name"]
            upper_1 = PatchEntry(patch_class=IntegratedTones.get_class_by_name(change["upper_1"]["patch_class"]),
                                 patch_entry=change["upper_1"]["patch_entry"])
            print upper_1.patch_entry
            print upper_1.patch_class
            patch_change = PatchChange(name, upper_1)
            all_changes.append(patch_change)

        return all_changes
예제 #3
0
class App:

    def __init__(self, master):
        self.current = None
        self.frame = Frame(master)
        self.frame.pack()

        self.midi_controller = MidiController()

        # Voice stack info
        self.chosen_bank = None
        self.chosen_voice = None
        self.voice_list = LoadSave.load()
        self.current_index = -1

        # Voice Display Info
        self.display_holder = LabelFrame(self.frame, padx=5, pady=5)
        self.display_holder.pack(side=RIGHT)
        self.display_voice_stringvar = StringVar()
        self.display_voice_label = Label(self.display_holder, textvariable=self.display_voice_stringvar)
        self.display_voice_label.pack(side=LEFT)

        self.button = Button(self.frame, text="QUIT", fg="red", command=self._exit)
        self.button.pack(side=LEFT)

        self.main_bank_select = Listbox(self.frame, exportselection=0, width=8)
        self.main_bank_select.pack(side=LEFT)

        self.voice_select = Listbox(self.frame, exportselection=0, width=12, height=10)
        self.voice_select.pack(side=LEFT)

        button_frame = Frame(self.frame)
        button_frame.pack(side=LEFT)

        self.name_entry = Entry(button_frame)
        self.name_entry.pack(side=TOP)
        chose_append_button = Button(button_frame, text="At End", bg="black", fg="blue",
                                     command=lambda: self._pick_voice(append=True))
        chose_append_button.pack(side=TOP)
        chose_before_button = Button(button_frame, text="Before",
                                     command=lambda: self._pick_voice(after=False))
        chose_before_button.pack(side=TOP)
        chose_before_button = Button(button_frame, text="After",
                                     command=lambda: self._pick_voice(after=True))
        chose_before_button.pack(side=TOP)
        spacer = Frame(button_frame, height=2)
        spacer.pack(side=TOP, pady=5)
        set_cursor_button = Button(button_frame, text="Set At",
                                   command=lambda: self._set_current_index(int(self.order_listbox.curselection()[0])))
        set_cursor_button.pack()

        self.order_listbox = Listbox(self.frame, exportselection=0, width=30)
        self.order_listbox.pack(side=LEFT)
        self.integrated_tones = IntegratedTones()
        self._update_listbox(self.main_bank_select, self.integrated_tones.groups)

        self.main_bank_select.bind("<<ListboxSelect>>", self._update_voice_listbox)
        self.voice_select.bind("<<ListboxSelect>>", self._choose_voice)
        self._update_order_listbox()

    def next_voice(self, event):
        if len(self.voice_list) == 0:
            return

        self.order_listbox.selection_clear(0, END)
        if self.current_index == len(self.voice_list) - 1:
            self.current_index = 0
        else:
            self.current_index += 1
        new_display = self.voice_list[self.current_index]
        self.display_voice_stringvar.set(str(new_display))

        self.order_listbox.selection_set(self.current_index)
        self.order_listbox.see(self.current_index + 3)
        print self.integrated_tones.get_change_info_for_patch_entry(new_display)
        self.midi_controller.send_messages(self.integrated_tones.get_change_info_for_patch_entry(new_display))

    def _update_voice_listbox(self, event):
        selection = self._get_listbox_selection_from_event(event)
        self.chosen_bank = self.integrated_tones.groups[selection]["class"]
        self._update_listbox(self.voice_select, self.chosen_bank.voices)

    def _choose_voice(self, event):
        selection = self._get_listbox_selection_from_event(event)
        self.chosen_voice = self.chosen_bank.voices[selection]

    def _pick_voice(self, append=False, after=False):
        if self.chosen_voice:
            name = self.name_entry.get()
            patch_entry = PatchEntry(self.chosen_bank, self.chosen_voice)
            patch_change = PatchChange(name, patch_entry)
            current_index_selection = map(int, self.order_listbox.curselection())

            if append or len(current_index_selection) == 0:
                self.voice_list.append(patch_change)
            else:
                index = current_index_selection[0]
                if after:
                    index += 1
                self.voice_list.insert(index, patch_change)

            self._update_order_listbox()

            print patch_change.serialise()
            LoadSave.write(self.voice_list)

    def _update_order_listbox(self):
        self.order_listbox.delete(0, END)
        for item in self.voice_list:
            self.order_listbox.insert(END, str(item))

    def _set_current_index(self, index):
        self.current_index = index

    def _exit(self):
        self.midi_controller.close()
        self.frame.quit()

    @staticmethod
    def _get_listbox_selection_from_event(event):
        return int(event.widget.curselection()[0])

    @staticmethod
    def _update_listbox(listbox, item_array):
        listbox.delete(0, END)
        for item in item_array:
            listbox.insert(END, item["name"])