Controller

This example creates a basic virtual control surface that sends MIDI control messages.

screenshot

Start by importing the Fltk package:



import Fltk


The controller application class is a subclass of Fltk.Window.



class Controller extends Fltk.Window {


Create a MIDI system output as class member data:


	output = Midi.Output("bipcontroller")	

The strip function adds a single control strip consisting of:


	function strip(x, y, control) {

Note we configure each widget to accept the MIDI value range of 0-127.


		local slider = Fltk.ValueSlider(x + 10, y, 25, 250)
		slider.selection_color = Fltk.Color.BLUE
		slider.color = Fltk.Color.LIGHT2
		slider.type = 4
		slider.maximum = 0
		slider.minimum = 127
		slider.step = 1
		slider.slidersize = 0.1

		local spinner = Fltk.Spinner(x, y + 260, 45, 25)
		spinner.value = control
		spinner.minimum = 0
		spinner.maximum = 127

When the slider value changes send the new value as a MIDI CC message using the control number from the spinner.


		slider.callback(function(slider, spinner) { 
			output.send(Midi.Control(spinner.value, slider.value))
		}, spinner, this)
	}


We set the spinner as user data so it is passed as the second parameter to the callback function and we set the context as "this" so the method will run as a method of this class and have access to the output member.

The constructor calls the base constructor with the initial size of the window and sets a callback to exit the application when closed.


	constructor() {

		base.constructor(905, 320)
		this.color = Fltk.Color.LIGHT3

		this.callback(function(e) {
			Script.exit(0)
		})


Loop to create sixteen control strips:


		local x = 20
		local y = 20
		for(local i = 0; i < 16; i++) {
			strip(x, y, i)
			x += 55			
		}

Don't forget to end() the window after adding the child widgets.


		this.end()
		this.show()
	}
}

Create the top level window and run the application:


Controller()
Fltk.run()



Complete Script

import Fltk

class Controller extends Fltk.Window {

	output = Midi.Output("bipcontroller")

	function strip(x, y, control) {

		local slider = Fltk.ValueSlider(x + 10, y, 25, 250)
		slider.selection_color = Fltk.Color.BLUE
		slider.color = Fltk.Color.LIGHT2
		slider.type = 4
		slider.maximum = 0
		slider.minimum = 127
		slider.step = 1
		slider.slidersize = 0.1

		local spinner = Fltk.Spinner(x, y + 260, 45, 25)
		spinner.value = control
		spinner.minimum = 0
		spinner.maximum = 127

		slider.callback(function(slider, spinner) { 
			output.send(Midi.Control(spinner.value, slider.value))
		}, spinner, this)
	}

	constructor() {

		base.constructor(905, 320)
		this.color = Fltk.Color.LIGHT3

		this.callback(function(e) {
			Script.exit(0)
		})

		local x = 20
		local y = 20
		for(local i = 0; i < 16; i++) {
			strip(x, y, i)
			x += 55			
		}

		this.end()
		this.show()
	}
}

Controller()
Fltk.run()


List of All Examples
Creative Commons License This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.