hdspmixer: Save preset before switching cards

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>
This commit is contained in:
Adrian Knoth 2011-04-04 14:34:28 +02:00 committed by Takashi Iwai
parent 0b018d9a23
commit 7a865ce040
5 changed files with 47 additions and 1 deletions

View file

@ -186,6 +186,7 @@ HDSPMixerCard::HDSPMixerCard(int cardtype, int id, char *shortname)
/* Set channels and mappings */ /* Set channels and mappings */
adjustSettings(); adjustSettings();
last_preset = last_dirty = 0;
basew = NULL; basew = NULL;
} }

View file

@ -48,6 +48,8 @@ public:
int channels_input, channels_playback, window_width, window_height, card_id; int channels_input, channels_playback, window_width, window_height, card_id;
int channels_output; int channels_output;
int type; 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 *channel_map_input, *channel_map_playback;
char *dest_map; char *dest_map;
char *meter_map_input, *meter_map_playback; char *meter_map_input, *meter_map_playback;

View file

@ -48,9 +48,11 @@ void HDSPMixerCardSelector::draw()
void HDSPMixerCardSelector::ActivateCard (int i) void HDSPMixerCardSelector::ActivateCard (int i)
{ {
card = i + 1; card = i + 1;
basew->stashPreset(); /* save current mixer state */
basew->current_card = i; basew->current_card = i;
basew->cards[i]->setMode (basew->cards[i]->getSpeed ()); basew->cards[i]->setMode (basew->cards[i]->getSpeed ());
basew->setTitleWithFilename(); basew->setTitleWithFilename();
basew->unstashPreset(); /* restore previous mixer state */
redraw (); redraw ();
} }

View file

@ -609,7 +609,44 @@ void HDSPMixerWindow::setTitleWithFilename(void)
setTitle(filename); 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) 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_handler(handler_cb);
Fl::add_timeout(0.030, readregisters_cb, this); Fl::add_timeout(0.030, readregisters_cb, this);
i = 0; i = 0;
while (i < MAX_CARDS && cards[i] != NULL) while (i < MAX_CARDS && cards[i] != NULL) {
current_card = i;
inputs->buttons->cardselector->ActivateCard (i++); inputs->buttons->cardselector->ActivateCard (i++);
}
} }
int HDSPMixerWindow::handle(int e) int HDSPMixerWindow::handle(int e)

View file

@ -95,6 +95,8 @@ public:
void load(); void load();
void setTitle(std::string suffix); void setTitle(std::string suffix);
void setTitleWithFilename(); void setTitleWithFilename();
void stashPreset();
void unstashPreset();
}; };
#endif #endif