Hello Rui,

I committed some changes which adds a new function fluid_synth_unset_program() and finalizes API for fluid_synth_get_channel_info().

Attached is a patch against qsynth 0.3.4 which adds support for the new fluid_synth_get_channel_info() for thread safety. It also supports older versions of FluidSynth by checking the version constants.

With the other changes I just committed and provided no one complains, version 1.1.1 should be released shortly. Speak up if there is something I overlooked, that you think should be in 1.1.1.

Cheers!

Josh

diff -ru qsynth-0.3.4-orig/src/qsynthChannelsForm.cpp qsynth-0.3.4/src/qsynthChannelsForm.cpp
--- qsynth-0.3.4-orig/src/qsynthChannelsForm.cpp	2009-02-19 02:00:05.000000000 -0800
+++ qsynth-0.3.4/src/qsynthChannelsForm.cpp	2009-11-27 14:52:39.481524000 -0800
@@ -213,6 +213,42 @@
 
 	qsynthChannelsItem *pItem = m_ppChannels[iChan];
 
+/* FluidSynth 1.1.1 and newer has fluid_synth_get_channel_info() */
+#if (FLUIDSYNTH_VERSION_MAJOR << 16 | FLUIDSYNTH_VERSION_MINOR << 8 | FLUIDSYNTH_VERSION_MICRO) >= 0x010101
+	fluid_synth_channel_info_t info;
+
+	fluid_synth_get_channel_info(m_pSynth, iChan, &info);
+
+	if (info.assigned) {
+		int iBank = info.bank;
+		fluid_sfont_t *sfont = fluid_synth_get_sfont_by_id (m_pSynth, info.sfont_id);
+
+#ifdef CONFIG_FLUID_BANK_OFFSET
+		iBank += ::fluid_synth_get_bank_offset(m_pSynth, info.sfont_id);
+#endif
+		pItem->setText(QSYNTH_CHANNELS_BANK,
+			QString::number(iBank));
+		pItem->setText(QSYNTH_CHANNELS_PROG,
+			QString::number(info.program));
+		pItem->setText(QSYNTH_CHANNELS_NAME,
+			info.name);
+		pItem->setText(QSYNTH_CHANNELS_SFID,
+			QString::number(info.sfont_id));
+		pItem->setText(QSYNTH_CHANNELS_SFNAME,
+			QFileInfo(sfont->get_name(sfont)).baseName());
+		// Make this a dirty-operation.
+		m_iDirtyCount++;
+	} else {
+		QString n = "-";
+		pItem->setText(QSYNTH_CHANNELS_BANK, n);
+		pItem->setText(QSYNTH_CHANNELS_PROG, n);
+		pItem->setText(QSYNTH_CHANNELS_NAME, n);
+		pItem->setText(QSYNTH_CHANNELS_SFID, n);
+		pItem->setText(QSYNTH_CHANNELS_SFNAME, n);
+	}
+
+#else	/* FluidSynth prior to 1.1.1: Use fluid_synth_get_channel_preset which is not thread safe */
+
 	fluid_preset_t *pPreset = ::fluid_synth_get_channel_preset(m_pSynth, iChan);
 	if (pPreset) {
 		int iBank = pPreset->get_banknum(pPreset);
@@ -239,6 +275,7 @@
 		pItem->setText(QSYNTH_CHANNELS_SFID, n);
 		pItem->setText(QSYNTH_CHANNELS_SFNAME, n);
 	}
+#endif
 }
 
 
diff -ru qsynth-0.3.4-orig/src/qsynthOptions.cpp qsynth-0.3.4/src/qsynthOptions.cpp
--- qsynth-0.3.4-orig/src/qsynthOptions.cpp	2009-05-05 15:54:57.000000000 -0700
+++ qsynth-0.3.4/src/qsynthOptions.cpp	2009-11-27 14:50:25.201524000 -0800
@@ -690,6 +690,27 @@
 	int iChannels = ::fluid_synth_count_midi_channels(pEngine->pSynth);
 	int iChan = 0;
 	for ( ; iChan < iChannels; iChan++) {
+/* FluidSynth 1.1.1 and newer has fluid_synth_get_channel_info() */
+#if (FLUIDSYNTH_VERSION_MAJOR << 16 | FLUIDSYNTH_VERSION_MINOR << 8 | FLUIDSYNTH_VERSION_MICRO) >= 0x010101
+		fluid_synth_channel_info_t info;
+
+		fluid_synth_get_channel_info(pEngine->pSynth, iChan, &info);
+
+		if (info.assigned) {
+			int iBank = info.bank;
+#ifdef CONFIG_FLUID_BANK_OFFSET
+			iBank += ::fluid_synth_get_bank_offset(pEngine->pSynth, info.sfont_id);
+#endif
+			QString sEntry = QString::number(iChan);
+			sEntry += ':';
+			sEntry += QString::number(iBank);
+			sEntry += ':';
+			sEntry += QString::number(info.program);
+			m_settings.setValue(sPrefix.arg(iChan + 1), sEntry);
+		}
+
+#else	/* FluidSynth prior to 1.1.1: Use fluid_synth_get_channel_preset which is not thread safe */
+
 		fluid_preset_t *pPreset = ::fluid_synth_get_channel_preset(pEngine->pSynth, iChan);
 		if (pPreset) {
 			int iBank = pPreset->get_banknum(pPreset);
@@ -703,6 +724,7 @@
 			sEntry += QString::number(pPreset->get_num(pPreset));
 			m_settings.setValue(sPrefix.arg(iChan + 1), sEntry);
 		}
+#endif
 	}
 	// Cleanup old entries, if any...
 	while (!m_settings.value(sPrefix.arg(++iChan)).toString().isEmpty())
diff -ru qsynth-0.3.4-orig/src/qsynthPresetForm.cpp qsynth-0.3.4/src/qsynthPresetForm.cpp
--- qsynth-0.3.4-orig/src/qsynthPresetForm.cpp	2007-07-08 09:03:56.000000000 -0700
+++ qsynth-0.3.4/src/qsynthPresetForm.cpp	2009-11-27 15:01:05.199524000 -0800
@@ -168,13 +168,31 @@
 
 	// Set the selected bank.
 	m_iBank = 0;
+
+/* FluidSynth 1.1.1 and newer has fluid_synth_get_channel_info() */
+#if (FLUIDSYNTH_VERSION_MAJOR << 16 | FLUIDSYNTH_VERSION_MINOR << 8 | FLUIDSYNTH_VERSION_MICRO) >= 0x010101
+	fluid_synth_channel_info_t info;
+
+	fluid_synth_get_channel_info(m_pSynth, m_iChan, &info);
+	if (info.assigned) {
+		m_iBank = info.bank;
+#ifdef CONFIG_FLUID_BANK_OFFSET
+		m_iBank += ::fluid_synth_get_bank_offset(m_pSynth, info.sfont_id);
+#endif
+		m_iProg = info.program;
+	}
+
+#else	/* FluidSynth prior to 1.1.1: Use fluid_synth_get_channel_preset which is not thread safe */
+
 	fluid_preset_t *pPreset = ::fluid_synth_get_channel_preset(m_pSynth, m_iChan);
 	if (pPreset) {
 		m_iBank = pPreset->get_banknum(pPreset);
 #ifdef CONFIG_FLUID_BANK_OFFSET
 		m_iBank += ::fluid_synth_get_bank_offset(m_pSynth, (pPreset->sfont)->id);
 #endif
+		m_iProg = pPreset->get_num(pPreset);
 	}
+#endif
 
 	pBankItem = findBankItem(m_iBank);
 	m_ui.BankListView->setCurrentItem(pBankItem);
@@ -182,8 +200,6 @@
 	bankChanged();
 
 	// Set the selected program.
-	if (pPreset)
-		m_iProg = pPreset->get_num(pPreset);
 	QTreeWidgetItem *pProgItem = findProgItem(m_iProg);
 	m_ui.ProgListView->setCurrentItem(pProgItem);
 //  m_ui.ProgListView->ensureItemVisible(pProgItem);

_______________________________________________
fluid-dev mailing list
fluid-dev@nongnu.org
http://lists.nongnu.org/mailman/listinfo/fluid-dev

Reply via email to