├── .gitignore ├── info.png ├── save.png ├── tick.png ├── led_red.png ├── restore.png ├── transfer.png ├── nanoKONTROL1.png ├── nanoKONTROL2.png ├── .vscode └── launch.json ├── test.py ├── README.md ├── ToolTips.py ├── LICENSE └── nanoKONTROL.py /.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__ 2 | -------------------------------------------------------------------------------- /info.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riban-bw/nanoKONTROL-Config/HEAD/info.png -------------------------------------------------------------------------------- /save.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riban-bw/nanoKONTROL-Config/HEAD/save.png -------------------------------------------------------------------------------- /tick.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riban-bw/nanoKONTROL-Config/HEAD/tick.png -------------------------------------------------------------------------------- /led_red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riban-bw/nanoKONTROL-Config/HEAD/led_red.png -------------------------------------------------------------------------------- /restore.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riban-bw/nanoKONTROL-Config/HEAD/restore.png -------------------------------------------------------------------------------- /transfer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riban-bw/nanoKONTROL-Config/HEAD/transfer.png -------------------------------------------------------------------------------- /nanoKONTROL1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riban-bw/nanoKONTROL-Config/HEAD/nanoKONTROL1.png -------------------------------------------------------------------------------- /nanoKONTROL2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riban-bw/nanoKONTROL-Config/HEAD/nanoKONTROL2.png -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "nanoKONTROL", 9 | "type": "python", 10 | "request": "launch", 11 | "program": "nanoKONTROL.py", 12 | "console": "integratedTerminal", 13 | "justMyCode": true 14 | } 15 | ] 16 | } -------------------------------------------------------------------------------- /test.py: -------------------------------------------------------------------------------- 1 | import jack 2 | 3 | client = jack.Client("riban") 4 | midi_in = client.midi_inports.register('in') 5 | midi_out = client.midi_outports.register('out') 6 | ev = [] 7 | 8 | @client.set_process_callback 9 | def process(frames): 10 | global ev 11 | midi_out.clear_buffer() 12 | if ev: 13 | midi_out.write_midi_event(0, ev) 14 | ev = None 15 | 16 | client.activate() 17 | 18 | def select_device(device): 19 | global ev 20 | if device == 1: 21 | ev = [0xF0,0x42,0x50,0x01,0x00,0x00,0x04,0x01,0x00,0x00,0x01,0x00,0x01,0x00,0xF7] 22 | elif device == 2: 23 | ev = [0xF0,0x42,0x50,0x01,0x00,0x00,0x13,0x01,0x00,0x00,0x01,0x00,0x01,0x00,0xF7] 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # nanoKONTROL-Config 2 | Configuration tool for Korg nanoKONTROL written in Python. 3 | 4 | Supports nanoKONTROL1 5 | ![image](https://user-images.githubusercontent.com/3158323/176915252-a606ced7-62b2-42ef-b5da-ecca2c2c3b12.png) 6 | 7 | Supports nanoKONTROL2 8 | ![image](https://user-images.githubusercontent.com/3158323/176915182-ca7fba06-30f5-4f93-bd36-8c0c3331ee31.png) 9 | 10 | This tool provides a graphical user interface allowing configuration of Korg nanoKONTROL1 and nanoKONTROL2 devices. Functionality is broadly similar to Korg's own configuration tool (which I have never seen!). This tool is cross platform and open source. 11 | 12 | MIDI connection is via JACK or ALSA (or both) hence a working JACK service and/or ALSA driver must be running before starting the application. It detects new MIDI ports so the device may be connected after starting the application. 13 | 14 | # Installation 15 | 16 | Clone this repository, e.g. `git clone git@github.com:riban-bw/nanoKONTROL-Config.git` or download and extract the zip. 17 | 18 | ## Install dependancies 19 | 20 | The application is written in Python3 and tested on GNU/Linux. It should run on any platform that can meet the following dependancies: 21 | 22 | - jack (for JACK MIDI interface) 23 | - alsa-midi (for ALSA MIDI interface) 24 | - tkinter 25 | - PIL 26 | - PIL Image 27 | 28 | On a DEBIAN based system the following may install the required Python modules: 29 | 30 | `sudo apt install python3-jack-client python3-tk python3-pil python3-pil.imagetk` 31 | 32 | To install alsa-midi: 33 | 34 | ``` 35 | sudo apt install python3-pip 36 | sudo pip3 install alsa-midi 37 | ``` 38 | 39 | On Windows 10 I found I could run the application after installing Python modules: Pillow and jack-client and installing and starting JACK. (The application crashes when trying to import jack if the JACK service is not running.) 40 | 41 | ``` 42 | python3 -m pip install --upgrade pip 43 | pip3 install Pillow 44 | pip3 install jack-client 45 | ``` 46 | 47 | Jack can be installed from: https://jackaudio.org/downloads. Configuring with "Dummy" audio driver may get it going quickly, e.g. if a supported soundcard is not installed. Adding "-Xwinmme" to the "Advanced" sub-tab of "Settings" tab in QjackCtrl added USB MIDI device to jack graph. I found this added two inputs and four outputs. The second input worked. Not sure about output (poor quality USB MIDI interface available for this test). 48 | 49 | # Usage 50 | 51 | To start the application, run `python3 nanoKONTROL.py` 52 | 53 | After starting the application, select the MIDI ports to which the nanoKONTROL is connected using the drop-down lists near the top, labelled "MIDI input" and "MIDI output". This is likely to be "nanoKONTROL" or "nanoKONTROL2" unless the device is connected to another machine and MIDI routed. The picture of the device should change to to indicate the device detected. 54 | 55 | Click the ![image](https://user-images.githubusercontent.com/3158323/176854990-1b05b67f-5ee8-4033-aa6b-4a9b08500a56.png) download button to retrieve a scene from the device. 56 | 57 | Click on a button, slider or knob on the image and adjust its parameters using the editor on the right hand side. 58 | 59 | Click the ![image](https://user-images.githubusercontent.com/3158323/176855266-c99b60f7-1762-4368-a889-5da36618160e.png) upload button to upload to the nanoKONTROL. 60 | 61 | Click the ![image](https://user-images.githubusercontent.com/3158323/176855361-4ea75e8b-cff0-47c8-bb37-3cf351f40b1d.png) save button to save the scene to the nanoKONTROL's internal persistent memory. 62 | 63 | Click the ![image](https://user-images.githubusercontent.com/3158323/176915479-baf8d65f-2365-489f-a51e-11723717cd29.png) restore button to restore the last downloaded scene. This restores locally in the application. To revert the device to its previous state you must then press the upload button. 64 | 65 | # Credits and Licensing 66 | 67 | Released under the [GPL 3.0 software licensing](https://www.gnu.org/licenses/gpl-3.0.en.html). You may use and distribute this software free of charge. It may not be used within a closed source project. There is no liability protection of its use. 68 | 69 | [Core code](https://github.com/riban-bw/nanoKONTROL-Config) written by [Brian Walton](http://riban.co.uk) 70 | 71 | [Tooltips](https://github.com/PedroHenriques/Tkinter_ToolTips) provided by [Pedro Henriques](http://www.pedrojhenriques.com) 72 | 73 | Icons from [freeicons](https://freeicons.io) 74 | 75 | ![image](https://user-images.githubusercontent.com/3158323/176854990-1b05b67f-5ee8-4033-aa6b-4a9b08500a56.png) ![image](https://user-images.githubusercontent.com/3158323/176855361-4ea75e8b-cff0-47c8-bb37-3cf351f40b1d.png) [ColourCreatype](https://freeicons.io/profile/5790) 76 | 77 | ![image](https://user-images.githubusercontent.com/3158323/176917301-d15296fb-79ab-421e-9d40-bc22f057394b.png) [MD Badsha Meah](https://freeicons.io/profile/3335) 78 | 79 | ![image](https://user-images.githubusercontent.com/3158323/176915479-baf8d65f-2365-489f-a51e-11723717cd29.png) [Anu Rocks](https://freeicons.io/profile/730) 80 | 81 | ![image](https://user-images.githubusercontent.com/3158323/178100762-9c3db76a-64b7-431c-8df6-ba40e2395564.png) [Reda](https://freeicons.io/profile/6156) 82 | 83 | ![led_red](https://user-images.githubusercontent.com/3158323/178287278-5d2e337b-b793-47f9-8261-42bb8ce27e64.png) [freesvg.org](https://freesvg.org) 84 | 85 | -------------------------------------------------------------------------------- /ToolTips.py: -------------------------------------------------------------------------------- 1 | # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 2 | # # 3 | # Python ToolTips for Tkinter v1.0.0 # 4 | # # 5 | # Copyright 2016, PedroHenriques # 6 | # http://www.pedrojhenriques.com # 7 | # https://github.com/PedroHenriques # 8 | # # 9 | # Free to use under the MIT license. # 10 | # http://www.opensource.org/licenses/mit-license.php # 11 | # # 12 | # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 13 | 14 | import math, tkinter as tk, tkinter.ttk as ttk, tkinter.font as tkFont 15 | 16 | class ToolTips : 17 | """This class will display a tooltip around a widget that is being hovered over. 18 | The constructor receives a list of widgets, a list of strings and an optional Tkinter font object. 19 | The lists should match their indexes so that the tooltip string for the first widget is in index zero, and so on. 20 | 21 | There are several class variables that can be used to customize the styling of the tooltips. 22 | """ 23 | 24 | # class variables with the fallback font information, to be used in the tooltip text 25 | tt_fallback_font_family_ = "Helvetica" 26 | tt_fallback_font_size_ = 12 27 | 28 | # class variables with the background and foreground colors 29 | bg_color_ = "#ffffe0" 30 | fg_color_ = "#000000" 31 | 32 | # class variables used to control the vertical space between the tooltip and the event widget 33 | vertical_margin_ = 0 34 | 35 | def __init__(self, widgets, tooltip_text, font=None) : 36 | # check if the 2 lists have the same number of items, and if not raise an exception 37 | if (len(widgets) != len(tooltip_text)) : 38 | raise ValueError("The number of widgets supplied does not match the number of tooltip strings provided.") 39 | 40 | # instance variable pointing to a list of widgets to be managed by this instance 41 | self.widgets = widgets 42 | 43 | # instance variable pointing to a list of strings to be used by the supplied widgets 44 | self.tooltip_text = tooltip_text 45 | 46 | # instance variable to flag whether a font was supplied or not 47 | if (font == None) : 48 | self.font_supplied = False 49 | else : 50 | self.font_supplied = True 51 | 52 | # instance variable pointing to a font object, to be used on the tooltip text 53 | self.font = font 54 | 55 | # instance variable with the font object for the tooltip text 56 | # starts with the fallback font 57 | self.tt_font = tkFont.Font(family=self.tt_fallback_font_family_, size=self.tt_fallback_font_size_) 58 | 59 | # loop through each widget and set the necessary binds 60 | for widget in self.widgets : 61 | # set the binds 62 | self.setWidgetBinds(widget) 63 | 64 | # instance variable where the tooltip widget will be stored 65 | self.tt_widget = None 66 | # instance variable where the tooltip's text will be stored 67 | self.tt_text = "" 68 | 69 | # this method will set the , and binds to the widgets related to this instance 70 | def setWidgetBinds(self, widget) : 71 | widget.bind("", self.showToolTips, add="+") 72 | widget.bind("", self.hideToolTips, add="+") 73 | widget.bind("", self.hideToolTips, add="+") 74 | 75 | # this method will be called when widgets with tooltips are hovered over 76 | def showToolTips(self, event) : 77 | # get a reference to the event widget 78 | widget_ref = event.widget 79 | 80 | # check if we were able to grab a pointer to a widget and that we have that widget in 81 | # widget list supplied to the constructor 82 | if (widget_ref == None or widget_ref not in self.widgets) : 83 | # either we couldn't grab a pointer to the event widget 84 | # or that widget is not in the list of widgets provided 85 | # to the constructor, so bail out 86 | print("The hovered widget is not in the list of widgets provided to this instance.") 87 | return(False) 88 | 89 | # grab this widget's tooltip text from the list 90 | try : 91 | self.tt_text = self.tooltip_text[self.widgets.index(widget_ref)] 92 | except (IndexError, ValueError) : 93 | # either widget_ref couldn't be found in self.widgets 94 | # or the tooltip text couldn't be found for the widget's index, so bail out 95 | print("An error occured while trying to find the tooltip text for the hovered widget.") 96 | return(False) 97 | 98 | # grab the event widget's top master (will be used for both measuring the position of the tooltip 99 | # and will be the direct master for the tooltip) 100 | top_master = widget_ref.winfo_toplevel() 101 | 102 | # grab the event widget's current width and height 103 | widget_width = widget_ref.winfo_width() 104 | widget_height = widget_ref.winfo_height() 105 | 106 | # local variables used to position the tooltip 107 | # starting at the NW corner of the event widget 108 | x = widget_ref.winfo_x() 109 | y = widget_ref.winfo_y() 110 | 111 | # loop through all the masters of the event widget, until we reach top_master 112 | # for each master, add it's x and y relative to it's master 113 | # by the end, we'll have the x and y coords of the event widget in relation to top_master 114 | w_master = top_master.nametowidget(widget_ref.winfo_parent()) # event widget's master 115 | while w_master != top_master : 116 | # update the x and y coords of the 117 | x += w_master.winfo_x() 118 | y += w_master.winfo_y() 119 | 120 | # grab next master in the hierarchy 121 | w_master = top_master.nametowidget(w_master.winfo_parent()) 122 | 123 | # local variables used to store the final position of the tooltip 124 | # we'll start with the values of x and y, but might be changed in the loop below 125 | final_x = x 126 | final_y = y 127 | 128 | # create the tooltip font based on the event widget's font 129 | self.setFont(widget_ref) 130 | 131 | # create the tooltip label widget and initial width + height 132 | self.handleTooltipWidget(top_master) 133 | 134 | # grab top master's width (index 2) and height (index 3), through it's bbox data 135 | tm_bbox = top_master.bbox() 136 | 137 | # local control variables 138 | update_x = False 139 | found_tt_place = False 140 | 141 | # calculate the maximum x coordinate for the tooltip, which is the lowest between 142 | # the window width and the east border of the event widget 143 | # this is relevant, for example, in the case where the event widget is partially outside the window 144 | # (by using a horizontal scrollbar), meaning that the event widget's east border is outisde the window 145 | # and thus we can't anchor the tooltip to it, but rather to the widnow's east border 146 | max_x = min(x + widget_width, tm_bbox[2]) 147 | 148 | # calculate the minimum x coordinate for the tooltip, which starts on the event widget's W border 149 | min_x = x 150 | 151 | while (not found_tt_place and self.tt_font_size > 1) : 152 | # by default we assume we'll find a position for the tooltip on this iteration 153 | found_tt_place = True 154 | 155 | # at this point, the tooltip's NW corner matches the event widget's NW corner 156 | # check if there's enough width in top_master to fit the tooltip in the default horizontal position 157 | # i.e., growing to the right 158 | if (min_x + self.tt_width > tm_bbox[2]) : 159 | # there isn't enough width to fit the tooltip 160 | # check if we can place the tooltip to the left of the event widget 161 | # i.e., make the E border of the tooltip match the E border of the event widget 162 | if (max_x - self.tt_width >= 0) : 163 | # it fits to the left 164 | # make the tooltip's E border match the event widget's E border 165 | final_x = max_x - self.tt_width 166 | else : 167 | # we need to add line breaks to the tooltip's text 168 | # start by checking which side has more width to work with 169 | if (min_x/tm_bbox[2] <= 0.5) : 170 | # the tooltip is in the left half of the top_master, so there is more width to the right of the event widget 171 | # set the tooltip to go as far left as the window's E border 172 | max_x = tm_bbox[2] 173 | else : 174 | # the tooltip is in the right half of the top_master, so there is more width to the left of the event widget 175 | # set the tooltip to go as far right as the window's W border 176 | min_x = 0 177 | # flag as needing to update the tooltip's X position after all the text changes 178 | update_x = True 179 | 180 | # calculate the tooltip's maximum width 181 | tt_max_width = max_x - min_x 182 | 183 | # calculate the len of the tooltip text 184 | tt_text_len = len(self.tt_text) 185 | # calculate the average width of each character, for the font in use by this widget 186 | tt_char_width = self.tt_width / tt_text_len 187 | # calculate the index increment for the loop below, rounded down ==> #characters per line 188 | # NOTE: by using math.ceil(tt_char_width) it greatly reduces the chance of the tooltip overflowing the window, but it also leads to some space not being used by the tooltip (a safety margin). 189 | # use just tt_char_width to maximize space usage...but in some cases it will lead to overflows. 190 | # This is due to the calculations using an average pixels per character, which in variable width fonts is not 100% accurate. In fixed width fonts this should not be an issue. 191 | increment = math.floor(tt_max_width / math.ceil(tt_char_width)) 192 | # first slice will be from index 0 to the 1st \n index 193 | start_index = 0 194 | end_index = increment 195 | # variable with the new tooltip text 196 | new_tt_text = "" 197 | 198 | # loop through the tooltip text and add the \n when needed 199 | while end_index < tt_text_len : 200 | # grab this iteration's slice of the tooltip text 201 | tt_text_slice = self.tt_text[start_index:end_index] 202 | 203 | # check if there are any \n added by the developer in this slice 204 | if ("\n" in tt_text_slice) : 205 | # split the slice into sub slices, based on \n 206 | tt_sub_slices = tt_text_slice.split("\n") 207 | 208 | # if there are more than 1 sub slices and the last one is not empty 209 | # i.e., the slice doesn't end with a \n, then don't run the last sub slice 210 | # now, since it doesn't end with a manual \n and one will be added if we run it now 211 | if (len(tt_sub_slices) > 1 and tt_sub_slices[-1] != "") : 212 | tt_sub_slices = tt_sub_slices[:-1] 213 | 214 | # reset the end index value, since we might not reach the end of this slice 215 | end_index = start_index 216 | 217 | # loop through each sub slice and if it doesn't exceed the max character number 218 | # for the available width, add it to the tooltip text as is 219 | # ends when all sub slices are dealt with OR we find one that overflows the available width 220 | # in which case we'll process it on the next iteration of the parent loop 221 | for tt_sub_slice in tt_sub_slices : 222 | # check if it overflows and if it does BREAK 223 | if (len(tt_sub_slice) > increment) : 224 | break 225 | 226 | # at this point this sub slice doesn't overflow 227 | # add it to the tooltip text, plus the \n 228 | new_tt_text += tt_sub_slice + "\n" 229 | 230 | # advance the end index value by the sub slice's len + 1 for the \n 231 | end_index += len(tt_sub_slice) + 1 232 | else : 233 | # there are no manual \n to deal with in this slice 234 | new_tt_text += tt_text_slice 235 | 236 | # if the next character in the source string is a \n, then don't add this iteration's 237 | # automatic \n, else add it. This avoids ending up with 2 \n in a row, when only 1 was intended 238 | if ("\n" not in self.tt_text[end_index:end_index+1]) : 239 | # add this iteration's \n 240 | new_tt_text += "\n" 241 | 242 | # advance to the index values 243 | start_index = end_index 244 | end_index += increment 245 | 246 | # if there is any remainder text, add it to the tooltip text 247 | # else, the tooltip text will end on a \n which needs to be removed 248 | if (start_index != tt_text_len - 1) : 249 | # the last index added to the tooltip's text was not the final index, so 250 | # add the final slice of the tooltip text 251 | new_tt_text += self.tt_text[start_index:tt_text_len] 252 | else : 253 | # there is no more text to add, so remove the ending \n 254 | new_tt_text = new_tt_text[:-1] 255 | 256 | # update the label's text 257 | self.tt_widget.configure(text=new_tt_text) 258 | # update the tooltip's width and height 259 | self.tt_width = self.tt_widget.winfo_reqwidth() 260 | self.tt_height = self.tt_widget.winfo_reqheight() 261 | else : 262 | final_x = min_x 263 | 264 | # at this point if the tooltip has more than 1 line, it is using as much width as possible, 265 | # taking into account the safety margin for variable width fonts 266 | 267 | # check if there's enough height in top_master to fit the tooltip in the default vertical position 268 | # i.e., below the event widget 269 | if (y + widget_height + self.vertical_margin_ + self.tt_height > tm_bbox[3]) : 270 | # there isn't enough height to fit the tooltip 271 | # check if we can place the tooltip to the top of the event widget 272 | if (y - self.tt_height - self.vertical_margin_ >= 0) : 273 | # it fits to the top 274 | # move the tooltip up 275 | final_y = y - self.tt_height - self.vertical_margin_ 276 | else : 277 | # it doesn't fit below or above the event widget 278 | 279 | # start by removing the default behaviour of having the tooltip anchored to the event widget's 280 | # east border, making the tooltip go from the window's W to the E border 281 | # if that isn't enough start reducing the font size used by the tooltip text by 1 point per loop iteration 282 | # the loop will end when we reach a situation where the tooltip fits on the screen OR the font 283 | # size goes all the way down to 1 point, at which point we conclude that there is no way to 284 | # fit the tooltip on the screen given the text in it, the event widget's position on the window 285 | # and the window's size 286 | 287 | # if we're already using the entire window's width, then work the font size 288 | if (max_x == tm_bbox[2] and min_x == 0) : 289 | # update the tooltip's font to reduce the font size by 1 point 290 | self.tt_font_size -= 1 291 | self.tt_font.configure(size = max(self.tt_font_size, 1)) 292 | 293 | # recalculate the requested width and height with the new font size 294 | self.handleTooltipWidget(top_master) 295 | else : 296 | # update the max_x to go all the way to the window's E border 297 | # instead of the event widget's E border 298 | max_x = tm_bbox[2] 299 | min_x = 0 300 | 301 | # signal the loop that we didn't find a position for the tooltip yet 302 | found_tt_place = False 303 | else : 304 | # there is enough height below the event widget to fit the tooltip 305 | # so move the tooltip down 306 | final_y = y + widget_height + self.vertical_margin_ 307 | 308 | # if the tooltip text was changed such that the width changed, then recalculate the 309 | # tooltip's X position 310 | if (update_x) : 311 | # move the tooltip to have it's E border matching the event widget's E border 312 | # or the window's E border, depending on the case 313 | final_x = max_x - self.tt_width 314 | 315 | # draw the tooltip 316 | self.tt_widget.place(relx=final_x/tm_bbox[2], rely=final_y/tm_bbox[3]) 317 | 318 | # this method will be called when widgets with tooltips sto being hovered over 319 | # or "entered" by any other means (ex: tab selecting) 320 | def hideToolTips(self, event) : 321 | # if there are no active tooltips bail out 322 | if (self.tt_widget == None) : 323 | return 324 | 325 | # remove the tooltip from the screen and any other tkinter internal references 326 | self.tt_widget.destroy() 327 | 328 | # free the variables 329 | self.tt_widget = None 330 | self.tt_text = "" 331 | 332 | # this method will create the tooltip widget, if one doesn't exist already, and will calculate 333 | # the required width and height of the tooltip text without any line breaks, which is used to later calculate 334 | # the average character width for the given font and the given tooltip text 335 | def handleTooltipWidget(self, top_master) : 336 | # if the tooltip widget doesn't exist create it, otherwise update the dimensions 337 | if (self.tt_widget == None) : 338 | # create the tooltip label widget 339 | # NOTE: we start with an altered version of the intended text, because of the need to calculate the required width 340 | # of the tooltip widget without any line breaks. If they are left in that calculation it will skew the 341 | # the calculation (later below) of the average #characters in each line that fit the window size. 342 | # The correct text will be added shortly below. 343 | self.tt_widget = ttk.Label(top_master, text=self.tt_text.replace("\n", " "), background=self.bg_color_, foreground=self.fg_color_, font=self.tt_font) 344 | else : 345 | # update the tooltip's text to recalculate the requested dimensions below 346 | self.tt_widget.configure(text=self.tt_text.replace("\n", " ")) 347 | 348 | # move the tooltip from being on top of the event widget to a reasonable relative location 349 | # by default the tooltip's NW corner will be close to the event widget's SW corner 350 | # however this might need to be adjusted, if it would make the tooltip overflow the program's window 351 | # calculate the width and height of the tooltip (using the required dimension since it hasn't been drawn to screen yet, meaning there are no actual dimensions yet) 352 | self.tt_width = self.tt_widget.winfo_reqwidth() 353 | self.tt_height = self.tt_widget.winfo_reqheight() 354 | 355 | # now that we have calculated the initial required dimensions, we can update the widget's text to the intended one 356 | self.tt_widget.configure(text=self.tt_text) 357 | 358 | # this method creates the font based on the event widget's font family and size 359 | def setFont(self, event_widget) : 360 | # grab the event widget's font info 361 | try : 362 | if (self.font_supplied) : 363 | # a font was supplied to the constructor, so create a copy of it's current values 364 | self.tt_font["family"] = self.font["family"] 365 | self.tt_font["size"] = self.font["size"] 366 | else : 367 | # a font wasn't supplied to the constructor, try getting the event widget's font 368 | ew_font_info = event_widget["font"].actual() 369 | self.tt_font["family"] = ew_font_info["family"] 370 | self.tt_font["size"] = ew_font_info["size"] 371 | except Exception : 372 | # we couldn't create a tkFont object 373 | # most likely the event widget is using a custom tkFont object which can't be accessed and edited from here 374 | # or the event widget doesn't have a "font" attribute 375 | # use the fallback font 376 | self.tt_font["family"] = self.tt_fallback_font_family_ 377 | self.tt_font["size"] = self.tt_fallback_font_size_ 378 | 379 | # grab the tt_font's font size 380 | self.tt_font_size = self.tt_font["size"] -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /nanoKONTROL.py: -------------------------------------------------------------------------------- 1 | # Configuration editor for Korg nanoKONTROL 2 | # 3 | # Copyright: riban ltd (riban.co.uk) 4 | # Licencse: GPL V3.0 5 | # Source: https://github.com/riban-bw/nanoKONTROL-Config 6 | # 7 | # Dependencies: tkinter, jack / alsa, PIL, ImageTk 8 | 9 | import struct 10 | from tkinter import messagebox 11 | try: 12 | import jack 13 | except: 14 | pass 15 | try: 16 | import alsa_midi 17 | except: 18 | pass 19 | import tkinter as tk 20 | from tkinter import ttk 21 | import logging 22 | from PIL import ImageTk, Image 23 | from threading import Thread 24 | import ToolTips 25 | from datetime import datetime 26 | 27 | ev = None # Used to pass MIDI messages for JACK to transmit 28 | echo_id = 0x00 # Used to identify own sysex messages 29 | 30 | credits = [ 31 | 'Code:', 32 | 'riban.co.uk', 33 | 'Tooltips', 34 | 'pedrojhenriques.com', 35 | '', 36 | 'Icons:', 37 | 'https://freeicons.io', 38 | 'profile/5790', # Transfer, Save 39 | 'profile/3335', # Info 40 | 'profile/730', # Restore 41 | 'profile/6156', # Selected 42 | 'https://freesvg.org' # LED 43 | ] 44 | 45 | mmc_commands = [ 46 | 'Stop', 47 | 'Play', 48 | 'Deferred Play', 49 | 'Fast Forward', 50 | 'Rewind', 51 | 'Record Strobe', 52 | 'Record Exit', 53 | 'Record Pause', 54 | 'Pause', 55 | 'Eject', 56 | 'Chase', 57 | 'Command Error Reset', 58 | 'MMC Reset' 59 | ] 60 | 61 | control_modes = [ 62 | 'MIDI CC', 63 | 'Cubase', 64 | 'Digital Performer', 65 | 'Ableton Live', 66 | 'ProTools', 67 | 'SONAR' 68 | ] 69 | 70 | assign_options = [ 71 | 'Disabled', 72 | 'CC', 'Note' 73 | ] 74 | 75 | behaviour_options = [ 76 | 'Momentary', 77 | 'Toggle' 78 | ] 79 | 80 | control_map = { 81 | 'nanoKONTROL1': { 82 | 'param_map': { 83 | 'assign':[0, 2], 84 | 'behaviour': [6, 1], 85 | 'cmd': [1, 127], 86 | 'min': [2, 127], 87 | 'max': [3, 127], 88 | 'attack': [4, 127], 89 | 'release': [5, 127], 90 | 'mmc_cmd': [2, 12], 91 | 'mmc_id': [3, 127], 92 | 'transport_behaviour': [4, 1] 93 | }, 94 | 'group_map': { 95 | 'channel': 0, 96 | 'slider': 1, 97 | 'knob': 5, 98 | 'button_a': 9, 99 | 'button_b': 16, 100 | 'rew': 1, 101 | 'play': 6, 102 | 'ff': 11, 103 | 'cycle': 16, 104 | 'stop': 21, 105 | 'rec': 26, 106 | }, 107 | 'num_group_ctrls': 4, 108 | 'groups': [16, 39, 62, 85, 108, 131, 154, 177, 200], 109 | 'transport': 224, 110 | 'group_coords': [(0.20,0.28), (0.29,0.36), (0.38,0.45), (0.47,0.54), (0.55,0.62), (0.64,0.71), (0.72,0.79), (0.81,0.88), (0.89,0.97), (0.01,0.19)], 111 | 'ctrl_coords': { 112 | 'knob': [0.03, 0.09, 0.08, 0.2], 113 | 'slider': [0.04, 0.47, 0.07, 0.75], 114 | 'button_a': [0.00, 0.44, 0.03, 0.54], 115 | 'button_b': [0.00, 0.71, 0.03, 0.80], 116 | 'rew': [0.01, 0.52, 0.06, 0.62], 117 | 'play': [0.07, 0.52, 0.12, 0.62], 118 | 'ff': [0.12, 0.52, 0.17, 0.62], 119 | 'cycle': [0.01, 0.66, 0.06, 0.74], 120 | 'stop': [0.07, 0.66, 0.12, 0.74], 121 | 'rec': [0.12, 0.66, 0.17, 0.74], 122 | 'scene': [0.01, 0.79, 0.05, 0.87] 123 | } 124 | }, 125 | 'nanoKONTROL2': { 126 | 'param_map': { 127 | 'assign':[0, 2], 128 | 'behaviour': [1, 1], 129 | 'cmd': [2, 127], 130 | 'min': [3, 127], 131 | 'max': [4, 127] 132 | }, 133 | 'group_map': { 134 | 'channel': 0, 135 | 'slider': 1, 136 | 'knob': 7, 137 | 'button_a': 13, 138 | 'solo': 13, 139 | 'button_b': 19, 140 | 'mute': 19, 141 | 'button_c': 25, 142 | 'prime': 25, 143 | 'transport 1': 1, 144 | 'prev_track': 1, 145 | 'transport 2': 7, 146 | 'next_track': 7, 147 | 'transport 3': 13, 148 | 'cycle': 13, 149 | 'transport 4': 19, 150 | 'set_marker': 19, 151 | 'transport 5': 25, 152 | 'prev_marker': 25, 153 | 'transport 6': 31, 154 | 'next_marker': 31, 155 | 'transport 7': 37, 156 | 'rew': 37, 157 | 'transport 8': 43, 158 | 'ff': 43, 159 | 'transport 9': 49, 160 | 'stop': 49, 161 | 'play': 55, 162 | 'rec': 61 163 | }, 164 | 'led_map': { 165 | 'solo': 0x20, 166 | 'mute': 0x30, 167 | 'prime': 0x40, 168 | 'play': 0x29, 169 | 'stop': 0x2A, 170 | 'rew': 0x2B, 171 | 'ff': 0x2C, 172 | 'rec': 0x2D, 173 | 'cycle': 0x2E 174 | }, 175 | 'num_group_ctrls': 5, 176 | 'groups': [3, 34, 65, 96, 127, 158, 189, 220], 177 | 'transport': 251, 178 | 'custom daw assign': 318, 179 | 'group_coords': [(0.30,0.37), (0.39,0.45), (0.47,0.54), (0.56,0.63), (0.64,0.71), (0.73,0.80), (0.81,0.88), (0.90,0.96), (0.04, 0.27)], 180 | 'ctrl_coords': { 181 | 'knob': [0.03, 0.12, 0.07, 0.26], 182 | 'slider': [0.04, 0.44, 0.06, 0.74], 183 | 'solo': [0.00, 0.40, 0.03, 0.48], 184 | 'mute': [0.00, 0.59, 0.03, 0.67], 185 | 'prime': [0.00, 0.78, 0.03, 0.86], 186 | 'prev_track': [0.00, 0.45, 0.03, 0.50], 187 | 'next_track': [0.05, 0.45, 0.08, 0.50], 188 | 'cycle': [0.00, 0.60, 0.03, 0.66], 189 | 'set_marker': [0.10, 0.60, 0.13, 0.66], 190 | 'prev_marker': [0.15, 0.60, 0.18, 0.66], 191 | 'next_marker': [0.20, 0.60, 0.23, 0.66], 192 | 'rew': [0.00, 0.76, 0.03, 0.88], 193 | 'ff': [0.05, 0.76, 0.08, 0.88], 194 | 'stop': [0.10, 0.76, 0.13, 0.88], 195 | 'play': [0.15, 0.76, 0.18, 0.88], 196 | 'rec': [0.20, 0.76, 0.23, 0.88], 197 | } 198 | } 199 | } 200 | 201 | ## Scene class encapsulates a nanoKONTROL scene data structure ## 202 | class scene: 203 | def __init__(self): 204 | self.global_midi_chan = 0 # Global MIDI channel (0 based) 205 | self.device_types = { 206 | 'nanoKONTROL1': { 207 | 'sysex_len': 293, 208 | 'sysex_id': (0x00, 0x01, 0x04, 0x00) 209 | }, 210 | 'nanoKONTROL2': { 211 | 'sysex_len': 388, 212 | 'sysex_id': (0x00, 0x01, 0x13, 0x00) 213 | } 214 | } 215 | self.device_type = None 216 | self.set_device_type('nanoKONTROL2') 217 | 218 | 219 | # Get the (4 byte) sysex segment defining the device type 220 | # returns: Device ID as 4 byte list 221 | def get_sysex_id(self): 222 | return self.device_types[self.device_type]['sysex_id'] 223 | 224 | 225 | # Set the device type 226 | # type: Device type ['nanoKONTROL1', 'nanoKONTROL2'] 227 | def set_device_type(self, type): 228 | if type == self.device_type or type not in self.device_types: 229 | return 230 | self.device_type = type 231 | self.reset_data() 232 | 233 | 234 | # Reset scene data to default values 235 | def reset_data(self): 236 | transport_offset = control_map[self.device_type]['transport'] 237 | if self.device_type == 'nanoKONTROL1': 238 | self.data = [0] * 256 239 | self.set_scene_name('') 240 | mmc_map = [5, 2, 0, 4, 3, 1] 241 | for i, control in enumerate(('rec', 'play', 'stop', 'rew', 'ff', 'cycle')): 242 | transport_offset = control_map[self.device_type]['transport'] 243 | self.set_control_parameter(transport_offset, control, 'assign', 1) 244 | self.set_control_parameter(transport_offset, control, 'cmd', 44 + i) 245 | self.set_control_parameter(transport_offset, control, 'mmc_cmd', mmc_map[i]) 246 | self.set_control_parameter(transport_offset, control, 'mmc_id', 127) 247 | self.set_control_parameter(transport_offset, control, 'transport_behaviour', 0) 248 | 249 | elif self.device_type == 'nanoKONTROL2': 250 | self.data = [0] * 339 251 | self.set_control_mode(0) 252 | self.set_led_mode(0) 253 | for i, control in enumerate(('play', 'stop', 'rew', 'ff', 'rec', 'cycle', 'prev_track', 'next_track', 'set_marker', 'prev_marker', 'next_marker')): 254 | transport_offset = control_map[self.device_type]['transport'] 255 | self.set_control_parameter(transport_offset, control, 'assign', 1) 256 | if i < 6: 257 | self.set_control_parameter(transport_offset, control, 'cmd', 0x29 + i) 258 | else: 259 | self.set_control_parameter(transport_offset, control, 'cmd', 0x34 + i) 260 | self.set_control_parameter(transport_offset, control, 'min', 0) 261 | self.set_control_parameter(transport_offset, control, 'max', 127) 262 | self.set_control_parameter(transport_offset, control, 'behaviour', 0) 263 | for i in range(318, 323): 264 | self.data[i] = 0 #TODO: What are default custom daw values? 265 | 266 | self.set_global_channel(0) 267 | self.set_group_channel(transport_offset, 16) 268 | 269 | for group, group_offset in enumerate(control_map[self.device_type]['groups']): 270 | self.set_group_channel(group_offset, 16) 271 | if self.device_type == 'nanoKONTROL1': 272 | for i, control in enumerate(('slider', 'knob', 'button_a', 'button_b')): 273 | self.set_control_parameter(group_offset, control, 'assign', 1) 274 | self.set_control_parameter(group_offset, control, 'cmd', 0x10 * i + group) #This differs from Korg's own defaults but that doesn't matter 275 | self.set_control_parameter(group_offset, control, 'min', 0) 276 | self.set_control_parameter(group_offset, control, 'max', 127) 277 | for i, control in enumerate(('button_a', 'button_b')): 278 | self.set_control_parameter(group_offset, control, 'behaviour', 0) 279 | self.set_control_parameter(group_offset, control, 'attack', 0) 280 | self.set_control_parameter(group_offset, control, 'release', 0) 281 | elif self.device_type == 'nanoKONTROL2': 282 | for i, control in enumerate(('slider', 'knob', 'solo', 'mute', 'prime')): 283 | self.set_control_parameter(group_offset, control, 'assign', 1) 284 | self.set_control_parameter(group_offset, control, 'cmd', 0x10 * i + group) 285 | self.set_control_parameter(group_offset, control, 'min', 0) 286 | self.set_control_parameter(group_offset, control, 'max', 127) 287 | self.set_control_parameter(group_offset, control, 'behaviour', 0) 288 | 289 | 290 | # Get data (payload) in MIDI sysex format 291 | # Convert Korg 8-bit data to 7-bit MIDI data 292 | # nanoKONTROL1 has 256 bytes of data which gives 36 blocks of 7 bytes plus 4 extra bytes 293 | # nanoKONTROL2 has 339 bytes of data which gives 48 blocks of 7 bytes plus 3 extra bytes 294 | # Each block is converted to 8 MIDI bytes (first byte represents most significant bit of subsequent 7 bytes) 295 | # Remaining 3 or 4 bytes are sent similarly but not padded to full block of 8, i.e. nanoKONTROL1 MIDI has 36 * 8 + 1 + 4 bytes in payload 296 | # data: 8-bit Korg data 297 | # returns: List containing sysex data 298 | def get_midi_data(self): 299 | sysex = () 300 | for offset in range(0, len(self.data), 7): 301 | block = self.data[offset:offset+7] 302 | b0 = 0 303 | for b in range(len(block)): 304 | b0 |= ((block[b] & 0x80) >> (7 - b)) 305 | sysex += (b0,) 306 | for word in block: 307 | sysex += (word & 0x7F,) 308 | return sysex 309 | 310 | 311 | # Set data from MIDI sysex format data 312 | # Convert raw 7-bit MIDI data to Korg 8-bit data 313 | # Raw data: 1st byte holds bit-7 of subsequent bytes, next 7 bytes hold bits 0..7 of each byte 314 | # data: raw 7-bit MIDI data (multiple 8 x 7-bit blocks of data) 315 | def set_data(self, data): 316 | if len(data) != self.device_types[self.device_type]['sysex_len']: 317 | logging.warning('Received wrong length data dump') 318 | return 319 | i = 0 320 | for offset in range(0, len(data), 8): 321 | block = data[offset:offset+8] 322 | for word in range(1, len(block)): 323 | self.data[i + word - 1] = (block[word] | (block[0] & 1 << (word - 1))) 324 | i += 7 325 | 326 | 327 | # Get scene name 328 | # returns: Scene name 329 | # nanoKONTROL1 only 330 | def get_scene_name(self): 331 | name = '' 332 | if self.device_type == 'nanoKONTROL1': 333 | for c in self.data[:12]: 334 | name += chr(c) 335 | return name 336 | 337 | 338 | # Set scene name 339 | # name: Scene name (12 characters) 340 | # nanoKONTROL1 only 341 | def set_scene_name(self, name): 342 | if self.device_type == 'nanoKONTROL1': 343 | for i in range(12): 344 | if i < len(name): 345 | self.data[i] = ord(name[i]) 346 | else: 347 | self.data[i] = ord(' ') 348 | 349 | 350 | # Get global MIDI channel 351 | # returns: MIDI channel 352 | def get_global_channel(self): 353 | if self.device_type == 'nanoKONTROL1': 354 | return self.data[12] 355 | elif self.device_type == 'nanoKONTROL2': 356 | return self.data[0] 357 | return 0 358 | 359 | 360 | # Set global MIDI channel 361 | # chan: MIDI channel 362 | def set_global_channel(self, chan): 363 | if chan < 16: 364 | if self.device_type == 'nanoKONTROL1': 365 | self.data[12] = chan 366 | elif self.device_type == 'nanoKONTROL2': 367 | self.data[0] = chan 368 | 369 | 370 | # Get control mode 371 | # returns: Control mode [0:CC, 1:Cubase, 2:DP, 3:Live, 4:ProTools, 5:SONAR] 372 | # nanoKONTROL2 only 373 | def get_control_mode(self): 374 | if self.device_type == 'nanoKONTROL2': 375 | return self.data[1] 376 | return 0 377 | 378 | 379 | # Set control mode 380 | # mode: Control mode [0:CC, 1:Cubase, 2:DP, 3:Live, 4:ProTools, 5:SONAR] 381 | # nanoKONTROL2 only 382 | def set_control_mode(self, mode): 383 | if self.device_type == 'nanoKONTROL2' and mode < 6: 384 | self.data[1] = mode 385 | return 0 386 | 387 | 388 | # Get LED mode 389 | # returns: LED mode [0:Internal, 1:External] 390 | # nanoKONTROL2 only 391 | def get_led_mode(self): 392 | if self.device_type == 'nanoKONTROL2': 393 | return self.data[2] 394 | return 0 395 | 396 | 397 | # Set LED mode 398 | # mode: LED mode [0:Internal, 1:External] 399 | # nanoKONTROL2 only 400 | def set_led_mode(self, mode): 401 | if self.device_type == 'nanoKONTROL2' and mode <= 1: 402 | self.data[2] = mode 403 | return 0 404 | 405 | 406 | # Get group MIDI channel 407 | # group_offset: Offset of the group within dataset 408 | # returns: MIDI channel 409 | def get_group_channel(self, group_offset): 410 | return self.data[group_offset] 411 | 412 | 413 | # Set group MIDI channel 414 | # group_offset: Offset of the group within dataset 415 | # chan: MIDI channel 416 | def set_group_channel(self, group_offset, chan): 417 | self.data[group_offset] = chan 418 | 419 | 420 | # Get control parameter 421 | # group_offset: Offset of group / transport 422 | # control: Control name, e.g. 'button_a' 423 | # param: Control parameter ['assign', 'behaviour', 'transport_behaviour', 'cmd', 'min', 'max'] 424 | # returns: Parameter value or 0 if parameter not available 425 | def get_control_parameter(self, group_offset, control, param): 426 | try: 427 | control_offset = control_map[self.device_type]['group_map'][control] 428 | param_offset = control_map[self.device_type]['param_map'][param][0] 429 | return self.data[group_offset + control_offset + param_offset] 430 | except: 431 | return 0 432 | 433 | 434 | # Set control parameter 435 | # group_offset: Offset of group / transport 436 | # control: Control name, e.g. 'button_a' 437 | # param: Control parameter ['assign', 'behaviour', 'transport_behaviour', 'cmd', 'min', 'max'] 438 | # value: Parameter value 439 | def set_control_parameter(self, group_offset, control, param, value): 440 | try: 441 | control_offset = control_map[self.device_type]['group_map'][control] 442 | param_offset = control_map[self.device_type]['param_map'][param][0] 443 | param_max = control_map[self.device_type]['param_map'][param][1] 444 | if value > param_max: 445 | return False 446 | self.data[group_offset + control_offset + param_offset] = value 447 | except: 448 | return False 449 | return True 450 | 451 | 452 | # Send a MIDI message to all connected devices 453 | # msg: Raw MIDI data as list of integers 454 | def send_midi(msg): 455 | global ev 456 | try: 457 | alsa_client.event_output(alsa_midi.MidiBytesEvent(bytes(msg)), port=alsa_midi_out) 458 | alsa_client.drain_output() 459 | except: 460 | pass # ALSA failed but let's try JACk as well 461 | ev = msg # Very simple slow (single message) JACK MIDI send mechanism 462 | 463 | ## Device specific MIDI messages - send from application to device ## 464 | 465 | # Send Inquiry Message Request 466 | def send_inquiry(): 467 | send_midi([0xF0, 0x7E, 0x7F, 0x06, 0x01, 0xF7]) 468 | 469 | 470 | # Send device search request 471 | def send_device_search(): 472 | send_midi([0xF0, 0x42, 0x50, 0x00, echo_id, 0xF7]) 473 | 474 | 475 | # Send a command list message 476 | # data: List containing the message payload 477 | def send_command_list(data): 478 | try: 479 | send_midi((0xF0, 0x42, 0x40 | scene_data.global_midi_chan) + scene_data.get_sysex_id() + data + (0xF7,)) 480 | except Exception as e: 481 | logging.warning(e) 482 | 483 | 484 | # Request current scene data dump from device 485 | def send_dump_request(): 486 | send_command_list((0x1F, 0x10, 0x00)) 487 | 488 | 489 | # Request current temporary scene data be saved on device 490 | def send_scene_write_request(): 491 | if scene_data.device_type == 'nanoKONTROL1': 492 | send_command_list((0x1F, 0x11, current_scene)) 493 | else: 494 | send_command_list((0x1F, 0x11, 0)) 495 | 496 | 497 | # Request native mode in (nanoKONTROL2) 498 | #TODO: Implement native mode in on nanoKONTROL2 499 | def send_native_mode(): 500 | send_command_list((0x00, 0x00, 0x00)) 501 | 502 | 503 | # Request native mode out (nanoKONTROL2) 504 | #TODO: Implement native mode out on nanoKONTROL2 505 | def send_native_mode(): 506 | send_command_list((0x00, 0x00, 0x01)) 507 | 508 | 509 | # Request mode (nanoKONTROL2) 510 | #TODO: Implement request mode on nanoKONTROL2 511 | def send_query_mode(): 512 | send_command_list((0x1F, 0x12, 0x00)) 513 | 514 | 515 | # Request a scene change (nanoKONTROL1) 516 | # scene: Requested scene [0..3] 517 | def send_scene_change_request(scene): 518 | if(scene >= 0 and scene <= 3): 519 | send_command_list((0x1F, 0x14, scene, 0xF7)) 520 | 521 | 522 | # Upload a scene to device 'current scene' 523 | # Must write scene to save to persistent memory 524 | def send_scene_data(): 525 | if scene_data.device_type == 'nanoKONTROL1': 526 | send_command_list((0x7F, 0x7F, 0x02, 0x02, 0x26, 0x40) + scene_data.get_midi_data()) 527 | elif scene_data.device_type == 'nanoKONTROL2': 528 | send_command_list((0x7F, 0x7F, 0x02, 0x03, 0x05, 0x40) + scene_data.get_midi_data()) 529 | 530 | 531 | # Send port detect request 532 | def send_port_detect(): 533 | send_command_list((0x1E, 0x00, echo_id)) 534 | 535 | 536 | ## UI Functions ## 537 | 538 | # Add and remove ALSA ports to global list of source ports 539 | def populate_alsa_source(event=None): 540 | global source_ports 541 | ports = alsa_client.list_ports(input=True, type=alsa_midi.PortType.ANY) 542 | temp_ports = {} 543 | for port in source_ports: 544 | if source_ports[port][0] == 'jack': 545 | temp_ports[port] = source_ports[port] 546 | source_ports = temp_ports 547 | for port in ports: 548 | name = port.client_name + ':' + port.name 549 | source_ports[name] = ['alsa', port] 550 | update_ports() 551 | 552 | 553 | # Add and remove ALSA ports to global list of destination ports 554 | def populate_alsa_dest(event=None): 555 | global destination_ports 556 | ports = alsa_client.list_ports(output=True, type=alsa_midi.PortType.ANY) 557 | temp_ports = {} 558 | for port in destination_ports: 559 | if destination_ports[port][0] == 'jack': 560 | temp_ports[port] = destination_ports[port] 561 | destination_ports = temp_ports 562 | for port in ports: 563 | name = port.client_name + ':' + port.name 564 | destination_ports[name] = ['alsa', port] 565 | update_ports() 566 | 567 | 568 | # Update drop-down lists of MIDI ports 569 | def update_ports(): 570 | values = [] 571 | for port in source_ports: 572 | values.append(port) 573 | cmb_midi_input['values'] = values 574 | values = [] 575 | for port in destination_ports: 576 | values.append(port) 577 | cmb_midi_output['values'] = values 578 | auto_connect() 579 | 580 | 581 | # Handle selection from MIDI source drop-down list 582 | def source_changed(event=None): 583 | name = midi_source_port.get() 584 | if name not in source_ports: 585 | return 586 | try: 587 | jack_midi_in.disconnect() 588 | except Exception as e: 589 | pass 590 | try: 591 | for port in ports: 592 | ports = alsa_client.list_ports(input=True, type=alsa_midi.PortType.ANY) 593 | try: 594 | alsa_midi_in.disconnect_from(port) 595 | except Exception as e: 596 | pass # Ignore any unconnected ports 597 | except: 598 | pass # ALSA may not be enabled 599 | 600 | try: 601 | if source_ports[name][0] == 'jack': 602 | jack_midi_in.connect(source_ports[name][1]) 603 | elif source_ports[name][0] == 'alsa': 604 | alsa_midi_in.connect_from(source_ports[name][1]) 605 | except Exception as e: 606 | pass 607 | send_device_search() 608 | 609 | 610 | # Handle selection from MIDI destination drop-down list 611 | def destination_changed(event=None): 612 | name = midi_dest_port.get() 613 | if name not in destination_ports: 614 | return 615 | try: 616 | jack_midi_out.disconnect() 617 | except Exception as e: 618 | pass 619 | try: 620 | ports = alsa_client.list_ports(output=True, type=alsa_midi.PortType.ANY) 621 | for port in ports: 622 | try: 623 | alsa_midi_out.disconnect_to(port) 624 | except Exception as e: 625 | pass # Ignore any unconnected ports 626 | except: 627 | pass # ALSA may not be enabled 628 | 629 | try: 630 | if destination_ports[name][0] == 'jack': 631 | jack_midi_out.connect(destination_ports[name][1]) 632 | elif destination_ports[name][0] == 'alsa': 633 | alsa_midi_out.connect_to(destination_ports[name][1]) 634 | except Exception as e: 635 | pass 636 | send_device_search() 637 | 638 | 639 | # Populate the control editor and connect to a control to edit 640 | # ctrl: Name of the control to edit (default: Repopulate with current selection) 641 | # group: Control group or None (default) for transport controls 642 | def populate_editor(ctrl=None, group=None): 643 | global editor_midi_channel 644 | global editor_midi_channel_is_global 645 | global editor_group_offset 646 | global editor_assign 647 | global editor_behaviour 648 | global editor_cmd 649 | global editor_min 650 | global editor_max 651 | global editor_attack 652 | global editor_release 653 | global editor_ctrl 654 | global editor_mmc_cmd 655 | global editor_mmc_id 656 | global editor_group 657 | 658 | if ctrl is not None: 659 | editor_ctrl = ctrl 660 | editor_group = group 661 | if editor_ctrl is None or editor_ctrl not in control_map[scene_data.device_type]['ctrl_coords']: 662 | # Must be first time so select first knob 663 | editor_ctrl = 'knob' 664 | editor_group = 0 665 | is_button = editor_ctrl not in ('knob', 'slider') 666 | 667 | if editor_group is None: 668 | editor_group_offset = control_map[scene_data.device_type]['transport'] 669 | editor_title.set('{}'.format(editor_ctrl.replace('_',' ').upper())) 670 | elif editor_group < len(control_map[scene_data.device_type]['groups']): 671 | editor_group_offset = control_map[scene_data.device_type]['groups'][editor_group] 672 | editor_title.set('{} {}'.format(editor_ctrl.replace('_',' ').upper(), editor_group + 1)) 673 | 674 | editor_assign.set(scene_data.get_control_parameter(editor_group_offset, editor_ctrl, 'assign')) 675 | editor_cmd.set(scene_data.get_control_parameter(editor_group_offset, editor_ctrl, 'cmd')) 676 | editor_note.set(notes[scene_data.get_control_parameter(editor_group_offset, editor_ctrl, 'cmd')]) 677 | editor_min.set(scene_data.get_control_parameter(editor_group_offset, editor_ctrl, 'min')) 678 | editor_max.set(scene_data.get_control_parameter(editor_group_offset, editor_ctrl, 'max')) 679 | editor_attack.set(scene_data.get_control_parameter(editor_group_offset, editor_ctrl, 'attack')) 680 | editor_release.set(scene_data.get_control_parameter(editor_group_offset, editor_ctrl, 'release')) 681 | mmc_cmd_index = scene_data.get_control_parameter(editor_group_offset, editor_ctrl, 'mmc_cmd') 682 | try: 683 | mmc_cmd = mmc_commands[mmc_cmd_index] 684 | editor_mmc_cmd.set(mmc_cmd) 685 | editor_mmc_id.set(scene_data.get_control_parameter(editor_group_offset, editor_ctrl, 'mmc_id')) 686 | except: 687 | logging.warning("Invalid MMC parameter") 688 | editor_global_midi_channel.set(scene_data.get_global_channel() + 1) 689 | editor_scene_name.set(scene_data.get_scene_name()) 690 | 691 | if is_button: 692 | rb_editor_note['state'] = tk.NORMAL 693 | if scene_data.device_type == 'nanoKONTROL1' and editor_group is None: 694 | editor_behaviour.set(scene_data.get_control_parameter(editor_group_offset, editor_ctrl, 'transport_behaviour')) 695 | rb_editor_note['text'] = 'MMC' 696 | else: 697 | editor_behaviour.set(scene_data.get_control_parameter(editor_group_offset, editor_ctrl, 'behaviour')) 698 | rb_editor_note['text'] = 'Note' 699 | rb_editor_momentary['state'] = tk.NORMAL 700 | rb_editor_toggle['state'] = tk.NORMAL 701 | lbl_min['text'] = 'Off' 702 | lbl_max['text'] = 'On' 703 | 704 | else: 705 | rb_editor_note['state'] = tk.DISABLED 706 | rb_editor_momentary['state'] = tk.DISABLED 707 | rb_editor_toggle['state'] = tk.DISABLED 708 | lbl_min['text'] = 'Min' 709 | lbl_max['text'] = 'Max' 710 | 711 | midi_chan = scene_data.get_group_channel(editor_group_offset) 712 | if midi_chan < 16: 713 | editor_midi_channel.set(midi_chan + 1) 714 | editor_midi_channel_is_global.set(0) 715 | else: 716 | editor_midi_channel_is_global.set(1) 717 | 718 | if editor_ctrl in ['button_a', 'button_b']: 719 | frame_ad.grid() 720 | else: 721 | frame_ad.grid_remove() 722 | 723 | if scene_data.device_type == 'nanoKONTROL2': 724 | editor_global_led_mode.set(scene_data.get_led_mode()) 725 | frame_led_mode.grid() 726 | editor_control_mode.set(control_modes[scene_data.get_control_mode()]) 727 | frame_control_mode.grid() 728 | frame_scene.grid_remove() 729 | else: 730 | frame_led_mode.grid_remove() 731 | frame_control_mode.grid_remove() 732 | frame_scene.grid() 733 | 734 | 735 | # Handle change of editor MIDI channel 736 | def on_editor_midi_chan(*args): 737 | if editor_midi_channel_is_global.get(): 738 | spn_chan['state'] = tk.DISABLED 739 | scene_data.set_group_channel(editor_group_offset, 16) 740 | else: 741 | spn_chan['state'] = tk.NORMAL 742 | scene_data.set_group_channel(editor_group_offset, editor_midi_channel.get() - 1) 743 | 744 | 745 | # Handle change of editor assign (control mode) 746 | def on_editor_assign(*args): 747 | try: 748 | scene_data.set_control_parameter(editor_group_offset, editor_ctrl, 'assign', editor_assign.get()) 749 | except: 750 | pass 751 | if editor_assign.get() == 0: 752 | # Disabled 753 | for ctrl in [rb_editor_momentary, rb_editor_toggle, spn_cmd, spn_min, spn_max, spn_attack, spn_release, spn_chan, chk_global, cmb_cmd, cmb_mmc_cmd, spn_mmc_id]: 754 | ctrl['state'] = tk.DISABLED 755 | elif editor_assign.get() == 1: 756 | # CC 757 | for ctrl in [spn_cmd, spn_min, spn_max, spn_attack, spn_release, chk_global]: 758 | ctrl['state'] = tk.NORMAL 759 | lbl_cmd['text'] = 'CC' 760 | if editor_ctrl in ['knob', 'slider']: 761 | lbl_max['text'] = 'Max' 762 | else: 763 | lbl_max['text'] = 'On' 764 | cmb_mmc_cmd.grid_remove() 765 | cmb_cmd.grid_remove() 766 | spn_mmc_id.grid_remove() 767 | spn_cmd.grid(columnspan=1) 768 | if editor_group is None and scene_data.device_type == 'nanoKONTROL1': 769 | lbl_min.grid_remove() 770 | lbl_max.grid_remove() 771 | spn_min.grid_remove() 772 | spn_max.grid_remove() 773 | else: 774 | lbl_cmd['text'] = 'CC' 775 | lbl_min.grid() 776 | lbl_max.grid() 777 | spn_min.grid() 778 | spn_max.grid() 779 | elif editor_assign.get() == 2: 780 | # Note / MMC 781 | for ctrl in [rb_editor_momentary, rb_editor_toggle, spn_cmd, spn_min, spn_max, spn_chan, chk_global, cmb_cmd, cmb_mmc_cmd, spn_mmc_id]: 782 | ctrl['state'] = tk.NORMAL 783 | if editor_group_offset == control_map[scene_data.device_type]['transport'] and scene_data.device_type == 'nanoKONTROL1': 784 | lbl_cmd['text'] = 'MMC Command' 785 | lbl_min.grid_remove() 786 | lbl_max['text'] = 'Device ID' 787 | lbl_max.grid() 788 | spn_cmd.grid_remove() 789 | spn_min.grid_remove() 790 | spn_max.grid_remove() 791 | cmb_mmc_cmd.grid() 792 | spn_mmc_id.grid() 793 | else: 794 | lbl_cmd['text'] = 'Note' 795 | cmb_cmd.grid() 796 | spn_cmd.grid_remove() 797 | 798 | if editor_assign.get(): 799 | if editor_ctrl not in ['slider', 'knob']: 800 | rb_editor_momentary['state'] = tk.NORMAL 801 | rb_editor_toggle['state'] = tk.NORMAL 802 | if scene_data.get_group_channel(editor_group_offset) < 16: 803 | spn_chan['state'] = tk.NORMAL 804 | else: 805 | spn_chan['state'] = tk.DISABLED 806 | 807 | 808 | # Handle change of editor behaviour 809 | def on_editor_behaviour(*args): 810 | try: 811 | if scene_data.device_type == 'nanoKONTROL1' and editor_group is None: 812 | scene_data.set_control_parameter(editor_group_offset, editor_ctrl, 'transport_behaviour', editor_behaviour.get()) 813 | else: 814 | scene_data.set_control_parameter(editor_group_offset, editor_ctrl, 'behaviour', editor_behaviour.get()) 815 | except: 816 | pass 817 | 818 | 819 | # Handle change of editor command (CC) 820 | def on_editor_cmd(*args): 821 | try: 822 | scene_data.set_control_parameter(editor_group_offset, editor_ctrl, 'cmd', editor_cmd.get()) 823 | except: 824 | pass 825 | 826 | 827 | # Handle change of editor command (Note) 828 | def on_editor_note(*args): 829 | try: 830 | scene_data.set_control_parameter(editor_group_offset, editor_ctrl, 'cmd', notes.index(editor_note.get())) 831 | except: 832 | pass 833 | 834 | 835 | # Handle change of editor min/off 836 | def on_editor_min(*args): 837 | try: 838 | scene_data.set_control_parameter(editor_group_offset, editor_ctrl, 'min', editor_min.get()) 839 | except: 840 | pass 841 | 842 | 843 | # Handle change of editor max/on 844 | def on_editor_max(*args): 845 | try: 846 | scene_data.set_control_parameter(editor_group_offset, editor_ctrl, 'max', editor_max.get()) 847 | except: 848 | pass 849 | 850 | 851 | # Handle change of editor attack (nanoKONTROL 1) 852 | def on_editor_attack(*args): 853 | try: 854 | scene_data.set_control_parameter(editor_group_offset, editor_ctrl, 'attack', editor_attack.get()) 855 | except: 856 | pass 857 | 858 | 859 | # Handle change of editor attack (nanoKONTROL 1) 860 | def on_editor_release(*args): 861 | try: 862 | scene_data.set_control_parameter(editor_group_offset, editor_ctrl, 'release', editor_release.get()) 863 | except: 864 | pass 865 | 866 | 867 | # Handle change of editor MMC command 868 | def on_editor_mmc_cmd(*args): 869 | try: 870 | mmc_cmd_index = mmc_commands.index(editor_mmc_cmd.get()) 871 | scene_data.set_control_parameter(editor_group_offset, editor_ctrl, 'mmc_cmd', mmc_cmd_index) 872 | except: 873 | pass 874 | 875 | 876 | # Handle change of editor MMC device ID 877 | def on_editor_mmc_id(*args): 878 | try: 879 | scene_data.set_control_parameter(editor_group_offset, editor_ctrl, 'mmc_id', editor_mmc_id.get()) 880 | except: 881 | pass 882 | 883 | 884 | # Handle change of global MIDI channel 885 | def on_editor_global_midi_chan(*args): 886 | try: 887 | scene_data.set_global_channel(editor_global_midi_channel.get() - 1) 888 | except: 889 | pass 890 | 891 | 892 | # Handle change of LED mode (nanoKONTROL2 only) 893 | def on_editor_global_led_mode(*args): 894 | try: 895 | scene_data.set_led_mode(editor_global_led_mode.get()) 896 | except: 897 | pass 898 | 899 | 900 | # Handle change of control mode (nanoKONTROL2 only) 901 | def on_editor_control_mode(*args): 902 | try: 903 | scene_data.set_control_mode(control_modes.index(editor_control_mode.get())) 904 | except: 905 | pass 906 | 907 | 908 | # Handle change of scene name (nanoKONTROL1 only) 909 | def on_editor_scene_name(*args): 910 | editor_scene_name.set(editor_scene_name.get()[:12]) 911 | scene_data.set_scene_name(editor_scene_name.get()) 912 | 913 | 914 | # Restore the data from last downloaded 915 | def restore_last_download(): 916 | scene_data.data = scene_backup.data.copy() 917 | populate_editor() 918 | set_statusbar('Restored to last downloaded scene', 1) 919 | 920 | 921 | # Show application info (about...) 922 | def show_info(): 923 | msg = 'nanoKONTROL-Config\nriban 2022\n' 924 | for credit in credits: 925 | msg += '\n{}'.format(credit) 926 | messagebox.showinfo('About...', msg) 927 | 928 | 929 | # Resize the device image 930 | def resize_image(event): 931 | global photo_img_device, photo_img_sel, photo_img_scene_led 932 | photo_img_device = ImageTk.PhotoImage(img_device.resize((event.width, event.width // 4), Image.LANCZOS)) 933 | photo_img_sel = ImageTk.PhotoImage(img_sel.resize((int(event.width * 0.03), int(event.width * 0.03)), Image.LANCZOS)) 934 | photo_img_scene_led = ImageTk.PhotoImage(img_scene_led.resize((int(event.width * 0.02), int(event.width * 0.02)), Image.LANCZOS)) 935 | canvas.itemconfig(img_id_device, image=photo_img_device) 936 | canvas.itemconfig(img_id_sel, image=photo_img_sel) 937 | canvas.itemconfig(img_id_scene_led, image=photo_img_scene_led) 938 | highlight_control() 939 | set_current_scene() 940 | 941 | 942 | # Handle mouse click on image - react to hot-spot clicks 943 | # event: Mouse event 944 | def on_canvas_click(event): 945 | x = event.x / photo_img_device.width() 946 | y = event.y / photo_img_device.height() 947 | #print(x,y) 948 | group = None 949 | for i, coord in enumerate(control_map[scene_data.device_type]['group_coords']): 950 | if x > coord[0] and x < coord[1]: 951 | group = i 952 | group_offset_x = coord[0] 953 | break 954 | 955 | if group is None: 956 | return 957 | if group == len(control_map[scene_data.device_type]['group_coords']) - 1: 958 | group = None 959 | for i, ctrl in enumerate(control_map[scene_data.device_type]['ctrl_coords']): 960 | if group is None and i < control_map[scene_data.device_type]['num_group_ctrls']: 961 | continue 962 | elif group is not None and i >= control_map[scene_data.device_type]['num_group_ctrls']: 963 | break 964 | if x > group_offset_x + control_map[scene_data.device_type]['ctrl_coords'][ctrl][0] and y > control_map[scene_data.device_type]['ctrl_coords'][ctrl][1] and x < group_offset_x + control_map[scene_data.device_type]['ctrl_coords'][ctrl][2] and y < control_map[scene_data.device_type]['ctrl_coords'][ctrl][3]: 965 | #print('Clicked on control {} {}'.format(ctrl, group + 1)) 966 | if ctrl == 'scene': 967 | set_current_scene(current_scene + 1) 968 | send_scene_change_request(current_scene) 969 | else: 970 | populate_editor(ctrl, group) 971 | highlight_control() 972 | break 973 | 974 | 975 | # Highlight selected control 976 | def highlight_control(): 977 | if editor_group is not None: 978 | group_offset_x = control_map[scene_data.device_type]['group_coords'][editor_group][0] 979 | else: 980 | group_offset_x = control_map[scene_data.device_type]['group_coords'][len(control_map[scene_data.device_type]['group_coords']) - 1][0] 981 | ctrl_offset_x = control_map[scene_data.device_type]['ctrl_coords'][editor_ctrl][0] 982 | ctrl_offset_y = control_map[scene_data.device_type]['ctrl_coords'][editor_ctrl][1] 983 | canvas.coords(img_id_sel, (group_offset_x + ctrl_offset_x) * photo_img_device.width(), ctrl_offset_y * photo_img_device.height()) 984 | 985 | 986 | # Update current scene 987 | # scene: Index of scene. None for to update display with current scene (default) 988 | def set_current_scene(scene=None): 989 | global current_scene 990 | if scene is not None: 991 | if scene < 0 or scene > 3: 992 | current_scene = 0 993 | else: 994 | current_scene = scene 995 | canvas.coords(img_id_scene_led, (0.09 + 0.025 * current_scene) * photo_img_device.width(), 0.82 * photo_img_device.height()) 996 | 997 | 998 | # Set the device type 999 | # type: Device type ['nanoKONTROL1', 'nanoKONTROL2'] 1000 | def set_device_type(type): 1001 | global img_device 1002 | global photo_img_device 1003 | scene_data.set_device_type(type) 1004 | width = photo_img_device.width() 1005 | height = photo_img_device.height() 1006 | img_device = Image.open('{}.png'.format(scene_data.device_type)) 1007 | photo_img_device = ImageTk.PhotoImage(img_device.resize((width, height), Image.LANCZOS)) 1008 | canvas.itemconfig(img_id_device, image=photo_img_device) 1009 | if scene_data.device_type == 'nanoKONTROL1': 1010 | set_current_scene() 1011 | canvas.itemconfig(img_id_scene_led, state=tk.NORMAL) 1012 | else: 1013 | canvas.itemconfig(img_id_scene_led, state=tk.HIDDEN) 1014 | populate_editor() 1015 | highlight_control() 1016 | set_statusbar('Device {} selected'.format(type)) 1017 | 1018 | 1019 | # Show status message 1020 | # msg: Text message to show in status bar 1021 | # status: Influences display [0: Info (default), 1: Success, 2: Error] 1022 | def set_statusbar(msg, status=None): 1023 | if status == 1: 1024 | bg = '#aacf55' 1025 | elif status == 2: 1026 | bg = '#cc0000' 1027 | else: 1028 | bg = '#cccccc' 1029 | lbl_statusbar.config(text=datetime.now().strftime('%H:%M:%S: ' + msg), background=bg) 1030 | 1031 | 1032 | # Handle MIDI data received from JACK or ALSA 1033 | # indata: List of raw MIDI data bytes 1034 | def handle_midi_input(indata): 1035 | 1036 | data = struct.unpack('{}B'.format(len(indata)), indata) 1037 | str = '[{}] '.format(len(data)) 1038 | for i in data: 1039 | str += '{:02X} '.format(i) 1040 | set_statusbar(str) 1041 | 1042 | if len(data) == 14 and data[:2] == (0xF0, 0x7E) and data[3:5] == (0x06, 0x02, 0x42): 1043 | # Device inquiry reply 1044 | scene_data.global_midi_chan = data[2] 1045 | major = data[12] + (data[13 << 7]) 1046 | minor = data[10] + (data[11] << 7) 1047 | elif data[:4] == (0xF0, 0x42, 0x50, 0x01) and data[5] == echo_id: 1048 | # Search device reply 1049 | scene_data.global_midi_chan = data[4] 1050 | family_id = data[6] + (data[7] << 7) 1051 | member_id = data[8] + (data[9] << 7) 1052 | minor = data[10] + (data[11] << 7) 1053 | major = data[12] + (data[13] << 7) 1054 | if family_id == 132: 1055 | set_device_type('nanoKONTROL1') 1056 | elif family_id == 147: 1057 | set_device_type('nanoKONTROL2') 1058 | device_info.set('Device version: {}.{}'.format(major,minor)) 1059 | elif len(data) == 3: 1060 | cmd = data[0] & 0xF0 1061 | if cmd == 0x80 or cmd == 0x90 and data[2] == 0: 1062 | # Note off 1063 | pass 1064 | elif cmd == 0x90: 1065 | # Note on 1066 | pass 1067 | elif cmd == 0xB0: 1068 | # CC 1069 | pass 1070 | elif cmd == 0xE0: 1071 | # Pitch bend 1072 | pass 1073 | elif len(data) > 10 and data[:7] == (0xF0, 0x42, 0x40 | scene_data.global_midi_chan) + scene_data.get_sysex_id(): 1074 | # Command list 1075 | if data[7:13] == (0x7F, 0x7F, 0x02, 0x03, 0x05, 0x40): 1076 | # nanoKONTROL2 data dump 1077 | scene_data.set_data(data[13:-1]) 1078 | scene_backup.data = scene_data.data.copy() 1079 | set_device_type('nanoKONTROL2') 1080 | elif data[7:13] == (0x7F, 0x7F, 0x02, 0x02, 0x26, 0x40): 1081 | # nanoKONTROL1 data dump 1082 | scene_data.set_data(data[13:-1]) 1083 | scene_backup.data = scene_data.data.copy() 1084 | set_device_type('nanoKONTROL1') 1085 | elif data[7:10] == (0x5F, 0x23, 0x00): 1086 | # Load data ACK 1087 | set_statusbar('Load data succeded', 1) 1088 | elif data[7:10] == (0x5F, 0x24, 0x00): 1089 | # Load data NAK 1090 | set_statusbar('Load data failed', 2) 1091 | elif data[7:10] == (0x5F, 0x21, 0x00): 1092 | # Write completed 1093 | set_statusbar('Scene saved to device', 1) 1094 | elif data[7:10] == (0x5F, 0x22, 0x00): 1095 | # Write error 1096 | set_statusbar('Scene failed to save to device', 2) 1097 | elif data[7:10] == (0x40, 0x00, 0x02): 1098 | # Native mode out 1099 | set_statusbar("Native mode 'out' set on device", 1) 1100 | elif data[7:10] == (0x40, 0x00, 0x03): 1101 | # Native mode in 1102 | set_statusbar("Native mode out set 'in' device", 1) 1103 | elif data[7:10] == (0x5F, 0x42, 0x00): 1104 | # Normal mode 1105 | set_statusbar('Normal mode set on device', 1) 1106 | elif data[7:10] == (0x5F, 0x42, 0x01): 1107 | # Native mode 1108 | set_statusbar('Native mode set on device', 1) 1109 | elif data[7:9] == (0x5F, 0x4F): 1110 | # Scene change 1111 | try: 1112 | set_current_scene(data[9]) 1113 | set_statusbar('Scene change {}'.format(current_scene + 1), 1) 1114 | except Exception as e: 1115 | logging.warning('Scene change error %s', e) 1116 | 1117 | 1118 | ## JACK Functions ## 1119 | 1120 | # Process jack frames 1121 | def jack_process(frames): 1122 | global ev 1123 | 1124 | jack_midi_out.clear_buffer() 1125 | if ev: 1126 | jack_midi_out.write_midi_event(0, ev) 1127 | ev = None 1128 | 1129 | # Process incoming messages 1130 | for offset, indata in jack_midi_in.incoming_midi_events(): 1131 | handle_midi_input(indata) 1132 | 1133 | 1134 | # Refresh jack MIDI ports 1135 | def refresh_jack_ports(): 1136 | global source_ports, destination_ports 1137 | 1138 | ports = jack_client.get_ports(is_midi=True, is_input=True) 1139 | temp_ports = {} 1140 | for port in destination_ports: 1141 | if destination_ports[port][0] == 'alsa': 1142 | temp_ports[port] = destination_ports[port] 1143 | destination_ports = temp_ports 1144 | for port in ports: 1145 | destination_ports[port.name] = ['jack', port] 1146 | 1147 | ports = jack_client.get_ports(is_midi=True, is_output=True) 1148 | temp_ports = {} 1149 | for port in source_ports: 1150 | if source_ports[port][0] == 'alsa': 1151 | temp_ports[port] = source_ports[port] 1152 | source_ports = temp_ports 1153 | for port in ports: 1154 | source_ports[port.name] = ['jack', port] 1155 | 1156 | update_ports() 1157 | 1158 | 1159 | ## ALSA Functions ## 1160 | 1161 | # Thread worker listening for ALSA MIDI events 1162 | def alsa_midi_in_thread(): 1163 | while True: 1164 | event = alsa_client.event_input(prefer_bytes=True) 1165 | try: 1166 | handle_midi_input(event.midi_bytes) 1167 | except: 1168 | #print(repr(event)) 1169 | pass 1170 | 1171 | 1172 | def auto_connect(force=False): 1173 | if not force and midi_dest_port.get() and midi_source_port.get(): 1174 | return 1175 | for name in source_ports: 1176 | if "nanoKONTROL" in name: 1177 | midi_source_port.set(name) 1178 | break 1179 | for name in destination_ports: 1180 | if "nanoKONTROL" in name: 1181 | midi_dest_port.set(name) 1182 | break 1183 | source_changed() 1184 | destination_changed() 1185 | 1186 | 1187 | ##################################### 1188 | ## Core sequential functional code ## 1189 | ##################################### 1190 | 1191 | scene_data = scene() 1192 | scene_backup = scene() 1193 | 1194 | ## Initialise MIDI interfaces ## 1195 | jack_client = None 1196 | try: 1197 | jack_client = jack.Client('riban-nanoKonfig', no_start_server=True) 1198 | jack_midi_in = jack_client.midi_inports.register('in') 1199 | jack_midi_out = jack_client.midi_outports.register('out') 1200 | except: 1201 | pass 1202 | 1203 | alsa_client = None 1204 | try: 1205 | alsa_client = alsa_midi.SequencerClient('riban-nanoKonfig') 1206 | alsa_midi_in = alsa_client.create_port('in', caps=alsa_midi.WRITE_PORT) 1207 | alsa_midi_out = alsa_client.create_port('out', caps=alsa_midi.READ_PORT) 1208 | except: 1209 | pass 1210 | 1211 | if alsa_client == jack_client == None: 1212 | logging.error('Failed to create ALSA or JACK client') 1213 | exit(-1) 1214 | 1215 | 1216 | # Create UI 1217 | current_scene = 0 1218 | source_ports = {} # Dictionary of available MIDI source ports: display_name:[type,port] where type is jack or alsa 1219 | destination_ports = {} # Dictionary of available MIDI destination ports: display_name:[type,port] where type is jack or alsa 1220 | 1221 | # Root window 1222 | root = tk.Tk() 1223 | root.grid_columnconfigure(0, weight=1) 1224 | root.grid_rowconfigure(2, weight=1) 1225 | root.title('riban nanoKONTROL editor') 1226 | 1227 | # Icons 1228 | img_transfer_down = ImageTk.PhotoImage(Image.open('transfer.png')) 1229 | img_transfer_up = ImageTk.PhotoImage(Image.open('transfer.png').rotate(180)) 1230 | img_save = ImageTk.PhotoImage(Image.open('save.png')) 1231 | img_info = ImageTk.PhotoImage(Image.open('info.png')) 1232 | img_restore = ImageTk.PhotoImage(Image.open('restore.png')) 1233 | 1234 | tk.Label(root, text='riban nanoKONTROL editor', bg='#80cde0').grid(columnspan=2, sticky='ew') 1235 | 1236 | # Top frame 1237 | frame_top = tk.Frame(root, padx=2, pady=2) 1238 | frame_top.columnconfigure(7, weight=1) 1239 | frame_top.grid(row=1, columnspan=2, sticky='enw') 1240 | 1241 | midi_source_port = tk.StringVar() 1242 | ttk.Label(frame_top, text='MIDI input').grid(row=0, column=0, sticky='w') 1243 | cmb_midi_input = ttk.Combobox(frame_top, textvariable=midi_source_port, state='readonly') 1244 | cmb_midi_input.bind('<>', source_changed) 1245 | cmb_midi_input.grid(row=1, column=0, sticky='n') 1246 | if alsa_client: 1247 | cmb_midi_input.bind('', populate_alsa_source) 1248 | 1249 | midi_dest_port = tk.StringVar() 1250 | ttk.Label(frame_top, text='MIDI output').grid(row=0, column=1, sticky='w') 1251 | cmb_midi_output = ttk.Combobox(frame_top, textvariable=midi_dest_port, state='readonly') 1252 | cmb_midi_output.bind('<>', destination_changed) 1253 | cmb_midi_output.grid(row=1, column=1, sticky='n') 1254 | if alsa_client: 1255 | cmb_midi_output.bind('', populate_alsa_dest) 1256 | 1257 | btn_download = ttk.Button(frame_top, image=img_transfer_down, command=send_dump_request) 1258 | btn_download.grid(row=0, column=2, rowspan=2) 1259 | btn_upload = ttk.Button(frame_top, image=img_transfer_up, command=send_scene_data) 1260 | btn_upload.grid(row=0, column=3, rowspan=2) 1261 | btn_save = ttk.Button(frame_top, image=img_save, command=send_scene_write_request) 1262 | btn_save.grid(row=0, column=4, rowspan=2) 1263 | btn_restore = ttk.Button(frame_top, image=img_restore, command=restore_last_download) 1264 | btn_restore.grid(row=0, column=5, rowspan=2) 1265 | btn_info = ttk.Button(frame_top, image=img_info, command=show_info) 1266 | btn_info.grid(row=0, column=6, rowspan=2) 1267 | device_info = tk.StringVar() 1268 | lbl_device_info = tk.Label(frame_top, textvariable=device_info) 1269 | lbl_device_info.grid(row=0, column=7, sticky='ne') 1270 | 1271 | # Control editor frame 1272 | editor_midi_channel = tk.IntVar() 1273 | editor_midi_channel_is_global = tk.IntVar() 1274 | editor_assign = tk.IntVar() 1275 | editor_behaviour = tk.IntVar() 1276 | editor_cmd = tk.IntVar() 1277 | editor_note = tk.StringVar() 1278 | editor_min = tk.IntVar() 1279 | editor_max = tk.IntVar() 1280 | editor_attack = tk.IntVar() 1281 | editor_release = tk.IntVar() 1282 | editor_group_offset = 0 1283 | editor_ctrl = None 1284 | editor_group = None 1285 | editor_mmc_cmd = tk.StringVar() 1286 | editor_mmc_id = tk.IntVar() 1287 | editor_title = tk.StringVar() 1288 | editor_global_midi_channel = tk.IntVar() 1289 | editor_global_led_mode = tk.IntVar() 1290 | editor_control_mode = tk.StringVar() 1291 | editor_scene_name = tk.StringVar() 1292 | 1293 | frame_editor = tk.Frame(root, padx=4, pady=4, bd=2, relief='groove') 1294 | frame_editor.grid(row=2, column=1, sticky='nsw') 1295 | 1296 | tk.Label(frame_editor, textvariable=editor_title, width=1, bg='#bf64ed').grid(row=0, column=0, sticky='wne') 1297 | 1298 | frame_assign = tk.Frame(frame_editor, bd=2, relief='groove') 1299 | frame_assign.grid(row=1, sticky='ew') 1300 | 1301 | tk.Radiobutton(frame_assign, text='Disabled', variable=editor_assign, value=0).grid(row=0, column=0) 1302 | rb_editor_cmd = tk.Radiobutton(frame_assign, text='CC', variable=editor_assign, value=1) 1303 | rb_editor_cmd.grid(row=0, column=1) 1304 | rb_editor_note = tk.Radiobutton(frame_assign, text='Note', variable=editor_assign, value=2) 1305 | rb_editor_note.grid(row=0, column=2) 1306 | 1307 | frame_behaviour = tk.Frame(frame_editor, bd=2, relief='groove') 1308 | frame_behaviour.grid(row=2, sticky='ew') 1309 | rb_editor_momentary = tk.Radiobutton(frame_behaviour, text='Momentary', variable=editor_behaviour, value=0) 1310 | rb_editor_momentary.grid(row=0, column=0, sticky='w') 1311 | rb_editor_toggle = tk.Radiobutton(frame_behaviour, text='Toggle', variable=editor_behaviour, value=1) 1312 | rb_editor_toggle.grid(row=0, column=1, sticky='w') 1313 | 1314 | frame_cmd = tk.Frame(frame_editor, bd=2, relief='groove') 1315 | frame_cmd.columnconfigure(0, uniform='cmd_uni', weight=1) 1316 | frame_cmd.columnconfigure(1, uniform='cmd_uni', weight=1) 1317 | frame_cmd.columnconfigure(2, uniform='cmd_uni', weight=1) 1318 | frame_cmd.grid(row=3, sticky='ew') 1319 | lbl_cmd = tk.Label(frame_cmd, text='CC', width=12, anchor='w') 1320 | lbl_cmd.grid(row=0, column=0, sticky='w') 1321 | lbl_min = tk.Label(frame_cmd, text='Min', width=5, anchor='w') 1322 | lbl_min.grid(row=0, column=1, sticky='w') 1323 | lbl_max = tk.Label(frame_cmd, text='Max', width=10, anchor='w') 1324 | lbl_max.grid(row=0, column=2, sticky='w') 1325 | 1326 | cmb_mmc_cmd = ttk.Combobox(frame_cmd, textvariable=editor_mmc_cmd, state='readonly', values=mmc_commands) 1327 | cmb_mmc_cmd.grid(row=1, column=0, columnspan=2, sticky='ew') 1328 | cmb_mmc_cmd.grid_remove() 1329 | note_names = ['C','C#','D','D#','E','F','F#','G','G#','A','A#','B'] 1330 | notes = [] 1331 | for octave in range(-1, 10): 1332 | for i in range(12): 1333 | notes.append('{}{} ({})'.format(note_names[i], octave, 12 * (octave + 1) + i)) 1334 | cmb_cmd = ttk.Combobox(frame_cmd, textvariable=editor_note, state='readonly', values=notes[:127], width=3) 1335 | cmb_cmd.grid(row=1, column=0, sticky='ew') 1336 | cmb_cmd.grid_remove() 1337 | spn_cmd = tk.Spinbox(frame_cmd, from_=0, to=127, textvariable=editor_cmd, width=3) 1338 | spn_cmd.grid(row=1, column=0, columnspan=2, sticky='ew') 1339 | spn_min = tk.Spinbox(frame_cmd, from_=0, to=127, textvariable=editor_min, width=3) 1340 | spn_min.grid(row=1, column=1, sticky='ew') 1341 | spn_mmc_id = tk.Spinbox(frame_cmd, from_=0, to=127, textvar=editor_mmc_id, width=3) 1342 | spn_mmc_id.grid(row=1, column=2, sticky='ew') 1343 | spn_mmc_id.grid_remove() 1344 | spn_max = tk.Spinbox(frame_cmd, from_=0, to=127, textvariable=editor_max, width=3) 1345 | spn_max.grid(row=1, column=2, sticky='ew') 1346 | 1347 | frame_ad = tk.Frame(frame_editor, bd=2, relief='groove') 1348 | frame_ad.columnconfigure(0, uniform='cmd_uni', weight=1) 1349 | frame_ad.columnconfigure(1, uniform='cmd_uni', weight=1) 1350 | frame_ad.columnconfigure(2, uniform='cmd_uni', weight=1) 1351 | frame_ad.grid(row=4, column=0, sticky='ew') 1352 | tk.Label(frame_ad, text='Attack time').grid(row=0, column=0, sticky='w') 1353 | tk.Label(frame_ad, text='Release time').grid(row=0, column=1, sticky='w') 1354 | spn_attack = tk.Spinbox(frame_ad, from_=0, to=127, textvariable=editor_attack, width=3) 1355 | spn_attack.grid(row=1, column=0, sticky='ew') 1356 | spn_release = tk.Spinbox(frame_ad, from_=0, to=127, textvariable=editor_release, width=3) 1357 | spn_release.grid(row=1, column=1, sticky='ew') 1358 | 1359 | frame_channel = tk.Frame(frame_editor, bd=2, relief='groove') 1360 | frame_channel.grid(row=5, sticky='ew') 1361 | tk.Label(frame_channel, text='MIDI Channel').grid(row=0, column=0, sticky='w') 1362 | spn_chan = tk.Spinbox(frame_channel, from_=1, to=16, textvariable=editor_midi_channel, width=3) 1363 | spn_chan.grid(row=0, column=1, sticky='ew') 1364 | chk_global = tk.Checkbutton(frame_channel, text='Global', variable=editor_midi_channel_is_global) 1365 | chk_global.grid(row=0, column=2, sticky='wsn') 1366 | 1367 | tk.Label(frame_editor, text='Global Settings', bg='#bf64ed').grid(row=6, column=0, sticky='we') 1368 | 1369 | frame_global_channel = tk.Frame(frame_editor, bd=2, relief='groove') 1370 | frame_global_channel.grid(row=7, sticky='ew') 1371 | tk.Label(frame_global_channel, text='MIDI Channel').grid(row=0, column=0, sticky='w') 1372 | tk.Spinbox(frame_global_channel, from_=1, to=16, textvar=editor_global_midi_channel, width=3).grid(row=0, column=1, sticky='ew') 1373 | 1374 | frame_led_mode = tk.Frame(frame_editor, bd=2, relief='groove') 1375 | frame_led_mode.grid(row=8, sticky='ew') 1376 | tk.Label(frame_led_mode, text="LED Mode").grid(row=0, column=0) 1377 | tk.Radiobutton(frame_led_mode, text='Internal', variable=editor_global_led_mode, value=0).grid(row=0, column=1) 1378 | tk.Radiobutton(frame_led_mode, text='External', variable=editor_global_led_mode, value=1).grid(row=0, column=2) 1379 | 1380 | frame_control_mode = tk.Frame(frame_editor, bd=2, relief='groove') 1381 | frame_control_mode.grid(row=9, sticky='ew') 1382 | lbl_control_mode = tk.Label(frame_control_mode, text='Control Mode', width=12, anchor='w') 1383 | lbl_control_mode.grid(row=0, column=0, sticky='ew') 1384 | cmb_control_mode = ttk.Combobox(frame_control_mode, textvariable=editor_control_mode, state='readonly', values=control_modes) 1385 | cmb_control_mode.grid(row=0, column=1, sticky='ew') 1386 | 1387 | frame_scene = tk.Frame(frame_editor, bd=2, relief='groove') 1388 | frame_scene.grid(row=9, sticky='ew') 1389 | lbl_scene_name = tk.Label(frame_scene, text="Scene name") 1390 | lbl_scene_name.grid(row=0, column=0, sticky='w') 1391 | txt_scene_name = tk.Entry(frame_scene, width=12, textvariable=editor_scene_name) 1392 | txt_scene_name.grid(row=0, column=1, sticky='ew') 1393 | 1394 | # Configure variable change event handlers 1395 | editor_midi_channel.trace('w', on_editor_midi_chan) 1396 | editor_midi_channel_is_global.trace('w', on_editor_midi_chan) 1397 | editor_assign.trace('w', on_editor_assign) 1398 | editor_behaviour.trace('w', on_editor_behaviour) 1399 | editor_cmd.trace('w', on_editor_cmd) 1400 | editor_note.trace('w', on_editor_note) 1401 | editor_min.trace('w', on_editor_min) 1402 | editor_max.trace('w', on_editor_max) 1403 | editor_attack.trace('w', on_editor_attack) 1404 | editor_release.trace('w', on_editor_release) 1405 | editor_mmc_cmd.trace('w', on_editor_mmc_cmd) 1406 | editor_mmc_id.trace('w', on_editor_mmc_id) 1407 | editor_global_midi_channel.trace('w', on_editor_global_midi_chan) 1408 | editor_global_led_mode.trace('w', on_editor_global_led_mode) 1409 | editor_control_mode.trace('w', on_editor_control_mode) 1410 | editor_scene_name.trace('w', on_editor_scene_name) 1411 | 1412 | lbl_statusbar = ttk.Label(root, anchor='w', width=1, background='#cccccc') # width= stops long messages stretching width of display 1413 | lbl_statusbar.grid(row=3, column=0, columnspan=2, sticky='ew') 1414 | 1415 | # Start jack client 1416 | if jack_client: 1417 | jack_client.set_process_callback(jack_process) 1418 | jack_client.set_graph_order_callback(refresh_jack_ports) 1419 | 1420 | # Activate jack client and get available MIDI ports 1421 | jack_client.activate() 1422 | 1423 | 1424 | # Start ALSA MIDI listening thread 1425 | if alsa_client: 1426 | alsa_thread = Thread(target=alsa_midi_in_thread, args=()) 1427 | alsa_thread.name = 'alsa_in' 1428 | alsa_thread.daemon = True 1429 | alsa_thread.start() 1430 | 1431 | 1432 | # Device image 1433 | canvas = tk.Canvas(root, width=800, height=250) 1434 | 1435 | img_device = Image.open('{}.png'.format(scene_data.device_type)) 1436 | photo_img_device = ImageTk.PhotoImage(img_device) 1437 | img_id_device = canvas.create_image(0, 0, anchor='nw', image=photo_img_device) 1438 | canvas.grid(row=2, column=0, sticky='nsew') 1439 | canvas.bind('', on_canvas_click) 1440 | canvas.bind('', resize_image) 1441 | 1442 | # Selected image 1443 | img_sel = Image.open('tick.png') 1444 | photo_img_sel = ImageTk.PhotoImage(img_sel) 1445 | img_id_sel = canvas.create_image(0, 0, image=photo_img_sel) 1446 | 1447 | # Scene LED image 1448 | img_scene_led = Image.open('led_red.png') 1449 | photo_img_scene_led = ImageTk.PhotoImage(img_scene_led) 1450 | img_id_scene_led = canvas.create_image(0, 0, image=photo_img_scene_led) 1451 | 1452 | set_device_type('nanoKONTROL2') 1453 | 1454 | tooltip_obj = ToolTips.ToolTips( 1455 | [btn_download, btn_upload, btn_save, btn_restore, btn_info], 1456 | ['Download from nanoKONTROL', 'Upload to nanoKONTROL', 'Save current scene on nanoKONTROL', 'Restore to last download', 'About'] 1457 | ) 1458 | 1459 | if alsa_client: 1460 | populate_alsa_source() 1461 | populate_alsa_dest() 1462 | if jack_client: 1463 | refresh_jack_ports() 1464 | 1465 | root.mainloop() 1466 | --------------------------------------------------------------------------------