mirror of
https://gitlab.com/then-try-this/samplebrain.git
synced 2025-05-12 02:27:21 +00:00
made the 3 osc ports configurable via (cross-platform) config scripts and move them outside of well used ranges for UDP
This commit is contained in:
parent
5469a8f253
commit
5e347f7f13
@ -27,9 +27,11 @@
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
MainWindow::MainWindow() :
|
MainWindow::MainWindow(const string &port, const string &audio_port, const string &process_port) :
|
||||||
m_last_file("."),
|
m_last_file("."),
|
||||||
m_feedback("8890")
|
m_feedback(port),
|
||||||
|
m_audio_port(audio_port),
|
||||||
|
m_process_port(process_port)
|
||||||
{
|
{
|
||||||
m_sound_item_enable_mapper = new QSignalMapper(this);
|
m_sound_item_enable_mapper = new QSignalMapper(this);
|
||||||
m_sound_item_delete_mapper = new QSignalMapper(this);
|
m_sound_item_delete_mapper = new QSignalMapper(this);
|
||||||
@ -59,8 +61,8 @@ MainWindow::MainWindow() :
|
|||||||
for (int i=0; i<10; i++) {
|
for (int i=0; i<10; i++) {
|
||||||
osc_destination d;
|
osc_destination d;
|
||||||
d.m_id=i;
|
d.m_id=i;
|
||||||
d.m_audio_address = lo_address_new_from_url("osc.udp://localhost:8888");
|
d.m_audio_address = lo_address_new_from_url(string("osc.udp://localhost:"+m_audio_port).c_str());
|
||||||
d.m_process_address = lo_address_new_from_url("osc.udp://localhost:8889");
|
d.m_process_address = lo_address_new_from_url(string("osc.udp://localhost:"+m_process_port).c_str());
|
||||||
if (i==0) d.m_enabled=true;
|
if (i==0) d.m_enabled=true;
|
||||||
else d.m_enabled=false;
|
else d.m_enabled=false;
|
||||||
add_gui_address(d,enable_mapper);
|
add_gui_address(d,enable_mapper);
|
||||||
|
593
app/MainWindow.h
593
app/MainWindow.h
@ -18,6 +18,7 @@
|
|||||||
#include <QDirIterator>
|
#include <QDirIterator>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
|
#include <QMessageBox>
|
||||||
#include "ui_samplebrain.h"
|
#include "ui_samplebrain.h"
|
||||||
#include "SettingsDialog.h"
|
#include "SettingsDialog.h"
|
||||||
|
|
||||||
@ -34,11 +35,19 @@ using namespace spiralcore;
|
|||||||
|
|
||||||
class MainWindow : public QMainWindow
|
class MainWindow : public QMainWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MainWindow();
|
MainWindow(const string &port, const string &audio_port, const string &process_port);
|
||||||
|
|
||||||
|
void message(const string &msg) {
|
||||||
|
QMessageBox::information(this,"problem",msg.c_str(), QMessageBox::Ok);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ok() {
|
||||||
|
return m_feedback.ok();
|
||||||
|
}
|
||||||
|
|
||||||
// all this to work around liblo's use of varargs...
|
// all this to work around liblo's use of varargs...
|
||||||
void send_audio_osc(const char *name, const char *types) {
|
void send_audio_osc(const char *name, const char *types) {
|
||||||
for (auto dest:m_destinations) {
|
for (auto dest:m_destinations) {
|
||||||
@ -102,344 +111,346 @@ protected:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
void play_slot() { send_audio_osc("/start",""); }
|
void play_slot() { send_audio_osc("/start",""); }
|
||||||
void stop_slot() { send_audio_osc("/pause",""); }
|
void stop_slot() { send_audio_osc("/pause",""); }
|
||||||
|
|
||||||
void ratio_slot(int s) {
|
void ratio_slot(int s) {
|
||||||
send_audio_osc("/ratio","f",s/100.0f);
|
send_audio_osc("/ratio","f",s/100.0f);
|
||||||
m_Ui.doubleSpinBoxRatio->setValue(s/100.0f);
|
m_Ui.doubleSpinBoxRatio->setValue(s/100.0f);
|
||||||
}
|
}
|
||||||
void ratio_slot(double s) {
|
void ratio_slot(double s) {
|
||||||
send_audio_osc("/ratio","f",s);
|
send_audio_osc("/ratio","f",s);
|
||||||
m_Ui.sliderRatio->setValue(s*100);
|
m_Ui.sliderRatio->setValue(s*100);
|
||||||
}
|
}
|
||||||
|
|
||||||
void n_ratio_slot(int s) {
|
void n_ratio_slot(int s) {
|
||||||
send_audio_osc("/n_ratio","f",s/100.0f);
|
send_audio_osc("/n_ratio","f",s/100.0f);
|
||||||
m_Ui.doubleSpinBoxNRatio->setValue(s/100.0f);
|
m_Ui.doubleSpinBoxNRatio->setValue(s/100.0f);
|
||||||
}
|
}
|
||||||
void n_ratio_slot(double s) {
|
void n_ratio_slot(double s) {
|
||||||
send_audio_osc("/n_ratio","f",s);
|
send_audio_osc("/n_ratio","f",s);
|
||||||
m_Ui.sliderNRatio->setValue(s*100);
|
m_Ui.sliderNRatio->setValue(s*100);
|
||||||
}
|
}
|
||||||
|
|
||||||
void autotune(int s) {
|
void autotune(int s) {
|
||||||
send_audio_osc("/autotune","f",s/100.0f);
|
send_audio_osc("/autotune","f",s/100.0f);
|
||||||
m_Ui.doubleSpinBoxAutotune->setValue(s/100.0f);
|
m_Ui.doubleSpinBoxAutotune->setValue(s/100.0f);
|
||||||
}
|
}
|
||||||
void autotune(double s) {
|
void autotune(double s) {
|
||||||
send_audio_osc("/autotune","f",s);
|
send_audio_osc("/autotune","f",s);
|
||||||
m_Ui.sliderAutotune->setValue(s*100);
|
m_Ui.sliderAutotune->setValue(s*100);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fft1_start_slot(int s) { send_audio_osc("/fft1_start","i",s); }
|
void fft1_start_slot(int s) { send_audio_osc("/fft1_start","i",s); }
|
||||||
void fft1_end_slot(int s) { send_audio_osc("/fft1_end","i",s); }
|
void fft1_end_slot(int s) { send_audio_osc("/fft1_end","i",s); }
|
||||||
void fft2_start_slot(int s){} // { m_renderer->get_params()->m_fft2_start=s; }
|
void fft2_start_slot(int s){} // { m_renderer->get_params()->m_fft2_start=s; }
|
||||||
void fft2_end_slot(int s){} // { m_renderer->get_params()->m_fft2_end=s; }
|
void fft2_end_slot(int s){} // { m_renderer->get_params()->m_fft2_end=s; }
|
||||||
|
|
||||||
void n_mix_slot(int s) {
|
void n_mix_slot(int s) {
|
||||||
send_audio_osc("/n_mix","f",s/100.0f);
|
send_audio_osc("/n_mix","f",s/100.0f);
|
||||||
m_Ui.doubleSpinBoxNMix->setValue(s/100.0f);
|
m_Ui.doubleSpinBoxNMix->setValue(s/100.0f);
|
||||||
}
|
}
|
||||||
void n_mix_slot(double s) {
|
void n_mix_slot(double s) {
|
||||||
send_audio_osc("/n_mix","f",s);
|
send_audio_osc("/n_mix","f",s);
|
||||||
m_Ui.sliderNMix->setValue(s*100);
|
m_Ui.sliderNMix->setValue(s*100);
|
||||||
}
|
}
|
||||||
|
|
||||||
void novelty_slot(int s) {
|
void novelty_slot(int s) {
|
||||||
send_audio_osc("/novelty","f",s/100.0f);
|
send_audio_osc("/novelty","f",s/100.0f);
|
||||||
m_Ui.doubleSpinBoxNovelty->setValue(s/100.0f);
|
m_Ui.doubleSpinBoxNovelty->setValue(s/100.0f);
|
||||||
}
|
}
|
||||||
void novelty_slot(double s) {
|
void novelty_slot(double s) {
|
||||||
send_audio_osc("/novelty","f",s);
|
send_audio_osc("/novelty","f",s);
|
||||||
m_Ui.sliderNovelty->setValue(s*100);
|
m_Ui.sliderNovelty->setValue(s*100);
|
||||||
}
|
}
|
||||||
|
|
||||||
void boredom_slot(int s) {
|
void boredom_slot(int s) {
|
||||||
float v=s/100.0f;
|
float v=s/100.0f;
|
||||||
send_audio_osc("/boredom","f",v);
|
send_audio_osc("/boredom","f",v);
|
||||||
m_Ui.doubleSpinBoxBoredom->setValue(v);
|
m_Ui.doubleSpinBoxBoredom->setValue(v);
|
||||||
}
|
}
|
||||||
void boredom_slot(double s) {
|
void boredom_slot(double s) {
|
||||||
send_audio_osc("/boredom","f",s);
|
send_audio_osc("/boredom","f",s);
|
||||||
m_Ui.sliderBoredom->setValue(s*100);
|
m_Ui.sliderBoredom->setValue(s*100);
|
||||||
}
|
}
|
||||||
void synapses(int s) {
|
void synapses(int s) {
|
||||||
send_audio_osc("/synapses","i",s);
|
send_audio_osc("/synapses","i",s);
|
||||||
}
|
}
|
||||||
void target_mix_slot(int s) {
|
void target_mix_slot(int s) {
|
||||||
send_audio_osc("/target_mix","f",s/100.0f);
|
send_audio_osc("/target_mix","f",s/100.0f);
|
||||||
m_Ui.doubleSpinBoxTargetMix->setValue(s/100.0f);
|
m_Ui.doubleSpinBoxTargetMix->setValue(s/100.0f);
|
||||||
}
|
}
|
||||||
void target_mix_slot(double s) {
|
void target_mix_slot(double s) {
|
||||||
send_audio_osc("/target_mix","f",s);
|
send_audio_osc("/target_mix","f",s);
|
||||||
m_Ui.sliderTargetMix->setValue(s*100);
|
m_Ui.sliderTargetMix->setValue(s*100);
|
||||||
}
|
}
|
||||||
void search_stretch(int s) {
|
void search_stretch(int s) {
|
||||||
send_audio_osc("/search-stretch","i",s);
|
send_audio_osc("/search-stretch","i",s);
|
||||||
}
|
}
|
||||||
void slide_error(int s) {
|
void slide_error(int s) {
|
||||||
send_audio_osc("/slide-error","i",s);
|
send_audio_osc("/slide-error","i",s);
|
||||||
}
|
}
|
||||||
void stickyness_slot(int s) {
|
void stickyness_slot(int s) {
|
||||||
send_audio_osc("/stickyness","f",s/100.0f);
|
send_audio_osc("/stickyness","f",s/100.0f);
|
||||||
m_Ui.doubleSpinBoxStickyness->setValue(s/100.0f);
|
m_Ui.doubleSpinBoxStickyness->setValue(s/100.0f);
|
||||||
}
|
}
|
||||||
void stickyness_slot(double s) {
|
void stickyness_slot(double s) {
|
||||||
send_audio_osc("/stickyness","f",s);
|
send_audio_osc("/stickyness","f",s);
|
||||||
m_Ui.sliderStickyness->setValue(s*100);
|
m_Ui.sliderStickyness->setValue(s*100);
|
||||||
}
|
}
|
||||||
|
|
||||||
void volume_slot(int s) { send_audio_osc("/volume","f",s/100.0f); }
|
void volume_slot(int s) { send_audio_osc("/volume","f",s/100.0f); }
|
||||||
void algo(int n) { send_audio_osc("/search_algo","i",n); }
|
void algo(int n) { send_audio_osc("/search_algo","i",n); }
|
||||||
|
|
||||||
void run_slot() {}
|
void run_slot() {}
|
||||||
void load_target() {
|
void load_target() {
|
||||||
m_last_file=QFileDialog::getOpenFileName(
|
m_last_file=QFileDialog::getOpenFileName(
|
||||||
this,
|
this,
|
||||||
QString("Select an wav file"),
|
QString("Select an wav file"),
|
||||||
m_last_file,
|
m_last_file,
|
||||||
QString("Sounds (*.wav)"));
|
QString("Sounds (*.wav)"));
|
||||||
|
|
||||||
send_process_osc("/load_target","s",m_last_file.toStdString().c_str());
|
send_process_osc("/load_target","s",m_last_file.toStdString().c_str());
|
||||||
}
|
}
|
||||||
void target_block_size(int s) { send_process_osc("/target_block_size","i",s); }
|
void target_block_size(int s) { send_process_osc("/target_block_size","i",s); }
|
||||||
void target_block_overlap(double s) { send_process_osc("/target_overlap","f",s); }
|
void target_block_overlap(double s) { send_process_osc("/target_overlap","f",s); }
|
||||||
void generate_target_blocks() { send_process_osc("/generate_target",""); }
|
void generate_target_blocks() { send_process_osc("/generate_target",""); }
|
||||||
void block_size(int s) { send_process_osc("/source_block_size","i",s); }
|
void block_size(int s) { send_process_osc("/source_block_size","i",s); }
|
||||||
void block_overlap(double s) { send_process_osc("/source_overlap","f",s); }
|
void block_overlap(double s) { send_process_osc("/source_overlap","f",s); }
|
||||||
void fft_spectrum_size(int) {}
|
void fft_spectrum_size(int) {}
|
||||||
void generate() { send_process_osc("/generate_brain",""); }
|
void generate() { send_process_osc("/generate_brain",""); }
|
||||||
void load_sound() {
|
void load_sound() {
|
||||||
m_last_file=QFileDialog::getOpenFileName(
|
m_last_file=QFileDialog::getOpenFileName(
|
||||||
this,
|
this,
|
||||||
QString("Select a wav file"),
|
QString("Select a wav file"),
|
||||||
m_last_file,
|
m_last_file,
|
||||||
QString("Sounds (*.wav)"));
|
QString("Sounds (*.wav)"));
|
||||||
|
|
||||||
send_process_osc("/load_sample","s",m_last_file.toStdString().c_str());
|
send_process_osc("/load_sample","s",m_last_file.toStdString().c_str());
|
||||||
|
|
||||||
sound_items::sound_item &si = m_sound_items.add(m_Ui.brain_contents, m_last_file.toStdString(),true);
|
sound_items::sound_item &si = m_sound_items.add(m_Ui.brain_contents, m_last_file.toStdString(),true);
|
||||||
|
|
||||||
|
QObject::connect(si.m_enable, SIGNAL(clicked()), m_sound_item_enable_mapper, SLOT(map()));
|
||||||
|
m_sound_item_enable_mapper->setMapping(si.m_enable, si.m_id);
|
||||||
|
QObject::connect(si.m_del, SIGNAL(clicked()), m_sound_item_delete_mapper, SLOT(map()));
|
||||||
|
m_sound_item_delete_mapper->setMapping(si.m_del, si.m_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void load_sounds() {
|
||||||
|
m_last_file=QFileDialog::getExistingDirectory(this,
|
||||||
|
QString("Select a directory"),
|
||||||
|
m_last_file);
|
||||||
|
|
||||||
|
|
||||||
|
QDirIterator dirIt(m_last_file,QDirIterator::Subdirectories);
|
||||||
|
while (dirIt.hasNext()) {
|
||||||
|
dirIt.next();
|
||||||
|
if (QFileInfo(dirIt.filePath()).isFile() &&
|
||||||
|
QFileInfo(dirIt.filePath()).suffix() == "wav") {
|
||||||
|
send_process_osc("/load_sample","s",dirIt.filePath().toStdString().c_str());
|
||||||
|
|
||||||
|
sound_items::sound_item &si = m_sound_items.add(m_Ui.brain_contents, dirIt.filePath().toStdString(),true);
|
||||||
|
|
||||||
QObject::connect(si.m_enable, SIGNAL(clicked()), m_sound_item_enable_mapper, SLOT(map()));
|
QObject::connect(si.m_enable, SIGNAL(clicked()), m_sound_item_enable_mapper, SLOT(map()));
|
||||||
m_sound_item_enable_mapper->setMapping(si.m_enable, si.m_id);
|
m_sound_item_enable_mapper->setMapping(si.m_enable, si.m_id);
|
||||||
QObject::connect(si.m_del, SIGNAL(clicked()), m_sound_item_delete_mapper, SLOT(map()));
|
QObject::connect(si.m_del, SIGNAL(clicked()), m_sound_item_delete_mapper, SLOT(map()));
|
||||||
m_sound_item_delete_mapper->setMapping(si.m_del, si.m_id);
|
m_sound_item_delete_mapper->setMapping(si.m_del, si.m_id);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void select_all() {
|
||||||
|
for (auto &si:m_sound_items.m_sound_items) {
|
||||||
|
si.m_enable->setChecked(true);
|
||||||
|
send_process_osc("/activate_sound","s",si.m_filename.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void load_sounds() {
|
void select_none() {
|
||||||
m_last_file=QFileDialog::getExistingDirectory(this,
|
for (auto &si:m_sound_items.m_sound_items) {
|
||||||
QString("Select a directory"),
|
si.m_enable->setChecked(false);
|
||||||
m_last_file);
|
send_process_osc("/deactivate_sound","s",si.m_filename.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void sound_enable(int id) {
|
||||||
QDirIterator dirIt(m_last_file,QDirIterator::Subdirectories);
|
// search for this id...
|
||||||
while (dirIt.hasNext()) {
|
for (auto &si:m_sound_items.m_sound_items) {
|
||||||
dirIt.next();
|
if (si.m_id==id) {
|
||||||
if (QFileInfo(dirIt.filePath()).isFile() &&
|
if (si.m_enable->isChecked()) {
|
||||||
QFileInfo(dirIt.filePath()).suffix() == "wav") {
|
send_process_osc("/activate_sound","s",si.m_filename.c_str());
|
||||||
send_process_osc("/load_sample","s",dirIt.filePath().toStdString().c_str());
|
} else {
|
||||||
|
send_process_osc("/deactivate_sound","s",si.m_filename.c_str());
|
||||||
sound_items::sound_item &si = m_sound_items.add(m_Ui.brain_contents, dirIt.filePath().toStdString(),true);
|
|
||||||
|
|
||||||
QObject::connect(si.m_enable, SIGNAL(clicked()), m_sound_item_enable_mapper, SLOT(map()));
|
|
||||||
m_sound_item_enable_mapper->setMapping(si.m_enable, si.m_id);
|
|
||||||
QObject::connect(si.m_del, SIGNAL(clicked()), m_sound_item_delete_mapper, SLOT(map()));
|
|
||||||
m_sound_item_delete_mapper->setMapping(si.m_del, si.m_id);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void select_all() {
|
|
||||||
for (auto &si:m_sound_items.m_sound_items) {
|
|
||||||
si.m_enable->setChecked(true);
|
|
||||||
send_process_osc("/activate_sound","s",si.m_filename.c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void select_none() {
|
|
||||||
for (auto &si:m_sound_items.m_sound_items) {
|
|
||||||
si.m_enable->setChecked(false);
|
|
||||||
send_process_osc("/deactivate_sound","s",si.m_filename.c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void sound_enable(int id) {
|
|
||||||
// search for this id...
|
|
||||||
for (auto &si:m_sound_items.m_sound_items) {
|
|
||||||
if (si.m_id==id) {
|
|
||||||
if (si.m_enable->isChecked()) {
|
|
||||||
send_process_osc("/activate_sound","s",si.m_filename.c_str());
|
|
||||||
} else {
|
|
||||||
send_process_osc("/deactivate_sound","s",si.m_filename.c_str());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void delete_sound(int id) {
|
void delete_sound(int id) {
|
||||||
// search for this id...
|
// search for this id...
|
||||||
for (auto &si:m_sound_items.m_sound_items) {
|
for (auto &si:m_sound_items.m_sound_items) {
|
||||||
if (si.m_id==id) {
|
if (si.m_id==id) {
|
||||||
send_process_osc("/delete_sample","s",si.m_filename.c_str());
|
|
||||||
m_sound_items.remove(si.m_filename);
|
|
||||||
// iterator is now invalidated...
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void clear_brain() {
|
|
||||||
for (auto &si:m_sound_items.m_sound_items) {
|
|
||||||
send_process_osc("/delete_sample","s",si.m_filename.c_str());
|
send_process_osc("/delete_sample","s",si.m_filename.c_str());
|
||||||
|
m_sound_items.remove(si.m_filename);
|
||||||
|
// iterator is now invalidated...
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
m_sound_items.clear();
|
|
||||||
}
|
}
|
||||||
void restart_audio() { send_audio_osc("/restart_audio",""); }
|
}
|
||||||
|
void clear_brain() {
|
||||||
void brain_shape(int n) { send_process_osc("/window_type","i",n); }
|
for (auto &si:m_sound_items.m_sound_items) {
|
||||||
void target_shape(int n) { send_process_osc("/target_window_type","i",n); }
|
send_process_osc("/delete_sample","s",si.m_filename.c_str());
|
||||||
void mic(bool n) { send_audio_osc("/mic","i",(int)n); }
|
|
||||||
|
|
||||||
void record() {
|
|
||||||
if (m_save_wav=="") {
|
|
||||||
m_last_file=QFileDialog::getSaveFileName(
|
|
||||||
this,
|
|
||||||
QString("Select a wav file"),
|
|
||||||
m_last_file,
|
|
||||||
QString("Sounds (*.wav)"));
|
|
||||||
m_save_wav = m_last_file.toStdString();
|
|
||||||
// chop off .wav
|
|
||||||
size_t pos = m_save_wav.find_last_of(".");
|
|
||||||
if (pos!=string::npos) {
|
|
||||||
m_save_wav = m_save_wav.substr(0,pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
char fn[1024];
|
|
||||||
snprintf(fn,1024,"%s-%i",m_save_wav.c_str(),m_record_id);
|
|
||||||
send_audio_osc("/record","s",fn);
|
|
||||||
cerr<<fn<<endl;
|
|
||||||
m_record_id++;
|
|
||||||
}
|
}
|
||||||
|
m_sound_items.clear();
|
||||||
|
}
|
||||||
|
void restart_audio() { send_audio_osc("/restart_audio",""); }
|
||||||
|
|
||||||
void stop_record() {
|
void brain_shape(int n) { send_process_osc("/window_type","i",n); }
|
||||||
send_audio_osc("/stop","");
|
void target_shape(int n) { send_process_osc("/target_window_type","i",n); }
|
||||||
}
|
void mic(bool n) { send_audio_osc("/mic","i",(int)n); }
|
||||||
|
|
||||||
void load_brain() {
|
void record() {
|
||||||
m_last_file=QFileDialog::getOpenFileName(
|
if (m_save_wav=="") {
|
||||||
this,
|
m_last_file=QFileDialog::getSaveFileName(
|
||||||
QString("Select a brain file"),
|
this,
|
||||||
m_last_file,
|
QString("Select a wav file"),
|
||||||
QString("Brains (*.brain)"));
|
m_last_file,
|
||||||
|
QString("Sounds (*.wav)"));
|
||||||
send_process_osc("/load_brain","s",m_last_file.toStdString().c_str());
|
m_save_wav = m_last_file.toStdString();
|
||||||
}
|
// chop off .wav
|
||||||
void save_brain() {
|
size_t pos = m_save_wav.find_last_of(".");
|
||||||
m_last_file=QFileDialog::getSaveFileName(
|
if (pos!=string::npos) {
|
||||||
this,
|
m_save_wav = m_save_wav.substr(0,pos);
|
||||||
QString("Select a brain file"),
|
|
||||||
m_last_file,
|
|
||||||
QString("Brains (*.brain)"));
|
|
||||||
|
|
||||||
send_process_osc("/save_brain","s",m_last_file.toStdString().c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
void load_session() {
|
|
||||||
m_last_file=QFileDialog::getOpenFileName(
|
|
||||||
this,
|
|
||||||
QString("Select a session file"),
|
|
||||||
m_last_file,
|
|
||||||
QString("Sessions *.samplebrain (*.samplebrain)"));
|
|
||||||
|
|
||||||
send_process_osc("/load_session","s",m_last_file.toStdString().c_str());
|
|
||||||
init_from_session(m_last_file.toStdString());
|
|
||||||
}
|
|
||||||
|
|
||||||
void save_session() {
|
|
||||||
m_last_file=QFileDialog::getSaveFileName(
|
|
||||||
this,
|
|
||||||
QString("Select a session file"),
|
|
||||||
m_last_file,
|
|
||||||
QString("Sessions *.samplebrain (*.samplebrain)"));
|
|
||||||
|
|
||||||
send_process_osc("/save_session","s",m_last_file.toStdString().c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
void update_status() {
|
|
||||||
m_feedback.poll(m_Ui.statusbar,&m_sound_items,m_settings_dialog);
|
|
||||||
}
|
|
||||||
|
|
||||||
void stereo_mode(bool s) {
|
|
||||||
send_audio_osc("/stereo","i",s);
|
|
||||||
}
|
|
||||||
|
|
||||||
void net_enable(int id) {
|
|
||||||
osc_destination &d = m_destinations[id];
|
|
||||||
|
|
||||||
if (d.m_enable->isChecked()) {
|
|
||||||
// reconnect
|
|
||||||
string url = d.m_address->text().toUtf8().constData();
|
|
||||||
lo_address_free(d.m_audio_address);
|
|
||||||
lo_address_free(d.m_process_address);
|
|
||||||
d.m_audio_address = lo_address_new_from_url(string(url+":8888").c_str());
|
|
||||||
d.m_process_address = lo_address_new_from_url(string(url+":8889").c_str());
|
|
||||||
// start sending messages here
|
|
||||||
d.m_enabled=true;
|
|
||||||
} else {
|
|
||||||
// stop sending messages here
|
|
||||||
d.m_enabled=false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char fn[1024];
|
||||||
|
snprintf(fn,1024,"%s-%i",m_save_wav.c_str(),m_record_id);
|
||||||
|
send_audio_osc("/record","s",fn);
|
||||||
|
cerr<<fn<<endl;
|
||||||
|
m_record_id++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void stop_record() {
|
||||||
|
send_audio_osc("/stop","");
|
||||||
|
}
|
||||||
|
|
||||||
|
void load_brain() {
|
||||||
|
m_last_file=QFileDialog::getOpenFileName(
|
||||||
|
this,
|
||||||
|
QString("Select a brain file"),
|
||||||
|
m_last_file,
|
||||||
|
QString("Brains (*.brain)"));
|
||||||
|
|
||||||
|
send_process_osc("/load_brain","s",m_last_file.toStdString().c_str());
|
||||||
|
}
|
||||||
|
void save_brain() {
|
||||||
|
m_last_file=QFileDialog::getSaveFileName(
|
||||||
|
this,
|
||||||
|
QString("Select a brain file"),
|
||||||
|
m_last_file,
|
||||||
|
QString("Brains (*.brain)"));
|
||||||
|
|
||||||
|
send_process_osc("/save_brain","s",m_last_file.toStdString().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void load_session() {
|
||||||
|
m_last_file=QFileDialog::getOpenFileName(
|
||||||
|
this,
|
||||||
|
QString("Select a session file"),
|
||||||
|
m_last_file,
|
||||||
|
QString("Sessions *.samplebrain (*.samplebrain)"));
|
||||||
|
|
||||||
|
send_process_osc("/load_session","s",m_last_file.toStdString().c_str());
|
||||||
|
init_from_session(m_last_file.toStdString());
|
||||||
|
}
|
||||||
|
|
||||||
|
void save_session() {
|
||||||
|
m_last_file=QFileDialog::getSaveFileName(
|
||||||
|
this,
|
||||||
|
QString("Select a session file"),
|
||||||
|
m_last_file,
|
||||||
|
QString("Sessions *.samplebrain (*.samplebrain)"));
|
||||||
|
|
||||||
|
send_process_osc("/save_session","s",m_last_file.toStdString().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void update_status() {
|
||||||
|
m_feedback.poll(m_Ui.statusbar,&m_sound_items,m_settings_dialog);
|
||||||
|
}
|
||||||
|
|
||||||
|
void stereo_mode(bool s) {
|
||||||
|
send_audio_osc("/stereo","i",s);
|
||||||
|
}
|
||||||
|
|
||||||
|
void net_enable(int id) {
|
||||||
|
osc_destination &d = m_destinations[id];
|
||||||
|
|
||||||
|
if (d.m_enable->isChecked()) {
|
||||||
|
// reconnect
|
||||||
|
string url = d.m_address->text().toUtf8().constData();
|
||||||
|
lo_address_free(d.m_audio_address);
|
||||||
|
lo_address_free(d.m_process_address);
|
||||||
|
d.m_audio_address = lo_address_new_from_url(string(url+":"+m_audio_port).c_str());
|
||||||
|
d.m_process_address = lo_address_new_from_url(string(url+":"+m_process_port).c_str());
|
||||||
|
// start sending messages here
|
||||||
|
d.m_enabled=true;
|
||||||
|
} else {
|
||||||
|
// stop sending messages here
|
||||||
|
d.m_enabled=false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void settings() {
|
void settings() {
|
||||||
m_settings_dialog->show();
|
m_settings_dialog->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
///////////////////////////////////////////////
|
///////////////////////////////////////////////
|
||||||
|
|
||||||
// we want to be able to send out to
|
// we want to be able to send out to
|
||||||
// multiple addresses over the network
|
// multiple addresses over the network
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
// we want to be able to send out to
|
// we want to be able to send out to
|
||||||
// multiple addresses over the network
|
// multiple addresses over the network
|
||||||
class osc_destination {
|
class osc_destination {
|
||||||
public:
|
public:
|
||||||
int m_id;
|
int m_id;
|
||||||
lo_address m_audio_address;
|
lo_address m_audio_address;
|
||||||
lo_address m_process_address;
|
lo_address m_process_address;
|
||||||
// can't find a way to address these via qt
|
// can't find a way to address these via qt
|
||||||
QLineEdit *m_address;
|
QLineEdit *m_address;
|
||||||
QCheckBox *m_enable;
|
QCheckBox *m_enable;
|
||||||
bool m_enabled;
|
bool m_enabled;
|
||||||
};
|
};
|
||||||
|
|
||||||
vector<osc_destination> m_destinations;
|
vector<osc_destination> m_destinations;
|
||||||
|
|
||||||
|
|
||||||
void init_from_session(const string &filename);
|
void init_from_session(const string &filename);
|
||||||
void add_gui_address(osc_destination &dest,
|
void add_gui_address(osc_destination &dest,
|
||||||
QSignalMapper* enable_mapper);
|
QSignalMapper* enable_mapper);
|
||||||
|
|
||||||
string m_save_wav;
|
string m_save_wav;
|
||||||
QString m_last_file;
|
QString m_last_file;
|
||||||
unsigned int m_record_id;
|
unsigned int m_record_id;
|
||||||
Ui_MainWindow m_Ui;
|
Ui_MainWindow m_Ui;
|
||||||
feedback m_feedback;
|
feedback m_feedback;
|
||||||
QSignalMapper* m_sound_item_enable_mapper;
|
QSignalMapper* m_sound_item_enable_mapper;
|
||||||
QSignalMapper* m_sound_item_delete_mapper;
|
QSignalMapper* m_sound_item_delete_mapper;
|
||||||
sound_items m_sound_items;
|
sound_items m_sound_items;
|
||||||
|
|
||||||
SettingsDialog *m_settings_dialog;
|
SettingsDialog *m_settings_dialog;
|
||||||
audio_thread *m_audio_thread;
|
audio_thread *m_audio_thread;
|
||||||
|
|
||||||
|
string m_audio_port;
|
||||||
|
string m_process_port;
|
||||||
};
|
};
|
||||||
|
@ -20,26 +20,23 @@
|
|||||||
using namespace spiralcore;
|
using namespace spiralcore;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
audio_thread::audio_thread(process_thread &p) :
|
audio_thread::audio_thread(const string &port, process_thread &p) :
|
||||||
m_audio_device(NULL),
|
m_audio_device(NULL),
|
||||||
m_osc("8888"),
|
m_osc(port),
|
||||||
m_process_thread(p),
|
m_process_thread(p),
|
||||||
m_brain_mutex(p.m_brain_mutex),
|
m_brain_mutex(p.m_brain_mutex),
|
||||||
m_stereo_mode(false),
|
m_stereo_mode(false),
|
||||||
m_mic_mode(false),
|
m_mic_mode(false),
|
||||||
m_bufsize(2048),
|
m_bufsize(2048),
|
||||||
m_samplerate(44100),
|
m_samplerate(44100),
|
||||||
m_device("")
|
m_device("") {
|
||||||
{
|
|
||||||
// start_audio();
|
|
||||||
pthread_mutex_lock(m_brain_mutex);
|
pthread_mutex_lock(m_brain_mutex);
|
||||||
m_left_renderer = new renderer(p.m_source,p.m_left_target);
|
m_left_renderer = new renderer(p.m_source,p.m_left_target);
|
||||||
m_right_renderer = new renderer(p.m_source,p.m_right_target);
|
m_right_renderer = new renderer(p.m_source,p.m_right_target);
|
||||||
m_block_stream = new block_stream();
|
m_block_stream = new block_stream();
|
||||||
pthread_mutex_unlock(m_brain_mutex);
|
pthread_mutex_unlock(m_brain_mutex);
|
||||||
m_osc.run();
|
m_osc.run();
|
||||||
// it this threadsafe?
|
|
||||||
// m_audio_device->report_devices();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool state = 1;
|
static bool state = 1;
|
||||||
|
@ -26,12 +26,12 @@ namespace spiralcore {
|
|||||||
|
|
||||||
class audio_thread {
|
class audio_thread {
|
||||||
public:
|
public:
|
||||||
audio_thread(process_thread &p);
|
audio_thread(const string &port, process_thread &p);
|
||||||
~audio_thread();
|
~audio_thread();
|
||||||
|
|
||||||
void start_audio();
|
void start_audio();
|
||||||
void restart_audio(const string device, unsigned int samplerate, unsigned int bufsize);
|
void restart_audio(const string device, unsigned int samplerate, unsigned int bufsize);
|
||||||
|
bool ok() { return m_osc.ok(); }
|
||||||
void process(sample &left_in, sample &right_in, sample &left_out, sample &right_out);
|
void process(sample &left_in, sample &right_in, sample &left_out, sample &right_out);
|
||||||
|
|
||||||
static void run_audio(void* c, unsigned int frames);
|
static void run_audio(void* c, unsigned int frames);
|
||||||
|
@ -29,7 +29,8 @@ class feedback {
|
|||||||
public:
|
public:
|
||||||
feedback(std::string address);
|
feedback(std::string address);
|
||||||
void poll(QStatusBar *s, sound_items *sound_items, SettingsDialog *settings);
|
void poll(QStatusBar *s, sound_items *sound_items, SettingsDialog *settings);
|
||||||
|
bool ok() { return m_osc.ok(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
OSC_server m_osc;
|
OSC_server m_osc;
|
||||||
|
@ -32,8 +32,8 @@ static void* _process(void *c) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
process_thread::process_thread() :
|
process_thread::process_thread(const string &port) :
|
||||||
m_osc("8889"),
|
m_osc(port),
|
||||||
m_source_block_size(1000),
|
m_source_block_size(1000),
|
||||||
m_source_overlap(0.75),
|
m_source_overlap(0.75),
|
||||||
m_target_block_size(1000),
|
m_target_block_size(1000),
|
||||||
|
@ -25,9 +25,9 @@
|
|||||||
|
|
||||||
namespace spiralcore {
|
namespace spiralcore {
|
||||||
|
|
||||||
class process_thread {
|
class process_thread {
|
||||||
public:
|
public:
|
||||||
process_thread();
|
process_thread(const string &port);
|
||||||
~process_thread();
|
~process_thread();
|
||||||
|
|
||||||
pthread_mutex_t* m_brain_mutex;
|
pthread_mutex_t* m_brain_mutex;
|
||||||
@ -47,10 +47,13 @@ public:
|
|||||||
void load_session(const std::string &filename);
|
void load_session(const std::string &filename);
|
||||||
void save_session(const std::string &filename);
|
void save_session(const std::string &filename);
|
||||||
|
|
||||||
|
|
||||||
|
bool ok() { return m_osc.ok(); }
|
||||||
|
|
||||||
// only for use in mutex
|
// only for use in mutex
|
||||||
brain m_source, m_left_target, m_right_target;
|
brain m_source, m_left_target, m_right_target;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
OSC_server m_osc;
|
OSC_server m_osc;
|
||||||
u32 m_source_block_size;
|
u32 m_source_block_size;
|
||||||
float m_source_overlap;
|
float m_source_overlap;
|
||||||
@ -64,6 +67,6 @@ private:
|
|||||||
renderer *m_left_renderer;
|
renderer *m_left_renderer;
|
||||||
renderer *m_right_renderer;
|
renderer *m_right_renderer;
|
||||||
block_stream *m_block_stream;
|
block_stream *m_block_stream;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,22 +19,54 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
|
#include <QSettings>
|
||||||
|
|
||||||
#include "MainWindow.h"
|
#include "MainWindow.h"
|
||||||
|
|
||||||
#include "process_thread.h"
|
#include "process_thread.h"
|
||||||
#include "audio_thread.h"
|
#include "audio_thread.h"
|
||||||
|
#include "status.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int main( int argc , char *argv[] ){
|
int main( int argc , char *argv[] ){
|
||||||
QApplication app(argc, argv);
|
|
||||||
MainWindow mainWin;
|
|
||||||
mainWin.show();
|
|
||||||
process_thread pt;
|
|
||||||
audio_thread at(pt);
|
|
||||||
pt.register_renderer(at.m_left_renderer, at.m_right_renderer, at.m_block_stream);
|
|
||||||
|
|
||||||
mainWin.set_audio_thread(&at);
|
|
||||||
|
QApplication app(argc, argv);
|
||||||
|
|
||||||
|
QSettings settings("thentrythis", "samplebrain");
|
||||||
|
|
||||||
return app.exec();
|
// slight over-use of OSC servers here, but the are packaged nicely for
|
||||||
|
// threadsafe (nonblocking) communication, and it's useful to expose all
|
||||||
|
// moving parts for external control (i.e. the processing and the audio)
|
||||||
|
|
||||||
|
if (!settings.contains("gui_port")) settings.setValue("gui_port", "62345");
|
||||||
|
if (!settings.contains("audio_port")) settings.setValue("audio_port", "62346");
|
||||||
|
if (!settings.contains("process_port")) settings.setValue("process_port", "62347");
|
||||||
|
|
||||||
|
string gui_port = settings.value("gui_port").toByteArray().constData();
|
||||||
|
string audio_port = settings.value("audio_port").toByteArray().constData();
|
||||||
|
string process_port = settings.value("process_port").toByteArray().constData();
|
||||||
|
|
||||||
|
status::set_port(gui_port);
|
||||||
|
|
||||||
|
MainWindow mainWin(gui_port,audio_port,process_port);
|
||||||
|
mainWin.show();
|
||||||
|
process_thread pt(process_port);
|
||||||
|
audio_thread at(audio_port,pt);
|
||||||
|
|
||||||
|
pt.register_renderer(at.m_left_renderer, at.m_right_renderer, at.m_block_stream);
|
||||||
|
mainWin.set_audio_thread(&at);
|
||||||
|
|
||||||
|
if (!at.ok()) {
|
||||||
|
mainWin.message("problem starting audio thread on port "+audio_port);
|
||||||
|
}
|
||||||
|
if (!pt.ok()) {
|
||||||
|
mainWin.message("problem starting process thread on port "+process_port);
|
||||||
|
}
|
||||||
|
if (!mainWin.ok()) {
|
||||||
|
mainWin.message("problem starting gui thread on port "+gui_port);
|
||||||
|
}
|
||||||
|
|
||||||
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
@ -31,117 +31,105 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
OSC_server::OSC_server(const string &port) :
|
OSC_server::OSC_server(const string &port) :
|
||||||
m_port(port),
|
m_port(port),
|
||||||
m_exit(false),
|
m_exit(false),
|
||||||
m_command_ring_buffer(262144)
|
m_command_ring_buffer(262144) {
|
||||||
{
|
//cerr<<"using port: ["<<port<<"]"<<endl;
|
||||||
//cerr<<"using port: ["<<port<<"]"<<endl;
|
m_server = lo_server_thread_new(port.c_str(), error_handler);
|
||||||
m_server = lo_server_thread_new(port.c_str(), error_handler);
|
if (m_server) {
|
||||||
|
cerr<<m_server<<endl;
|
||||||
lo_server_thread_add_method(m_server, NULL, NULL, default_handler, this);
|
lo_server_thread_add_method(m_server, NULL, NULL, default_handler, this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OSC_server::~OSC_server()
|
OSC_server::~OSC_server() {
|
||||||
{
|
m_exit=true;
|
||||||
m_exit=true;
|
lo_server_thread_stop(m_server);
|
||||||
lo_server_thread_stop(m_server);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OSC_server::run()
|
void OSC_server::run() {
|
||||||
{
|
if (!m_server) return;
|
||||||
lo_server_thread_start(m_server);
|
lo_server_thread_start(m_server);
|
||||||
// while (!m_exit) usleep(1000);
|
// while (!m_exit) usleep(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OSC_server::error_handler(int num, const char *msg, const char *path)
|
void OSC_server::error_handler(int num, const char *msg, const char *path) {
|
||||||
{
|
//cerr<<"liblo server error "<<num<<" in path "<<path<<": "<<msg<<endl;
|
||||||
//cerr<<"liblo server error "<<num<<" in path "<<path<<": "<<msg<<endl;
|
cerr<<"liblo server error "<<num<<endl;
|
||||||
cerr<<"liblo server error "<<num<<endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int OSC_server::default_handler(const char *path, const char *types, lo_arg **argv,
|
int OSC_server::default_handler(const char *path, const char *types, lo_arg **argv,
|
||||||
int argc, void *data, void *user_data)
|
int argc, void *data, void *user_data) {
|
||||||
{
|
OSC_server *server = (OSC_server*)user_data;
|
||||||
OSC_server *server = (OSC_server*)user_data;
|
if (!server) return -1;
|
||||||
|
|
||||||
unsigned int size = 0;
|
unsigned int size = 0;
|
||||||
for (int i=0; i<argc; i++)
|
for (int i=0; i<argc; i++) {
|
||||||
{
|
size+=lo_arg_size((lo_type)types[i],argv[i]);
|
||||||
size+=lo_arg_size((lo_type)types[i],argv[i]);
|
// add one for the null terminator
|
||||||
// add one for the null terminator
|
if (types[i]=='s') size++;
|
||||||
if (types[i]=='s') size++;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
char *newdata=new char[size];
|
|
||||||
unsigned int pos=0;
|
|
||||||
for (int i=0; i<argc; i++)
|
|
||||||
{
|
|
||||||
switch (types[i])
|
|
||||||
{
|
|
||||||
case LO_INT32:
|
|
||||||
{
|
|
||||||
if (pos+4>COMMAND_DATA_SIZE)
|
|
||||||
{
|
|
||||||
cerr<<"osc data too big for ringbuffer command"<<endl;
|
|
||||||
delete[] newdata;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy(newdata+pos,(char*)argv[i],4);
|
|
||||||
pos+=4;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case LO_FLOAT:
|
|
||||||
{
|
|
||||||
if (pos+4>COMMAND_DATA_SIZE)
|
|
||||||
{
|
|
||||||
cerr<<"osc data too big for ringbuffer command"<<endl;
|
|
||||||
delete[] newdata;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy(newdata+pos,(char*)argv[i],4);
|
|
||||||
pos+=4;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case LO_STRING:
|
|
||||||
{
|
|
||||||
int size=strlen(&argv[i]->s);
|
|
||||||
|
|
||||||
if (pos+size+1>COMMAND_DATA_SIZE)
|
|
||||||
{
|
|
||||||
cerr<<"osc data too big for ringbuffer command"<<endl;
|
|
||||||
delete[] newdata;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy(newdata+pos,&argv[i]->s,size);
|
|
||||||
newdata[pos+size]='\0';
|
|
||||||
pos+=size+1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
cerr<<"unsupported type: "<<types[i]<<endl;
|
|
||||||
delete[] newdata;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (1)//pos==size) hmm
|
|
||||||
{
|
|
||||||
command_ring_buffer::command command(path,types,newdata,pos);
|
|
||||||
if (!server->m_command_ring_buffer.send(command))
|
|
||||||
{
|
|
||||||
//cerr<<"OSC_server - ringbuffer full!"<<endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cerr<<"OSC_server::default_handler: size mismatch ["<<pos<<":"<<size<<"], not sending message"<<endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
char *newdata=new char[size];
|
||||||
|
unsigned int pos=0;
|
||||||
|
for (int i=0; i<argc; i++) {
|
||||||
|
switch (types[i]) {
|
||||||
|
case LO_INT32: {
|
||||||
|
if (pos+4>COMMAND_DATA_SIZE) {
|
||||||
|
cerr<<"osc data too big for ringbuffer command"<<endl;
|
||||||
delete[] newdata;
|
delete[] newdata;
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(newdata+pos,(char*)argv[i],4);
|
||||||
|
pos+=4;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case LO_FLOAT: {
|
||||||
|
if (pos+4>COMMAND_DATA_SIZE) {
|
||||||
|
cerr<<"osc data too big for ringbuffer command"<<endl;
|
||||||
|
delete[] newdata;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(newdata+pos,(char*)argv[i],4);
|
||||||
|
pos+=4;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case LO_STRING: {
|
||||||
|
int size=strlen(&argv[i]->s);
|
||||||
|
|
||||||
|
if (pos+size+1>COMMAND_DATA_SIZE) {
|
||||||
|
cerr<<"osc data too big for ringbuffer command"<<endl;
|
||||||
|
delete[] newdata;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(newdata+pos,&argv[i]->s,size);
|
||||||
|
newdata[pos+size]='\0';
|
||||||
|
pos+=size+1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default: {
|
||||||
|
cerr<<"unsupported type: "<<types[i]<<endl;
|
||||||
|
delete[] newdata;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (1) { //pos==size) hmm
|
||||||
|
|
||||||
|
command_ring_buffer::command command(path,types,newdata,pos);
|
||||||
|
if (!server->m_command_ring_buffer.send(command)) {
|
||||||
|
//cerr<<"OSC_server - ringbuffer full!"<<endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cerr<<"OSC_server::default_handler: size mismatch ["<<pos<<":"<<size<<"], not sending message"<<endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete[] newdata;
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -24,20 +24,21 @@
|
|||||||
class OSC_server
|
class OSC_server
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
OSC_server(const std::string &port);
|
OSC_server(const std::string &port);
|
||||||
~OSC_server();
|
~OSC_server();
|
||||||
|
|
||||||
void run();
|
void run();
|
||||||
bool get(command_ring_buffer::command& command) { return m_command_ring_buffer.get(command);}
|
bool get(command_ring_buffer::command& command) { return m_command_ring_buffer.get(command);}
|
||||||
|
bool ok() { return m_server!=NULL; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static int default_handler(const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data);
|
static int default_handler(const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data);
|
||||||
static void error_handler(int num, const char *m, const char *path);
|
static void error_handler(int num, const char *m, const char *path);
|
||||||
|
|
||||||
lo_server_thread m_server;
|
lo_server_thread m_server;
|
||||||
std::string m_port;
|
std::string m_port;
|
||||||
bool m_exit;
|
bool m_exit;
|
||||||
command_ring_buffer m_command_ring_buffer;
|
command_ring_buffer m_command_ring_buffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -22,6 +22,10 @@ using namespace std;
|
|||||||
|
|
||||||
lo_address status::m_address = lo_address_new_from_url("osc.udp://localhost:8890");
|
lo_address status::m_address = lo_address_new_from_url("osc.udp://localhost:8890");
|
||||||
|
|
||||||
|
void status::set_port(const std::string &port) {
|
||||||
|
status::m_address = lo_address_new_from_url(string("osc.udp://localhost:"+port).c_str());
|
||||||
|
}
|
||||||
|
|
||||||
void status::_update(const std::string &msg) {
|
void status::_update(const std::string &msg) {
|
||||||
lo_send(m_address,"/report","s",msg.c_str());
|
lo_send(m_address,"/report","s",msg.c_str());
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ namespace spiralcore {
|
|||||||
|
|
||||||
class status {
|
class status {
|
||||||
public:
|
public:
|
||||||
|
static void set_port(const std::string &port);
|
||||||
static void _update(const std::string &msg);
|
static void _update(const std::string &msg);
|
||||||
static void update(const char *msg, ...);
|
static void update(const char *msg, ...);
|
||||||
static void sound_item(const std::string &name, const std::string &colour);
|
static void sound_item(const std::string &name, const std::string &colour);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user