Example #1
0
void Equalizer::createEvents()
{
    connect(defaultButton, SIGNAL(clicked()), this, SLOT(defaultEqualizer()));
    connect(okButton, SIGNAL(clicked()), this, SLOT(ok()));
    connect(cancelButton, SIGNAL(clicked()), this, SLOT(close()));

    connect(newButton, SIGNAL(clicked()), this, SLOT(newPreset()));
    connect(editButton, SIGNAL(clicked()), this, SLOT(editPreset()));
    connect(saveButton, SIGNAL(clicked()), this, SLOT(savePreset()));
    connect(deleteButton, SIGNAL(clicked()), this, SLOT(deletePreset()));

    connect(presetCombo, SIGNAL(activated(int)), this, SLOT(loadPreset()));
    connect(presetCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(indexChanged()));

    for (int i = 0; i < 16; i++)
    {
        connect(eq[i], &QSlider::valueChanged, [this,i](int arg) {
            equalizerChanged(i, arg);
            eqDb[i]->setText(QString("%1dB").arg(arg));
        });
    }
}
// Constructor.
synthv1widget_preset::synthv1widget_preset ( QWidget *pParent )
	: QWidget (pParent)
{
	m_pNewButton    = new QToolButton();
	m_pOpenButton   = new QToolButton();
	m_pComboBox     = new QComboBox();
	m_pSaveButton   = new QToolButton();
	m_pDeleteButton = new QToolButton();
	m_pResetButton  = new QToolButton();

	m_pNewButton->setIcon(QIcon(":/images/presetNew.png"));
	m_pOpenButton->setIcon(QIcon(":/images/presetOpen.png"));
	m_pComboBox->setEditable(true);
	m_pComboBox->setMinimumWidth(240);
#if QT_VERSION >= 0x040200
	m_pComboBox->setCompleter(NULL);
#endif
	m_pComboBox->setInsertPolicy(QComboBox::NoInsert);
	m_pSaveButton->setIcon(QIcon(":/images/presetSave.png"));
	m_pDeleteButton->setIcon(QIcon(":/images/presetDelete.png"));
	m_pResetButton->setText("Reset");

	m_pNewButton->setToolTip(tr("New Preset"));
	m_pOpenButton->setToolTip(tr("Open Preset"));
	m_pSaveButton->setToolTip(tr("Save Preset"));
	m_pDeleteButton->setToolTip(tr("Delete Preset"));
	m_pResetButton->setToolTip(tr("Reset Preset"));

	QHBoxLayout *pHBoxLayout = new QHBoxLayout();
	pHBoxLayout->setMargin(2);
	pHBoxLayout->setSpacing(4);
	pHBoxLayout->addWidget(m_pNewButton);
	pHBoxLayout->addWidget(m_pOpenButton);
	pHBoxLayout->addWidget(m_pComboBox);
	pHBoxLayout->addWidget(m_pSaveButton);
	pHBoxLayout->addWidget(m_pDeleteButton);
	pHBoxLayout->addSpacing(4);
	pHBoxLayout->addWidget(m_pResetButton);
	QWidget::setLayout(pHBoxLayout);

	m_iInitPreset  = 0;
	m_iDirtyPreset = 0;

	// UI signal/slot connections...
	QObject::connect(m_pNewButton,
		SIGNAL(clicked()),
		SLOT(newPreset()));
	QObject::connect(m_pOpenButton,
		SIGNAL(clicked()),
		SLOT(openPreset()));
	QObject::connect(m_pComboBox,
		SIGNAL(editTextChanged(const QString&)),
		SLOT(stabilizePreset()));
	QObject::connect(m_pComboBox,
		SIGNAL(activated(const QString&)),
		SLOT(activatePreset(const QString&)));
	QObject::connect(m_pSaveButton,
		SIGNAL(clicked()),
		SLOT(savePreset()));
	QObject::connect(m_pDeleteButton,
		SIGNAL(clicked()),
		SLOT(deletePreset()));
	QObject::connect(m_pResetButton,
		SIGNAL(clicked()),
		SLOT(resetPreset()));

	refreshPreset();
	stabilizePreset();
}
void ofxRemoteUIServer::updateServer(float dt){

	timeCounter += dt;
	broadcastTime += dt;
	timeSinceLastReply  += dt;

	if(readyToSend){
		if (timeCounter > updateInterval){
			timeCounter = 0.0f;
			//vector<string> changes = scanForUpdatedParamsAndSync(); //sends changed params to client
			//cout << "ofxRemoteUIServer: sent " << ofToString(changes.size()) << " updates to client" << endl;
			//sendUpdateForParamsInList(changes);
		}
	}

	//let everyone know I exist and which is my port, every now and then
	if(broadcastTime > OFXREMOTEUI_BORADCAST_INTERVAL){
		if(doBroadcast){
			broadcastTime = 0.0f;
			if (computerName.size() == 0){
				#ifdef OF_AVAILABLE
					Poco::Environment e;
					computerName = e.nodeName();

					char pathbuf[2048];
					uint32_t  bufsize = sizeof(pathbuf);
					#ifdef TARGET_OSX
						_NSGetExecutablePath(pathbuf, &bufsize);
						Poco::Path p = Poco::Path(pathbuf);
						binaryName = p[p.depth()];
					#endif
					#ifdef TARGET_WIN32						
						GetModuleFileNameA( NULL, pathbuf, bufsize ); //no iea why, but GetModuleFileName() is not defined?
						Poco::Path p = Poco::Path(pathbuf);
						binaryName = p[p.depth()];
					#endif
				#endif
			}
			ofxOscMessage m;
			m.addIntArg(port); //0
			m.addStringArg(computerName); //1
			m.addStringArg(binaryName);	//2
			broadcastSender.sendMessage(m);
		}
	}

	while( oscReceiver.hasWaitingMessages() ){// check for waiting messages from client

		ofxOscMessage m;
		oscReceiver.getNextMessage(&m);
		if (!readyToSend){ // if not connected, connect to our friend so we can talk back
			connect(m.getRemoteIp(), port + 1);
		}

		DecodedMessage dm = decode(m);
		RemoteUIServerCallBackArg cbArg; // to notify our "delegate"
		cbArg.host = m.getRemoteIp();
		switch (dm.action) {

			case HELO_ACTION: //if client says hi, say hi back
				sendHELLO();
				if(callBack != NULL){
					cbArg.action = CLIENT_CONNECTED;
					callBack(cbArg);
				}
				if(verbose_) cout << "ofxRemoteUIServer: " << m.getRemoteIp() << " says HELLO!"  << endl;
				onScreenNotifications.addNotification("CONNECTED (" + cbArg.host +  ")!");
				break;

			case REQUEST_ACTION:{ //send all params to client
				if(verbose_) cout << "ofxRemoteUIServer: " << m.getRemoteIp() << " sends REQU!"  << endl;
				vector<string>paramsList = getAllParamNamesList();
				syncAllParamsToPointers();
				sendUpdateForParamsInList(paramsList);
				sendREQU(true); //once all send, confirm to close the REQU
			}
				break;

			case SEND_PARAM_ACTION:{ //client is sending us an updated val
				if(verbose_) cout << "ofxRemoteUIServer: " << m.getRemoteIp() << " sends SEND!"  << endl;
				updateParamFromDecodedMessage(m, dm);
				if(callBack != NULL){
					cbArg.action = CLIENT_UPDATED_PARAM;
					cbArg.paramName = dm.paramName;
					cbArg.param = params[dm.paramName];  //copy the updated param to the callbakc arg
					callBack(cbArg);
				}
			}
				break;

			case CIAO_ACTION:{
				if(verbose_) cout << "ofxRemoteUIServer: " << m.getRemoteIp() << " says CIAO!" << endl;
				sendCIAO();
				onScreenNotifications.addNotification("DISCONNECTED (" + cbArg.host +  ")!");
				if(callBack != NULL){
					cbArg.action = CLIENT_DISCONNECTED;
					callBack(cbArg);
				}
				clearOscReceiverMsgQueue();
				readyToSend = false;
			}break;

			case TEST_ACTION: // we got a request from client, lets bounce back asap.
				sendTEST();
				//if(verbose)cout << "ofxRemoteUIServer: " << m.getRemoteIp() << " says TEST!" << endl;
				break;

			case PRESET_LIST_ACTION: //client wants us to send a list of all available presets
				presetNames = getAvailablePresets();
				if (presetNames.size() == 0){
					presetNames.push_back(OFXREMOTEUI_NO_PRESETS);
				}
				sendPREL(presetNames);
				break;

			case SET_PRESET_ACTION:{ // client wants to set a preset
				//presetNames = getAvailablePresets();
				string presetName = m.getArgAsString(0);
				vector<string> missingParams = loadFromXML(string(OFXREMOTEUI_PRESET_DIR) + "/" + presetName + ".xml");
				if(verbose_) cout << "ofxRemoteUIServer: setting preset: " << presetName << endl;
				sendSETP(presetName);
				sendMISP(missingParams);
				if(callBack != NULL){
					cbArg.action = CLIENT_DID_SET_PRESET;
					cbArg.msg = presetName;
					callBack(cbArg);
				}
				onScreenNotifications.addNotification("SET PRESET to '" + string(OFXREMOTEUI_PRESET_DIR) + "/" + presetName + ".xml'");
			}break;

			case SAVE_PRESET_ACTION:{ //client wants to save current xml as a new preset
				string presetName = m.getArgAsString(0);
				if(verbose_) cout << "ofxRemoteUIServer: saving NEW preset: " << presetName << endl;
				saveToXML(string(OFXREMOTEUI_PRESET_DIR) + "/" + presetName + ".xml");
				sendSAVP(presetName);
				onScreenNotifications.addNotification("SAVED PRESET to '" + string(OFXREMOTEUI_PRESET_DIR) + "/" + presetName + ".xml'");
				if(callBack != NULL){
					cbArg.action = CLIENT_SAVED_PRESET;
					cbArg.msg = presetName;
					callBack(cbArg);
				}
			}break;

			case DELETE_PRESET_ACTION:{
				string presetName = m.getArgAsString(0);
				if(verbose_) cout << "ofxRemoteUIServer: DELETE preset: " << presetName << endl;
				deletePreset(presetName);
				sendDELP(presetName);
				onScreenNotifications.addNotification("DELETED PRESET '" + string(OFXREMOTEUI_PRESET_DIR) + "/" + presetName + ".xml'");
				if(callBack != NULL){
					cbArg.action = CLIENT_DELETED_PRESET;
					cbArg.msg = presetName;
					callBack(cbArg);
				}
			}break;

			case SAVE_CURRENT_STATE_ACTION:{
				if(verbose_) cout << "ofxRemoteUIServer: SAVE CURRENT PARAMS TO DEFAULT XML: " << endl;
				saveToXML(OFXREMOTEUI_SETTINGS_FILENAME);
				onScreenNotifications.addNotification("SAVED CONFIG to default XML");
				sendSAVE(true);
				if(callBack != NULL){
					cbArg.action = CLIENT_SAVED_STATE;
					callBack(cbArg);
				}
			}break;

			case RESET_TO_XML_ACTION:{
				if(verbose_) cout << "ofxRemoteUIServer: RESET TO XML: " << endl;
				restoreAllParamsToInitialXML();
				sendRESX(true);
				onScreenNotifications.addNotification("RESET CONFIG TO SERVER-LAUNCH XML values");
				if(callBack != NULL){
					cbArg.action = CLIENT_DID_RESET_TO_XML;
					callBack(cbArg);
				}
			}break;

			case RESET_TO_DEFAULTS_ACTION:{
				if(verbose_) cout << "ofxRemoteUIServer: RESET TO DEFAULTS: " << endl;
				restoreAllParamsToDefaultValues();
				sendRESD(true);
				onScreenNotifications.addNotification("RESET CONFIG TO DEFAULTS (source defined values)");
				if(callBack != NULL){
					cbArg.action = CLIENT_DID_RESET_TO_DEFAULTS;
					callBack(cbArg);
				}
			}break;

			default: cout << "ofxRemoteUIServer::update >> ERR!" <<endl; break;
		}
	}
}