mirror of
https://gitlab.com/then-try-this/samplebrain.git
synced 2025-05-12 10:37:20 +00:00
fixed sample crash and added network gui
This commit is contained in:
parent
7f0b469709
commit
1b0c6f04d5
@ -11,7 +11,7 @@
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>samplebrain 0.14</string>
|
||||
<string>samplebrain 0.15</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
@ -25,7 +25,7 @@
|
||||
</font>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
<number>1</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="controlTab">
|
||||
<attribute name="title">
|
||||
@ -1427,13 +1427,13 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="logTab">
|
||||
<widget class="QWidget" name="netTab">
|
||||
<attribute name="title">
|
||||
<string>log</string>
|
||||
<string>net</string>
|
||||
</attribute>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_15">
|
||||
<item>
|
||||
<widget class="QPlainTextEdit" name="plainTextEdit"/>
|
||||
<layout class="QVBoxLayout" name="netContainer"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
|
@ -31,8 +31,32 @@ MainWindow::MainWindow() :
|
||||
m_Ui.setupUi(this);
|
||||
setUnifiedTitleAndToolBarOnMac(true);
|
||||
|
||||
m_audio_address = lo_address_new_from_url("osc.udp://localhost:8888");
|
||||
m_process_address = lo_address_new_from_url("osc.udp://localhost:8889");
|
||||
// add default local dest
|
||||
// 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);
|
||||
connect(timer, SIGNAL(timeout()), this, SLOT(update_status()));
|
||||
@ -43,6 +67,27 @@ MainWindow::MainWindow() :
|
||||
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) {
|
||||
// pull the bits out of the file to set the interface...
|
||||
// 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::HANN: m_Ui.radioButton_hannTarget->setChecked(true); break;
|
||||
case window::RECTANGLE: m_Ui.radioButton_rectangleTarget->setChecked(true); break;
|
||||
default: break;
|
||||
};
|
||||
|
||||
// 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::HANN: m_Ui.radioButton_hann->setChecked(true); break;
|
||||
case window::RECTANGLE: m_Ui.radioButton_rectagle->setChecked(true); break;
|
||||
default: break;
|
||||
};
|
||||
|
||||
// brain samples
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include <iostream>
|
||||
#include <lo/lo.h>
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include "window.h"
|
||||
#include "feedback.h"
|
||||
|
||||
@ -34,105 +35,104 @@ public:
|
||||
MainWindow();
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
private slots:
|
||||
|
||||
void play_slot() { lo_send(m_audio_address,"/start",""); }
|
||||
void stop_slot() { lo_send(m_audio_address,"/pause",""); }
|
||||
void play_slot() { send_audio_osc("/start",""); }
|
||||
void stop_slot() { send_audio_osc("/pause",""); }
|
||||
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
void autotune(double s) {
|
||||
lo_send(m_audio_address,"/autotune","f",s);
|
||||
send_audio_osc("/autotune","f",s);
|
||||
m_Ui.sliderAutotune->setValue(s*100);
|
||||
}
|
||||
|
||||
void fft1_start_slot(int s) { lo_send(m_audio_address,"/fft1_start","i",s); }
|
||||
void fft1_end_slot(int s) { lo_send(m_audio_address,"/fft1_end","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 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 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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
void boredom_slot(int s) {
|
||||
float v=s/100.0f;
|
||||
lo_send(m_audio_address,"/boredom","f",v);
|
||||
send_audio_osc("/boredom","f",v);
|
||||
m_Ui.doubleSpinBoxBoredom->setValue(v);
|
||||
}
|
||||
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);
|
||||
}
|
||||
void synapses(int s) {
|
||||
lo_send(m_audio_address,"/synapses","i",s);
|
||||
send_audio_osc("/synapses","i",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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
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) {
|
||||
lo_send(m_audio_address,"/slide-error","i",s);
|
||||
send_audio_osc("/slide-error","i",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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
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_rev_basic(bool s) { if (s) lo_send(m_audio_address,"/search_algo","i",1); }
|
||||
void algo_synaptic(bool s) { if (s) lo_send(m_audio_address,"/search_algo","i",2); }
|
||||
void algo_synaptic_slide(bool s) { if (s) lo_send(m_audio_address,"/search_algo","i",3); }
|
||||
void algo_basic(bool s) { if (s) send_audio_osc("/search_algo","i",0); }
|
||||
void algo_rev_basic(bool s) { if (s) send_audio_osc("/search_algo","i",1); }
|
||||
void algo_synaptic(bool s) { if (s) send_audio_osc("/search_algo","i",2); }
|
||||
void algo_synaptic_slide(bool s) { if (s) send_audio_osc("/search_algo","i",3); }
|
||||
|
||||
void run_slot() {}
|
||||
void load_target() {
|
||||
@ -142,15 +142,15 @@ private slots:
|
||||
m_last_file,
|
||||
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_overlap(double s) { lo_send(m_process_address,"/target_overlap","f",s); }
|
||||
void generate_target_blocks() { lo_send(m_process_address,"/generate_target",""); }
|
||||
void block_size(int s) { lo_send(m_process_address,"/source_block_size","i",s); }
|
||||
void block_overlap(double s) { lo_send(m_process_address,"/source_overlap","f",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 generate_target_blocks() { send_process_osc("/generate_target",""); }
|
||||
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 fft_spectrum_size(int) {}
|
||||
void generate() { lo_send(m_process_address,"/generate_brain",""); }
|
||||
void generate() { send_process_osc("/generate_brain",""); }
|
||||
void load_sound() {
|
||||
m_last_file=QFileDialog::getOpenFileName(
|
||||
this,
|
||||
@ -158,42 +158,42 @@ private slots:
|
||||
m_last_file,
|
||||
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);
|
||||
}
|
||||
void delete_sound() {
|
||||
QList<QListWidgetItem *> itemList = m_Ui.listWidgetSounds->selectedItems();
|
||||
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());
|
||||
}
|
||||
void clear_brain() {
|
||||
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();
|
||||
}
|
||||
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_bartlett(bool s) { if (s) lo_send(m_process_address,"/window_type","i",window::BARTLETT); }
|
||||
void window_blackman(bool s) { if (s) lo_send(m_process_address,"/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_gaussian(bool s) { if (s) lo_send(m_process_address,"/window_type","i",window::GAUSSIAN); }
|
||||
void window_hamming(bool s) { if (s) lo_send(m_process_address,"/window_type","i",window::HAMMING); }
|
||||
void window_hann(bool s) { if (s) lo_send(m_process_address,"/window_type","i",window::HANN); }
|
||||
void window_rectangle(bool s) { if (s) lo_send(m_process_address,"/window_type","i",window::RECTANGLE); }
|
||||
void window_dodgy(bool s) { if (s) send_process_osc("/window_type","i",window::DODGY); }
|
||||
void window_bartlett(bool s) { if (s) send_process_osc("/window_type","i",window::BARTLETT); }
|
||||
void window_blackman(bool s) { if (s) send_process_osc("/window_type","i",window::BLACKMAN); }
|
||||
void window_flattop(bool s) { if (s) send_process_osc("/window_type","i",window::FLAT_TOP); }
|
||||
void window_gaussian(bool s) { if (s) send_process_osc("/window_type","i",window::GAUSSIAN); }
|
||||
void window_hamming(bool s) { if (s) send_process_osc("/window_type","i",window::HAMMING); }
|
||||
void window_hann(bool s) { if (s) send_process_osc("/window_type","i",window::HANN); }
|
||||
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_bartlett(bool s) { if (s) lo_send(m_process_address,"/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_flattop(bool s) { if (s) lo_send(m_process_address,"/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_hamming(bool s) { if (s) lo_send(m_process_address,"/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_rectangle(bool s) { if (s) lo_send(m_process_address,"/target_window_type","i",window::RECTANGLE); }
|
||||
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) send_process_osc("/target_window_type","i",window::BARTLETT); }
|
||||
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) send_process_osc("/target_window_type","i",window::FLAT_TOP); }
|
||||
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) send_process_osc("/target_window_type","i",window::HAMMING); }
|
||||
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) send_process_osc("/target_window_type","i",window::RECTANGLE); }
|
||||
|
||||
void record() {
|
||||
if (m_save_wav=="") {
|
||||
@ -213,13 +213,13 @@ private slots:
|
||||
|
||||
char fn[1024];
|
||||
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;
|
||||
m_record_id++;
|
||||
}
|
||||
|
||||
void stop_record() {
|
||||
lo_send(m_audio_address,"/stop","");
|
||||
send_audio_osc("/stop","");
|
||||
}
|
||||
|
||||
void load_brain() {
|
||||
@ -229,7 +229,7 @@ private slots:
|
||||
m_last_file,
|
||||
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() {
|
||||
m_last_file=QFileDialog::getSaveFileName(
|
||||
@ -238,7 +238,7 @@ private slots:
|
||||
m_last_file,
|
||||
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() {
|
||||
@ -248,7 +248,7 @@ private slots:
|
||||
m_last_file,
|
||||
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());
|
||||
}
|
||||
|
||||
@ -259,7 +259,7 @@ private slots:
|
||||
m_last_file,
|
||||
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() {
|
||||
@ -267,18 +267,95 @@ private slots:
|
||||
}
|
||||
|
||||
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:
|
||||
|
||||
// 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 add_gui_address(osc_destination &dest,
|
||||
QSignalMapper* enable_mapper,
|
||||
QSignalMapper* connect_mapper);
|
||||
|
||||
string m_save_wav;
|
||||
QString m_last_file;
|
||||
u32 m_record_id;
|
||||
Ui_MainWindow m_Ui;
|
||||
lo_address m_audio_address;
|
||||
lo_address m_process_address;
|
||||
feedback m_feedback;
|
||||
};
|
||||
|
@ -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
|
||||
**
|
||||
** WARNING! All changes made in this file will be lost when recompiling UI file!
|
||||
********************************************************************************/
|
||||
|
||||
#ifndef SAMPLEBRAINSM7172_H
|
||||
#define SAMPLEBRAINSM7172_H
|
||||
#ifndef SAMPLEBRAINZ17592_H
|
||||
#define SAMPLEBRAINZ17592_H
|
||||
|
||||
#include <QtCore/QVariant>
|
||||
#include <QtGui/QAction>
|
||||
@ -22,7 +22,6 @@
|
||||
#include <QtGui/QLabel>
|
||||
#include <QtGui/QListWidget>
|
||||
#include <QtGui/QMainWindow>
|
||||
#include <QtGui/QPlainTextEdit>
|
||||
#include <QtGui/QPushButton>
|
||||
#include <QtGui/QRadioButton>
|
||||
#include <QtGui/QSlider>
|
||||
@ -153,9 +152,9 @@ public:
|
||||
QPushButton *pushButtonLoadBrain;
|
||||
QPushButton *pushButtonSaveBrain;
|
||||
QSpacerItem *verticalSpacer_2;
|
||||
QWidget *logTab;
|
||||
QWidget *netTab;
|
||||
QHBoxLayout *horizontalLayout_15;
|
||||
QPlainTextEdit *plainTextEdit;
|
||||
QVBoxLayout *netContainer;
|
||||
QHBoxLayout *horizontalLayout_12;
|
||||
QPushButton *pushButtonPlay;
|
||||
QPushButton *pushButtonStop;
|
||||
@ -951,16 +950,16 @@ public:
|
||||
horizontalLayout_5->addLayout(verticalLayout_2);
|
||||
|
||||
tabWidget->addTab(controlTab, QString());
|
||||
logTab = new QWidget();
|
||||
logTab->setObjectName(QString::fromUtf8("logTab"));
|
||||
horizontalLayout_15 = new QHBoxLayout(logTab);
|
||||
netTab = new QWidget();
|
||||
netTab->setObjectName(QString::fromUtf8("netTab"));
|
||||
horizontalLayout_15 = new QHBoxLayout(netTab);
|
||||
horizontalLayout_15->setObjectName(QString::fromUtf8("horizontalLayout_15"));
|
||||
plainTextEdit = new QPlainTextEdit(logTab);
|
||||
plainTextEdit->setObjectName(QString::fromUtf8("plainTextEdit"));
|
||||
netContainer = new QVBoxLayout();
|
||||
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);
|
||||
|
||||
@ -1127,7 +1126,7 @@ public:
|
||||
|
||||
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_6->setText(QApplication::translate("MainWindow", "fft / mfcc", 0, QApplication::UnicodeUTF8));
|
||||
#ifndef QT_NO_TOOLTIP
|
||||
@ -1264,7 +1263,7 @@ public:
|
||||
pushButtonLoadBrain->setText(QApplication::translate("MainWindow", "load 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(logTab), QApplication::translate("MainWindow", "log", 0, QApplication::UnicodeUTF8));
|
||||
tabWidget->setTabText(tabWidget->indexOf(netTab), QApplication::translate("MainWindow", "net", 0, QApplication::UnicodeUTF8));
|
||||
pushButtonPlay->setText(QString());
|
||||
pushButtonStop->setText(QString());
|
||||
pushButtonRecord->setText(QString());
|
||||
@ -1282,4 +1281,4 @@ namespace Ui {
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // SAMPLEBRAINSM7172_H
|
||||
#endif // SAMPLEBRAINZ17592_H
|
||||
|
@ -46,7 +46,8 @@ void brain::load_sound(std::string filename, stereo_mode mode) {
|
||||
if (f!=NULL) {
|
||||
sample s(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) {
|
||||
for(u32 i=0; i<sfinfo.frames; i++) {
|
||||
|
@ -25,9 +25,13 @@
|
||||
#include "block.h"
|
||||
#include "brain.h"
|
||||
#include "renderer.h"
|
||||
#include <pthread.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
pthread_mutex_t* m_fuz_mutex;
|
||||
|
||||
|
||||
void unit_test() {
|
||||
cerr<<"testing block"<<endl;
|
||||
if (block::unit_test()) cerr<<"passed"<<endl;
|
||||
@ -45,69 +49,85 @@ audio_device *a = NULL;
|
||||
void run_audio(void* c, unsigned int frames) {
|
||||
a->left_out.zero();
|
||||
renderer *rr = (renderer*)c;
|
||||
pthread_mutex_lock(m_fuz_mutex);
|
||||
rr->process(frames,a->left_out.get_non_const_buffer());
|
||||
pthread_mutex_unlock(m_fuz_mutex);
|
||||
a->right_out=a->left_out;
|
||||
a->maybe_record();
|
||||
|
||||
// sleep(1);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// unit_test();
|
||||
u32 len=1000;
|
||||
search_params p(0.5,0,0,99,0);
|
||||
|
||||
cerr<<"starting"<<endl;
|
||||
/* {
|
||||
brain source;
|
||||
const char *fuz_samplefile() {
|
||||
switch (rand()%20) {
|
||||
case 0: return "../sound/source/KONG.WAV";
|
||||
case 1: return "../sound/source/KONG.WAV";
|
||||
case 2: return "../sound/source/CCBEGIN.WAV";
|
||||
case 3: return "../sound/source/cc-end.wav";
|
||||
case 4: return "../sound/source/cc-extra.wav";
|
||||
case 5: return "../sound/source/cc-high.wav";
|
||||
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");
|
||||
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");
|
||||
// source.load_sound("../sound/source/joey.wav");
|
||||
// source.load_sound("../sound/source/pw2.wav");
|
||||
// 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");
|
||||
float fuz_rr_f(float start, float end) {
|
||||
float t=rand()%999999/9999999.0f;
|
||||
return t*(end-start)+start;
|
||||
}
|
||||
|
||||
// source.load_sound("../sound/source/sailingbybit.wav");
|
||||
// source.load_sound("../sound/source/dreambit.wav");
|
||||
source.load_sound("../sound/source/KONG.WAV");
|
||||
source.load_sound("../sound/source/BIRD.WAV");
|
||||
source.load_sound("../sound/source/CCBEGIN.WAV");
|
||||
source.load_sound("../sound/source/cc-end.wav");
|
||||
source.load_sound("../sound/source/cc-extra.wav");
|
||||
source.load_sound("../sound/source/cc-high.wav");
|
||||
source.load_sound("../sound/source/cc-magic.wav");
|
||||
source.load_sound("../sound/source/cc-start.wav");
|
||||
source.load_sound("../sound/source/cc-warp.wav");
|
||||
int fuz_rr_i(int start, int end) {
|
||||
return (int)fuz_rr_f(start,end);
|
||||
}
|
||||
|
||||
void fuz_new_brain(search_params p) {
|
||||
u32 len=fuz_rr_i(500,5000);
|
||||
brain source;
|
||||
for (int i=0; i<5; i++) {
|
||||
cerr<<"loading sound..."<<endl;
|
||||
source.load_sound(fuz_samplefile(),brain::MIX);
|
||||
}
|
||||
|
||||
cerr<<"loaded sounds"<<endl;
|
||||
cerr<<endl;
|
||||
source.init(len,len-len,window::HANN);
|
||||
|
||||
source.build_synapses_fixed(p);
|
||||
source.set_usage_falloff(0.9);
|
||||
|
||||
ofstream of("8bit.brain",ios::binary);
|
||||
cerr<<"saving brain"<<endl;
|
||||
ofstream of("fuz.brain",ios::binary);
|
||||
of||source;
|
||||
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;
|
||||
ifstream ifs("mix.brain",ios::binary);
|
||||
ifstream ifs("fuz.brain",ios::binary);
|
||||
ifs||source;
|
||||
ifs.close();
|
||||
|
||||
brain target;
|
||||
target.load_sound("../sound/source/apache.wav");
|
||||
//target.load_sound("../sound/source/pw2.wav");
|
||||
//target.load_sound("../sound/source/sailingbybit.wav");
|
||||
|
||||
target.init(len,len-len/8,window::HANN);
|
||||
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);
|
||||
|
||||
cerr<<"ready..."<<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);
|
||||
rr.set_playing(true);
|
||||
rr.get_params()->m_ratio=0;
|
||||
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->start_recording("debug");
|
||||
a->m_client.set_callback(run_audio, &rr);
|
||||
|
||||
//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();
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ using namespace std;
|
||||
lo_address status::m_address = lo_address_new_from_url("osc.udp://localhost:8890");
|
||||
|
||||
void status::_update(std::string msg) {
|
||||
cerr<<msg<<endl;
|
||||
//cerr<<msg<<endl;
|
||||
lo_send(m_address,"/report","s",msg.c_str());
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user