Skip to content

Commit

Permalink
Added checkbox disabling
Browse files Browse the repository at this point in the history
  • Loading branch information
KinoMyu committed Dec 24, 2017
1 parent 0f63407 commit e8c584f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 35 deletions.
78 changes: 45 additions & 33 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ MainWindow::MainWindow(QWidget *parent) :
ui->setupUi(this);

mix_stream = BASS_Mixer_StreamCreate(44100,2,0);
idol_mix_stream = BASS_Mixer_StreamCreate(44100,2,BASS_STREAM_DECODE);
BASS_Mixer_StreamAddChannel(mix_stream, idol_mix_stream, 0);

idolsel[0] = ui->idolsel0;
idolsel[1] = ui->idolsel1;
Expand Down Expand Up @@ -101,17 +103,26 @@ void MainWindow::updateIdolActivity()
DWORD pos;
for(int i = 0; i < NUM_IDOLS; ++i)
{
VolumePan vp;
pos = BASS_ChannelGetPosition(idols[i].get_decode_channel() , BASS_POS_BYTE) / 2;
DWORD last_pos = 0;
for (std::pair<DWORD, VolumePan> pos_vp : idolInfo[i].second)
if(idols[i].get_decode_channel() == 0)
{
if (pos >= last_pos && pos <= pos_vp.first)
break;
last_pos = pos_vp.first;
vp = pos_vp.second;
idolactivity[i]->setDisabled(true);
idolactivity[i]->setChecked(false);
}
else
{
idolactivity[i]->setEnabled(true);
VolumePan vp;
pos = BASS_ChannelGetPosition(idols[i].get_decode_channel() , BASS_POS_BYTE) / 2;
DWORD last_pos = 0;
for (std::pair<DWORD, VolumePan> pos_vp : idolInfo[i].second)
{
if (pos >= last_pos && pos <= pos_vp.first)
break;
last_pos = pos_vp.first;
vp = pos_vp.second;
}
idolactivity[i]->setChecked(vp.vol > 0);
}
idolactivity[i]->setChecked(vp.vol > 0);
}
}

Expand Down Expand Up @@ -139,46 +150,30 @@ void MainWindow::setIdolVol(int value)
void MainWindow::setIdol0(const QString& qStr)
{
currIdols[0] = readableidol_to_filename[qStr.toUtf8().constData()];
// A bit hacky, as the pixmap goes out of scope.
QString filename = QString::fromStdString("res/img/" + currIdols[0] + ".png");
QPixmap pixmap = QPixmap(filename);
idolimg[0]->setPixmap(pixmap);
setIdol(0);
}

void MainWindow::setIdol1(const QString& qStr)
{
currIdols[1] = readableidol_to_filename[qStr.toUtf8().constData()];
QString filename = QString::fromStdString("res/img/" + currIdols[1] + ".png");
QPixmap pixmap = QPixmap(filename);
idolimg[1]->setPixmap(pixmap);
setIdol(1);
}

void MainWindow::setIdol2(const QString& qStr)
{
currIdols[2] = readableidol_to_filename[qStr.toUtf8().constData()];
QString filename = QString::fromStdString("res/img/" + currIdols[2] + ".png");
QPixmap pixmap = QPixmap(filename);
idolimg[2]->setPixmap(pixmap);
setIdol(2);
}

void MainWindow::setIdol3(const QString& qStr)
{
currIdols[3] = readableidol_to_filename[qStr.toUtf8().constData()];
QString filename = QString::fromStdString("res/img/" + currIdols[3] + ".png");
QPixmap pixmap = QPixmap(filename);
idolimg[3]->setPixmap(pixmap);
setIdol(3);
}

void MainWindow::setIdol4(const QString& qStr)
{
currIdols[4] = readableidol_to_filename[qStr.toUtf8().constData()];
QString filename = QString::fromStdString("res/img/" + currIdols[4] + ".png");
QPixmap pixmap = QPixmap(filename);
idolimg[4]->setPixmap(pixmap);
setIdol(4);
}

Expand All @@ -198,8 +193,15 @@ void MainWindow::setBGM(const QString& qStr)
BASS_Mixer_ChannelRemove(idols[i].get_decode_channel());
idols[i].unload();
idols[i].load("res/" + currSong + "/" + currIdols[i] + ".hca");
BASS_Mixer_StreamAddChannel(mix_stream, idols[i].get_decode_channel(), 0);
idolInfo[i].second.clear();
if(solo && i != 2)
{
idols[i].destroy_channels();
}
else
{
BASS_Mixer_StreamAddChannel(idol_mix_stream, idols[i].get_decode_channel(), 0);
}
}
parse_control_file(idolInfo, "res/" + currSong + "/control" + (solo?"solo":"") + ".txt", idolVol);
DWORD idoldecodechannels[NUM_IDOLS];
Expand Down Expand Up @@ -285,18 +287,28 @@ void MainWindow::save()

void MainWindow::setIdol(int index)
{
QString filename = QString::fromStdString("res/img/" + currIdols[index] + ".png");
idolpixmap[index] = QPixmap(filename);
idolimg[index]->setPixmap(idolpixmap[index]);
// Cleanup wave and channel data
if(idols[index].get_decode_channel() != 0)
{
BASS_Mixer_ChannelRemove(idols[index].get_decode_channel());
idols[index].unload();
}
idols[index].load("res/" + currSong + "/" + currIdols[index] + ".hca");
set_auto_vol_pan(idolInfo[index], idols[index].get_decode_channel());
DWORD position = BASS_ChannelGetPosition(bgm.get_decode_channel(), BASS_POS_BYTE);
BASS_ChannelSetPosition(idols[index].get_decode_channel(), position / 2, BASS_POS_BYTE);
fuzzy_adjust_vol_pan(idols[index].get_decode_channel(), idolInfo[index]);
BASS_Mixer_StreamAddChannel(mix_stream, idols[index].get_decode_channel(), 0);
if(solo && index != 2)
{
idols[index].destroy_channels();
}
else
{
set_auto_vol_pan(idolInfo[index], idols[index].get_decode_channel());
DWORD position = BASS_ChannelGetPosition(bgm.get_decode_channel(), BASS_POS_BYTE);
BASS_ChannelSetPosition(idols[index].get_decode_channel(), position / 2, BASS_POS_BYTE);
fuzzy_adjust_vol_pan(idols[index].get_decode_channel(), idolInfo[index]);
BASS_Mixer_StreamAddChannel(idol_mix_stream, idols[index].get_decode_channel(), 0);
}
}

void MainWindow::setUnit(bool checked)
Expand All @@ -320,7 +332,7 @@ void MainWindow::setUnit(bool checked)
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(mix_stream, idols[i].get_decode_channel(), 0);
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);
Expand All @@ -343,7 +355,7 @@ void MainWindow::setSolo(bool checked)
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(mix_stream, idols[i].get_decode_channel(), 0);
BASS_Mixer_StreamAddChannel(idol_mix_stream, idols[i].get_decode_channel(), 0);
idolInfo[i].second.clear();
}
// Set control and volume
Expand Down
3 changes: 2 additions & 1 deletion src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,13 @@ public slots:
HCAStreamChannel bgm;
HCAStreamChannel idols[NUM_IDOLS];
ControlInfo idolInfo[NUM_IDOLS];
HSTREAM mix_stream;
HSTREAM mix_stream, idol_mix_stream;
std::string currSong, currIdols[NUM_IDOLS];
std::unordered_map<std::string, std::string> readableidol_to_filename, readablesong_to_filename;
QComboBox* idolsel[NUM_IDOLS];
QCheckBox* idolactivity[NUM_IDOLS];
QLabel* idolimg[NUM_IDOLS];
QPixmap idolpixmap[NUM_IDOLS];
};

#endif // MAINWINDOW_H
2 changes: 1 addition & 1 deletion src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,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.68, 0.57, 0.48, 0.425, 0.38 };
double volTable[] = { 0.75, 0.62, 0.53, 0.47, 0.42 };
VolumePan idolvolpan[NUM_IDOLS];
std::ifstream infilestream(control_file);
std::string line;
Expand Down

0 comments on commit e8c584f

Please sign in to comment.