From cc8d62af149323752ed6a6ea0fb3b6b7407ea77b Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 29 Sep 2018 18:48:05 +0200 Subject: Remove all channel map ids if in use when deleting a channel. --- src/mainwindow.cc | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/src/mainwindow.cc b/src/mainwindow.cc index 4084df1..ad13975 100644 --- a/src/mainwindow.cc +++ b/src/mainwindow.cc @@ -148,13 +148,6 @@ MainWindow::MainWindow(Settings& settings) channel_list = new QListWidget(); connect(channel_list, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(channelDoubleClicked(QListWidgetItem*))); -// channel_list->addItems({"AmbL", "AmbR", "Kdrum_back", "Kdrum_front", -// "Hihat", "OHL", "OHR", "Ride","Snare_bottom", -// "Snare_top", "Tom1", "Tom2", "Tom3"}); -// for(int i = 0; i < channel_list->count(); ++i) -// { -// channel_list->item(i)->setIcon(QPixmap(":icons/channel.png")); -// } l->addWidget(tools); l->addWidget(channel_list); @@ -222,9 +215,8 @@ void MainWindow::removeInstrument() int ret = QMessageBox::question(this, tr("Delete Instrument"), tr("Are you sure you want to delete the selected " - "instrument?"), - QMessageBox::Yes | QMessageBox::No | - QMessageBox::Cancel); + "instrument(s)?"), + QMessageBox::Yes | QMessageBox::Cancel); if(ret != QMessageBox::Yes) { return; @@ -289,10 +281,36 @@ void MainWindow::addChannel() void MainWindow::removeChannel() { + int ret = + QMessageBox::question(this, tr("Delete Channel"), + tr("Are you sure you want to delete the selected " + "channel(s)?"), + QMessageBox::Yes | QMessageBox::Cancel); + if(ret != QMessageBox::Yes) + { + return; + } + auto items = channel_list->selectedItems(); for(auto item : items) { auto id = item->data(Qt::UserRole).toInt(); + + auto instrument_ids = project.getInstrumentList(); + for(auto instrument_id : instrument_ids) + { + auto& instrument = project.getInstrument(instrument_id); + auto audiofile_ids = instrument.getAudioFileList(); + for(auto audiofile_id : audiofile_ids) + { + auto& audiofile = instrument.getAudioFile(audiofile_id); + if(audiofile.getChannelMapId() == id) + { + audiofile.setChannelMapId(-1); // Unset channel map + } + } + } + project.deleteChannel(id); delete item; } -- cgit v1.2.3