From 055b2fdafaf6174c767fb5022f409b8ea1d30656 Mon Sep 17 00:00:00 2001 From: Alexander Diamadis Date: Sun, 31 Oct 2021 16:08:34 +0100 Subject: [PATCH] Added DAC to Library --- PA_Calculator.pro | 2 + cdac.cpp | 43 +++++++ cdac.h | 26 +++++ library.cpp | 277 ++++++++++++++++++++++++++++++++++++++-------- library.h | 45 +++++++- library.ui | 78 ++++++++++++- main.cpp | 10 +- mainwindow.cpp | 46 ++++++++ mainwindow.h | 8 ++ mainwindow.ui | 70 +++++++++++- 10 files changed, 540 insertions(+), 65 deletions(-) create mode 100644 cdac.cpp create mode 100644 cdac.h diff --git a/PA_Calculator.pro b/PA_Calculator.pro index 116901e..d28fff8 100644 --- a/PA_Calculator.pro +++ b/PA_Calculator.pro @@ -11,6 +11,7 @@ CONFIG += c++11 SOURCES += \ camp.cpp \ campmode.cpp \ + cdac.cpp \ cspeaker.cpp \ library.cpp \ main.cpp \ @@ -19,6 +20,7 @@ SOURCES += \ HEADERS += \ camp.h \ campmode.h \ + cdac.h \ cspeaker.h \ library.h \ mainwindow.h diff --git a/cdac.cpp b/cdac.cpp new file mode 100644 index 0000000..185b32f --- /dev/null +++ b/cdac.cpp @@ -0,0 +1,43 @@ +#include "cdac.h" +#include + +cdac::cdac() +{ + +} + +const std::string &cdac::name() const +{ + return m_name; +} + +void cdac::setName(const std::string &newName) +{ + m_name = newName; +} + +double cdac::outputLevel() const +{ + return m_outputLevel; +} + +void cdac::setOutputLevel(double newOutputLevel) +{ + m_outputLevel = newOutputLevel; +} + +QDataStream& operator >>(QDataStream& in, cdac& dac){ + QString name; + in >> name; + dac.m_name=name.toStdString(); + qreal outputLevel; + in >>outputLevel; + dac.setOutputLevel((double)outputLevel); + + return in; +} +QDataStream& operator <<(QDataStream& out,cdac& dac){ + out << QString::fromStdString(dac.name()); + out << qreal(dac.outputLevel()); + return out; +} diff --git a/cdac.h b/cdac.h new file mode 100644 index 0000000..1aaf7df --- /dev/null +++ b/cdac.h @@ -0,0 +1,26 @@ +#ifndef CDAC_H +#define CDAC_H +#include +#include +class cdac +{ +public: + cdac(); + cdac(std::string name,double outputLevel); + + const std::string &name() const; + void setName(const std::string &newName); + + double outputLevel() const; + void setOutputLevel(double newOutputLevel); + + friend QDataStream& operator <<(QDataStream& out,cdac& speaker); + friend QDataStream& operator >>(QDataStream& in,cdac& speaker); + +private: + std::string m_name; + double m_outputLevel; // in dBu + +}; + +#endif // CDAC_H diff --git a/library.cpp b/library.cpp index e02e993..bee948b 100644 --- a/library.cpp +++ b/library.cpp @@ -5,6 +5,7 @@ #include #include #include +#include "cdac.h" library::library(QWidget *parent) : QDialog(parent), @@ -13,6 +14,7 @@ library::library(QWidget *parent) : ui->setupUi(this); unsaved=false; speakerUnsaved=false; + dacUnsaved=false; } library::~library() @@ -51,6 +53,22 @@ cSpeaker *library::getSpeaker() return m_pSpeaker; } +void library::setDacPoint(cdac *dac, unsigned int dacCount) +{ + m_pDac=dac; + m_dacCount=dacCount; +} + +unsigned int library::getDacCount() +{ + return m_dacCount; +} + +cdac *library::getDacs() +{ + return m_pDac; +} + void library::open() { @@ -62,23 +80,15 @@ void library::open() //qDebug() << settings.value("library/path","none").toString(); refreshAmpView(); refreshSpeakerView(); + refreshDacView(); this->exec(); - if (unsaved or speakerUnsaved){ - QMessageBox::StandardButton reply; - reply = QMessageBox::question(this, "Unsaved Changes", "Save unsaved Changes?", - QMessageBox::Yes|QMessageBox::No); - if (reply == QMessageBox::Yes) { - on_pushButton_applyChanges_clicked(); - on_pushButton_applySpeaker_clicked(); - } - } - saveLibraryToFile(); } void library::on_pushButton_addAmp_clicked() { + confirmAmpChanges(); m_cAmpCount+=1; cAmp* tempAmps=new cAmp[m_cAmpCount]; for (unsigned int i=0;ilistWidget_dacView->clear(); + for (unsigned int i=0;ilistWidget_dacView->addItem(QString::fromStdString(m_pDac[i].name())); + } +} + int library::getCurrentAmpIndex() { return ui->listWidget_ampView->currentRow(); @@ -148,6 +166,83 @@ int library::getCurrentSpeakerIndex() return ui->listWidget_speakerView->currentRow(); } +int library::getCurrentDacIndex() +{ + return ui->listWidget_dacView->currentRow(); +} + +void library::ampEdited() +{ + if(unsaved==false){ + ui->listWidget_ampView->currentItem()->setText(ui->listWidget_ampView->currentItem()->text()+QString::fromStdString("*")); + unsaved =true; + } +} + +void library::speakerEdited() +{ + if (speakerUnsaved==false){ + ui->listWidget_speakerView->currentItem()->setText(ui->listWidget_speakerView->currentItem()->text()+QString::fromStdString("*")); + speakerUnsaved =true; + } +} + +void library::dacEdited() +{ + if (dacUnsaved==false){ + ui->listWidget_dacView->currentItem()->setText(ui->listWidget_dacView->currentItem()->text()+QString::fromStdString("*")); + dacUnsaved =true; + } +} + +void library::confirmAmpChanges() +{ + if (unsaved){ + int selectedRow=getCurrentAmpIndex(); + ui->tabWidget->setCurrentIndex(0); + QMessageBox::StandardButton reply; + reply = QMessageBox::question(this, "Unsaved Changes", "Save unsaved Changes?", + QMessageBox::Yes|QMessageBox::No); + if (reply == QMessageBox::Yes) { + on_pushButton_applyChanges_clicked(); + } + refreshAmpView(); + ui->listWidget_ampView->setCurrentRow(selectedRow); + } +} + +void library::confirmSpeakerChanges() +{ + if (speakerUnsaved){ + int selectedRow=getCurrentSpeakerIndex(); + ui->tabWidget->setCurrentIndex(1); + QMessageBox::StandardButton reply; + reply = QMessageBox::question(this, "Unsaved Changes", "Save unsaved Changes?", + QMessageBox::Yes|QMessageBox::No); + if (reply == QMessageBox::Yes) { + on_pushButton_applySpeaker_clicked(); + } + refreshSpeakerView(); + ui->listWidget_speakerView->setCurrentRow(selectedRow); + } +} + +void library::confirmDacChanges() +{ + if (dacUnsaved){ + int selectedRow=getCurrentDacIndex(); + ui->tabWidget->setCurrentIndex(2); + QMessageBox::StandardButton reply; + reply = QMessageBox::question(this, "Unsaved Changes", "Save unsaved Changes?", + QMessageBox::Yes|QMessageBox::No); + if (reply == QMessageBox::Yes) { + on_pushButton_Apply_clicked(); + } + refreshDacView(); + ui->listWidget_dacView->setCurrentRow(selectedRow); + } +} + void library::printAllAmps() { std::cout << "Number of Amps: "<doubleSpinBox_inputSensitivity->value(); if (index==0){ ui->doubleSpinBox_inputSensitivity->setSuffix(QString(" V")); @@ -257,7 +326,7 @@ void library::on_pushButton_deleteAmp_clicked() m_pCamp=tempAmps; refreshAmpView(); - if (selectedRow-1<0 && m_cAmpCount>0){ + if ((selectedRow<1) and (m_cAmpCount>0)){ ui->listWidget_ampView->setCurrentRow(0); }else { @@ -302,7 +371,7 @@ void library::on_pushButton_deleteMode_clicked() int selectedRow=getCurrentAmpModeIndex(); m_pCamp[getCurrentAmpIndex()].deleteAmpMode(getCurrentAmpModeIndex()); refreshModeOverview(); - if (selectedRow-1<0 && m_pCamp[getCurrentAmpIndex()].getAmpModesCount()){ + if ((selectedRow<1) && (m_pCamp[getCurrentAmpIndex()].getAmpModesCount())>0){ ui->listWidget_modeSelector->setCurrentRow(0); }else { @@ -329,15 +398,13 @@ void library::on_pushButton_applyMode_clicked() void library::on_lineEdit_ampName_textEdited(const QString &arg1) { - if (unsaved==false){ - ui->listWidget_ampView->currentItem()->setText(ui->listWidget_ampView->currentItem()->text()+QString::fromStdString("*")); - unsaved =true; - } + ampEdited(); } void library::on_pushButton_addSpeaker_clicked() { + confirmSpeakerChanges(); m_SpeakerCount+=1; cSpeaker* tempSpeaker=new cSpeaker[m_SpeakerCount]; for (unsigned int i=0;ispinBox_speakerHPF->setEnabled(true); }else { - //ui->lineEdit_speakerName->setEnabled(false); + ui->lineEdit_speakerName->setEnabled(false); //ui->spinBox_speakerImp->setEnabled(false); //ui->spinBox_speakerRMSPower->setEnabled(false); //ui->spinBox_speakerPeakPower->setEnabled(false); @@ -399,7 +466,7 @@ void library::on_pushButton_deleteSpeaker_clicked() m_pSpeaker=tempSpeaker; refreshSpeakerView(); - if (selectedRow-1<0 && m_SpeakerCount>0){ + if ((selectedRow<1) and (m_SpeakerCount>0)){ ui->listWidget_speakerView->setCurrentRow(0); }else { @@ -430,9 +497,123 @@ void library::on_pushButton_applySpeaker_clicked() void library::on_lineEdit_speakerName_textEdited(const QString &arg1) { - if (speakerUnsaved==false){ - ui->listWidget_speakerView->currentItem()->setText(ui->listWidget_speakerView->currentItem()->text()+QString::fromStdString("*")); - speakerUnsaved =true; + speakerEdited(); + +} + + +void library::on_pushButton_dacAdd_clicked() +{ + confirmDacChanges(); + m_dacCount+=1; + cdac* tempDac=new cdac[m_dacCount]; + for (unsigned int i=0;ilistWidget_dacView->setCurrentRow(m_dacCount-1); + ui->lineEdit_dacName->setFocus(); + ui->lineEdit_dacName->selectAll(); +} + + +void library::on_pushButton_deleteDac_clicked() +{ + if (getCurrentDacIndex()>=0){ + m_dacCount-=1; + cdac* tempdac=new cdac[m_dacCount]; + unsigned int selectedRow=getCurrentDacIndex(); + for (unsigned int i=0;i0)){ + ui->listWidget_dacView->setCurrentRow(0); + }else + { + ui->listWidget_dacView->setCurrentRow(selectedRow-1); + } } } + +void library::on_pushButton_Apply_clicked() +{ + if (getCurrentDacIndex()>=0){ + dacUnsaved =false; + m_pDac[getCurrentDacIndex()].setName(ui->lineEdit_dacName->text().toStdString()); + m_pDac[getCurrentDacIndex()].setOutputLevel(ui->spinBox_dacOutputLevel->value()); + + + int selectedRow=getCurrentDacIndex(); + refreshDacView(); + ui->listWidget_dacView->setCurrentRow(selectedRow); + } +} + + +void library::on_listWidget_dacView_currentRowChanged(int currentRow) +{ + if (currentRow>=0){ + ui->lineEdit_dacName->setText(QString::fromStdString(m_pDac[currentRow].name())); + ui->spinBox_dacOutputLevel->setValue(m_pDac[currentRow].outputLevel()); + ui->lineEdit_dacName->setEnabled(true); + }else{ + ui->lineEdit_dacName->setEnabled(false); + } +} + + +void library::on_lineEdit_dacName_textEdited(const QString &arg1) +{ + //dacEdited(); +} + + + +void library::on_spinBox_dacOutputLevel_editingFinished() +{ + //dacEdited(); +} + + +void library::on_spinBox_speakerImp_editingFinished() +{ + //speakerEdited(); +} + + +void library::on_spinBox_speakerRMSPower_editingFinished() +{ + //speakerEdited(); +} + + +void library::on_spinBox_speakerPeakPower_editingFinished() +{ + //speakerEdited(); +} + + +void library::on_spinBox_speakerHPF_editingFinished() +{ + //speakerEdited(); +} + + +void library::on_doubleSpinBox_inputSensitivity_editingFinished() +{ + //ampEdited(); +} + diff --git a/library.h b/library.h index 26de696..e521a02 100644 --- a/library.h +++ b/library.h @@ -4,6 +4,8 @@ #include #include "camp.h" #include "cspeaker.h" +#include "cdac.h" +#include namespace Ui { class library; @@ -15,6 +17,7 @@ class library : public QDialog public: explicit library(QWidget *parent = nullptr); + void setAmpPointer(cAmp* pAmp,unsigned int ampCount); unsigned int getAmpCount(); cAmp* getAmps(); @@ -23,6 +26,10 @@ public: unsigned int getSpeakerCount(); cSpeaker* getSpeaker(); + void setDacPoint(cdac* dac, unsigned int dacCount); + unsigned int getDacCount(); + cdac* getDacs(); + void open(); ~library(); @@ -63,6 +70,28 @@ private slots: void on_lineEdit_speakerName_textEdited(const QString &arg1); + void on_pushButton_dacAdd_clicked(); + + void on_pushButton_deleteDac_clicked(); + + void on_pushButton_Apply_clicked(); + + void on_listWidget_dacView_currentRowChanged(int currentRow); + + void on_lineEdit_dacName_textEdited(const QString &arg1); + + void on_spinBox_dacOutputLevel_editingFinished(); + + void on_spinBox_speakerImp_editingFinished(); + + void on_spinBox_speakerRMSPower_editingFinished(); + + void on_spinBox_speakerPeakPower_editingFinished(); + + void on_spinBox_speakerHPF_editingFinished(); + + void on_doubleSpinBox_inputSensitivity_editingFinished(); + private: Ui::library *ui; cAmp* m_pCamp; @@ -71,20 +100,34 @@ private: cSpeaker* m_pSpeaker; unsigned int m_SpeakerCount; + cdac* m_pDac; + unsigned int m_dacCount; + void refreshAmpView(); void refreshModeOverview(); void refreshSpeakerView(); + void refreshDacView(); + int getCurrentAmpIndex(); int getCurrentAmpModeIndex(); int getCurrentSpeakerIndex(); + int getCurrentDacIndex(); + + void ampEdited(); + void speakerEdited(); + void dacEdited(); + + void confirmAmpChanges(); + void confirmSpeakerChanges(); + void confirmDacChanges(); void printAllAmps(); bool unsaved; bool speakerUnsaved; + bool dacUnsaved; - void saveLibraryToFile(); }; #endif // LIBRARY_H diff --git a/library.ui b/library.ui index 4095d42..6c09857 100644 --- a/library.ui +++ b/library.ui @@ -20,14 +20,14 @@ Qt::Horizontal - QDialogButtonBox::Cancel|QDialogButtonBox::Save + QDialogButtonBox::Close - 0 + 2 @@ -367,6 +367,80 @@ + + + Mixer/DAC + + + + + + + + + + + + + Add + + + + + + + Delete + + + + + + + Apply + + + + + + + + + + + + + Name + + + + + + + false + + + + + + + Nominal Output Level (at -18 dBFS) + + + + + + + dBU + + + -100.000000000000000 + + + + + + + diff --git a/main.cpp b/main.cpp index 755929d..950db3a 100644 --- a/main.cpp +++ b/main.cpp @@ -8,15 +8,7 @@ int main(int argc, char *argv[]) { QApplication a(argc, argv); - QTranslator translator; - const QStringList uiLanguages = QLocale::system().uiLanguages(); - for (const QString &locale : uiLanguages) { - const QString baseName = "PA_Calculator_" + QLocale(locale).name(); - if (translator.load(":/i18n/" + baseName)) { - a.installTranslator(&translator); - break; - } - } + MainWindow w; w.show(); return a.exec(); diff --git a/mainwindow.cpp b/mainwindow.cpp index f48766f..f582d88 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -20,10 +20,14 @@ MainWindow::MainWindow(QWidget *parent) m_speakerCount=0; m_pSpeaker=Q_NULLPTR; + m_dacCount=0; + m_pDac=Q_NULLPTR; + loadLibrary(); refreshLibraryAmps(); refreshLibraryAmpModes(); refreshLibrarySpeaker(); + refreshLibraryDacs(); } MainWindow::~MainWindow() @@ -127,17 +131,23 @@ void MainWindow::on_actionEditLibrary_triggered() library* dialog=new library; dialog->setAmpPointer(m_pCAmp,m_ampCount); dialog->setSpeakerPointer(m_pSpeaker,m_speakerCount); + dialog->setDacPoint(m_pDac,m_dacCount); dialog->open(); m_ampCount=dialog->getAmpCount(); m_pCAmp=dialog->getAmps(); m_pSpeaker=dialog->getSpeaker(); m_speakerCount=dialog->getSpeakerCount(); + m_pDac=dialog->getDacs(); + m_dacCount=dialog->getDacCount(); refreshLibraryAmps(); refreshLibraryAmpModes(); refreshLibrarySpeaker(); + refreshLibraryDacs(); + delete dialog; + saveLibrary(); } void MainWindow::refreshLibraryAmps() @@ -166,6 +176,14 @@ void MainWindow::refreshLibrarySpeaker() } } +void MainWindow::refreshLibraryDacs() +{ + ui->comboBox_dacPreset->clear(); + for (unsigned int i=0;icomboBox_dacPreset->addItem(QString::fromStdString(m_pDac[i].name())); + } +} + void MainWindow::loadLibrary() { QSettings settings("DKM-Tech","Pa-Calculator"); @@ -200,6 +218,16 @@ void MainWindow::loadLibrary() for (unsigned int j=0;j> m_pSpeaker[j]; } + in >> count; + m_dacCount=count; + if (m_dacCount>0){ + delete [] m_pDac; + m_pDac=new cdac[m_dacCount]; + } + + for (unsigned int j=0;j> m_pDac[j]; + } } } @@ -222,6 +250,14 @@ void MainWindow::saveLibrary() for (unsigned int j=0;jcomboBox_dacPreset->currentIndex()>=0){ + ui->spinBox_digitalNominalLevel->setValue(m_pDac[ui->comboBox_dacPreset->currentIndex()].outputLevel()); + } +} + diff --git a/mainwindow.h b/mainwindow.h index 834a6e0..7936c04 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -4,6 +4,7 @@ #include #include "camp.h" #include "cspeaker.h" +#include QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } @@ -34,6 +35,9 @@ private slots: void on_pushButton_loadSpeaker_clicked(); + + void on_pushButton_loadDac_clicked(); + private: Ui::MainWindow *ui; cAmp* m_pCAmp; @@ -42,12 +46,16 @@ private: cSpeaker* m_pSpeaker; unsigned int m_speakerCount; + cdac* m_pDac; + unsigned int m_dacCount; void refreshLibraryAmps(); void refreshLibraryAmpModes(); void refreshLibrarySpeaker(); + void refreshLibraryDacs(); + void loadLibrary(); void saveLibrary(); diff --git a/mainwindow.ui b/mainwindow.ui index 1fe8dd0..8ba9788 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -6,8 +6,8 @@ 0 0 - 1167 - 608 + 1230 + 611 @@ -19,6 +19,12 @@ + + + 0 + 0 + + 14 @@ -174,6 +180,12 @@ + + + 408 + 0 + + 14 @@ -302,6 +314,12 @@ + + + 179 + 33 + + Load Speaker-Preset @@ -320,7 +338,7 @@ - DA-Converter Specifications + Mixer/DAC specifications @@ -328,7 +346,7 @@ - Nominal Output Level (at -18 dBFS) + Nominal Output Level @@ -345,6 +363,43 @@ + + + + Load DAC from library + + + + + + + + + + Load DAC-Preset + + + + + + + (at -18 dBFS) + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + @@ -354,6 +409,11 @@ + + + 16 + + Request Limiter Settings @@ -612,7 +672,7 @@ 0 0 - 1167 + 1230 24