Hi Pete,
Why not pass a pointer to the midX part of the structure and pass that to a
routine that sets the values as per your code fragment.
{
...
case midi1:
Function(&prefs.mid1, &save, &handle, &prefs);
break;
...
case midiX:
Function(&prefs.midX, &save, &handle, &prefs);
break;
...
}
void Function(ptrMidX, ptrSave, ptrHandle, ptrPrefs)
{
if (ptrSave)
{
ptrMidX->chan = ptrPrefs->chan;
ptrMidX->instrument = ptrPrefs->instrument;
ptrMidX->vel = ptrPrefs->vel;
ptrMidX->pitch = ptrPrefs->pitch;
ptrMidX->range = ptrPrefs->range;
ptrSave = false;
}
else
{
SetFieldInt(instrumentlbl, ptrMidX->instrument + 1);
SetFieldInt(pitchlbl, ptrMidX->pitch + 1);
SetFieldInt(vellbl, ptrMidX->vel + 1);
SetFieldInt(rangelbl, ptrMidX->range + 1);
SetFieldInt(chanlbl, ptrMidX->chan + 1);
}
ptrHandled = true;
return;
}
Neil D. Brown
Software Manager
Applied Interactive Ltd.
Phone: +44 (0)1234 756049/50
Fax : +44 (0)1234 756138
-----Original Message-----
From: pete moss [mailto:[EMAIL PROTECTED]]
Sent: 01 July 1999 06:31
To: [EMAIL PROTECTED]
Subject: stupid (?) C question
i am not the best C programmer, so this might be a stupid question but:
in my app, i have 16 presets. here is the code for one of the preset
button handlers:
case midi1:
if (save)
{
prefs.mid1.chan=prefs.chan;
prefs.mid1.instrument=prefs.instrument;
prefs.mid1.vel=prefs.vel;
prefs.mid1.pitch=prefs.pitch;
prefs.mid1.range=prefs.range;
save = false;
}
else
{
SetFieldInt(instrumentlbl, prefs.mid1.instrument+1);
SetFieldInt(pitchlbl, prefs.mid1.pitch+1);
SetFieldInt(vellbl, prefs.mid1.vel+1);
SetFieldInt(rangelbl, prefs.mid1.range+1);
SetFieldInt(chanlbl, prefs.mid1.chan+1);
}
handled = true;
break;
it either sets the fields with a saved value or saves the current values
into a preset. i have sixteen version of this (16 presets), with mid1,
mid2, mid3, mid4, etc, so my code is quite huge. is there a
way to do this in a function where i could pass prefs.midX instead of
having 16 copies of nearly the same code?
i seem to remember someone recently saying that one shouldnt pass
structs in function parameters. if that is bad, then how can i take 16
code segments with nearly the same code and make 1 code segment with the
ability to fill in the changing part?
any ptrs?
:P