|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- /*
- * Carla plugin host
- * Copyright (C) 2011-2022 Filipe Coelho <falktx@falktx.com>
- *
- * 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 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.
- *
- * For a full copy of the GNU General Public License see the doc/GPL.txt file.
- */
-
- #include "jackappdialog.hpp"
-
- #ifdef __clang__
- # pragma clang diagnostic push
- # pragma clang diagnostic ignored "-Wdeprecated-copy-with-user-provided-copy"
- # pragma clang diagnostic ignored "-Wdeprecated-register"
- #elif defined(__GNUC__) && __GNUC__ >= 8
- # pragma GCC diagnostic push
- # pragma GCC diagnostic ignored "-Wclass-memaccess"
- # pragma GCC diagnostic ignored "-Wdeprecated-copy"
- #endif
-
- #include "jackappdialog_ui.hpp"
- #include <QtCore/QFileInfo>
- #include <QtCore/QVector>
- #include <QtWidgets/QPushButton>
-
- #ifdef __clang__
- # pragma clang diagnostic pop
- #elif defined(__GNUC__) && __GNUC__ >= 8
- # pragma GCC diagnostic pop
- #endif
-
- #include "../utils/qsafesettings.hpp"
- #include "../../includes/CarlaLibJackHints.h"
-
- // --------------------------------------------------------------------------------------------------------------------
- // Jack Application Dialog
-
- enum {
- UI_SESSION_NONE = 0,
- UI_SESSION_LADISH = 1,
- UI_SESSION_NSM = 2,
- };
-
- struct JackApplicationW::Self {
- Ui_Dialog ui;
- const QString fProjectFilename;
-
- Self(const char* const projectFilename)
- : fProjectFilename(projectFilename) {}
-
- static Self& create(const char* const projectFilename)
- {
- Self* const self = new Self(projectFilename);
- return *self;
- }
- };
-
- JackApplicationW::JackApplicationW(QWidget* const parent, const char* const projectFilename)
- : QDialog(parent),
- self(Self::create(projectFilename))
- {
- self.ui.setupUi(this);
-
- // -------------------------------------------------------------------------------------------------------------
- // UI setup
-
- self.ui.group_error->setVisible(false);
- adjustSize();
- setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
-
- // -------------------------------------------------------------------------------------------------------------
- // Load settings
-
- loadSettings();
-
- // -------------------------------------------------------------------------------------------------------------
- // Set-up connections
-
- connect(this, &QDialog::finished,
- this, &JackApplicationW::slot_saveSettings);
- connect(self.ui.cb_session_mgr, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
- this, &JackApplicationW::slot_sessionManagerChanged);
- connect(self.ui.le_command, &QLineEdit::textChanged,
- this, &JackApplicationW::slot_commandChanged);
- }
-
- JackApplicationW::~JackApplicationW()
- {
- delete &self;
- }
-
- // -----------------------------------------------------------------------------------------------------------------
- // public methods
-
- JackApplicationW::CommandAndFlags JackApplicationW::getCommandAndFlags() const
- {
- const QString command = self.ui.le_command->text();
- QString name = self.ui.le_name->text();
-
- if (name.isEmpty())
- {
- name = QFileInfo(command.split(' ').first()).baseName();
- name[0] = name[0].toTitleCase();
- }
-
- SessionManager smgr;
- switch(self.ui.cb_session_mgr->currentIndex())
- {
- case UI_SESSION_LADISH:
- smgr = LIBJACK_SESSION_MANAGER_LADISH;
- break;
- case UI_SESSION_NSM:
- smgr = LIBJACK_SESSION_MANAGER_NSM;
- break;
- default:
- smgr = LIBJACK_SESSION_MANAGER_NONE;
- break;
- }
-
- uint flags = 0x0;
- if (self.ui.cb_manage_window->isChecked())
- flags |= LIBJACK_FLAG_CONTROL_WINDOW;
- if (self.ui.cb_capture_first_window->isChecked())
- flags |= LIBJACK_FLAG_CAPTURE_FIRST_WINDOW;
- if (self.ui.cb_buffers_addition_mode->isChecked())
- flags |= LIBJACK_FLAG_AUDIO_BUFFERS_ADDITION;
- if (self.ui.cb_out_midi_mixdown->isChecked())
- flags |= LIBJACK_FLAG_MIDI_OUTPUT_CHANNEL_MIXDOWN;
- if (self.ui.cb_external_start->isChecked())
- flags |= LIBJACK_FLAG_EXTERNAL_START;
-
- const QString labelSetup(QString("%1%2%3%4%5%6").arg(QChar('0' + self.ui.sb_audio_ins->value()))
- .arg(QChar('0' + self.ui.sb_audio_outs->value()))
- .arg(QChar('0' + self.ui.sb_midi_ins->value()))
- .arg(QChar('0' + self.ui.sb_midi_outs->value()))
- .arg(QChar('0' + smgr))
- .arg(QChar('0' + flags)));
-
- return {command, name, labelSetup};
- }
-
- // -----------------------------------------------------------------------------------------------------------------
- // private methods
-
- void JackApplicationW::checkIfButtonBoxShouldBeEnabled(const int index, const QCarlaString& command)
- {
- bool enabled = command.isNotEmpty();
- QCarlaString showErr;
-
- // NSM applications must not be abstract or absolute paths, and must not contain arguments
- if (enabled and index == UI_SESSION_NSM)
- {
- if (QVector<QChar>{'.', '/'}.contains(command[0]))
- showErr = tr("NSM applications cannot use abstract or absolute paths");
- else if (command.contains(' ') or command.contains(';') or command.contains('&'))
- showErr = tr("NSM applications cannot use CLI arguments");
- else if (self.fProjectFilename.isEmpty())
- showErr = tr("You need to save the current Carla project before NSM can be used");
- }
-
- if (showErr.isNotEmpty())
- {
- enabled = false;
- self.ui.l_error->setText(showErr);
- self.ui.group_error->setVisible(true);
- }
- else
- {
- self.ui.group_error->setVisible(false);
- }
-
- if (QPushButton* const button = self.ui.buttonBox->button(QDialogButtonBox::Ok))
- button->setEnabled(enabled);
- }
-
- void JackApplicationW::loadSettings()
- {
- const QSafeSettings settings("falkTX", "CarlaAddJackApp");
-
- const QString smName = settings.valueString("SessionManager", "");
-
- if (smName == "LADISH (SIGUSR1)")
- self.ui.cb_session_mgr->setCurrentIndex(UI_SESSION_LADISH);
- else if (smName == "NSM")
- self.ui.cb_session_mgr->setCurrentIndex(UI_SESSION_NSM);
- else
- self.ui.cb_session_mgr->setCurrentIndex(UI_SESSION_NONE);
-
- self.ui.le_command->setText(settings.valueString("Command", ""));
- self.ui.le_name->setText(settings.valueString("Name", ""));
- self.ui.sb_audio_ins->setValue(settings.valueIntPositive("NumAudioIns", 2));
- self.ui.sb_audio_ins->setValue(settings.valueIntPositive("NumAudioIns", 2));
- self.ui.sb_audio_outs->setValue(settings.valueIntPositive("NumAudioOuts", 2));
- self.ui.sb_midi_ins->setValue(settings.valueIntPositive("NumMidiIns", 0));
- self.ui.sb_midi_outs->setValue(settings.valueIntPositive("NumMidiOuts", 0));
- self.ui.cb_manage_window->setChecked(settings.valueBool("ManageWindow", true));
- self.ui.cb_capture_first_window->setChecked(settings.valueBool("CaptureFirstWindow", false));
- self.ui.cb_out_midi_mixdown->setChecked(settings.valueBool("MidiOutMixdown", false));
-
- checkIfButtonBoxShouldBeEnabled(self.ui.cb_session_mgr->currentIndex(),
- self.ui.le_command->text());
- }
-
- // -----------------------------------------------------------------------------------------------------------------
- // private slots
-
- void JackApplicationW::slot_commandChanged(const QString& command)
- {
- checkIfButtonBoxShouldBeEnabled(self.ui.cb_session_mgr->currentIndex(), command);
- }
-
- void JackApplicationW::slot_sessionManagerChanged(const int index)
- {
- checkIfButtonBoxShouldBeEnabled(index, self.ui.le_command->text());
- }
-
- void JackApplicationW::slot_saveSettings()
- {
- QSafeSettings settings("falkTX", "CarlaAddJackApp");
- settings.setValue("Command", self.ui.le_command->text());
- settings.setValue("Name", self.ui.le_name->text());
- settings.setValue("SessionManager", self.ui.cb_session_mgr->currentText());
- settings.setValue("NumAudioIns", self.ui.sb_audio_ins->value());
- settings.setValue("NumAudioOuts", self.ui.sb_audio_outs->value());
- settings.setValue("NumMidiIns", self.ui.sb_midi_ins->value());
- settings.setValue("NumMidiOuts", self.ui.sb_midi_outs->value());
- settings.setValue("ManageWindow", self.ui.cb_manage_window->isChecked());
- settings.setValue("CaptureFirstWindow", self.ui.cb_capture_first_window->isChecked());
- settings.setValue("MidiOutMixdown", self.ui.cb_out_midi_mixdown->isChecked());
- }
-
- // --------------------------------------------------------------------------------------------------------------------
- // Testing
-
- #include "../utils/qsafesettings.cpp"
-
- int main(int argc, char* argv[])
- {
- QApplication app(argc, argv);
- JackApplicationW gui(nullptr, "");
- gui.show();
-
- if (gui.exec())
- {
- auto cf = gui.getCommandAndFlags();
- printf("Results:\n");
- printf("\tCommand: %s\n", cf.command.toUtf8().constData());
- printf("\tName: %s\n", cf.name.toUtf8().constData());
- printf("\tLabelSetup: %s\n", cf.labelSetup.toUtf8().constData());
- }
-
- return 0;
- }
-
- // --------------------------------------------------------------------------------------------------------------------
|