]> git.alsa-project.org Git - alsa-tools.git/commitdiff
hdspmixer: Save preset before switching cards
authorAdrian Knoth <adi@drcomp.erfurt.thur.de>
Mon, 4 Apr 2011 12:34:28 +0000 (14:34 +0200)
committerTakashi Iwai <tiwai@suse.de>
Wed, 6 Apr 2011 06:22:15 +0000 (08:22 +0200)
When running with more than one card, switching cards would lose any
changes made to the current card. To avoid this inconvenience, save the
current settings to the virtual 9th preset and restore them when
switching back.

Signed-off-by: Adrian Knoth <adi@drcomp.erfurt.thur.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
hdspmixer/src/HDSPMixerCard.cxx
hdspmixer/src/HDSPMixerCard.h
hdspmixer/src/HDSPMixerCardSelector.cxx
hdspmixer/src/HDSPMixerWindow.cxx
hdspmixer/src/HDSPMixerWindow.h

index f3205b9330bf8190f3b8868176d06e1b1952b85b..fbd5de5f5aee9e678a779b73f5cf2f08cb88c1ea 100644 (file)
@@ -186,6 +186,7 @@ HDSPMixerCard::HDSPMixerCard(int cardtype, int id, char *shortname)
     
     /* Set channels and mappings */
     adjustSettings();
+    last_preset = last_dirty = 0;
         
     basew = NULL;
 }
index 032c61f2e0ad84190925e7ac717e41cf73b264ab..d2ef8a6f59f68168e0fc3b4c207f8ad45c5e52ed 100644 (file)
@@ -48,6 +48,8 @@ public:
     int channels_input, channels_playback, window_width, window_height, card_id;
     int channels_output;
     int type;
+    int last_preset; /* Last activated preset before switching to another card */
+    int last_dirty; /* Last dirty flag before switching to another card */
     char *channel_map_input, *channel_map_playback;
     char *dest_map;
     char *meter_map_input, *meter_map_playback;
index d83c4c9f4745c3f07aa343503d6946d5a823a178..d685009c90c5c6fc6a3c5164dd3e4e885c7af90f 100644 (file)
@@ -48,9 +48,11 @@ void HDSPMixerCardSelector::draw()
 void HDSPMixerCardSelector::ActivateCard (int i)
 {
   card = i + 1;
+  basew->stashPreset(); /* save current mixer state */
   basew->current_card = i;
   basew->cards[i]->setMode (basew->cards[i]->getSpeed ());
   basew->setTitleWithFilename();
+  basew->unstashPreset(); /* restore previous mixer state */
   redraw ();
 }
 
index a3279047957144fda85a94abd08badec385823f5..784819068267ba9c0b816f14cb461f75ebb5d24f 100644 (file)
@@ -609,7 +609,44 @@ void HDSPMixerWindow::setTitleWithFilename(void)
     setTitle(filename);
 }
 
+void HDSPMixerWindow::stashPreset(void)
+{
+    cards[current_card]->last_preset = current_preset;
+    cards[current_card]->last_dirty = dirty;
+    /* save the current mixer state to the virtual 9th preset */
+    inputs->buttons->presets->save_preset(9);
+}
 
+void HDSPMixerWindow::unstashPreset(void)
+{
+    /* load temporary data from virtual 9th preset */
+    inputs->buttons->presets->restore_preset(9);
+    
+    current_preset = cards[current_card]->last_preset;
+    /* Internal notion of playback in use. Relevant for blinking buttons */
+    inputs->buttons->presets->preset = current_preset + 1;
+    dirty = cards[current_card]->last_dirty;
+    /* Preset masks (which preset button is green) */
+    inputs->buttons->presets->presetmask = (int)pow(2, current_preset);
+    if (dirty) {
+        /* make the buttons blink if it's unsaved. We need to remove any
+         * existing triggers to dirty_cb, because dirty_cb is called
+         * every 0.3 seconds and enabling/disabling (highlight/unlight) the
+         * buttons, so if we have too many callbacks, the buttons would
+         * remain in one state --> no blinking. We need exactly one.
+         */
+        Fl::remove_timeout(dirty_cb, (void *)this);
+        Fl::add_timeout(0.3, dirty_cb, (void *)this);
+    } else {
+        /* Hack. I don't know why this is necessary, but if we're clean,
+         * we need to recall the preset again to correctly reflect
+         * the dirty/undirty state.
+         *
+         * Though it's a little bit redundant, it at least won't do any harm.
+         */
+        inputs->buttons->presets->preset_change(current_preset+1);
+    }
+}
 
 void HDSPMixerWindow::restoreDefaults(int card)
 {
@@ -848,8 +885,10 @@ HDSPMixerWindow::HDSPMixerWindow(int x, int y, int w, int h, const char *label,
     Fl::add_handler(handler_cb);
     Fl::add_timeout(0.030, readregisters_cb, this);
     i = 0;
-    while (i < MAX_CARDS && cards[i] != NULL)
+    while (i < MAX_CARDS && cards[i] != NULL) {
+      current_card = i;
       inputs->buttons->cardselector->ActivateCard (i++);
+    }
 }
 
 int HDSPMixerWindow::handle(int e) 
index 0c2674f19bfc58845cf17036b89b5a1644891d26..134db3efe03eb718d34fca08991eb99152c49b93 100644 (file)
@@ -95,6 +95,8 @@ public:
     void load();
     void setTitle(std::string suffix);
     void setTitleWithFilename();
+    void stashPreset();
+    void unstashPreset();
 };
 
 #endif