Skip to content

Commit fe84d73

Browse files
* New Menu system
- Class-based - Supports multiple pages * Configurable DirectSound effects - Dedicated page (F11) and menus (F1-F8) * Apply some optimizations - Use static for compile-time constants inside functions - Envelope generator handles zero-time values without conditionals
1 parent fe4c70a commit fe84d73

37 files changed

+1677
-563
lines changed

Console.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ int PrintConsoleWithAttribute(HANDLE out, COORD pos, WORD attrib, char const *fo
3737
void Clear(HANDLE hOut)
3838
{
3939
CONSOLE_SCREEN_BUFFER_INFO bufInfo;
40-
COORD osc_phase = { 0, 0 };
40+
static COORD const zero = { 0, 0 };
4141
DWORD written;
4242
DWORD size;
4343
GetConsoleScreenBufferInfo(hOut, &bufInfo);
4444
size = bufInfo.dwSize.X * bufInfo.dwSize.Y;
45-
FillConsoleOutputCharacter(hOut, (TCHAR)' ', size, osc_phase, &written);
46-
FillConsoleOutputAttribute(hOut, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE, size, osc_phase, &written);
47-
SetConsoleCursorPosition(hOut, osc_phase);
45+
FillConsoleOutputCharacter(hOut, 0, size, zero, &written);
46+
FillConsoleOutputAttribute(hOut, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE, size, zero, &written);
47+
SetConsoleCursorPosition(hOut, zero);
4848
}

DisplayLowFrequencyOscillator.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,15 @@ Low-Frequency Oscillator Display
88

99
#include "DisplayLowFrequencyOscillator.h"
1010
#include "Menu.h"
11+
#include "MenuLFO.h"
1112
#include "Math.h"
1213
#include "OscillatorLFO.h"
1314

15+
// local position
16+
static COORD const pos = { 0, 0 };
17+
static COORD const size = { 18, 1 };
18+
19+
// plotting characters
1420
static CHAR_INFO const negative = { 0, BACKGROUND_RED | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE };
1521
static CHAR_INFO const positive = { 0, BACKGROUND_GREEN | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE };
1622
static WORD const plot[2] = { 221, 222 };
@@ -26,15 +32,13 @@ void UpdateLowFrequencyOscillatorDisplay(HANDLE hOut)
2632

2733
// plot low-frequency oscillator value
2834
float const lfo = lfo_state.Update(lfo_config, 0.0f);
29-
int grid_x = Clamp(FloorInt(18.0f * lfo + 18.0f), 0, 35);
35+
int const grid_x = Clamp(FloorInt(18.0f * lfo + 18.0f), 0, 35);
3036
buf[grid_x / 2].Char.UnicodeChar = plot[grid_x & 1];
3137

3238
// draw the gauge
33-
COORD const pos = { 0, 0 };
34-
COORD const size = { 18, 1 };
3539
SMALL_RECT region = {
36-
Menu::pos[Menu::MENU_LFO].X, Menu::pos[Menu::MENU_LFO].Y + 4,
37-
Menu::pos[Menu::MENU_LFO].X + 19, Menu::pos[Menu::MENU_LFO].Y + 4
40+
Menu::menu_lfo.pos.X, Menu::menu_lfo.pos.Y + 4,
41+
Menu::menu_lfo.pos.X + 19, Menu::menu_lfo.pos.Y + 4
3842
};
3943
WriteConsoleOutput(hOut, &buf[0], size, pos, &region);
4044
}

DisplayOscillatorFrequency.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Oscillator Frequency Display
88

99
#include "DisplayOscillatorFrequency.h"
1010
#include "Menu.h"
11+
#include "MenuOSC.h"
1112
#include "Voice.h"
1213
#include "Control.h"
1314
#include "Console.h"
@@ -20,10 +21,9 @@ void UpdateOscillatorFrequencyDisplay(HANDLE hOut, int const v, int const o)
2021
float const key_freq = Control::pitch_scale * note_frequency[voice_note[v]];
2122

2223
// get attributes to use
23-
Menu::MenuMode menu = Menu::MenuMode(Menu::MENU_OSC1 + o);
24-
COORD const pos = { Menu::pos[menu].X + 8, Menu::pos[menu].Y };
25-
bool const selected = (Menu::active == menu);
26-
bool const title_selected = selected && Menu::item[menu] == 0;
24+
COORD const pos = { Menu::menu_osc[o].pos.X + 8, Menu::menu_osc[o].pos.Y };
25+
bool const selected = (Menu::active_page == Menu::PAGE_MAIN && Menu::active_menu == Menu::MAIN_OSC1 + o);
26+
bool const title_selected = selected && Menu::menu_osc[o].item == 0;
2727
WORD const title_attrib = Menu::title_attrib[true][selected + title_selected];
2828
WORD const num_attrib = (title_attrib & 0xF8) | (FOREGROUND_GREEN);
2929
WORD const unit_attrib = (title_attrib & 0xF8) | (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);

DisplaySpectrumAnalyzer.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ Spectrum Analyzer Display
1111

1212
#define FREQUENCY_BINS 4096
1313

14+
// frequency constants
15+
static float const semitone = 1.0594630943592952645618252949463f; //powf(2.0f, 1.0f / 12.0f);
16+
static float const quartertone = 0.97153194115360586874328941582127f; //1/sqrtf(semitone)
17+
static float const freq_scale = FREQUENCY_BINS * 2.0f * quartertone;
18+
19+
// position and size
20+
static COORD const pos = { 0, 0 };
21+
static COORD const size = { SPECTRUM_WIDTH, SPECTRUM_HEIGHT };
22+
23+
// plotting characters
1424
static CHAR_INFO const bar_full = { 0, BACKGROUND_GREEN };
1525
static CHAR_INFO const bar_top = { 223, BACKGROUND_GREEN | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE };
1626
static CHAR_INFO const bar_bottom = { 220, BACKGROUND_BLUE | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE };
@@ -28,8 +38,7 @@ void UpdateSpectrumAnalyzer(HANDLE hOut, DWORD stream, BASS_INFO const &info, fl
2838

2939
// get the lower frequency bin for the zeroth semitone band
3040
// (half a semitone down from the center frequency)
31-
float const semitone = powf(2.0f, 1.0f / 12.0f);
32-
float freq = freq_min * FREQUENCY_BINS * 2.0f / info.freq / sqrtf(semitone);
41+
float freq = freq_scale * freq_min / info.freq;
3342
int b0 = Max(RoundInt(freq), 0);
3443

3544
// get power in each semitone band
@@ -62,13 +71,11 @@ void UpdateSpectrumAnalyzer(HANDLE hOut, DWORD stream, BASS_INFO const &info, fl
6271
}
6372

6473
// inaudible band
65-
int xinaudible = RoundInt(logf(20000 / freq_min) * 12 / logf(2));
74+
int xinaudible = RoundInt(log2f(20000 / freq_min) * 12);
6675

6776
// plot log-log spectrum
6877
// each grid cell is one semitone wide and 6 dB high
6978
CHAR_INFO buf[SPECTRUM_HEIGHT][SPECTRUM_WIDTH];
70-
COORD const pos = { 0, 0 };
71-
COORD const size = { SPECTRUM_WIDTH, SPECTRUM_HEIGHT };
7279
SMALL_RECT region = { 0, 0, 79, 49 };
7380
float threshold = 1.0f;
7481
for (int y = 0; y < SPECTRUM_HEIGHT; ++y)

Effect.cpp

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ char const * const fx_name[9] =
1414
};
1515

1616
// effect config
17-
bool fx_enable;
1817
bool fx_active[9];
1918

2019
// effect handles
@@ -23,14 +22,38 @@ HFX fx[9];
2322
// channel to apply effects
2423
DWORD fx_channel;
2524

25+
// effect parameters
26+
BASS_DX8_CHORUS fx_chorus = { 50, 10, 25, 1, 1, 16, 3 }; // 1.1f
27+
BASS_DX8_COMPRESSOR fx_compressor = { 0, 10, 200, -20, 3, 4 };
28+
BASS_DX8_DISTORTION fx_distortion = { -18, 15, 2400, 2400, 8000 };
29+
BASS_DX8_ECHO fx_echo = { 50, 50, 500, 500, 0 };
30+
BASS_DX8_FLANGER fx_flanger = { 50, 100, -50, 0.25f, 1, 2, 2 };
31+
BASS_DX8_GARGLE fx_gargle = { 20, 0 };
32+
BASS_DX8_I3DL2REVERB fx_reverb3d = { -1000, -100, 0, 1.49f, 0.83f, -2602, 0.007f, 200, 0.011f, 100, 100, 5000 };
33+
BASS_DX8_PARAMEQ fx_parameq = { 8000, 12, 0 }; // should be an array of these
34+
BASS_DX8_REVERB fx_reverb = { 0, 0, 1000, 0.001f };
35+
36+
// map index to parameters
37+
void *fx_params[] =
38+
{
39+
&fx_chorus,
40+
&fx_compressor,
41+
&fx_distortion,
42+
&fx_echo,
43+
&fx_flanger,
44+
&fx_gargle,
45+
&fx_reverb3d,
46+
&fx_parameq,
47+
&fx_reverb
48+
};
49+
2650
// enable/disable effect
2751
void EnableEffect(int index, bool enable)
2852
{
2953
if (enable)
3054
{
3155
if (!fx[index])
3256
{
33-
// set the effect, not bothering with parameters (use defaults)
3457
fx[index] = BASS_ChannelSetFX(fx_channel, BASS_FX_DX8_CHORUS + index, 0);
3558
}
3659
}
@@ -43,3 +66,12 @@ void EnableEffect(int index, bool enable)
4366
}
4467
}
4568
}
69+
70+
// update effect
71+
void UpdateEffect(int index)
72+
{
73+
if (fx[index])
74+
{
75+
BASS_FXSetParameters(fx[index], fx_params[index]);
76+
}
77+
}

Effect.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,19 @@ extern HFX fx[9];
1818
// channel to apply effects
1919
extern DWORD fx_channel;
2020

21+
// effect parameters
22+
extern BASS_DX8_CHORUS fx_chorus;
23+
extern BASS_DX8_COMPRESSOR fx_compressor;
24+
extern BASS_DX8_DISTORTION fx_distortion;
25+
extern BASS_DX8_ECHO fx_echo;
26+
extern BASS_DX8_FLANGER fx_flanger;
27+
extern BASS_DX8_GARGLE fx_gargle;
28+
extern BASS_DX8_I3DL2REVERB fx_reverb3d;
29+
extern BASS_DX8_PARAMEQ fx_parameq;
30+
extern BASS_DX8_REVERB fx_reverb;
31+
2132
// enable/disable effect
2233
extern void EnableEffect(int index, bool enable);
34+
35+
// update effect (after changing parameters)
36+
extern void UpdateEffect(int index);

Envelope.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ static float const ENV_DECAY_BIAS = 1.0f - 1.0f / (1.0f - expf(-ENV_DECAY_CONSTA
2121
EnvelopeConfig::EnvelopeConfig(bool const enable, float const attack_time, float const decay_time, float const sustain_level, float const release_time)
2222
: enable(enable)
2323
, attack_time(attack_time)
24-
, attack_rate(1 / Max(attack_time, 0.0001f))
24+
, attack_rate(1 / (attack_time + FLT_MIN))
2525
, decay_time(decay_time)
26-
, decay_rate(1 / Max(decay_time, 0.0001f))
26+
, decay_rate(1 / (decay_time + FLT_MIN))
2727
, sustain_level(sustain_level)
2828
, release_time(release_time)
29-
, release_rate(1 / Max(release_time, 0.0001f))
29+
, release_rate(1 / (release_time + FLT_MIN))
3030
{
3131
}
3232

0 commit comments

Comments
 (0)