From 0480d42dfd5d031f40bba02069bea0093a330d44 Mon Sep 17 00:00:00 2001 From: KinoMyu Date: Thu, 15 Feb 2018 04:32:57 -0800 Subject: [PATCH] Add 13 mode --- mainwindow.ui | 640 ++++++++++++++++++++++++++++++++++++++++----- src/mainwindow.cpp | 172 ++++++++---- src/mainwindow.h | 12 +- src/utils.cpp | 18 +- src/utils.h | 3 +- 5 files changed, 721 insertions(+), 124 deletions(-) diff --git a/mainwindow.ui b/mainwindow.ui index 5867b9f..3d0f1b5 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -6,8 +6,8 @@ 0 0 - 410 - 293 + 413 + 554 @@ -18,14 +18,14 @@ - 410 - 293 + 413 + 554 - 410 - 293 + 413 + 554 @@ -46,14 +46,14 @@ - + true - 40 - 148 + 41 + 278 16 16 @@ -76,8 +76,8 @@ - 120 - 148 + 121 + 278 16 16 @@ -94,14 +94,14 @@ - + true - 200 - 148 + 201 + 278 16 16 @@ -118,14 +118,14 @@ - + true - 280 - 148 + 281 + 278 16 16 @@ -148,8 +148,8 @@ - 360 - 148 + 361 + 278 16 16 @@ -178,9 +178,9 @@ - 20 - 220 - 371 + 14 + 480 + 381 22 @@ -205,8 +205,8 @@ - 210 - 185 + 214 + 445 181 22 @@ -238,8 +238,8 @@ - 20 - 185 + 14 + 445 181 22 @@ -268,11 +268,11 @@ 10 - + - 9 - 40 + 10 + 170 73 22 @@ -289,8 +289,8 @@ - 89 - 40 + 90 + 170 73 22 @@ -304,11 +304,11 @@ false - + - 169 - 40 + 170 + 170 73 22 @@ -322,11 +322,11 @@ false - + - 249 - 40 + 250 + 170 73 22 @@ -343,8 +343,8 @@ - 329 - 40 + 330 + 170 73 22 @@ -361,8 +361,8 @@ - 18 - 250 + 12 + 510 70 23 @@ -382,8 +382,8 @@ - 94 - 250 + 88 + 510 70 23 @@ -403,8 +403,8 @@ - 322 - 250 + 330 + 510 70 23 @@ -424,8 +424,8 @@ - 170 - 250 + 164 + 510 70 23 @@ -445,7 +445,7 @@ - 89 + 90 10 153 22 @@ -487,7 +487,7 @@ - 330 + 304 11 61 21 @@ -536,8 +536,8 @@ - 20 - 159 + 14 + 419 181 31 @@ -560,8 +560,8 @@ - 210 - 159 + 214 + 419 181 31 @@ -581,11 +581,11 @@ Qt::AlignCenter - + - 9 - 70 + 10 + 200 73 73 @@ -602,8 +602,8 @@ - 89 - 70 + 90 + 200 73 73 @@ -617,11 +617,11 @@ - + - 169 - 70 + 170 + 200 73 73 @@ -635,11 +635,11 @@ - + - 249 - 70 + 250 + 200 73 73 @@ -656,8 +656,8 @@ - 329 - 70 + 330 + 200 73 73 @@ -674,8 +674,8 @@ - 246 - 250 + 254 + 510 70 23 @@ -689,6 +689,510 @@ Random + + + true + + + + 281 + 148 + 16 + 16 + + + + + Segoe UI + + + + false + + + + + + + + + 10 + 40 + 73 + 22 + + + + + Segoe UI + + + + false + + + + + + 170 + 70 + 73 + 73 + + + + + Segoe UI + + + + + + + + + + 10 + 70 + 73 + 73 + + + + + Segoe UI + + + + + + + + + + 250 + 70 + 73 + 73 + + + + + Segoe UI + + + + + + + + + true + + + + 41 + 148 + 16 + 16 + + + + + Segoe UI + + + + false + + + + + + + + true + + + + 121 + 148 + 16 + 16 + + + + + Segoe UI + + + + false + + + + + + + + + 250 + 40 + 73 + 22 + + + + + Segoe UI + + + + false + + + + + + 90 + 40 + 73 + 22 + + + + + Segoe UI + + + + false + + + + + + 170 + 40 + 73 + 22 + + + + + Segoe UI + + + + false + + + + + true + + + + 201 + 148 + 16 + 16 + + + + + Segoe UI + + + + false + + + + + + + + + 90 + 70 + 73 + 73 + + + + + Segoe UI + + + + + + + + + true + + + + 361 + 408 + 16 + 16 + + + + + Segoe UI + + + + false + + + + + + + + + 90 + 300 + 73 + 22 + + + + + Segoe UI + + + + false + + + + + + 250 + 330 + 73 + 73 + + + + + Segoe UI + + + + + + + + + + 90 + 330 + 73 + 73 + + + + + Segoe UI + + + + + + + + + + 330 + 330 + 73 + 73 + + + + + Segoe UI + + + + + + + + + true + + + + 121 + 408 + 16 + 16 + + + + + Segoe UI + + + + false + + + + + + + + true + + + + 201 + 408 + 16 + 16 + + + + + Segoe UI + + + + false + + + + + + + + + 330 + 300 + 73 + 22 + + + + + Segoe UI + + + + false + + + + + + 170 + 300 + 73 + 22 + + + + + Segoe UI + + + + false + + + + + + 250 + 300 + 73 + 22 + + + + + Segoe UI + + + + false + + + + + true + + + + 281 + 408 + 16 + 16 + + + + + Segoe UI + + + + false + + + + + + + + + 170 + 330 + 73 + 73 + + + + + Segoe UI + + + + + + + + + + 360 + 11 + 61 + 21 + + + + + Segoe UI + + + + false + + + 13 + + + false + + diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 3b7be0c..b11bb39 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -21,25 +21,49 @@ MainWindow::MainWindow(QWidget *parent) : idol_mix_stream = BASS_Mixer_StreamCreate(44100,2,BASS_STREAM_DECODE); BASS_Mixer_StreamAddChannel(mix_stream, idol_mix_stream, 0); + unitsize = 5; idolsel[0] = ui->idolsel0; idolsel[1] = ui->idolsel1; idolsel[2] = ui->idolsel2; idolsel[3] = ui->idolsel3; idolsel[4] = ui->idolsel4; + idolsel[5] = ui->idolsel5; + idolsel[6] = ui->idolsel6; + idolsel[7] = ui->idolsel7; + idolsel[8] = ui->idolsel8; + idolsel[9] = ui->idolsel9; + idolsel[10] = ui->idolsel10; + idolsel[11] = ui->idolsel11; + idolsel[12] = ui->idolsel12; idolactivity[0] = ui->idolactive0; idolactivity[1] = ui->idolactive1; idolactivity[2] = ui->idolactive2; idolactivity[3] = ui->idolactive3; idolactivity[4] = ui->idolactive4; + idolactivity[5] = ui->idolactive5; + idolactivity[6] = ui->idolactive6; + idolactivity[7] = ui->idolactive7; + idolactivity[8] = ui->idolactive8; + idolactivity[9] = ui->idolactive9; + idolactivity[10] = ui->idolactive10; + idolactivity[11] = ui->idolactive11; + idolactivity[12] = ui->idolactive12; idolimg[0] = ui->idolimage0; idolimg[1] = ui->idolimage1; idolimg[2] = ui->idolimage2; idolimg[3] = ui->idolimage3; idolimg[4] = ui->idolimage4; + idolimg[5] = ui->idolimage5; + idolimg[6] = ui->idolimage6; + idolimg[7] = ui->idolimage7; + idolimg[8] = ui->idolimage8; + idolimg[9] = ui->idolimage9; + idolimg[10] = ui->idolimage10; + idolimg[11] = ui->idolimage11; + idolimg[12] = ui->idolimage12; bgmVol = 0.6; idolVol = 0.6; - solo = false; bgm = new HCAStreamChannel(&dec); currSong = ""; @@ -54,11 +78,19 @@ MainWindow::MainWindow(QWidget *parent) : connect(ui->idolSlider, SIGNAL(valueChanged(int)), this, SLOT(setIdolVol(int))); connect(ui->positionSlider, SIGNAL(valueChanged(int)), this, SLOT(setPosition(int))); connect(ui->songsel, SIGNAL(currentIndexChanged(QString)), this, SLOT(setBGM(QString))); - connect(ui->idolsel0, SIGNAL(currentIndexChanged(QString)), this, SLOT(setIdol0(QString))); - connect(ui->idolsel1, SIGNAL(currentIndexChanged(QString)), this, SLOT(setIdol1(QString))); - connect(ui->idolsel2, SIGNAL(currentIndexChanged(QString)), this, SLOT(setIdol2(QString))); - connect(ui->idolsel3, SIGNAL(currentIndexChanged(QString)), this, SLOT(setIdol3(QString))); - connect(ui->idolsel4, SIGNAL(currentIndexChanged(QString)), this, SLOT(setIdol4(QString))); + connect(idolsel[0], SIGNAL(currentIndexChanged(QString)), this, SLOT(setIdol0(QString))); + connect(idolsel[1], SIGNAL(currentIndexChanged(QString)), this, SLOT(setIdol1(QString))); + connect(idolsel[2], SIGNAL(currentIndexChanged(QString)), this, SLOT(setIdol2(QString))); + connect(idolsel[3], SIGNAL(currentIndexChanged(QString)), this, SLOT(setIdol3(QString))); + connect(idolsel[4], SIGNAL(currentIndexChanged(QString)), this, SLOT(setIdol4(QString))); + connect(idolsel[5], SIGNAL(currentIndexChanged(QString)), this, SLOT(setIdol5(QString))); + connect(idolsel[6], SIGNAL(currentIndexChanged(QString)), this, SLOT(setIdol6(QString))); + connect(idolsel[7], SIGNAL(currentIndexChanged(QString)), this, SLOT(setIdol7(QString))); + connect(idolsel[8], SIGNAL(currentIndexChanged(QString)), this, SLOT(setIdol8(QString))); + connect(idolsel[9], SIGNAL(currentIndexChanged(QString)), this, SLOT(setIdol9(QString))); + connect(idolsel[10], SIGNAL(currentIndexChanged(QString)), this, SLOT(setIdol10(QString))); + connect(idolsel[11], SIGNAL(currentIndexChanged(QString)), this, SLOT(setIdol11(QString))); + connect(idolsel[12], SIGNAL(currentIndexChanged(QString)), this, SLOT(setIdol12(QString))); connect(ui->randomizeButton, SIGNAL(released()), this, SLOT(randomize())); connect(ui->playButton, SIGNAL(released()), this, SLOT(play())); connect(ui->pauseButton, SIGNAL(released()), this, SLOT(pause())); @@ -66,6 +98,7 @@ MainWindow::MainWindow(QWidget *parent) : connect(ui->saveButton, SIGNAL(released()), this, SLOT(save())); connect(ui->soloButton, SIGNAL(toggled(bool)), this, SLOT(setSolo(bool))); connect(ui->unitButton, SIGNAL(toggled(bool)), this, SLOT(setUnit(bool))); + connect(ui->unitButton13, SIGNAL(toggled(bool)), this, SLOT(set13(bool))); parse_names(readablesong_to_filename, "res/songlist.txt", &(ui->songsel), 1); @@ -97,7 +130,7 @@ void MainWindow::updateUIPosition() if(!ui->positionSlider->isSliderDown()) { ui->positionSlider->blockSignals(true); - ui->positionSlider->setValue((double)pos/len*500); + ui->positionSlider->setValue((double)pos/len*ui->positionSlider->maximum()); ui->positionSlider->blockSignals(false); } DWORD p = BASS_ChannelBytes2Seconds(bgm->get_decode_channel(),pos); @@ -164,7 +197,7 @@ void MainWindow::randomize() { std::set seenset; int n; - for(int i = 0; i < NUM_IDOLS; ++i) + for(int i = 0; i < unitsize; ++i) { do { @@ -205,6 +238,53 @@ void MainWindow::setIdol4(const QString& qStr) setIdol(4); } +void MainWindow::setIdol5(const QString& qStr) +{ + currIdols[5] = qStr.toLocal8Bit().constData(); + setIdol(5); +} + +void MainWindow::setIdol6(const QString& qStr) +{ + currIdols[6] = qStr.toLocal8Bit().constData(); + setIdol(6); +} + +void MainWindow::setIdol7(const QString& qStr) +{ + currIdols[7] = qStr.toLocal8Bit().constData(); + setIdol(7); +} + +void MainWindow::setIdol8(const QString& qStr) +{ + currIdols[8] = qStr.toLocal8Bit().constData(); + setIdol(8); +} + +void MainWindow::setIdol9(const QString& qStr) +{ + currIdols[9] = qStr.toLocal8Bit().constData(); + setIdol(9); +} +void MainWindow::setIdol10(const QString& qStr) +{ + currIdols[10] = qStr.toLocal8Bit().constData(); + setIdol(10); +} + +void MainWindow::setIdol11(const QString& qStr) +{ + currIdols[11] = qStr.toLocal8Bit().constData(); + setIdol(11); +} + +void MainWindow::setIdol12(const QString& qStr) +{ + currIdols[12] = qStr.toLocal8Bit().constData(); + setIdol(12); +} + void MainWindow::setBGM(const QString& qStr) { currSong = qStr.toLocal8Bit().constData(); @@ -217,7 +297,7 @@ void MainWindow::setBGM(const QString& qStr) BASS_Mixer_StreamAddChannel(mix_stream, bgm->get_decode_channel(), 0); BASS_Mixer_ChannelSetPosition(bgm->get_decode_channel(), 0, BASS_POS_BYTE | BASS_POS_MIXER_RESET); BASS_ChannelSetAttribute(bgm->get_decode_channel(),BASS_ATTRIB_VOL,bgmVol); - parse_control_file(idolInfo, "res/" + convSongName + "/control" + (solo?"solo":"") + ".txt", idolVol); + parse_control_file(idolInfo, "res/" + convSongName + "/control" + std::to_string(unitsize) + ".txt", idolVol); for(int i = 0; i < NUM_IDOLS; ++i) { idolsel[i]->blockSignals(true); @@ -331,7 +411,7 @@ void MainWindow::setIdol(int index) HCAStreamChannel&& hcastream = HCAStreamChannel(&dec); DWORD pos = BASS_ChannelGetPosition(bgm->get_decode_channel(), BASS_POS_BYTE); hcastream.load("res/" + convSongName + "/" + convIdolName + ".hca", pos/4); - if(solo && index != 2) + if(index >= unitsize) { hcastream.destroy_channels(); } @@ -353,56 +433,48 @@ void MainWindow::setIdol(int index) void MainWindow::setUnit(bool checked) { - std::string convSongName = readablesong_to_filename[currSong]; - if(solo && checked) + if(unitsize!=5 && checked) { - solo = false; - for(int i = 0; i < NUM_IDOLS; ++i) - { - // Don't unload, rather just cleanup channels - BASS_Mixer_ChannelRemove(idols[i]->get_decode_channel()); - idols[i]->destroy_channels(); - idols[i]->make_channels(); - idolInfo[i].second.clear(); - } - // Set control and volume - parse_control_file(idolInfo, "res/" + convSongName + "/control.txt", idolVol); - DWORD idoldecodechannels[NUM_IDOLS]; - for(int i = 0; i < NUM_IDOLS; ++i) - { - idoldecodechannels[i] = idols[i]->get_decode_channel(); - DWORD position = BASS_ChannelGetPosition(bgm->get_decode_channel(), BASS_POS_BYTE); - BASS_ChannelSetPosition(idols[i]->get_decode_channel(), position / 2, BASS_POS_BYTE); - BASS_Mixer_StreamAddChannel(idol_mix_stream, idols[i]->get_decode_channel(), 0); - fuzzy_adjust_vol_pan(idoldecodechannels[i], idolInfo[i]); - } - set_auto_vol_pan_all(idolInfo, idoldecodechannels); + unitsize = 5; + reautomateVolumes(); } } void MainWindow::setSolo(bool checked) +{ + if(unitsize!=1 && checked) + { + unitsize = 1; + reautomateVolumes(); + } +} + +void MainWindow::set13(bool checked) +{ + if(unitsize!=13 && checked) + { + unitsize = 13; + reautomateVolumes(); + } +} + +void MainWindow::reautomateVolumes() { std::string convSongName = readablesong_to_filename[currSong]; - if(!solo && checked) + parse_control_file(idolInfo, "res/" + convSongName + "/control" + std::to_string(unitsize) + ".txt", idolVol); + for(int i = 0; i < NUM_IDOLS; ++i) { - solo = true; - for(int i = 0; i < NUM_IDOLS; ++i) + // Don't unload, rather just cleanup channels + BASS_Mixer_ChannelRemove(idols[i]->get_decode_channel()); + idols[i]->destroy_channels(); + if(i < unitsize) { - // Don't unload, rather just cleanup channels - BASS_Mixer_ChannelRemove(idols[i]->get_decode_channel()); - idols[i]->destroy_channels(); - if(i == 2) - { - idols[i]->make_channels(); - DWORD position = BASS_ChannelGetPosition(bgm->get_decode_channel(), BASS_POS_BYTE); - BASS_ChannelSetPosition(idols[i]->get_decode_channel(), position / 2, BASS_POS_BYTE); - } + idols[i]->make_channels(); + DWORD position = BASS_ChannelGetPosition(bgm->get_decode_channel(), BASS_POS_BYTE); + BASS_ChannelSetPosition(idols[i]->get_decode_channel(), position / 2, BASS_POS_BYTE); + fuzzy_adjust_vol_pan(idols[i]->get_decode_channel(), idolInfo[i]); + set_auto_vol_pan(idolInfo[i], idols[i]->get_decode_channel()); BASS_Mixer_StreamAddChannel(idol_mix_stream, idols[i]->get_decode_channel(), 0); - idolInfo[i].second.clear(); } - // Set control and volume - parse_control_file(idolInfo, "res/" + convSongName + "/controlsolo.txt", idolVol); - fuzzy_adjust_vol_pan(idols[2]->get_decode_channel(), idolInfo[2]); - set_auto_vol_pan(idolInfo[2], idols[2]->get_decode_channel()); } } diff --git a/src/mainwindow.h b/src/mainwindow.h index 0f8132f..75aa144 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -28,6 +28,7 @@ class MainWindow : public QMainWindow void setIdol(int index); void updateUIPosition(); void updateIdolActivity(); + void reautomateVolumes(); public slots: void setBGMVol(int value); @@ -39,6 +40,14 @@ public slots: void setIdol2(const QString& qStr); void setIdol3(const QString& qStr); void setIdol4(const QString& qStr); + void setIdol5(const QString& qStr); + void setIdol6(const QString& qStr); + void setIdol7(const QString& qStr); + void setIdol8(const QString& qStr); + void setIdol9(const QString& qStr); + void setIdol10(const QString& qStr); + void setIdol11(const QString& qStr); + void setIdol12(const QString& qStr); void setPosition(int value); void play(); void pause(); @@ -46,13 +55,14 @@ public slots: void save(); void setUnit(bool checked); void setSolo(bool checked); + void set13(bool checked); private: Ui::MainWindow *ui; + int unitsize; double bgmVol; double idolVol; int updateTimerId; - bool solo; HCAStreamChannel* bgm; HCAStreamChannel* idols[NUM_IDOLS]; ControlInfo idolInfo[NUM_IDOLS]; diff --git a/src/utils.cpp b/src/utils.cpp index 7327e8c..c485cf8 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include "../bass/bass.h" #include "utils.h" @@ -12,6 +13,13 @@ short safeadd(const short& a, const short& b) return a + b; } +double clamp(const double& d, const double& lower, const double& upper) +{ + if(d < lower) return lower; + if(d > upper) return upper; + return d; +} + void export_to_wav(DWORD bgm, DWORD idols[], const double& bgmVol, const double& idolVol, ControlInfo idolControlInfo[], const std::string& filename) { int pos = 0; @@ -95,7 +103,7 @@ void export_to_wav(DWORD bgm, DWORD idols[], const double& bgmVol, const double& void parse_control_file(ControlInfo idolInfo[], const std::string & control_file, double& idolVol) { - double volTable[] = { 0.75, 0.62, 0.53, 0.47, 0.42 }; + double volTable[] = { 0.75, 0.62, 0.55, 0.47, 0.42, 0.39, 0.37, 0.35, 0.33, 0.31, 0.3, 0.29, 0.28 }; VolumePan idolvolpan[NUM_IDOLS]; std::ifstream infilestream(control_file); std::string line; @@ -113,10 +121,12 @@ void parse_control_file(ControlInfo idolInfo[], const std::string & control_file { idolvolpan[i] = { 0, 0 }; } - int numIdols = line.length() - 1; - for (int i = 0; i <= numIdols; ++i) + size_t n = std::count(line.begin(), line.end(), 'x'); + int numIdols = (int)line.length() - 1 - n; + for (int i = 0; i <= (int)line.length() - 1; ++i) { - idolvolpan[line.at(i) - 48] = { volTable[numIdols], -0.2 * (numIdols / 2.0 - i) }; + if(line.at(i) != 'x') + idolvolpan[line.at(i) - 48] = { volTable[numIdols], clamp(-0.15 * ((line.length() - 1) / 2.0 - i), -1, 1) }; } for (int i = 0; i < NUM_IDOLS; ++i) { diff --git a/src/utils.h b/src/utils.h index 6c6b4b7..f6d3d82 100644 --- a/src/utils.h +++ b/src/utils.h @@ -3,7 +3,7 @@ #include #include -#define NUM_IDOLS 5 +#define NUM_IDOLS 13 struct VolumePan { @@ -14,6 +14,7 @@ struct VolumePan typedef std::pair> ControlInfo; short safeadd(const short& a, const short& b); +double clamp(const double& d, const double& lower, const double& upper); void export_to_wav(DWORD bgm, DWORD idols[], const double& bgmVol, const double& idolVol, ControlInfo idolControlInfo[], const std::string& filename); void parse_control_file(ControlInfo idolInfo[], const std::string& control_file, double& idolVol); void convert_to_left_right(VolumePan vp, double& leftVol, double& rightVol);