samplebrain/app/MainWindow.cpp

188 lines
6.3 KiB
C++
Raw Normal View History

2022-09-08 08:21:53 -03:00
// Copyright (C) 2022 Then Try This
2015-07-21 10:58:13 -03:00
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2015-07-11 07:28:35 -03:00
#include <QtGui>
#include <iostream>
2015-10-16 12:23:51 -03:00
#include <list>
2015-07-11 07:28:35 -03:00
#include "MainWindow.h"
#include "feedback.h"
2015-10-16 12:23:51 -03:00
#include "renderer.h"
2015-07-11 07:28:35 -03:00
using namespace std;
2015-07-21 10:58:13 -03:00
MainWindow::MainWindow() :
m_last_file("."),
m_feedback("8890")
2015-07-11 07:28:35 -03:00
{
2016-02-26 13:11:46 -03:00
m_sound_item_enable_mapper = new QSignalMapper(this);
m_sound_item_delete_mapper = new QSignalMapper(this);
connect(m_sound_item_enable_mapper,
SIGNAL(mapped(int)), this, SLOT(sound_enable(int)));
connect(m_sound_item_delete_mapper,
SIGNAL(mapped(int)), this, SLOT(delete_sound(int)));
m_Ui.setupUi(this);
setUnifiedTitleAndToolBarOnMac(true);
2016-02-29 13:24:57 -03:00
m_Ui.verticalLayout_5->setSpacing(0);
m_Ui.verticalLayout_5->setMargin(0);
m_Ui.verticalLayout_5->setContentsMargins(0,0,0,0);
2016-02-26 13:11:46 -03:00
m_Ui.brain_contents->setAlignment(Qt::AlignTop);
m_Ui.brain_contents->setSpacing(0);
m_Ui.brain_contents->setMargin(0);
m_Ui.brain_contents->setContentsMargins(0,0,0,0);
2016-02-29 13:24:57 -03:00
// add default local dest
// turn on first one
2016-02-26 13:11:46 -03:00
QSignalMapper* enable_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;
2016-02-26 11:05:15 -03:00
add_gui_address(d,enable_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)));
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()));
timer->start(1000);
timer->setInterval(500);
m_save_wav="";
m_record_id=0;
2015-07-11 07:28:35 -03:00
}
2015-10-16 12:23:51 -03:00
void MainWindow::add_gui_address(osc_destination &dest,
2016-02-26 11:05:15 -03:00
QSignalMapper* enable_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);
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);
}
2015-10-16 12:23:51 -03:00
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??
ifstream ifs(filename.c_str(),ios::binary);
if (!ifs) return;
2015-10-16 12:23:51 -03:00
brain s,t;
2016-02-03 13:45:09 -02:00
u32 version=0;
ifs||version;
2015-10-16 12:23:51 -03:00
renderer r(s,t);
ifs||r;
2016-02-03 13:45:09 -02:00
ifs||r;
2015-10-16 12:23:51 -03:00
u32 target_windowsize;
u32 source_windowsize;
window::type target_window;
window::type source_window;
float target_overlap;
float source_overlap;
int t_int;
// skip this...
ifs||source_windowsize||source_overlap;
2016-02-25 09:47:38 -03:00
ifs||target_windowsize||target_overlap;
ifs||source_window||target_window;
2015-10-16 12:23:51 -03:00
// todo: probably don't need to load all the sample data too :/
ifs||s;
ifs||t;
// brain tweaks
search_params * p = r.get_params();
m_Ui.sliderRatio->setValue(p->m_ratio*100);
m_Ui.doubleSpinBoxRatio->setValue(p->m_ratio);
m_Ui.sliderNRatio->setValue(p->m_n_ratio*100);
m_Ui.doubleSpinBoxNRatio->setValue(p->m_n_ratio);
m_Ui.spinBoxFFT1Start->setValue(p->m_fft1_start);
m_Ui.spinBoxFFT1End->setValue(p->m_fft1_end);
m_Ui.sliderNovelty->setValue(p->m_usage_importance*100);
m_Ui.doubleSpinBoxNovelty->setValue(p->m_usage_importance);
m_Ui.sliderBoredom->setValue(s.get_usage_falloff()*100);
m_Ui.doubleSpinBoxBoredom->setValue(s.get_usage_falloff());
m_Ui.sliderStickyness->setValue(p->m_stickyness*100);
m_Ui.doubleSpinBoxStickyness->setValue(p->m_stickyness);
m_Ui.sliderSearchStretch->setValue(r.get_stretch());
m_Ui.spinBoxSearchStretch->setValue(r.get_stretch());
2016-02-25 09:47:38 -03:00
m_Ui.comboBoxAlgorithm->setCurrentIndex(r.get_search_algo());
2015-10-16 12:23:51 -03:00
m_Ui.sliderSynapses->setValue(p->m_num_synapses);
m_Ui.spinBoxSynapses->setValue(p->m_num_synapses);
m_Ui.sliderSlideError->setValue(r.get_slide_error());
m_Ui.spinBoxSlideError->setValue(r.get_slide_error());
// target
m_Ui.spinBoxBlockSizeTarget->setValue(t.get_block_size());
m_Ui.doubleSpinBoxBlockOverlapTarget->setValue(t.get_overlap()/(float)t.get_block_size());
2016-02-25 09:47:38 -03:00
m_Ui.comboBoxTargetShape->setCurrentIndex(target_window);
2015-10-16 12:23:51 -03:00
// source
m_Ui.spinBoxBlockSize->setValue(s.get_block_size());
m_Ui.doubleSpinBoxBlockOverlap->setValue(s.get_overlap()/(float)s.get_block_size());
2016-02-25 09:47:38 -03:00
m_Ui.comboBoxBrainShape->setCurrentIndex(source_window);
2015-10-16 12:23:51 -03:00
// brain samples
2016-02-26 13:11:46 -03:00
m_sound_items.clear();
2016-02-26 11:05:15 -03:00
for (auto &i:s.get_samples()) {
2016-02-26 13:11:46 -03:00
sound_items::sound_item &si = m_sound_items.add(m_Ui.brain_contents,i.m_filename,i.m_enabled);
2015-10-16 12:23:51 -03:00
2016-02-26 13:11:46 -03:00
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);
}
// todo: might contain unprocessed samples in colour scheme
m_sound_items.recolour();
2016-02-25 09:47:38 -03:00
2015-10-16 12:23:51 -03:00
// mix
m_Ui.sliderTargetMix->setValue(r.get_target_mix()*100);
m_Ui.doubleSpinBoxTargetMix->setValue(r.get_target_mix());
m_Ui.sliderNMix->setValue(r.get_n_mix()*100);
m_Ui.doubleSpinBoxNMix->setValue(r.get_n_mix());
m_Ui.sliderAutotune->setValue(r.get_autotune()*100);
m_Ui.doubleSpinBoxAutotune->setValue(r.get_autotune());
}