Skip to contentSkip to conversation

hdspmixer: rescue current mixer settings when switching cards

PATCH In review Adrian Knoth 2 participants 6 messages Apr 4, 2011 – Apr 6, 2011

lore
Share & tools
lore
#0 lore raw

cover hdspmixer: rescue current mixer settings when switching cards

Hi!

This series of patches was developed for EMAtech. They discovered that when running with multiple cards, switching between cards would lose all current changes made to the last active card.

Obviously, this is undesired behaviour. Though rather small, it nearly took me 6hrs to get this right, and it could still be improved, but I like to take hdspmixer into a completely different direction:

I want to remove the card switching code completely and simply run a single instance per card, that is, if you have more than one card, you'll say something like hdspmixer -c 1 (or even a card name).

Likewise, the preset files should then only contain the settings for a single card. Right now, it stores everything for three cards, and if you have four, then you'd be left in the rain. Also, when the order of cards changes, the mixer settings would end up on the wrong card.

Long story short: the current approach is a dead-end.

Cheers

Adrian Knoth (4):
hdspmixer: Add a 9th pseudo preset
hdspmixer: Save preset before switching cards
hdspmixer: Recall 1st preset on all cards, not just on the first
hdspmixer: Initialize headphones out in presets

 hdspmixer/src/HDSPMixerCard.cxx         |    1 +
 hdspmixer/src/HDSPMixerCard.h           |    2 +
 hdspmixer/src/HDSPMixerCardSelector.cxx |    2 +
 hdspmixer/src/HDSPMixerIOMixer.cxx      |    2 +-
 hdspmixer/src/HDSPMixerIOMixer.h        |    2 +-
 hdspmixer/src/HDSPMixerOutput.cxx       |    4 +-
 hdspmixer/src/HDSPMixerOutput.h         |    2 +-
 hdspmixer/src/HDSPMixerWindow.cxx       |   48 ++++++++++++++++++++++++++++--
 hdspmixer/src/HDSPMixerWindow.h         |    4 ++-
 hdspmixer/src/defines.h                 |    6 ++++
 10 files changed, 63 insertions(+), 10 deletions(-)
Signature · 1 line
1.7.4.1
#1 lore raw

PATCH 1/4 hdspmixer: Add a 9th pseudo preset

When switching cards, all current settings are lost. To have a place where to store them, let's add a virtual 9th preset which can be used as a temporary scratch pad.

---
 hdspmixer/src/HDSPMixerIOMixer.cxx |    2 +-
 hdspmixer/src/HDSPMixerIOMixer.h   |    2 +-
 hdspmixer/src/HDSPMixerOutput.cxx  |    4 ++--
 hdspmixer/src/HDSPMixerOutput.h    |    2 +-
 hdspmixer/src/HDSPMixerWindow.cxx  |    2 +-
 hdspmixer/src/HDSPMixerWindow.h    |    2 +-
 hdspmixer/src/defines.h            |    6 ++++++
 7 files changed, 13 insertions(+), 7 deletions(-)
hdspmixer/src/HDSPMixerIOMixer.cxx +1 -1
index 987be41..9283d64 100644
@@ -38,7 +38,7 @@ HDSPMixerIOMixer::HDSPMixerIOMixer(int x, int y, int w, int h, int ch, int type)
 	p_iomixer_xpm = iomixer_r_xpm;
     }
     for (int j = 0; j < MAX_CARDS; ++j) {
-	for (int i = 0; i < 8; ++i) {
+	for (int i = 0; i < NUM_PRESETS; ++i) {
 	    data[j][0][i] = new HDSPMixerStripData();
 	    data[j][1][i] = new HDSPMixerStripData();
 	    data[j][2][i] = new HDSPMixerStripData();
hdspmixer/src/HDSPMixerIOMixer.h +1 -1
index 2ec7f05..aa12487 100644
@@ -56,7 +56,7 @@ private:
 	std::stringstream channel_name;
     void update_child(Fl_Widget &widget);
 public:
-    HDSPMixerStripData *data[MAX_CARDS][3][8]; /* data[card][mode(ss/ds/qs)][preset number] */
+    HDSPMixerStripData *data[MAX_CARDS][3][NUM_PRESETS]; /* data[card][mode(ss/ds/qs)][preset number] */
     HDSPMixerPan *pan;
     HDSPMixerFader *fader;
     HDSPMixerPeak *peak;
hdspmixer/src/HDSPMixerOutput.cxx +2 -2
index 5047825..f5981b0 100644
@@ -170,8 +170,8 @@ static char const *labels_9632_qs[8] = {
 HDSPMixerOutput::HDSPMixerOutput(int x, int y, int w, int h, int num):Fl_Group(x, y, w, h)
 {
 
-    for (int j = 0; j < 3; ++j) {
-	for (int i = 0; i < 8; ++i) {
+    for (int j = 0; j < MAX_CARDS; ++j) {
+	for (int i = 0; i < NUM_PRESETS; ++i) {
 	    data[j][0][i] = new HDSPMixerOutputData();
 	    data[j][1][i] = new HDSPMixerOutputData();
 	    data[j][2][i] = new HDSPMixerOutputData();
hdspmixer/src/HDSPMixerOutput.h +1 -1
index 2bc3d5c..6278cfd 100644
@@ -52,7 +52,7 @@ private:
     HDSPMixerWindow *basew;    
     void update_child(Fl_Widget& widget);
 public:
-    HDSPMixerOutputData *data[MAX_CARDS][3][8]; /* data[card][mode(ss/ds/qs)][preset number] */
+    HDSPMixerOutputData *data[MAX_CARDS][3][NUM_PRESETS]; /* data[card][mode(ss/ds/qs)][preset number] */
     HDSPMixerFader *fader;
     HDSPMixerGain *gain;
     HDSPMixerMeter *meter;
hdspmixer/src/HDSPMixerWindow.cxx +1 -1
index 960ec0f..a327904 100644
@@ -791,7 +791,7 @@ HDSPMixerWindow::HDSPMixerWindow(int x, int y, int w, int h, const char *label,
 	}	
     }
     for (int j = 0; j < MAX_CARDS; j++) {
-	for (int i = 0; i < 8; ++i) {
+	for (int i = 0; i < NUM_PRESETS; ++i) {
 	    data[j][0][i] = new HDSPMixerPresetData();
 	    data[j][1][i] = new HDSPMixerPresetData();
 	    data[j][2][i] = new HDSPMixerPresetData();
hdspmixer/src/HDSPMixerWindow.h +1 -1
index dfc7d59..0c2674f 100644
@@ -73,7 +73,7 @@ public:
     Fl_Scroll *scroll;
     HDSPMixerSetup *setup;
     HDSPMixerAbout *about;
-    HDSPMixerPresetData *data[MAX_CARDS][3][8]; /* data[card number][mode(ss/ds/qs)][preset number] */
+    HDSPMixerPresetData *data[MAX_CARDS][3][NUM_PRESETS]; /* data[card number][mode(ss/ds/qs)][preset number] */
     HDSPMixerCard *cards[MAX_CARDS];
     HDSPMixerInputs *inputs;
     HDSPMixerPlaybacks *playbacks;
hdspmixer/src/defines.h +6 -0
index d29c37c..af5c382 100644
@@ -49,6 +49,12 @@
 
 #define MAX_CARDS	3
 
+/* Number of presets. 8 presets visible to the user, the 9th is used for
+ * holding temporary mixer data when switching cards, so it's not a real
+ * preset but more like a scratch pad.
+ */
+#define NUM_PRESETS	9
+
 typedef unsigned long long int int64;
 
 #endif
Signature · 1 line
1.7.4.1
#2 lore raw

PATCH 2/4 hdspmixer: Save preset before switching cards

In reply to Adrian Knoth

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.

---
 hdspmixer/src/HDSPMixerCard.cxx         |    1 +
 hdspmixer/src/HDSPMixerCard.h           |    2 +
 hdspmixer/src/HDSPMixerCardSelector.cxx |    2 +
 hdspmixer/src/HDSPMixerWindow.cxx       |   41 ++++++++++++++++++++++++++++++-
 hdspmixer/src/HDSPMixerWindow.h         |    2 +
 5 files changed, 47 insertions(+), 1 deletions(-)
hdspmixer/src/HDSPMixerCard.cxx +1 -0
index f3205b9..fbd5de5 100644
@@ -186,6 +186,7 @@ HDSPMixerCard::HDSPMixerCard(int cardtype, int id, char *shortname)
     
     /* Set channels and mappings */
     adjustSettings();
+    last_preset = last_dirty = 0;
         
     basew = NULL;
 }
hdspmixer/src/HDSPMixerCard.h +2 -0
index 032c61f..d2ef8a6 100644
@@ -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;
hdspmixer/src/HDSPMixerCardSelector.cxx +2 -0
index d83c4c9..d685009 100644
@@ -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 ();
 }
 
hdspmixer/src/HDSPMixerWindow.cxx +40 -1

55 lines not on this page · raw message

hdspmixer/src/HDSPMixerWindow.h +2 -0
index 0c2674f..134db3e 100644
@@ -95,6 +95,8 @@ public:
     void load();
     void setTitle(std::string suffix);
     void setTitleWithFilename();
+    void stashPreset();
+    void unstashPreset();
 };
 
 #endif
Signature · 1 line
1.7.4.1
#3 lore raw

PATCH 3/4 hdspmixer: Recall 1st preset on all cards, not just on the first

In reply to Adrian Knoth

With the new "store current settings to the virtual 9th preset" before switching cards code, one needs to make sure the actual mixer state is loaded with sane values, either from the preset file or a generic builtin preset.

Calling preset_change(1) is sufficient, setting all the required data. However, in case of more than one RME card in the system, one needs to call this function for each card, otherwise, some of the cards store uninitialized data to the 9th preset, resulting in a weird mixer state afterwards.

---
 hdspmixer/src/HDSPMixerWindow.cxx |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
hdspmixer/src/HDSPMixerWindow.cxx +2 -1
index 7848190..5a7dac0 100644
@@ -877,9 +877,10 @@ HDSPMixerWindow::HDSPMixerWindow(int x, int y, int w, int h, const char *label,
 	printf("Initializing default presets\n");
 	i = 0;
 	while (i < MAX_CARDS && cards[i] != NULL) {
+	    current_card = i;
 	    restoreDefaults(i++);
+	    inputs->buttons->presets->preset_change(1);
 	}
-	inputs->buttons->presets->preset_change(1);
     }
     Fl::atclose = atclose_cb;
     Fl::add_handler(handler_cb);
Signature · 1 line
1.7.4.1
#4 lore raw

PATCH 4/4 hdspmixer: Initialize headphones out in presets

In reply to Adrian Knoth

Cards like the multiface/digiface have additional headphones out. Those were not initialized in the presets due to wrong loop boundaries:
maxdest represents the amount of physical stereo pairs, and chnls is either equal or less, so the output fader array needs more iterations than the playback section.

---
 hdspmixer/src/HDSPMixerWindow.cxx |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
hdspmixer/src/HDSPMixerWindow.cxx +1 -1
index 5a7dac0..75fbc4f 100644
@@ -734,7 +734,7 @@ void HDSPMixerWindow::restoreDefaults(int card)
 
     for (int preset = 0; preset < 8; ++preset) {
 	for (int speed = 0; speed < num_modes; ++speed) {
-	    for (int i = 0; i < chnls[speed]; i+=2) {
+	    for (int i = 0; i < 2*maxdest[speed]; i+=2) {
     		for (int z = 0; z < maxdest[speed]; ++z) {
 		    /* Gain setup */
 		    if (cards[card]->type == H9632) {
Signature · 1 line
1.7.4.1
#5 lore raw
In reply to Adrian Knoth

At Mon, 4 Apr 2011 14:34:26 +0200,

Quoted 12 lines · Adrian Knoth

Hi!

This series of patches was developed for EMAtech. They discovered that when running with multiple cards, switching between cards would lose all current changes made to the last active card.

Obviously, this is undesired behaviour. Though rather small, it nearly took me 6hrs to get this right, and it could still be improved, but I like to take hdspmixer into a completely different direction:

Quoted 8 lines

I want to remove the card switching code completely and simply run a single instance per card, that is, if you have more than one card, you'll say something like hdspmixer -c 1 (or even a card name).

Likewise, the preset files should then only contain the settings for a single card. Right now, it stores everything for three cards, and if you have four, then you'd be left in the rain. Also, when the order of cards changes, the mixer settings would end up on the wrong card.

But if you have single setup files, the card-order issue still applies, no?

Though, I understand that a file-per-card is far easier to handle.

Quoted 1 line

Long story short: the current approach is a dead-end.

Go ahead!

Anyway, I applied your patches now. Thanks.

Takashi