ref: 3922b88bda427a03486ce01fc9a11739a570b545
parent: 29415dfac1fb18f32d86433c00b4b4942c4c24d6
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Thu Mar 19 16:42:37 EDT 2020
ay: add "Hit" button to apply envelope changes
--- a/ay/ay.c
+++ b/ay/ay.c
@@ -32,8 +32,10 @@
float enable;
}chan[3];
float hold, alternate, attack, cont;
- float noise;
- float envelope;
+ float noisefreq;
+ float envperiod;
+ float hit;
+ int envmode;
};
static Aux rootaux[] = {
@@ -151,7 +153,7 @@
}
}
- if (ui->zone == &dsp->envelope) {
+ if (ui->zone == &dsp->envperiod) {
pd = MAX(1, MIN(65535, (tickhz / 1000) * (*ui->zone) / 256));
regw(ay, AY38910_REG_ENV_PERIOD_FINE, pd&0xff);
regw(ay, AY38910_REG_ENV_PERIOD_COARSE, pd>>8);
@@ -159,7 +161,7 @@
return 0;
}
- if (ui->zone == &dsp->noise) {
+ if (ui->zone == &dsp->noisefreq) {
r = MAX(1, MIN(31, tickhz/(16 * (*ui->zone))));
regw(ay, AY38910_REG_PERIOD_NOISE, r);
*ui->zone = tickhz/16/r;
@@ -166,16 +168,21 @@
return 0;
}
- r = 0;
+ if (ui->zone == &dsp->hit) {
+ if (*ui->zone)
+ regw(ay, AY38910_REG_ENV_SHAPE_CYCLE, dsp->envmode);
+ return 0;
+ }
+
+ dsp->envmode = 0;
if (dsp->hold)
- r |= 1<<0;
+ dsp->envmode |= 1<<0;
if (dsp->alternate)
- r |= 1<<1;
+ dsp->envmode |= 1<<1;
if (dsp->attack)
- r |= 1<<2;
+ dsp->envmode |= 1<<2;
if (dsp->cont)
- r |= 1<<3;
- regw(ay, AY38910_REG_ENV_SHAPE_CYCLE, r);
+ dsp->envmode |= 1<<3;
return 0;
}
@@ -223,15 +230,15 @@
min = ceil(tickhz/496);
max = floor(tickhz/16);
step = MAX(1, tickhz/480 - tickhz/496);
- ui->declare(ui->f, &dsp->noise, "unit", "Hz");
- ui->addHorizontalSlider(ui->f, "Noise", &dsp->noise, min, min, max, step);
+ ui->declare(ui->f, &dsp->noisefreq, "unit", "Hz");
+ ui->addHorizontalSlider(ui->f, "Noise", &dsp->noisefreq, min, min, max, step);
ui->openVerticalBox(ui->f, "Envelope");
min = MAX(1, 256000/tickhz);
max = floor(16776960000LL/tickhz);
- ui->declare(ui->f, &dsp->envelope, "0", "");
- ui->declare(ui->f, &dsp->envelope, "unit", "ms");
- ui->addHorizontalSlider(ui->f, "Period", &dsp->envelope, 500, min, max, 1);
+ ui->declare(ui->f, &dsp->envperiod, "0", "");
+ ui->declare(ui->f, &dsp->envperiod, "unit", "ms");
+ ui->addHorizontalSlider(ui->f, "Period", &dsp->envperiod, 500, min, max, 1);
ui->declare(ui->f, &dsp->hold, "1", "");
ui->addCheckButton(ui->f, "Hold", &dsp->hold);
ui->declare(ui->f, &dsp->alternate, "2", "");
@@ -240,6 +247,8 @@
ui->addCheckButton(ui->f, "Attack", &dsp->attack);
ui->declare(ui->f, &dsp->cont, "4", "");
ui->addCheckButton(ui->f, "Continue", &dsp->cont);
+ ui->declare(ui->f, &dsp->hit, "5", "");
+ ui->addButton(ui->f, "Hit", &dsp->hit);
ui->closeBox(ui->f);
ui->closeBox(ui->f);