Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new UI #1

Merged
merged 2 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 12 additions & 25 deletions librdpiano/src/sound_chip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,26 +175,16 @@ u8 SoundChip::read(size_t offset)

void SoundChip::write(size_t offset, u8 data)
{
// handled in mcu.cpp
// m_irq_triggered = false;

// flags seems to be common for all parts?
if (offset % 8 == 0x6)
offset = (offset / 0x100) * 0x100 + 0x6;

m_ctrl_mem[offset] = data;
// printf("SA write %04x=%02x\n", offset, data);
// fflush(stdout);

// hack
if (offset % 8 == 0x7 && data == 0xff)
{
m_parts[offset / 0x100][0].sub_phase = 0;
m_parts[offset / 0x100][1].sub_phase = 0;
m_parts[offset / 0x100][2].sub_phase = 0;
m_parts[offset / 0x100][3].sub_phase = 0;
m_parts[offset / 0x100][4].sub_phase = 0;
m_parts[offset / 0x100][5].sub_phase = 0;
m_parts[offset / 0x100][6].sub_phase = 0;
m_parts[offset / 0x100][7].sub_phase = 0;
m_parts[offset / 0x100][8].sub_phase = 0;
m_parts[offset / 0x100][9].sub_phase = 0;
}
}

s16 SoundChip::update()
Expand All @@ -212,7 +202,7 @@ s16 SoundChip::update()
uint32_t wave_addr_high = m_ctrl_mem[mem_offset + 3];
uint32_t env_dest = m_ctrl_mem[mem_offset + 4];
uint32_t env_speed = m_ctrl_mem[mem_offset + 5];
uint32_t flags = m_ctrl_mem[mem_offset + 6];
uint32_t flags = m_ctrl_mem[voiceI * 0x100 + 6];
uint32_t env_offset = m_ctrl_mem[mem_offset + 7];

bool irq = false;
Expand All @@ -222,17 +212,14 @@ s16 SoundChip::update()
bool ag3_sel_sample_type;
bool ag1_phase_hi;

// hack
flags = 0x00;

// IC19
{
bool env_speed_some_high =
BIT(env_speed, 6) || BIT(env_speed, 5) || BIT(env_speed, 4) || BIT(env_speed, 3) ||
BIT(env_speed, 2) || BIT(env_speed, 1) || BIT(env_speed, 0);

uint32_t adder1_a = part.env_value;
if (BIT(flags, 0))
if (!BIT(flags, 0))
adder1_a = 1 << 25;
uint32_t adder1_b = env_table[env_speed];
bool adder1_ci = env_speed_some_high && BIT(env_speed, 7);
Expand All @@ -244,7 +231,7 @@ s16 SoundChip::update()
adder3_o &= 0xff;

volume = ~(
((adder1_a >> 14) & 0b111111) |
(BIT(flags, 0) ? ((adder1_a >> 14) & 0b111111) : 0) |
((adder3_o & 0b1111) << 6) |
(adder3_of ? ((adder3_o & 0b11110000) << 6) : 0)
) & 0x3fff;
Expand All @@ -268,8 +255,8 @@ s16 SoundChip::update()
uint32_t adder2 = 1 + (adder1 >> 16) + ((~wave_addr_loop) & 0xff);
bool adder2_co = adder2 > 0xff;
adder2 &= 0xff;
uint32_t adder1_and = BIT(flags, 1) ? 0 : (adder1 & 0xffff);
adder1_and |= (BIT(flags, 1) ? 0 : (adder2_co ? adder2 : (adder1 >> 16))) << 16;
uint32_t adder1_and = !BIT(flags, 1) ? 0 : (adder1 & 0xffff);
adder1_and |= (!BIT(flags, 1) ? 0 : (adder2_co ? adder2 : (adder1 >> 16))) << 16;

part.sub_phase = adder1_and;
waverom_addr = (wave_addr_high << 11) | ((part.sub_phase >> 9) & 0x7ff);
Expand All @@ -279,7 +266,7 @@ s16 SoundChip::update()
ag1_phase_hi = (
(BIT(pitch_lut_i, 15) && BIT(pitch_lut_i, 14)) ||
(BIT(part.sub_phase, 23) || BIT(part.sub_phase, 22) || BIT(part.sub_phase, 21) || BIT(part.sub_phase, 20)) ||
BIT(flags, 1)
!BIT(flags, 1)
);
}

Expand Down Expand Up @@ -325,7 +312,7 @@ s16 SoundChip::update()
exp_val2 = exp_val2 - 0x8000;
int32_t exp_val = exp_val1 + exp_val2;

// hack
// hack to prevent voices ringing when env value is 0, investigate
if (part.env_value != 0)
result += exp_val;
}
Expand Down
225 changes: 217 additions & 8 deletions rdpiano_juce/Source/PluginEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,228 @@
==============================================================================
*/

#include "PluginProcessor.h"
#include "PluginEditor.h"
#include "PluginProcessor.h"

static int bgWidth = 6140;
static int bgHeight = 1503;
static float scaleFactor = 5;
static int uiWidth = bgWidth / scaleFactor;
static int uiHeight = bgHeight / scaleFactor;

//==============================================================================
RdPiano_juceAudioProcessorEditor::RdPiano_juceAudioProcessorEditor (RdPiano_juceAudioProcessor& p)
: AudioProcessorEditor (&p), audioProcessor (p)
{
RdPiano_juceAudioProcessorEditor::RdPiano_juceAudioProcessorEditor(
RdPiano_juceAudioProcessor &p)
: AudioProcessorEditor(&p), audioProcessor(p), midiMessageTimer(*this) {
addAndMakeVisible(lcd);

addAndMakeVisible(buttonMks20);
addAndMakeVisible(buttonMk80);
addAndMakeVisible(button1);
addAndMakeVisible(button2);
addAndMakeVisible(button3);
addAndMakeVisible(button4);
addAndMakeVisible(button5);
addAndMakeVisible(button6);
addAndMakeVisible(button7);
addAndMakeVisible(button8);
addAndMakeVisible(buttonTune);
buttonMks20.addListener(this);
buttonMk80.addListener(this);
button1.addListener(this);
button2.addListener(this);
button3.addListener(this);
button4.addListener(this);
button5.addListener(this);
button6.addListener(this);
button7.addListener(this);
button8.addListener(this);
buttonTune.addListener(this);

addAndMakeVisible(alphaDial);
alphaDial.setLookAndFeel(&knobLF);
alphaDial.setSliderStyle(juce::Slider::Rotary);
alphaDial.setTextBoxStyle(juce::Slider::NoTextBox, true, 0, 0);
alphaDial.setRange(-1, 1);
alphaDial.addListener(this);

addAndMakeVisible(volumeSlider);
volumeSlider.setSliderStyle(juce::Slider::LinearVertical);
volumeSlider.setTextBoxStyle(juce::Slider::NoTextBox, true, 0, 0);
volumeSlider.setRange(0, 1);
volumeSlider.addListener(this);
volumeSlider.setAlpha(0);

setResizeLimits(uiWidth, uiHeight, uiWidth, uiHeight);
setSize(uiWidth, uiHeight);

updateValues();
p.addChangeListener(this);
}

RdPiano_juceAudioProcessorEditor::~RdPiano_juceAudioProcessorEditor() {
alphaDial.setLookAndFeel(nullptr);
}

void RdPiano_juceAudioProcessorEditor::resized() {
float sfC = (float)bgWidth / getBounds().getWidth();

lcd.setBounds((1984 + 60) / sfC, (272 + 50) / sfC, (1394 - 60 * 2) / sfC,
(309 - 40 * 2) / sfC);

buttonMks20.setBounds(2602 / sfC, 806 / sfC, 248 / sfC, 248 / sfC);
buttonMk80.setBounds(2602 / sfC, 1068 / sfC, 248 / sfC, 248 / sfC);
button1.setBounds(1504 / sfC, 806 / sfC, 250 / sfC, 248 / sfC);
button2.setBounds(1764 / sfC, 806 / sfC, 248 / sfC, 248 / sfC);
button3.setBounds(2024 / sfC, 806 / sfC, 248 / sfC, 248 / sfC);
button4.setBounds(2284 / sfC, 806 / sfC, 248 / sfC, 248 / sfC);
button5.setBounds(1504 / sfC, 1068 / sfC, 250 / sfC, 248 / sfC);
button6.setBounds(1764 / sfC, 1068 / sfC, 248 / sfC, 248 / sfC);
button7.setBounds(2024 / sfC, 1068 / sfC, 248 / sfC, 248 / sfC);
button8.setBounds(2284 / sfC, 1068 / sfC, 248 / sfC, 248 / sfC);
buttonTune.setBounds(669 / sfC, 295 / sfC, 273 / sfC, 273 / sfC);

buttonMks20.position(2598, 800, 257, 258, sfC);
buttonMk80.position(2598, 1058, 257, 260, sfC);
button1.position(1478, 800, 290, 260, sfC);
button2.position(1759, 800, 262, 260, sfC);
button3.position(2018, 800, 262, 260, sfC);
button4.position(2279, 800, 262, 260, sfC);
button5.position(1478, 1058, 290, 260, sfC);
button6.position(1759, 1058, 262, 260, sfC);
button7.position(2018, 1058, 262, 260, sfC);
button8.position(2279, 1058, 262, 260, sfC);
buttonTune.position(669, 295, 273, 273, sfC);

alphaDial.setBounds(
(204.564) * (6140 / 311.92) / sfC, (24.061) * (6140 / 311.92) / sfC,
(39.145) * (6140 / 311.92) / sfC, (39.145) * (6140 / 311.92) / sfC);
volumeSlider.setBounds(1188 / sfC, 660 / sfC, 100 / sfC, 656 / sfC);
}

RdPiano_juceAudioProcessorEditor::~RdPiano_juceAudioProcessorEditor()
{
void RdPiano_juceAudioProcessorEditor::paint(juce::Graphics &g) {
float sfC = (float)bgWidth / getBounds().getWidth();

g.drawImage(juce::ImageCache::getFromMemory(BinaryData::background_png,
BinaryData::background_pngSize),
getLocalBounds().toFloat());

// Volume
float volumeY =
660 / sfC + (1 - audioProcessor.status.volume) * (656 - 131) / sfC;
g.drawImage(juce::ImageCache::getFromMemory(BinaryData::interactable_png,
BinaryData::interactable_pngSize),
1188 / sfC, volumeY, 100 / sfC, 131 / sfC, 1188, 1179, 100, 131);

if (audioProcessor.midiMessageCount != lastMidiMessageCount) {
g.setColour(juce::Colours::greenyellow);
g.fillRect(5197 / sfC, 517 / sfC, 85 / sfC, 38 / sfC);
lastMidiMessageCount = audioProcessor.midiMessageCount;
midiMessageTimer.restart();
}
}

void RdPiano_juceAudioProcessorEditor::buttonClicked(juce::Button *button) {
bool prevTuneMode = tuneMode;
tuneMode = false;
if (button == &buttonMks20) {
audioProcessor.setCurrentProgram(0);
} else if (button == &buttonMk80) {
audioProcessor.setCurrentProgram(8);
} else if (button == &button1) {
audioProcessor.setCurrentProgram(
0 + (audioProcessor.status.currentPatch >= 8 ? 8 : 0));
} else if (button == &button2) {
audioProcessor.setCurrentProgram(
1 + (audioProcessor.status.currentPatch >= 8 ? 8 : 0));
} else if (button == &button3) {
audioProcessor.setCurrentProgram(
2 + (audioProcessor.status.currentPatch >= 8 ? 8 : 0));
} else if (button == &button4) {
audioProcessor.setCurrentProgram(
3 + (audioProcessor.status.currentPatch >= 8 ? 8 : 0));
} else if (button == &button5) {
audioProcessor.setCurrentProgram(
4 + (audioProcessor.status.currentPatch >= 8 ? 8 : 0));
} else if (button == &button6) {
audioProcessor.setCurrentProgram(
5 + (audioProcessor.status.currentPatch >= 8 ? 8 : 0));
} else if (button == &button7) {
audioProcessor.setCurrentProgram(
6 + (audioProcessor.status.currentPatch >= 8 ? 8 : 0));
} else if (button == &button8) {
audioProcessor.setCurrentProgram(
7 + (audioProcessor.status.currentPatch >= 8 ? 8 : 0));
} else if (button == &buttonTune) {
tuneMode = !prevTuneMode;
updateValues();
}
}

void RdPiano_juceAudioProcessorEditor::sliderValueChanged(
juce::Slider *slider) {
if (slider == &alphaDial) {
if (tuneMode) {
audioProcessor.setMasterTune(alphaDial.getValue() * 32767.0);
} else {
audioProcessor.setCurrentProgram((alphaDial.getValue() + 1) * 8);
}
} else if (slider == &volumeSlider) {
audioProcessor.status.volume = volumeSlider.getValue();
}
}

void RdPiano_juceAudioProcessorEditor::visibilityChanged() { updateValues(); }

void RdPiano_juceAudioProcessorEditor::changeListenerCallback(
juce::ChangeBroadcaster *) {
updateValues();
}

void RdPiano_juceAudioProcessorEditor::resized()
{
const char *displayPatchNames[] = {
"MKS-20 Piano 1 ", "MKS-20 Piano 2 ",
"MKS-20 Piano 3 ", "MKS-20 Harpsichord ",
"MKS-20 Clavi ", "MKS-20 Vibraphone ",
"MKS-20 E-Piano 1 ", "MKS-20 E-Piano 2 ",
"MK-80 Classic ", "MK-80 Special ",
"MK-80 Blend ", "MK-80 Contemporary ",
"MK-80 A. Piano 1 ", "MK-80 A. Piano 2 ",
"MK-80 Clavi ", "MK-80 Vibraphone "};

void RdPiano_juceAudioProcessorEditor::updateValues() {
buttonMks20.enabled = !tuneMode && audioProcessor.status.currentPatch < 8;
buttonMk80.enabled = !tuneMode && audioProcessor.status.currentPatch >= 8;
buttonMks20.enabled = !tuneMode && audioProcessor.status.currentPatch < 8;
buttonMk80.enabled = !tuneMode && audioProcessor.status.currentPatch >= 8;

button1.enabled = !tuneMode && audioProcessor.status.currentPatch % 8 == 0;
button2.enabled = !tuneMode && audioProcessor.status.currentPatch % 8 == 1;
button3.enabled = !tuneMode && audioProcessor.status.currentPatch % 8 == 2;
button4.enabled = !tuneMode && audioProcessor.status.currentPatch % 8 == 3;
button5.enabled = !tuneMode && audioProcessor.status.currentPatch % 8 == 4;
button6.enabled = !tuneMode && audioProcessor.status.currentPatch % 8 == 5;
button7.enabled = !tuneMode && audioProcessor.status.currentPatch % 8 == 6;
button8.enabled = !tuneMode && audioProcessor.status.currentPatch % 8 == 7;

buttonTune.enabled = tuneMode;

if (tuneMode) {
juce::String tuningString =
"TUNING " +
juce::String(442.0 + audioProcessor.status.masterTune / 32767.0 * 3.85,
1) +
"Hz ";
lcd.setText(tuningString);
alphaDial.setValue(audioProcessor.status.masterTune / 32767.0,
juce::dontSendNotification);
} else {
lcd.setText(displayPatchNames[audioProcessor.status.currentPatch]);
alphaDial.setValue(audioProcessor.status.currentPatch / 16.0 * 2.0 - 1,
juce::dontSendNotification);
}

volumeSlider.setValue(audioProcessor.status.volume,
juce::dontSendNotification);

this->repaint();
}
Loading