fixed sample crash and added network gui

This commit is contained in:
dave griffiths 2016-02-07 13:17:33 +00:00
parent 7f0b469709
commit 1b0c6f04d5
7 changed files with 339 additions and 148 deletions

View File

@ -11,7 +11,7 @@
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>samplebrain 0.14</string> <string>samplebrain 0.15</string>
</property> </property>
<widget class="QWidget" name="centralwidget"> <widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout_4"> <layout class="QVBoxLayout" name="verticalLayout_4">
@ -25,7 +25,7 @@
</font> </font>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>0</number> <number>1</number>
</property> </property>
<widget class="QWidget" name="controlTab"> <widget class="QWidget" name="controlTab">
<attribute name="title"> <attribute name="title">
@ -1427,13 +1427,13 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="logTab"> <widget class="QWidget" name="netTab">
<attribute name="title"> <attribute name="title">
<string>log</string> <string>net</string>
</attribute> </attribute>
<layout class="QHBoxLayout" name="horizontalLayout_15"> <layout class="QHBoxLayout" name="horizontalLayout_15">
<item> <item>
<widget class="QPlainTextEdit" name="plainTextEdit"/> <layout class="QVBoxLayout" name="netContainer"/>
</item> </item>
</layout> </layout>
</widget> </widget>

View File

@ -31,8 +31,32 @@ MainWindow::MainWindow() :
m_Ui.setupUi(this); m_Ui.setupUi(this);
setUnifiedTitleAndToolBarOnMac(true); setUnifiedTitleAndToolBarOnMac(true);
m_audio_address = lo_address_new_from_url("osc.udp://localhost:8888"); // add default local dest
m_process_address = lo_address_new_from_url("osc.udp://localhost:8889"); // turn on first one
QSignalMapper* enable_mapper = new QSignalMapper(this);
QSignalMapper* connect_mapper = new QSignalMapper(this);
for (int i=0; i<10; i++) {
osc_destination d;
d.m_id=i;
d.m_audio_address = lo_address_new_from_url("osc.udp://localhost:8888");
d.m_process_address = lo_address_new_from_url("osc.udp://localhost:8889");
if (i==0) d.m_enabled=true;
else d.m_enabled=false;
add_gui_address(d,enable_mapper,connect_mapper);
if (i==0) {
d.m_enable->setChecked(true);
d.m_address->setText("osc.udp://localhost");
}
m_destinations.push_back(d);
}
connect(enable_mapper, SIGNAL(mapped(int)), this, SLOT(net_enable(int)));
connect(connect_mapper, SIGNAL(mapped(int)), this, SLOT(net_connect(int)));
m_Ui.netContainer->addItem(new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding));
QTimer *timer = new QTimer(this); QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(update_status())); connect(timer, SIGNAL(timeout()), this, SLOT(update_status()));
@ -43,6 +67,27 @@ MainWindow::MainWindow() :
m_record_id=0; m_record_id=0;
} }
void MainWindow::add_gui_address(osc_destination &dest,
QSignalMapper* enable_mapper,
QSignalMapper* connect_mapper) {
QHBoxLayout *h = new QHBoxLayout();
dest.m_enable = new QCheckBox();
dest.m_enable->setText("enable");
dest.m_enable->setChecked(false);
h->addWidget(dest.m_enable);
dest.m_address = new QLineEdit();
h->addWidget(dest.m_address);
//QPushButton *ping = new QPushButton();
//ping->setText("connect");
//h->addWidget(ping);
m_Ui.netContainer->addLayout(h);
QObject::connect(dest.m_enable, SIGNAL(clicked()), enable_mapper, SLOT(map()));
enable_mapper->setMapping(dest.m_enable, dest.m_id);
//QObject::connect(ping, SIGNAL(clicked()), connect_mapper, SLOT(map()));
//connect_mapper->setMapping(ping, dest.m_id);
}
void MainWindow::init_from_session(const string &filename) { void MainWindow::init_from_session(const string &filename) {
// pull the bits out of the file to set the interface... // pull the bits out of the file to set the interface...
// is this easier than direct access? no idea?? // is this easier than direct access? no idea??
@ -122,6 +167,7 @@ void MainWindow::init_from_session(const string &filename) {
case window::HAMMING: m_Ui.radioButton_hammingTarget->setChecked(true); break; case window::HAMMING: m_Ui.radioButton_hammingTarget->setChecked(true); break;
case window::HANN: m_Ui.radioButton_hannTarget->setChecked(true); break; case window::HANN: m_Ui.radioButton_hannTarget->setChecked(true); break;
case window::RECTANGLE: m_Ui.radioButton_rectangleTarget->setChecked(true); break; case window::RECTANGLE: m_Ui.radioButton_rectangleTarget->setChecked(true); break;
default: break;
}; };
// source // source
@ -136,6 +182,7 @@ void MainWindow::init_from_session(const string &filename) {
case window::HAMMING: m_Ui.radioButton_hamming->setChecked(true); break; case window::HAMMING: m_Ui.radioButton_hamming->setChecked(true); break;
case window::HANN: m_Ui.radioButton_hann->setChecked(true); break; case window::HANN: m_Ui.radioButton_hann->setChecked(true); break;
case window::RECTANGLE: m_Ui.radioButton_rectagle->setChecked(true); break; case window::RECTANGLE: m_Ui.radioButton_rectagle->setChecked(true); break;
default: break;
}; };
// brain samples // brain samples

View File

@ -20,6 +20,7 @@
#include <iostream> #include <iostream>
#include <lo/lo.h> #include <lo/lo.h>
#include <string> #include <string>
#include <list>
#include "window.h" #include "window.h"
#include "feedback.h" #include "feedback.h"
@ -34,105 +35,104 @@ public:
MainWindow(); MainWindow();
protected: protected:
private slots: private slots:
void play_slot() { lo_send(m_audio_address,"/start",""); } void play_slot() { send_audio_osc("/start",""); }
void stop_slot() { lo_send(m_audio_address,"/pause",""); } void stop_slot() { send_audio_osc("/pause",""); }
void ratio_slot(int s) { void ratio_slot(int s) {
lo_send(m_audio_address,"/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) {
lo_send(m_audio_address,"/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) {
lo_send(m_audio_address,"/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) {
lo_send(m_audio_address,"/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) {
lo_send(m_audio_address,"/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) {
lo_send(m_audio_address,"/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) { lo_send(m_audio_address,"/fft1_start","i",s); } void fft1_start_slot(int s) { send_audio_osc("/fft1_start","i",s); }
void fft1_end_slot(int s) { lo_send(m_audio_address,"/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) {
lo_send(m_audio_address,"/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) {
lo_send(m_audio_address,"/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) {
lo_send(m_audio_address,"/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) {
lo_send(m_audio_address,"/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;
lo_send(m_audio_address,"/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) {
lo_send(m_audio_address,"/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) {
lo_send(m_audio_address,"/synapses","i",s); send_audio_osc("/synapses","i",s);
} }
void target_mix_slot(int s) { void target_mix_slot(int s) {
lo_send(m_audio_address,"/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) {
lo_send(m_audio_address,"/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) {
lo_send(m_audio_address,"/search-stretch","i",s); send_audio_osc("/search-stretch","i",s);
} }
void slide_error(int s) { void slide_error(int s) {
lo_send(m_audio_address,"/slide-error","i",s); send_audio_osc("/slide-error","i",s);
} }
void stickyness_slot(int s) { void stickyness_slot(int s) {
lo_send(m_audio_address,"/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) {
lo_send(m_audio_address,"/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) { lo_send(m_audio_address,"/volume","f",s/100.0f); } void volume_slot(int s) { send_audio_osc("/volume","f",s/100.0f); }
void algo_basic(bool s) { if (s) lo_send(m_audio_address,"/search_algo","i",0); } void algo_basic(bool s) { if (s) send_audio_osc("/search_algo","i",0); }
void algo_rev_basic(bool s) { if (s) lo_send(m_audio_address,"/search_algo","i",1); } void algo_rev_basic(bool s) { if (s) send_audio_osc("/search_algo","i",1); }
void algo_synaptic(bool s) { if (s) lo_send(m_audio_address,"/search_algo","i",2); } void algo_synaptic(bool s) { if (s) send_audio_osc("/search_algo","i",2); }
void algo_synaptic_slide(bool s) { if (s) lo_send(m_audio_address,"/search_algo","i",3); } void algo_synaptic_slide(bool s) { if (s) send_audio_osc("/search_algo","i",3); }
void run_slot() {} void run_slot() {}
void load_target() { void load_target() {
@ -142,15 +142,15 @@ private slots:
m_last_file, m_last_file,
QString("Sounds (*.wav)")); QString("Sounds (*.wav)"));
lo_send(m_process_address,"/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) { lo_send(m_process_address,"/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) { lo_send(m_process_address,"/target_overlap","f",s); } void target_block_overlap(double s) { send_process_osc("/target_overlap","f",s); }
void generate_target_blocks() { lo_send(m_process_address,"/generate_target",""); } void generate_target_blocks() { send_process_osc("/generate_target",""); }
void block_size(int s) { lo_send(m_process_address,"/source_block_size","i",s); } void block_size(int s) { send_process_osc("/source_block_size","i",s); }
void block_overlap(double s) { lo_send(m_process_address,"/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() { lo_send(m_process_address,"/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,
@ -158,42 +158,42 @@ private slots:
m_last_file, m_last_file,
QString("Sounds (*.wav)")); QString("Sounds (*.wav)"));
lo_send(m_process_address,"/load_sample","s",m_last_file.toStdString().c_str()); send_process_osc("/load_sample","s",m_last_file.toStdString().c_str());
m_Ui.listWidgetSounds->addItem(m_last_file); m_Ui.listWidgetSounds->addItem(m_last_file);
} }
void delete_sound() { void delete_sound() {
QList<QListWidgetItem *> itemList = m_Ui.listWidgetSounds->selectedItems(); QList<QListWidgetItem *> itemList = m_Ui.listWidgetSounds->selectedItems();
for (int i=0; i<itemList.size(); i++) { for (int i=0; i<itemList.size(); i++) {
lo_send(m_process_address,"/delete_sample","s",itemList[i]->text().toStdString().c_str()); send_process_osc("/delete_sample","s",itemList[i]->text().toStdString().c_str());
} }
qDeleteAll(m_Ui.listWidgetSounds->selectedItems()); qDeleteAll(m_Ui.listWidgetSounds->selectedItems());
} }
void clear_brain() { void clear_brain() {
for (int i=0; i<m_Ui.listWidgetSounds->count(); i++) { for (int i=0; i<m_Ui.listWidgetSounds->count(); i++) {
lo_send(m_process_address,"/delete_sample","s",m_Ui.listWidgetSounds->item(i)->text().toStdString().c_str()); send_process_osc("/delete_sample","s",m_Ui.listWidgetSounds->item(i)->text().toStdString().c_str());
} }
m_Ui.listWidgetSounds->clear(); m_Ui.listWidgetSounds->clear();
} }
void restart_audio() { lo_send(m_audio_address,"/restart_audio",""); } void restart_audio() { send_audio_osc("/restart_audio",""); }
void window_dodgy(bool s) { if (s) lo_send(m_process_address,"/window_type","i",window::DODGY); } void window_dodgy(bool s) { if (s) send_process_osc("/window_type","i",window::DODGY); }
void window_bartlett(bool s) { if (s) lo_send(m_process_address,"/window_type","i",window::BARTLETT); } void window_bartlett(bool s) { if (s) send_process_osc("/window_type","i",window::BARTLETT); }
void window_blackman(bool s) { if (s) lo_send(m_process_address,"/window_type","i",window::BLACKMAN); } void window_blackman(bool s) { if (s) send_process_osc("/window_type","i",window::BLACKMAN); }
void window_flattop(bool s) { if (s) lo_send(m_process_address,"/window_type","i",window::FLAT_TOP); } void window_flattop(bool s) { if (s) send_process_osc("/window_type","i",window::FLAT_TOP); }
void window_gaussian(bool s) { if (s) lo_send(m_process_address,"/window_type","i",window::GAUSSIAN); } void window_gaussian(bool s) { if (s) send_process_osc("/window_type","i",window::GAUSSIAN); }
void window_hamming(bool s) { if (s) lo_send(m_process_address,"/window_type","i",window::HAMMING); } void window_hamming(bool s) { if (s) send_process_osc("/window_type","i",window::HAMMING); }
void window_hann(bool s) { if (s) lo_send(m_process_address,"/window_type","i",window::HANN); } void window_hann(bool s) { if (s) send_process_osc("/window_type","i",window::HANN); }
void window_rectangle(bool s) { if (s) lo_send(m_process_address,"/window_type","i",window::RECTANGLE); } void window_rectangle(bool s) { if (s) send_process_osc("/window_type","i",window::RECTANGLE); }
void window_target_dodgy(bool s) { if (s) lo_send(m_process_address,"/target_window_type","i",window::DODGY); } void window_target_dodgy(bool s) { if (s) send_process_osc("/target_window_type","i",window::DODGY); }
void window_target_bartlett(bool s) { if (s) lo_send(m_process_address,"/target_window_type","i",window::BARTLETT); } void window_target_bartlett(bool s) { if (s) send_process_osc("/target_window_type","i",window::BARTLETT); }
void window_target_blackman(bool s) { if (s) lo_send(m_process_address,"/target_window_type","i",window::BLACKMAN); } void window_target_blackman(bool s) { if (s) send_process_osc("/target_window_type","i",window::BLACKMAN); }
void window_target_flattop(bool s) { if (s) lo_send(m_process_address,"/target_window_type","i",window::FLAT_TOP); } void window_target_flattop(bool s) { if (s) send_process_osc("/target_window_type","i",window::FLAT_TOP); }
void window_target_gaussian(bool s) { if (s) lo_send(m_process_address,"/target_window_type","i",window::GAUSSIAN); } void window_target_gaussian(bool s) { if (s) send_process_osc("/target_window_type","i",window::GAUSSIAN); }
void window_target_hamming(bool s) { if (s) lo_send(m_process_address,"/target_window_type","i",window::HAMMING); } void window_target_hamming(bool s) { if (s) send_process_osc("/target_window_type","i",window::HAMMING); }
void window_target_hann(bool s) { if (s) lo_send(m_process_address,"/target_window_type","i",window::HANN); } void window_target_hann(bool s) { if (s) send_process_osc("/target_window_type","i",window::HANN); }
void window_target_rectangle(bool s) { if (s) lo_send(m_process_address,"/target_window_type","i",window::RECTANGLE); } void window_target_rectangle(bool s) { if (s) send_process_osc("/target_window_type","i",window::RECTANGLE); }
void record() { void record() {
if (m_save_wav=="") { if (m_save_wav=="") {
@ -213,13 +213,13 @@ private slots:
char fn[1024]; char fn[1024];
snprintf(fn,1024,"%s-%i",m_save_wav.c_str(),m_record_id); snprintf(fn,1024,"%s-%i",m_save_wav.c_str(),m_record_id);
lo_send(m_audio_address,"/record","s",fn); send_audio_osc("/record","s",fn);
cerr<<fn<<endl; cerr<<fn<<endl;
m_record_id++; m_record_id++;
} }
void stop_record() { void stop_record() {
lo_send(m_audio_address,"/stop",""); send_audio_osc("/stop","");
} }
void load_brain() { void load_brain() {
@ -229,7 +229,7 @@ private slots:
m_last_file, m_last_file,
QString("Brains (*.brain)")); QString("Brains (*.brain)"));
lo_send(m_process_address,"/load_brain","s",m_last_file.toStdString().c_str()); send_process_osc("/load_brain","s",m_last_file.toStdString().c_str());
} }
void save_brain() { void save_brain() {
m_last_file=QFileDialog::getSaveFileName( m_last_file=QFileDialog::getSaveFileName(
@ -238,7 +238,7 @@ private slots:
m_last_file, m_last_file,
QString("Brains (*.brain)")); QString("Brains (*.brain)"));
lo_send(m_process_address,"/save_brain","s",m_last_file.toStdString().c_str()); send_process_osc("/save_brain","s",m_last_file.toStdString().c_str());
} }
void load_session() { void load_session() {
@ -248,7 +248,7 @@ private slots:
m_last_file, m_last_file,
QString("Sessions (*.samplebrain)")); QString("Sessions (*.samplebrain)"));
lo_send(m_process_address,"/load_session","s",m_last_file.toStdString().c_str()); send_process_osc("/load_session","s",m_last_file.toStdString().c_str());
init_from_session(m_last_file.toStdString()); init_from_session(m_last_file.toStdString());
} }
@ -259,7 +259,7 @@ private slots:
m_last_file, m_last_file,
QString("Sessions (*.samplebrain)")); QString("Sessions (*.samplebrain)"));
lo_send(m_process_address,"/save_session","s",m_last_file.toStdString().c_str()); send_process_osc("/save_session","s",m_last_file.toStdString().c_str());
} }
void update_status() { void update_status() {
@ -267,18 +267,95 @@ private slots:
} }
void stereo_mode(bool s) { void stereo_mode(bool s) {
lo_send(m_audio_address,"/stereo","i",s); send_audio_osc("/stereo","i",s);
}
void net_enable(int id) {
cerr<<"enable "<<id<<endl;
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;
}
}
void net_connect(int id) {
cerr<<"connect "<<id<<endl;
} }
private: private:
// we want to be able to send out to
// multiple addresses over the network
class osc_destination {
public:
int m_id;
lo_address m_audio_address;
lo_address m_process_address;
// can't find a way to address these via qt
QLineEdit *m_address;
QCheckBox *m_enable;
bool m_enabled;
};
vector<osc_destination> m_destinations;
// all this to work around liblo's use of varargs...
void send_audio_osc(const char *name, const char *types) {
for (auto dest:m_destinations) {
if (dest.m_enabled) {
lo_send(dest.m_audio_address,name,types);
}
}
}
template <class T>
void send_audio_osc(const char *name, const char *types, T val) {
for (auto dest:m_destinations) {
if (dest.m_enabled) {
lo_send(dest.m_audio_address,name,types,val);
}
}
}
void send_process_osc(const char *name, const char *types) {
for (auto dest:m_destinations) {
if (dest.m_enabled) {
lo_send(dest.m_process_address,name,types);
}
}
}
template <class T>
void send_process_osc(const char *name, const char *types, T val) {
for (auto dest:m_destinations) {
if (dest.m_enabled) {
lo_send(dest.m_process_address,name,types,val);
}
}
}
void init_from_session(const string &filename); void init_from_session(const string &filename);
void add_gui_address(osc_destination &dest,
QSignalMapper* enable_mapper,
QSignalMapper* connect_mapper);
string m_save_wav; string m_save_wav;
QString m_last_file; QString m_last_file;
u32 m_record_id; u32 m_record_id;
Ui_MainWindow m_Ui; Ui_MainWindow m_Ui;
lo_address m_audio_address;
lo_address m_process_address;
feedback m_feedback; feedback m_feedback;
}; };

View File

@ -1,13 +1,13 @@
/******************************************************************************** /********************************************************************************
** Form generated from reading UI file 'samplebrainSm7172.ui' ** Form generated from reading UI file 'samplebrainZ17592.ui'
** **
** Created by: Qt User Interface Compiler version 4.8.6 ** Created by: Qt User Interface Compiler version 4.8.6
** **
** WARNING! All changes made in this file will be lost when recompiling UI file! ** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/ ********************************************************************************/
#ifndef SAMPLEBRAINSM7172_H #ifndef SAMPLEBRAINZ17592_H
#define SAMPLEBRAINSM7172_H #define SAMPLEBRAINZ17592_H
#include <QtCore/QVariant> #include <QtCore/QVariant>
#include <QtGui/QAction> #include <QtGui/QAction>
@ -22,7 +22,6 @@
#include <QtGui/QLabel> #include <QtGui/QLabel>
#include <QtGui/QListWidget> #include <QtGui/QListWidget>
#include <QtGui/QMainWindow> #include <QtGui/QMainWindow>
#include <QtGui/QPlainTextEdit>
#include <QtGui/QPushButton> #include <QtGui/QPushButton>
#include <QtGui/QRadioButton> #include <QtGui/QRadioButton>
#include <QtGui/QSlider> #include <QtGui/QSlider>
@ -153,9 +152,9 @@ public:
QPushButton *pushButtonLoadBrain; QPushButton *pushButtonLoadBrain;
QPushButton *pushButtonSaveBrain; QPushButton *pushButtonSaveBrain;
QSpacerItem *verticalSpacer_2; QSpacerItem *verticalSpacer_2;
QWidget *logTab; QWidget *netTab;
QHBoxLayout *horizontalLayout_15; QHBoxLayout *horizontalLayout_15;
QPlainTextEdit *plainTextEdit; QVBoxLayout *netContainer;
QHBoxLayout *horizontalLayout_12; QHBoxLayout *horizontalLayout_12;
QPushButton *pushButtonPlay; QPushButton *pushButtonPlay;
QPushButton *pushButtonStop; QPushButton *pushButtonStop;
@ -951,16 +950,16 @@ public:
horizontalLayout_5->addLayout(verticalLayout_2); horizontalLayout_5->addLayout(verticalLayout_2);
tabWidget->addTab(controlTab, QString()); tabWidget->addTab(controlTab, QString());
logTab = new QWidget(); netTab = new QWidget();
logTab->setObjectName(QString::fromUtf8("logTab")); netTab->setObjectName(QString::fromUtf8("netTab"));
horizontalLayout_15 = new QHBoxLayout(logTab); horizontalLayout_15 = new QHBoxLayout(netTab);
horizontalLayout_15->setObjectName(QString::fromUtf8("horizontalLayout_15")); horizontalLayout_15->setObjectName(QString::fromUtf8("horizontalLayout_15"));
plainTextEdit = new QPlainTextEdit(logTab); netContainer = new QVBoxLayout();
plainTextEdit->setObjectName(QString::fromUtf8("plainTextEdit")); netContainer->setObjectName(QString::fromUtf8("netContainer"));
horizontalLayout_15->addWidget(plainTextEdit); horizontalLayout_15->addLayout(netContainer);
tabWidget->addTab(logTab, QString()); tabWidget->addTab(netTab, QString());
verticalLayout_4->addWidget(tabWidget); verticalLayout_4->addWidget(tabWidget);
@ -1127,7 +1126,7 @@ public:
void retranslateUi(QMainWindow *MainWindow) void retranslateUi(QMainWindow *MainWindow)
{ {
MainWindow->setWindowTitle(QApplication::translate("MainWindow", "samplebrain 0.14", 0, QApplication::UnicodeUTF8)); MainWindow->setWindowTitle(QApplication::translate("MainWindow", "samplebrain 0.15", 0, QApplication::UnicodeUTF8));
label_19->setText(QApplication::translate("MainWindow", "brain tweaks", 0, QApplication::UnicodeUTF8)); label_19->setText(QApplication::translate("MainWindow", "brain tweaks", 0, QApplication::UnicodeUTF8));
label_6->setText(QApplication::translate("MainWindow", "fft / mfcc", 0, QApplication::UnicodeUTF8)); label_6->setText(QApplication::translate("MainWindow", "fft / mfcc", 0, QApplication::UnicodeUTF8));
#ifndef QT_NO_TOOLTIP #ifndef QT_NO_TOOLTIP
@ -1264,7 +1263,7 @@ public:
pushButtonLoadBrain->setText(QApplication::translate("MainWindow", "load brain", 0, QApplication::UnicodeUTF8)); pushButtonLoadBrain->setText(QApplication::translate("MainWindow", "load brain", 0, QApplication::UnicodeUTF8));
pushButtonSaveBrain->setText(QApplication::translate("MainWindow", "save brain", 0, QApplication::UnicodeUTF8)); pushButtonSaveBrain->setText(QApplication::translate("MainWindow", "save brain", 0, QApplication::UnicodeUTF8));
tabWidget->setTabText(tabWidget->indexOf(controlTab), QApplication::translate("MainWindow", "search", 0, QApplication::UnicodeUTF8)); tabWidget->setTabText(tabWidget->indexOf(controlTab), QApplication::translate("MainWindow", "search", 0, QApplication::UnicodeUTF8));
tabWidget->setTabText(tabWidget->indexOf(logTab), QApplication::translate("MainWindow", "log", 0, QApplication::UnicodeUTF8)); tabWidget->setTabText(tabWidget->indexOf(netTab), QApplication::translate("MainWindow", "net", 0, QApplication::UnicodeUTF8));
pushButtonPlay->setText(QString()); pushButtonPlay->setText(QString());
pushButtonStop->setText(QString()); pushButtonStop->setText(QString());
pushButtonRecord->setText(QString()); pushButtonRecord->setText(QString());
@ -1282,4 +1281,4 @@ namespace Ui {
QT_END_NAMESPACE QT_END_NAMESPACE
#endif // SAMPLEBRAINSM7172_H #endif // SAMPLEBRAINZ17592_H

View File

@ -46,7 +46,8 @@ void brain::load_sound(std::string filename, stereo_mode mode) {
if (f!=NULL) { if (f!=NULL) {
sample s(sfinfo.frames); sample s(sfinfo.frames);
float *temp = new float[sfinfo.channels * sfinfo.frames]; float *temp = new float[sfinfo.channels * sfinfo.frames];
sf_readf_float(f, temp, sfinfo.channels * sfinfo.frames);
sf_read_float(f, temp, sfinfo.channels * sfinfo.frames);
if (mode==MIX) { if (mode==MIX) {
for(u32 i=0; i<sfinfo.frames; i++) { for(u32 i=0; i<sfinfo.frames; i++) {

View File

@ -25,9 +25,13 @@
#include "block.h" #include "block.h"
#include "brain.h" #include "brain.h"
#include "renderer.h" #include "renderer.h"
#include <pthread.h>
using namespace std; using namespace std;
pthread_mutex_t* m_fuz_mutex;
void unit_test() { void unit_test() {
cerr<<"testing block"<<endl; cerr<<"testing block"<<endl;
if (block::unit_test()) cerr<<"passed"<<endl; if (block::unit_test()) cerr<<"passed"<<endl;
@ -45,69 +49,85 @@ audio_device *a = NULL;
void run_audio(void* c, unsigned int frames) { void run_audio(void* c, unsigned int frames) {
a->left_out.zero(); a->left_out.zero();
renderer *rr = (renderer*)c; renderer *rr = (renderer*)c;
pthread_mutex_lock(m_fuz_mutex);
rr->process(frames,a->left_out.get_non_const_buffer()); rr->process(frames,a->left_out.get_non_const_buffer());
pthread_mutex_unlock(m_fuz_mutex);
a->right_out=a->left_out; a->right_out=a->left_out;
a->maybe_record(); a->maybe_record();
// sleep(1); // sleep(1);
} }
int main(int argc, char *argv[]) const char *fuz_samplefile() {
{ switch (rand()%20) {
// unit_test(); case 0: return "../sound/source/KONG.WAV";
u32 len=1000; case 1: return "../sound/source/KONG.WAV";
search_params p(0.5,0,0,99,0); case 2: return "../sound/source/CCBEGIN.WAV";
case 3: return "../sound/source/cc-end.wav";
cerr<<"starting"<<endl; case 4: return "../sound/source/cc-extra.wav";
/* { case 5: return "../sound/source/cc-high.wav";
brain source; case 6: return "../sound/source/cc-magic.wav";
case 7: return "../sound/source/cc-start.wav";
case 8: return "../sound/source/cc-warp.wav";
// source.load_sound("../sound/source/shostakovich6.wav"); // source.load_sound("../sound/source/shostakovich6.wav");
case 9: return "../sound/source/808.wav";
case 10: return "../sound/source/joey.wav";
case 11: return "../sound/source/pw2.wav";
case 12: return "../sound/source/pw3.wav";
case 13: return "../sound/source/claps.wav";
case 14: return "../sound/source/eagle.wav";
case 15: return "../sound/source/rise.wav";
case 16: return "../sound/source/totalsine.wav";
case 17: return "../sound/source/sailingbybit.wav";
case 18: return "../sound/source/dreambit.wav";
case 19: return "../sound/source/apache.wav";
}
}
// source.load_sound("../sound/source/808.wav"); float fuz_rr_f(float start, float end) {
// source.load_sound("../sound/source/joey.wav"); float t=rand()%999999/9999999.0f;
// source.load_sound("../sound/source/pw2.wav"); return t*(end-start)+start;
// source.load_sound("../sound/source/pw3.wav"); }
// source.load_sound("../sound/source/claps.wav");
// source.load_sound("../sound/source/eagle.wav");
// source.load_sound("../sound/source/rise.wav");
// source.load_sound("../sound/source/totalsine.wav");
// source.load_sound("../sound/source/sailingbybit.wav"); int fuz_rr_i(int start, int end) {
// source.load_sound("../sound/source/dreambit.wav"); return (int)fuz_rr_f(start,end);
source.load_sound("../sound/source/KONG.WAV"); }
source.load_sound("../sound/source/BIRD.WAV");
source.load_sound("../sound/source/CCBEGIN.WAV"); void fuz_new_brain(search_params p) {
source.load_sound("../sound/source/cc-end.wav"); u32 len=fuz_rr_i(500,5000);
source.load_sound("../sound/source/cc-extra.wav"); brain source;
source.load_sound("../sound/source/cc-high.wav"); for (int i=0; i<5; i++) {
source.load_sound("../sound/source/cc-magic.wav"); cerr<<"loading sound..."<<endl;
source.load_sound("../sound/source/cc-start.wav"); source.load_sound(fuz_samplefile(),brain::MIX);
source.load_sound("../sound/source/cc-warp.wav"); }
cerr<<"loaded sounds"<<endl; cerr<<"loaded sounds"<<endl;
cerr<<endl; cerr<<endl;
source.init(len,len-len,window::HANN); source.init(len,len-len,window::HANN);
source.build_synapses_fixed(p); source.build_synapses_fixed(p);
source.set_usage_falloff(0.9); cerr<<"saving brain"<<endl;
ofstream of("fuz.brain",ios::binary);
ofstream of("8bit.brain",ios::binary);
of||source; of||source;
of.close(); of.close();
} }
*/
void fuz() {
search_params p(0.5,0,0,99,0);
cerr<<"starting"<<endl;
fuz_new_brain(p);
cerr<<"reloading brain"<<endl;
brain source; brain source;
ifstream ifs("mix.brain",ios::binary); ifstream ifs("fuz.brain",ios::binary);
ifs||source; ifs||source;
ifs.close(); ifs.close();
brain target; brain target;
target.load_sound("../sound/source/apache.wav"); target.load_sound(fuz_samplefile(),brain::MIX);
//target.load_sound("../sound/source/pw2.wav"); u32 len=fuz_rr_i(500,5000);
//target.load_sound("../sound/source/sailingbybit.wav"); target.init(len,len-len/fuz_rr_i(1,16),window::HANN);
target.init(len,len-len/8,window::HANN);
cerr<<"ready..."<<endl; cerr<<"ready..."<<endl;
cerr<<"we have "<<source.get_num_blocks()<<" brain blocks ("<<source.get_num_blocks()*len/44100.0<<" secs)"<<endl<<endl; cerr<<"we have "<<source.get_num_blocks()<<" brain blocks ("<<source.get_num_blocks()*len/44100.0<<" secs)"<<endl<<endl;
@ -118,21 +138,68 @@ int main(int argc, char *argv[])
renderer rr(source,target); renderer rr(source,target);
rr.set_playing(true); rr.set_playing(true);
rr.get_params()->m_ratio=0; // a->start_recording("debug");
rr.get_params()->m_usage_importance=0.6;
source.set_usage_falloff(0.9);
rr.get_params()->m_num_synapses=40;
rr.set_slide_error(3400.5);
rr.set_search_algo(renderer::SYNAPTIC);
rr.set_target_mix(0.9);
rr.set_stretch(10);
a->start_recording("debug");
a->m_client.set_callback(run_audio, &rr); a->m_client.set_callback(run_audio, &rr);
//target.resynth("shosta-dream-0.5.wav",source,0.5); //target.resynth("shosta-dream-0.5.wav",source,0.5);
u32 counter=0;
while (true) {
if (counter>5) {
pthread_mutex_lock(m_fuz_mutex);
while (true) sleep(1); switch (rand()%10) {
case 0: {
fuz_new_brain(*rr.get_params());
cerr<<"reloading brain"<<endl;
ifstream ifs("fuz.brain",ios::binary);
ifs||source;
ifs.close();
} break;
case 1: {
cerr<<"reloading target"<<endl;
target.clear();
target.load_sound(fuz_samplefile(),brain::MIX);
u32 len=fuz_rr_i(500,5000);
target.init(len,len-len/fuz_rr_i(1,16),window::HANN);
} break;
}
cerr<<"switch"<<endl;
rr.get_params()->m_ratio=fuz_rr_f(0,1);
rr.get_params()->m_n_ratio=fuz_rr_f(0,1);
rr.get_params()->m_fft1_start=fuz_rr_i(0,49);
rr.get_params()->m_fft1_end=fuz_rr_f(50,100);
rr.get_params()->m_stickyness=fuz_rr_f(0,1);
rr.get_params()->m_usage_importance=fuz_rr_f(0,1);
source.set_usage_falloff(fuz_rr_f(0,1));
rr.get_params()->m_num_synapses=fuz_rr_i(2,1000);
rr.set_slide_error(fuz_rr_i(100,10000));
switch(rand()%3) {
case 0: rr.set_search_algo(renderer::BASIC); break;
case 1: rr.set_search_algo(renderer::SYNAPTIC); break;
case 2: rr.set_search_algo(renderer::SYNAPTIC_SLIDE); break;
}
rr.set_target_mix(0.2);
rr.set_stretch(1);
counter=0;
pthread_mutex_unlock(m_fuz_mutex);
}
sleep(1);
cerr<<counter<<endl;
counter++;
}
} }
int main(int argc, char *argv[])
{
m_fuz_mutex = new pthread_mutex_t;
pthread_mutex_init(m_fuz_mutex,NULL);
//unit_test();
fuz();
}

View File

@ -7,7 +7,7 @@ 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::_update(std::string msg) { void status::_update(std::string msg) {
cerr<<msg<<endl; //cerr<<msg<<endl;
lo_send(m_address,"/report","s",msg.c_str()); lo_send(m_address,"/report","s",msg.c_str());
} }