Yet Another Synthesizer Engine
 
Loading...
Searching...
No Matches
yase::Buttons Class Reference

#include <buttons.hh>

+ Inheritance diagram for yase::Buttons:
+ Collaboration diagram for yase::Buttons:

Detailed Description

A class for managing MIDI buttons.

Public Member Functions

 Buttons (string output_device_name)
 
void init ()
 
void update ()
 
Buttonson (unsigned char id)
 
Buttonson (unsigned char id, unsigned char color)
 
Buttonsoff (unsigned char id)
 
Buttonsblink_on (int id, double period)
 
Buttonsblink_off (int id)
 
Buttonsmomentary (int id, function< void(const Event &)> handler, int type=MIDI_KEYDOWN)
 
Buttonsmutex (vector< int > ids, vector< function< void(const Event &)> > handlers)
 
Buttonstoggle (int id, function< void(const Event &)> handler, bool init_on)
 
Buttonssend (std::vector< unsigned char > msg)
 
void set (int id, BUTTON_STATE state)
 
map< int, BUTTON_STATEget_states ()
 
void set_states (map< int, BUTTON_STATE > states)
 
void clear_leds ()
 Turn off all the currently illuminated LEDs.
 
- Public Member Functions inherited from yase::EventManager
 EventManager ()
 Make a new event manager.
 
void process_events (vector< Module * > &modules)
 
void respond_to (const Event &event)
 
EventManagerlisten (int event_type, function< void(const Event &)> handler)
 
EventManagerlisten (int event_type, int port, function< void(const Event &)> handler)
 
- Public Member Functions inherited from yase::Module
virtual void init ()=0
 
virtual void update ()=0
 
int add_input (string name)
 
int add_output (string name)
 
int get_input_index (string name) const
 
string get_input_name (int index) const
 
string get_output_name (int index) const
 
int get_output_index (string name) const
 
void set_input (string name, double value)
 
void set_input (int index, double value)
 
double get_input (int index) const
 
double get_input (string name) const
 
double get_output (string name) const
 
double get_output (int index) const
 
void set_output (int index, double value)
 
void copy_inputs (const Module &source)
 
void copy_outputs (Module &destination) const
 
void configure (std::vector< std::tuple< string, double > > assignments)
 
int num_inputs () const
 
int num_outputs () const
 
void emit (Event e)
 
void set_ts (double s)
 
double get_ts ()
 

Constructor & Destructor Documentation

◆ Buttons()

yase::Buttons::Buttons ( string  device_name)

Constructor for a new Buttons object.

Parameters
device_nameThe name of the MIDI device who's buttons should be be used.

Member Function Documentation

◆ blink_off()

Buttons & yase::Buttons::blink_off ( int  id)

Stop a button blinking

Parameters
idThe MIDI id of the button

◆ blink_on()

Buttons & yase::Buttons::blink_on ( int  id,
double  period 
)

Set a button blinking.

Parameters
idThe MIDI id of the button
periodThe period in seconds

◆ init()

void yase::Buttons::init ( )
virtual

This method should be overridden by derived classes. It will usually be called once, after all modules and connections objects have been added to a synthesizer, but before the synthesizer starts running.

Implements yase::Module.

◆ momentary()

Buttons & yase::Buttons::momentary ( int  id,
function< void(const Event &)>  handler,
int  type = MIDI_KEYDOWN 
)

Associate a button with an method to run when the button is pressed. The LED of the button is illumiated momentarily. For example

buttons.momentary(123, [](const Event &e) {
cout << "You pressed buton 123\n";
});
Contains MIDI event information.
Definition event.hh:32
Parameters
idThe MIDI id of the button
handlerThe method to run

◆ mutex()

Buttons & yase::Buttons::mutex ( vector< int >  ids,
vector< function< void(const Event &)> >  handlers 
)

Associate a set of buttons with a set of method to run when the associated button is pressed. The LED of the most recently pressed button is For example

buttons.mutex({123, 234}, [](const Event &e) {
cout << "You pressed buton 123\n";
}, [](const Event &e) {
cout << "You pressed buton 234\n";
});
Parameters
idThe MIDI id of the button
handlerThe method to run

◆ off()

Buttons & yase::Buttons::off ( unsigned char  id)

Turn a button off, unilluminating it's LED

Parameters
idThe MIDI id of the button

◆ on() [1/2]

Buttons & yase::Buttons::on ( unsigned char  id)

Turn a button on, illuminating it's LED

Parameters
idThe MIDI id of the button

◆ on() [2/2]

Buttons & yase::Buttons::on ( unsigned char  id,
unsigned char  color 
)

Turn a button on, illuminating it's LED

Parameters
idThe MIDI id of the button

◆ set()

void yase::Buttons::set ( int  id,
BUTTON_STATE  state 
)

Set a button's state.

Parameters
idThe MIDI id of the button
stateThe desired state of the button

◆ toggle()

Buttons & yase::Buttons::toggle ( int  id,
function< void(const Event &)>  handler,
bool  init_on 
)

Set up a toggle button. When it is pressed, the method is run and the led is illumated (unless init_on is true). When it is pressed again, the LED is turned off.

Parameters
idThe midi id of the button
handlerThe function to call when the button is pressed
init_onWhether the led for the button is initially on or off

◆ update()

void yase::Buttons::update ( )
virtual

This method should be overridden by derived classes. It will be called repeatedly by a synthesizer at a frequency determined by SAMPLE_RATE.

Implements yase::Module.


The documentation for this class was generated from the following files: