summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--kmix/mixertoolbox.cpp103
-rw-r--r--kmix/mixertoolbox.h4
2 files changed, 94 insertions, 13 deletions
diff --git a/kmix/mixertoolbox.cpp b/kmix/mixertoolbox.cpp
index 396d4bd3..1021fd8c 100644
--- a/kmix/mixertoolbox.cpp
+++ b/kmix/mixertoolbox.cpp
@@ -55,8 +55,7 @@ extern MixerFactory g_mixerFactories[];
***********************************************************************************/
/**
- * Scan for Mixers in the System. This is the method that implicitely fills the
- * list of Mixer's, which is accessible via the static Mixer::mixer() method.
+ * Scan for Mixers in the System and fills the given list.
* @par mixers The list where to add the found Mixers. This parameter is superfluous
* nowadays, as it is now really trivial to get it - just call the static
* Mixer::mixer() method.
@@ -114,10 +113,11 @@ void MixerToolBox::initMixer(TQPtrList<Mixer> &mixers, bool multiDriverMode, TQS
// New: We don't try be that clever anymore. We now blindly scan 20 cards, as the clever
// approach doesn't work for the one or other user.
int devNumMax = 19;
- getDevIteratorFunc* f = g_mixerFactories[drv].getDevIterator;
- for (DevIterator* I = f ? f() : new DevIterator(); !I->end(); I->next())
+ getDevIteratorFunc *f = g_mixerFactories[drv].getDevIterator;
+ DevIterator *devIt = f ? f() : new DevIterator();
+ for (; !devIt->end(); devIt->next())
{
- int dev = I->getdev();
+ int dev = devIt->getdev();
// Check with backend if mixer is invalid
if (!Mixer::isValid(drv, dev))
{
@@ -211,6 +211,7 @@ void MixerToolBox::initMixer(TQPtrList<Mixer> &mixers, bool multiDriverMode, TQS
} // !multipleDriversActive
} // loop over sound card devices of current driver
+ delete devIt;
} // loop over soundcard drivers
if (Mixer::masterCard() == 0)
@@ -250,18 +251,96 @@ void MixerToolBox::initMixer(TQPtrList<Mixer> &mixers, bool multiDriverMode, TQS
/*
- * Clean up and free all ressources of all found Mixers, which were found in the initMixer() call
+ * Clean up and free all resources of all found Mixers, which were found in the initMixer() call
*/
void MixerToolBox::deinitMixer()
{
- //kdDebug(67100) << "IN MixerToolBox::deinitMixer()"<<endl;
- Mixer *mixer;
- while ( (mixer=Mixer::mixers().first()) != 0)
+ // kdDebug(67100) << "IN MixerToolBox::deinitMixer()" << endl;
+ deinitMixer(Mixer::mixers());
+ // kdDebug(67100) << "OUT MixerToolBox::deinitMixer()" << endl;
+}
+
+/**
+ * Clean up and free all resources of the given mixers
+ * @par mixers The list of mixers to deinitialize.
+ */
+void MixerToolBox::deinitMixer(TQPtrList<Mixer> &mixers)
+{
+ // kdDebug(67100) << "IN MixerToolBox::deinitMixer(TQPtrList<Mixer> &mixers)" << endl;
+ while (!mixers.isEmpty())
{
- //kdDebug(67100) << "MixerToolBox::deinitMixer() Remove Mixer" << endl;
+ Mixer *mixer=mixers.first();
+ //kdDebug(67100) << "MixerToolBox::deinitMixer(TQPtrList<Mixer> &mixers) remove mixer " << mixer->mixerName() << endl;
mixer->close();
- Mixer::mixers().remove(mixer);
+ mixers.remove(mixer);
delete mixer;
}
- // kdDebug(67100) << "OUT MixerToolBox::deinitMixer()"<<endl;
+ // kdDebug(67100) << "OUT MixerToolBox::deinitMixer(TQPtrList<Mixer> &mixers)" << endl;
+}
+
+/**
+ * Clean up and free all resources of the given mixers
+ * @par mixers The list of mixers to deinitialize.
+ */
+/**
+ * Scan for Mixers in the System and update the given list. No longer existing mixers
+ * will be deinitialized.
+ * @par mixers The list where to add the found Mixers. This parameter is superfluous
+ * nowadays, as it is now really trivial to get it - just call the static
+ * Mixer::mixer() method.
+ * @par multiDriverMode Whether the Mixer scan should try more all backendends.
+ * 'true' means to scan all backends. 'false' means: After scanning the
+ * current backend the next backend is only scanned if no Mixers were found yet.
+ */
+void MixerToolBox::updateMixer(TQPtrList<Mixer> &mixers, bool multiDriverMode, TQString& ref_hwInfoString)
+{
+ TQPtrList<Mixer> newMixers;
+ // Scan for new mixers
+ initMixer(newMixers, multiDriverMode, ref_hwInfoString);
+ // Remove no longer existing mixers
+ TQPtrList<Mixer> mixersToDeinit;
+ Mixer *searchMixer = NULL;
+ Mixer *currMixer = mixers.first();
+ while (currMixer)
+ {
+ Mixer *searchMixer = newMixers.first();
+ while (searchMixer)
+ {
+ if (currMixer->id() == searchMixer->id())
+ {
+ break;
+ }
+ searchMixer = newMixers.next();
+ }
+ if (!searchMixer)
+ {
+ mixers.take();
+ mixersToDeinit.append(currMixer);
+ }
+ currMixer = mixers.next();
+ }
+ deinitMixer(mixersToDeinit);
+ // Add newly found mixers
+ searchMixer = newMixers.first();
+ while (searchMixer)
+ {
+ currMixer = mixers.first();
+ while (currMixer)
+ {
+ if (searchMixer->id() == currMixer->id())
+ {
+ break;
+ }
+ currMixer = mixers.next();
+ }
+ if (!currMixer)
+ {
+ // New mixer, append to existing list
+ newMixers.take();
+ mixers.append(searchMixer);
+ }
+ searchMixer = newMixers.next();
+ }
+ // Deallocate duplicated mixers
+ deinitMixer(newMixers);
}
diff --git a/kmix/mixertoolbox.h b/kmix/mixertoolbox.h
index 884471ef..a964e9a9 100644
--- a/kmix/mixertoolbox.h
+++ b/kmix/mixertoolbox.h
@@ -14,8 +14,10 @@ class Mixer;
*/
class MixerToolBox {
public:
- static void initMixer(TQPtrList<Mixer>&, bool, TQString&);
+ static void initMixer(TQPtrList<Mixer> &mixers, bool multiDriverMode, TQString& ref_hwInfoString);
static void deinitMixer();
+ static void deinitMixer(TQPtrList<Mixer>&);
+ static void updateMixer(TQPtrList<Mixer> &mixers, bool multiDriverMode, TQString& ref_hwInfoString);
};