kf Python library¶
The kf
library has a number of objects useful for building performance
control scripts and GUIs. It is included in several zip packages and the individual files can be browsed at kf.
Contents
Core Modules (non-GUI)¶
kf.midi¶
Objects related to MIDI event processing.
-
class
kf.midi.
MIDIEncoder
[source]¶ Abstract class for composing MIDI messages.
-
channel_pressure
(channel, value)[source]¶ Send a Channel Pressure (aftertouch) message.
- Parameters
channel – MIDI channel, integer on [1,16]
value – MIDI value, integer on [0,127]
-
control_change
(channel, controller, value)[source]¶ Send a Controller Change message.
- Parameters
channel – MIDI channel, integer on [1,16]
controller – MIDI controller index, integer on [0,127]
value – MIDI value, integer on [0,127]
-
message
(message)[source]¶ Overridable method to output a single MIDI message.
- Parameters
message – list of integers constituting a MIDI message
-
note_off
(channel, note, velocity=0)[source]¶ Send a Note On message.
- Parameters
channel – MIDI channel, integer on [1,16]
note – MIDI note, integer on [0,127]
velocity – optional MIDI velocity, integer on [0,127], normally zero, default zero
-
-
class
kf.midi.
MIDIProcessor
[source]¶ Abstract class for processing MIDI events. Provides a callback for the specific MIDI events we use in our systems so this may be subclassed to implement a MIDI stream processor. This defines an informal protocol for MIDI input. This may be extended to more event times as needed.
-
channel_pressure
(channel, value)[source]¶ Function to receive messages starting with 0xD0 through 0xDF.
- Parameters
channel – integer from 1 to 16
value – integer from 0 to 127
-
control_change
(channel, control, value)[source]¶ Function to receive messages starting with 0xB0 through 0xBF.
- Parameters
channel – integer from 1 to 16
control – integer from 0 to 127; some have special meanings
value – integer from 0 to 127
-
decode_message
(message)[source]¶ Decode a MIDI message expressed as a list of integers and perform callbacks for recognized message types.
- Parameters
message – list of integers containing a single MIDI message
-
decode_mpd218_cc
(cc)[source]¶ Interpret a MPD218 knob control change event as a knob index and bank position. The MPD218 uses a non-contiguous set of channel indices so this normalizes the result. The knob index ranges from 1 to 6 matching the knob labels. Bank 0 is the A bank, bank 1 is the B bank, bank 2 is the C bank.
- Parameters
cc – an integer MIDI control channel identifier
- Returns
(knob, bank)
-
decode_mpd218_key
(key)[source]¶ Interpret a MPD218 pad event key value as a row, column, and bank position. Row 0 is the front/bottom row (Pads 1-4), row 3 is the back/top row (Pads 13-16). Column 0 is the left, column 3 is the right. Bank 0 is the A bank, bank 1 is the B bank, bank 2 is the C bank.
- Parameters
key – an integer MIDI note value
- Returns
(row, column, bank)
-
note_off
(channel, key, velocity)[source]¶ Function to receive messages starting with 0x80 through 0x8F.
- Parameters
channel – integer from 1 to 16
key – integer from 0 to 127
velocity – integer from 0 to 127
-
-
class
kf.midi.
QtMIDIListener
[source]¶ Object to manage a MIDI input connection.
-
connect_midi_processor
(processor)[source]¶ Attach an object to receive MIDI input events, generally a subclass of MIDIProcessor.
-
kf.app¶
Objects related to the application event loop and life cycle. This uses QtCore but not QtGui so this functionality is compatible with non-graphical command-line programs.
-
class
kf.app.
MainApp
[source]¶ Root application class for managing common elements of our applications. This is intended to be inherited by an top-level application controller along with other root classes which define specific interface API.
- Variables
config – configuration parser object to hold persistent user selections
configuration_file_path – path of current configuration file, possibly not yet existing
-
app_has_started
()[source]¶ Callback to be invoked right after the main event loop begins. This may be extended in child classes to implement startup behaviors which require a running event loop.
-
app_is_exiting
()[source]¶ Callback invoked right before the program ends, either from a keyboard interrupt window close. This may be extended in child classes to clean up external resources, e.g., close any serial ports to remove associated lock files.
-
initialize_default_configuration
()[source]¶ Method to add default configuration values. This is intended to be extended in child classes. It is called during object initialization.
-
kf.app.
add_console_log_handler
(level=10)[source]¶ Add an additional root log handler to stream messages to the console.
kf.valve¶
Interfaces to hardware valve systems. Uses the QtSerialPort module for communication event processing using the Qt event loop.
-
class
kf.valve.
QtSerialValve
[source]¶ Class to manage a serial connection to a hardware valve system using Qt QSerialPort object for data transport. The data protocol is based on the ValveControl Arduino sketch.
-
open
()[source]¶ Open the serial port and initialize communications. If the port is already open, this will close it first. If the current name is None, this will not open anything. Returns True if the port is open, else False.
-
Core GUI Modules¶
kf.QtConfig¶
PyQt5 widgets to create configuration fields and forms.
-
class
kf.QtConfig.
QtConfigComboBox
(callback=None, default='<no selection>')[source]¶ Composite widget enabling a user to select an item from a drop down list.
- Parameters
callback – function called with argument (string)
default – name of initial selection, defaults to ‘<no selection>’
-
class
kf.QtConfig.
QtConfigFileButtons
(delegate=None, path=None, extension='config')[source]¶ Composite widget with buttons to control loading and saving a configuration file.
-
class
kf.QtConfig.
QtConfigForm
[source]¶ Composite widget to display a form of user-configuration entries.
-
class
kf.QtConfig.
QtConfigOSCPort
(callback=None, address='localhost', portnum=3761)[source]¶ Composite widget enabling a user to configure an address:portnum field.
- Parameters
callback – function called with arguments (address-string, port-integer)
address – host address string, defaults to ‘localhost’
portnum – UDP port integer, defaults to 3761
kf.QtLog¶
PyQt5 widgets to show and control logging output.
kf.QtMPD218¶
A PyQt5 GUI to simulate an Akai MPD218 MIDI controller. The actual controller has pressure-sensitive pads, so the simulation is approximate, this is only intended for testing offline without the physical controller.