Acoustic Touch Recognition
Classes | Public Member Functions | Static Public Member Functions | Private Types | Private Attributes | List of all members
ChucKHandler Class Reference

This class is in charge of handling multiple instances of chuck, as much instances as the user wants, but one per device. More...

#include <libacoustic_touch.h>

Classes

struct  ck_soundCardAttributes
 

Public Member Functions

 ChucKHandler (const vector< string > &)
 Construct a new Chuck Handler:: Chuck Handler object. More...
 
 ChucKHandler (const vector< string > &, const vector< int > &, const vector< int > &, const string &="default")
 Construct a new ChucKHandler object with a set of parameters. More...
 
 ChucKHandler (const vector< string > &, const vector< int > &, const vector< int > &, const vector< bool > &, const string &="default")
 Construct a new ChucKHandler object with a set of parameters. More...
 
 ~ChucKHandler ()
 
string getRobot () const
 Returns the value of the attribute robot_. More...
 
string getChucKMode () const
 Returns the current mode of ChucK installed in the system. More...
 
map< string, ck_cardAttribs_tgetSoundCards () const
 Returns a map containing the soundcards' ID's and its assigned attributes. More...
 
vector< string > getSoundCardIDs () const
 Returns the set of soundcard ids. More...
 
string getSoundCardID (const int &) const
 Returns a single soundcard id from an attribute vector containing all the soundcard id's. More...
 
int getSoundCardIndex (const string &) const
 Returns the index (order given by the system) of a soundcard from its id. More...
 
int getSoundCardNumber (const string &) const
 Returns the number (order given by the user) of a soundcard from its id. More...
 
int getSoundCardVolume (const string &) const
 Returns the volume assigned to a soundcard. More...
 
bool getSoundCardCapacitive (const string &) const
 Returns the capacitive condition assigned to a soundcard. More...
 
bool getKillChucK () const
 Returns the value of the attribute kill_chuck_. More...
 
void setRobot (const string &)
 Sets the attribute robot_. More...
 
void setChucKMode ()
 Obtains the ChucK version (alsa, pulse or jack) from the proper CLI ChucK command. More...
 
void setSoundCards (const vector< string > &)
 Create the list of tuples based in a set of soundcard ID. It is assumed that the number of the card is correlated to its position in the vector. More...
 
void setSoundCards (const vector< string > &, const vector< int > &)
 Sets values for a set of soundcards. It assumes no soundcards with the selected ids, so the function creates them from zero (revise this behaviour) More...
 
void setSoundCards (const vector< string > &, const vector< int > &, const vector< int > &)
 Sets values for a set of soundcards. It assumes no soundcards with the selected ids, so the function creates them from zero (revise this behaviour) More...
 
void setSoundCards (const vector< string > &, const vector< int > &, const vector< int > &, const vector< bool > &)
 
void setSoundCardIDs (const vector< string > &)
 Changes values of the soundcard ids contained in a vector. More...
 
void setSoundCardIndex (const int &, const string &)
 Sets the Index (pulse or alsa) of the selected soundcard. More...
 
void setSoundCardNumber (const int &, const string &)
 Sets the number of a soundcard internal attribute. More...
 
void setSoundCardVolume (const int &, const string &)
 Changes the assigned volume for a certain soundcard internal attribute. It actually does not changes the values externally (e.g. in pulse or alsa) More...
 
void setSoundCardCapacitive (const bool &, const string &)
 Sets the capacitive condition for a certain soundcard internal attribute. This capacitive condition means if there is a capacitive sensor attached to the microphone. More...
 
void setKillChucK (const bool &)
 Changes the value of the attribute kill_chuck_. More...
 
void printSoundCards () const
 Prints the id's and the attributes of all the soundcards contained in the Handler. Designed for debugging purpouses. More...
 
void setAttributesAlsa ()
 Fills the soundcard attributes for ChucK's Alsa mode. More...
 
void setAttributesPulse ()
 Fills the soundcard attributes for ChucK's Pulse mode. More...
 
void setSoundCardInputVol (const int &, const string &)
 Changes the capture volume of a soundcard. More...
 
void chucKThread (const string &)
 This function is destined to run an instance of ChucK in a C++11 thread. More...
 
void launchChucK (const bool &=CK_DEBUG)
 Init function, prepares the ChucK command and launches an instance per soundcard through several fork() calls. More...
 
void killChucK ()
 

Static Public Member Functions

static void getShellOutput (const string &, string *, string *)
 Gets the shell output. Returns from sterr and stdout. More...
 
static string fetchAlsaModel (const string &)
 Finds the corresponding model for a certain ALSA soundcard. More...
 
static vector< string > fetchAlsaModels (const vector< string > &)
 From a given set of soundcard ids, this function return a vector with their unique soundcard models. There could be more than one model in the output, but there will not be repeated models within the resultant string. More...
 
static vector< string > fetchAlsaIDs (const string &)
 This function tries to find a set of devices and their attributes by their common soundcard model. More...
 
static vector< int > fetchChucKIndexes (const string &)
 Retrieves all the devices' indexes from the command 'chuck –probe' for a given soundcard model. More...
 

Private Types

typedef struct ChucKHandler::ck_soundCardAttributes ck_cardAttribs_t
 

Private Attributes

string robot_
 
string chuck_mode_
 
vector< string > sndcard_ids_
 
map< string, ck_cardAttribs_tsound_cards_
 
vector< thread > ck_threads_
 
bool kill_chuck_
 

Detailed Description

This class is in charge of handling multiple instances of chuck, as much instances as the user wants, but one per device.

Member Typedef Documentation

◆ ck_cardAttribs_t

Constructor & Destructor Documentation

◆ ChucKHandler() [1/3]

ChucKHandler::ChucKHandler ( const vector< string > &  soundcards)

Construct a new Chuck Handler:: Chuck Handler object.

Parameters
soundcardsA set of strings containing the soundcard names in the desired order

◆ ChucKHandler() [2/3]

ChucKHandler::ChucKHandler ( const vector< string > &  soundcards,
const vector< int > &  mic_numbers,
const vector< int > &  mic_vols,
const string &  robot = "default" 
)

Construct a new ChucKHandler object with a set of parameters.

Parameters
soundcardsA set of soundcard ids
mic_numbersA number representing the order of the soundcards
mic_volsThe corresponding input volume of the soundcards

◆ ChucKHandler() [3/3]

ChucKHandler::ChucKHandler ( const vector< string > &  soundcards,
const vector< int > &  mic_numbers,
const vector< int > &  mic_vols,
const vector< bool > &  is_capacitive,
const string &  robot = "default" 
)

Construct a new ChucKHandler object with a set of parameters.

Parameters
soundcards
mic_numbers
mic_vols
is_capacitive
robot

◆ ~ChucKHandler()

ChucKHandler::~ChucKHandler ( )
inline

Member Function Documentation

◆ chucKThread()

void ChucKHandler::chucKThread ( const string &  command)

This function is destined to run an instance of ChucK in a C++11 thread.

Parameters
command

◆ fetchAlsaIDs()

vector< string > ChucKHandler::fetchAlsaIDs ( const string &  sndcard_model)
static

This function tries to find a set of devices and their attributes by their common soundcard model.

Parameters
sndcard_modelThe soundcard model
Returns
vector<string> The set of soundcards that share a model

◆ fetchAlsaModel()

string ChucKHandler::fetchAlsaModel ( const string &  soundcard_id)
static

Finds the corresponding model for a certain ALSA soundcard.

Parameters
soundcard_idThe id of the soundcard to find
Returns
string The corresponding model of the selected id

◆ fetchAlsaModels()

vector< string > ChucKHandler::fetchAlsaModels ( const vector< string > &  soundcard_ids)
static

From a given set of soundcard ids, this function return a vector with their unique soundcard models. There could be more than one model in the output, but there will not be repeated models within the resultant string.

Parameters
soundcard_idsA set of soundcard ids
Returns
vector<string> A set of unique soundcard models

◆ fetchChucKIndexes()

vector< int > ChucKHandler::fetchChucKIndexes ( const string &  sndcard_model)
static

Retrieves all the devices' indexes from the command 'chuck –probe' for a given soundcard model.

Parameters
sndcard_model
Returns
vector<int>

◆ getChucKMode()

string ChucKHandler::getChucKMode ( ) const

Returns the current mode of ChucK installed in the system.

Returns
string The value of the current mode of ChucK

◆ getKillChucK()

bool ChucKHandler::getKillChucK ( ) const

Returns the value of the attribute kill_chuck_.

Returns
true
false

◆ getRobot()

string ChucKHandler::getRobot ( ) const

Returns the value of the attribute robot_.

Returns
string The value of the attribute

◆ getShellOutput()

void ChucKHandler::getShellOutput ( const string &  command,
string *  std_out,
string *  std_err 
)
static

Gets the shell output. Returns from sterr and stdout.

Parameters
commandThe command
std_outThe stdout output
std_errThe stderr output

◆ getSoundCardCapacitive()

bool ChucKHandler::getSoundCardCapacitive ( const string &  id) const

Returns the capacitive condition assigned to a soundcard.

Parameters
id
Returns
true
false

◆ getSoundCardID()

string ChucKHandler::getSoundCardID ( const int &  pos) const

Returns a single soundcard id from an attribute vector containing all the soundcard id's.

Parameters
posThe position of the id in the vector
Returns
string The id in this position

◆ getSoundCardIDs()

vector< string > ChucKHandler::getSoundCardIDs ( ) const

Returns the set of soundcard ids.

Returns
vector<string> The ids in a vector

◆ getSoundCardIndex()

int ChucKHandler::getSoundCardIndex ( const string &  id) const

Returns the index (order given by the system) of a soundcard from its id.

Parameters
idThe id of the soundcard
Returns
int The index of the selected soundcard

◆ getSoundCardNumber()

int ChucKHandler::getSoundCardNumber ( const string &  id) const

Returns the number (order given by the user) of a soundcard from its id.

Parameters
idThe id of the soundcard
Returns
int The number (order) of the soundcard

◆ getSoundCards()

map< string, ChucKHandler::ck_cardAttribs_t > ChucKHandler::getSoundCards ( ) const

Returns a map containing the soundcards' ID's and its assigned attributes.

Returns
map<string, ChucKHandler::ck_cardAttribs_t> A map containing a set of soundcard attributes

◆ getSoundCardVolume()

int ChucKHandler::getSoundCardVolume ( const string &  id) const

Returns the volume assigned to a soundcard.

Parameters
idThe id of the selected soundcard
Returns
int The input volume assigned to this soundcard

◆ killChucK()

void ChucKHandler::killChucK ( )

◆ launchChucK()

void ChucKHandler::launchChucK ( const bool &  debug = CK_DEBUG)

Init function, prepares the ChucK command and launches an instance per soundcard through several fork() calls.

Returns
void

◆ printSoundCards()

void ChucKHandler::printSoundCards ( ) const

Prints the id's and the attributes of all the soundcards contained in the Handler. Designed for debugging purpouses.

◆ setAttributesAlsa()

void ChucKHandler::setAttributesAlsa ( )

Fills the soundcard attributes for ChucK's Alsa mode.

◆ setAttributesPulse()

void ChucKHandler::setAttributesPulse ( )

Fills the soundcard attributes for ChucK's Pulse mode.

◆ setChucKMode()

void ChucKHandler::setChucKMode ( )

Obtains the ChucK version (alsa, pulse or jack) from the proper CLI ChucK command.

◆ setKillChucK()

void ChucKHandler::setKillChucK ( const bool &  kill_chuck)

Changes the value of the attribute kill_chuck_.

Parameters
kill_chuckA boolean representing the value to set

◆ setRobot()

void ChucKHandler::setRobot ( const string &  robot)

Sets the attribute robot_.

Parameters
robotThe robot in which the Handler is running

◆ setSoundCardCapacitive()

void ChucKHandler::setSoundCardCapacitive ( const bool &  cap,
const string &  id 
)

Sets the capacitive condition for a certain soundcard internal attribute. This capacitive condition means if there is a capacitive sensor attached to the microphone.

Parameters
cap
id

◆ setSoundCardIDs()

void ChucKHandler::setSoundCardIDs ( const vector< string > &  sndcard_ids)

Changes values of the soundcard ids contained in a vector.

Parameters
sndcard_ids

◆ setSoundCardIndex()

void ChucKHandler::setSoundCardIndex ( const int &  indx,
const string &  id 
)

Sets the Index (pulse or alsa) of the selected soundcard.

Parameters
indxThe selected index to be changed
idThe id of the card that will suffer the change

◆ setSoundCardInputVol()

void ChucKHandler::setSoundCardInputVol ( const int &  vol,
const string &  id 
)

Changes the capture volume of a soundcard.

Parameters
volThe desired volume for the soundcard
idThe id of the corresponding soundcard

◆ setSoundCardNumber()

void ChucKHandler::setSoundCardNumber ( const int &  num,
const string &  id 
)

Sets the number of a soundcard internal attribute.

Parameters
numThe number, commonly associated with the order set by the user
idThe id of the soundcard whose number will change

◆ setSoundCards() [1/4]

void ChucKHandler::setSoundCards ( const vector< string > &  sndcard_ids)

Create the list of tuples based in a set of soundcard ID. It is assumed that the number of the card is correlated to its position in the vector.

Parameters
sndcard_idsA vector containing a set of soundcard ids

◆ setSoundCards() [2/4]

void ChucKHandler::setSoundCards ( const vector< string > &  sndcard_ids,
const vector< int > &  volumes 
)

Sets values for a set of soundcards. It assumes no soundcards with the selected ids, so the function creates them from zero (revise this behaviour)

Parameters
sndcard_idsThe ids of the soundcards to create
volumesThe input volume of the soundcards

◆ setSoundCards() [3/4]

void ChucKHandler::setSoundCards ( const vector< string > &  sndcard_ids,
const vector< int > &  mic_nums,
const vector< int > &  volumes 
)

Sets values for a set of soundcards. It assumes no soundcards with the selected ids, so the function creates them from zero (revise this behaviour)

Parameters
sndcard_idsThe ids of the soundcards to create
mic_numsThe order of the soundcards desired by the user
volumesThe input volume of the soundcards

◆ setSoundCards() [4/4]

void ChucKHandler::setSoundCards ( const vector< string > &  sndcard_ids,
const vector< int > &  mic_nums,
const vector< int > &  volumes,
const vector< bool > &  is_capacitive 
)

◆ setSoundCardVolume()

void ChucKHandler::setSoundCardVolume ( const int &  vol,
const string &  id 
)

Changes the assigned volume for a certain soundcard internal attribute. It actually does not changes the values externally (e.g. in pulse or alsa)

Parameters
volThe desired volume
idThe id of the soundcard

Member Data Documentation

◆ chuck_mode_

string ChucKHandler::chuck_mode_
private

◆ ck_threads_

vector<thread> ChucKHandler::ck_threads_
private

◆ kill_chuck_

bool ChucKHandler::kill_chuck_
private

◆ robot_

string ChucKHandler::robot_
private

◆ sndcard_ids_

vector<string> ChucKHandler::sndcard_ids_
private

◆ sound_cards_

map<string, ck_cardAttribs_t> ChucKHandler::sound_cards_
private

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