Skip to content

Commit

Permalink
do not use boost for command line option parsing, fix documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
gisogrimm committed Mar 12, 2024
1 parent 0af7268 commit 3697c8c
Show file tree
Hide file tree
Showing 9 changed files with 237 additions and 251 deletions.
9 changes: 7 additions & 2 deletions apps/src/tascar_cli.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,18 @@ int main(int argc, char** argv)
{"output", 1, 0, 'o'}, {"range", 1, 0, 'r'},
{"licenses", 0, 0, 'l'}, {"validate", 0, 0, 'v'},
{"variables", 0, 0, 'a'}, {0, 0, 0, 0}};
std::map<std::string, std::string> helpmap;
helpmap["output"] = "Output sound file name.";
helpmap["licenses"] = "Show licenses";
helpmap["variables"] = "Show variables";
int opt(0);
int option_index(0);
while((opt = getopt_long(argc, argv, options, long_options,
&option_index)) != -1) {
switch(opt) {
case 'h':
TASCAR::app_usage("tascar_cli", long_options, "configfile");
TASCAR::app_usage("tascar_cli", long_options, "configfile", "",
helpmap);
return 0;
case 'j':
jackname = optarg;
Expand All @@ -107,7 +112,7 @@ int main(int argc, char** argv)
if(optind < argc)
cfgfile = argv[optind++];
if(cfgfile.size() == 0) {
TASCAR::app_usage("tascar_cli", long_options, "configfile");
TASCAR::app_usage("tascar_cli", long_options, "sessionfile", "", helpmap);
return -1;
}
TASCAR::session_t session(cfgfile, TASCAR::xml_doc_t::LOAD_FILE, cfgfile);
Expand Down
98 changes: 48 additions & 50 deletions apps/src/tascar_hdspmixer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,28 @@
* Version 3 along with TASCAR. If not, see <http://www.gnu.org/licenses/>.
*/


/*
* hos_mainmix - read gain from jack port, create direct mapping in
* HDSP 9652 from software output to hardware output with gain from
* jack port.
*/

#include "cli.h"
#include "tascar.h"
#include <alsa/asoundlib.h>
#include <getopt.h>
#include <iostream>
#include "tascar.h"

class mainmix_t {
public:
mainmix_t(const std::string& dev, uint32_t channels);
virtual ~mainmix_t();
void activate(uint32_t ch_in, uint32_t ch_out,uint32_t nch);
void activate(uint32_t ch_in, uint32_t ch_out, uint32_t nch);

private:
snd_ctl_elem_id_t *id;
snd_ctl_elem_value_t *ctl;
snd_ctl_t *handle;
snd_ctl_elem_id_t* id;
snd_ctl_elem_value_t* ctl;
snd_ctl_t* handle;
};

mainmix_t::mainmix_t(const std::string& device, uint32_t channels)
Expand All @@ -51,18 +52,18 @@ mainmix_t::mainmix_t(const std::string& device, uint32_t channels)
snd_ctl_elem_value_alloca(&ctl);
snd_ctl_elem_value_set_id(ctl, id);
int err;
if ((err = snd_ctl_open(&handle, device.c_str(), SND_CTL_NONBLOCK)) < 0) {
if((err = snd_ctl_open(&handle, device.c_str(), SND_CTL_NONBLOCK)) < 0) {
std::string msg("Alsa error: ");
msg += snd_strerror(err);
msg += " (device: "+device+")";
msg += " (device: " + device + ")";
throw TASCAR::ErrMsg(msg);
}
for( uint32_t k_in=0;k_in<2*channels;k_in++ ){
for( uint32_t k_out=0;k_out<channels;k_out++ ){
for(uint32_t k_in = 0; k_in < 2 * channels; k_in++) {
for(uint32_t k_out = 0; k_out < channels; k_out++) {
snd_ctl_elem_value_set_integer(ctl, 0, k_in);
snd_ctl_elem_value_set_integer(ctl, 1, k_out);
snd_ctl_elem_value_set_integer(ctl, 2, 0);
if ((err = snd_ctl_elem_write(handle, ctl)) < 0) {
if((err = snd_ctl_elem_write(handle, ctl)) < 0) {
std::string msg("Alsa error: ");
msg += snd_strerror(err);
throw TASCAR::ErrMsg(msg);
Expand All @@ -76,56 +77,53 @@ mainmix_t::~mainmix_t()
snd_ctl_close(handle);
}

void mainmix_t::activate(uint32_t ch_in, uint32_t ch_out,uint32_t nch)
void mainmix_t::activate(uint32_t ch_in, uint32_t ch_out, uint32_t nch)
{
for( uint32_t k=0;k<nch;k++ ){
snd_ctl_elem_value_set_integer(ctl, 0, k+ch_in);
snd_ctl_elem_value_set_integer(ctl, 1, k+ch_out);
for(uint32_t k = 0; k < nch; k++) {
snd_ctl_elem_value_set_integer(ctl, 0, k + ch_in);
snd_ctl_elem_value_set_integer(ctl, 1, k + ch_out);
snd_ctl_elem_value_set_integer(ctl, 2, 32767);
int err(0);
if ((err = snd_ctl_elem_write(handle, ctl)) < 0) {
if((err = snd_ctl_elem_write(handle, ctl)) < 0) {
std::string msg("Alsa error: ");
msg += snd_strerror(err);
throw TASCAR::ErrMsg(msg);
}
}
}

void usage(struct option * opt)
{
std::cout << "Usage:\n\ntascar_hdspmixer [options]\n\nOptions:\n\n";
std::cout << "Simple control of HDSP 9652 matrix mixer\n";
while( opt->name ){
std::cout << " -" << (char)(opt->val) << " " << (opt->has_arg?"#":"") <<
"\n --" << opt->name << (opt->has_arg?"=#":"") << "\n\n";
opt++;
}
}
// void usage(struct option * opt)
//{
// std::cout << "Usage:\n\ntascar_hdspmixer [options]\n\nOptions:\n\n";
// std::cout << "Simple control of HDSP 9652 matrix mixer\n";
// while( opt->name ){
// std::cout << " -" << (char)(opt->val) << " " << (opt->has_arg?"#":"") <<
// "\n --" << opt->name << (opt->has_arg?"=#":"") << "\n\n";
// opt++;
// }
// }

int main(int argc, char** argv)
{
const char *options = "hisad:c:";
struct option long_options[] = {
{ "help", 0, 0, 'h' },
{ "input", 0, 0, 'i' },
{ "alsa", 0, 0, 'a' },
{ "stereo", 0, 0, 's' },
{ "device", 1,0,'d'},
{"channels",1,0,'c'},
{ 0, 0, 0, 0 }
};
const char* options = "hisad:c:";
struct option long_options[] = {
{"help", 0, 0, 'h'}, {"input", 0, 0, 'i'}, {"alsa", 0, 0, 'a'},
{"stereo", 0, 0, 's'}, {"device", 1, 0, 'd'}, {"channels", 1, 0, 'c'},
{0, 0, 0, 0}};
std::string device("hw:DSP");
uint32_t channels(26);
bool b_input(false);
bool b_soft(false);
bool b_stereo(false);
int opt(0);
int option_index(0);
while( (opt = getopt_long(argc, argv, options,
long_options, &option_index)) != -1){
switch(opt){
while((opt = getopt_long(argc, argv, options, long_options, &option_index)) !=
-1) {
switch(opt) {
case 'h':
usage(long_options);
TASCAR::app_usage("tascar_hdspmixer", long_options, "",
"Simple control of HDSP 9652 matrix mixer.\n\n");
// usage(long_options);
return 0;
case 'i':
b_input = true;
Expand All @@ -144,19 +142,19 @@ int main(int argc, char** argv)
break;
}
}
try{
mainmix_t mm(device,channels);
if( b_input )
mm.activate(0,0,channels);
if( b_soft )
mm.activate(channels,0,channels);
if( b_stereo ){
for(uint32_t k=0;k<(channels>>1);k++){
mm.activate(channels,2*k,2);
try {
mainmix_t mm(device, channels);
if(b_input)
mm.activate(0, 0, channels);
if(b_soft)
mm.activate(channels, 0, channels);
if(b_stereo) {
for(uint32_t k = 0; k < (channels >> 1); k++) {
mm.activate(channels, 2 * k, 2);
}
}
}
catch( const std::exception& e ){
catch(const std::exception& e) {
std::cerr << "Error: " << e.what() << std::endl;
return 1;
}
Expand Down
Loading

0 comments on commit 3697c8c

Please sign in to comment.