Skip to content

Commit

Permalink
Added Middle C option for UI display, update ct_midikey_or_channel ty…
Browse files Browse the repository at this point in the history
…pein behavior (#1936)

* also display note values instead of numbers for ct_midikey(_or_channel) types
  • Loading branch information
mkruselj authored May 23, 2020
1 parent bada868 commit 2b179f5
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 36 deletions.
71 changes: 62 additions & 9 deletions src/common/Parameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1088,19 +1088,27 @@ void Parameter::get_display_alt(char* txt, bool external, float ef)
float f = val.f;
int i_value = (int)( f + 0.5 ) + 69; // that 1/2th centers us
if( i_value < 0 ) i_value = 0;
int octave = (i_value / 12) - 1;
char notenames[12][3] = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"};
sprintf(txt, "~%s%d", notenames[i_value % 12], octave);

int oct_offset = 1;
if (storage)
oct_offset = Surge::Storage::getUserDefaultValue(storage, "middleC", 1);
char notename[8];
sprintf(txt, "%s", get_notename(notename, i_value, oct_offset));

break;
}
case ct_flangerpitch:
{
float f = val.f;
int i_value = (int)( f );
if( i_value < 0 ) i_value = 0;
int octave = (i_value / 12) - 1;
char notenames[12][3] = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"};
sprintf(txt, "~%s%d", notenames[i_value % 12], octave);

int oct_offset = 1;
if (storage)
oct_offset = Surge::Storage::getUserDefaultValue(storage, "middleC", 1);
char notename[8];
sprintf(txt, "%s", get_notename(notename, i_value, oct_offset));

break;
}
case ct_countedset_percent:
Expand All @@ -1115,7 +1123,6 @@ void Parameter::get_display_alt(char* txt, bool external, float ef)
}

break;

}
}

Expand Down Expand Up @@ -1266,8 +1273,28 @@ void Parameter::get_display(char* txt, bool external, float ef)
i = (int)((1 / 0.99) * (ef - 0.005) * (float)(val_max.i - val_min.i) + 0.5) + val_min.i;
else
i = val.i;

switch (ctrltype)
{
case ct_midikey_or_channel:
{
auto sm = storage->getPatch().scenemode.val.i;

if (sm == sm_chsplit)
{
sprintf(txt, "Channel %d", (val.i / 8) + 1);
break;
}
}
case ct_midikey:
{
int oct_offset = 1;
if (storage)
oct_offset = Surge::Storage::getUserDefaultValue(storage, "middleC", 1);
char notename[8];
sprintf(txt, "%s", get_notename(notename, val.i, oct_offset));
break;
}
case ct_osctype:
sprintf(txt, "%s", osctype_abberations[limit_range(i, 0, (int)num_osctypes - 1)]);
break;
Expand Down Expand Up @@ -1731,12 +1758,38 @@ bool Parameter::set_value_from_string( std::string s )

if( valtype == vt_int )
{
auto ni = std::atoi( c );
if( ni >= val_min.i && ni <= val_max.i )
auto ni = std::atoi(c);

switch (ctrltype)
{
case ct_midikey_or_channel:
{
auto sm = storage->getPatch().scenemode.val.i;

if (sm == sm_chsplit)
{
const char* strip = &(c[0]);
while (*strip != '\0' && !std::isdigit(*strip))
++strip;
ni = (std::atof(strip) * 8) - 1;
}

break;
}
case ct_midikey:
{
// TODO: parse note name text as valid integer input

break;
}
}

if (ni >= val_min.i && ni <= val_max.i)
{
val.i = ni;
return true;
}

return false;
}

Expand Down
17 changes: 11 additions & 6 deletions src/common/gui/CNumberField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#include "CNumberField.h"
#include "Colors.h"
#include "SurgeStorage.h"
#include "UserDefaults.h"
#include <string>
#include <math.h>
#include "unitconversion.h"
Expand Down Expand Up @@ -65,7 +67,8 @@ void unit_prefix(float value, char* text, bool allow_milli = true, bool allow_ki
CNumberField::CNumberField(const CRect& size,
IControlListener* listener,
long tag,
CBitmap* pBackground)
CBitmap* pBackground,
SurgeStorage* storage)
: CControl(size, listener, tag, pBackground)
{
i_value = 60;
Expand All @@ -83,6 +86,7 @@ CNumberField::CNumberField(const CRect& size,
setLabelPlacement(lp_left);
i_poly = 0;
altlook = false;
this->storage = storage;
}

CNumberField::~CNumberField()
Expand Down Expand Up @@ -321,15 +325,16 @@ void CNumberField::draw(CDrawContext* pContext)
case cm_midichannel_from_127:
{
int mc = i_value / 8 + 1;
sprintf(the_text, "Ch. %i", mc );
sprintf(the_text, "Ch %i", mc );
}
break;
case cm_notename:
{
int octave = (i_value / 12) - 2;
char notenames[12][3] = {"C ", "C#", "D ", "D#", "E ", "F ",
"F#", "G ", "G#", "A ", "A#", "B "};
sprintf(the_text, "%s%i", notenames[i_value % 12], octave);
int oct_offset = 1;
if (storage)
oct_offset = Surge::Storage::getUserDefaultValue(storage, "middleC", 1);
char notename[8];
sprintf(the_text, "%s", get_notename(notename, i_value, oct_offset));
}
break;
case cm_envshape:
Expand Down
4 changes: 3 additions & 1 deletion src/common/gui/CNumberField.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ class CNumberField : public VSTGUI::CControl, public Surge::UI::SkinConsumingCom
CNumberField(const VSTGUI::CRect& size,
VSTGUI::IControlListener* listener = 0,
long tag = 0,
VSTGUI::CBitmap* pBackground = 0);
VSTGUI::CBitmap* pBackground = 0,
SurgeStorage* storage = nullptr);
~CNumberField();

virtual void setFontColor(VSTGUI::CColor color);
Expand Down Expand Up @@ -238,6 +239,7 @@ class CNumberField : public VSTGUI::CControl, public Surge::UI::SkinConsumingCom

virtual bool onWheel(const VSTGUI::CPoint& where, const float& distance, const VSTGUI::CButtonState& buttons) override;
bool altlook;
SurgeStorage* storage = nullptr;

private:
VSTGUI::CColor fontColor;
Expand Down
66 changes: 49 additions & 17 deletions src/common/gui/SurgeGUIEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1651,7 +1651,7 @@ void SurgeGUIEditor::openOrRecreateEditor()
{
CRect rect(0, 0, 43, 14);
rect.offset(p->posx, p->posy);
CNumberField* key = new CNumberField(rect, this, p->id + start_paramtags);
CNumberField* key = new CNumberField(rect, this, p->id + start_paramtags, nullptr, &(synth->storage));
key->setSkin(currentSkin,bitmapStore);
auto sm = this->synth->storage.getPatch().scenemode.val.i;

Expand Down Expand Up @@ -1680,7 +1680,7 @@ void SurgeGUIEditor::openOrRecreateEditor()
{
CRect rect(0, 0, 43, 14);
rect.offset(p->posx, p->posy);
CNumberField* key = new CNumberField(rect, this, p->id + start_paramtags);
CNumberField* key = new CNumberField(rect, this, p->id + start_paramtags, nullptr, &(synth->storage));
key->setSkin(currentSkin,bitmapStore);
key->setControlMode(cm_notename);
// key->altlook = true;
Expand All @@ -1693,7 +1693,7 @@ void SurgeGUIEditor::openOrRecreateEditor()
{
CRect rect(0, 0, 24, 10);
rect.offset(p->posx, p->posy);
CNumberField* pbd = new CNumberField(rect, this, p->id + start_paramtags);
CNumberField* pbd = new CNumberField(rect, this, p->id + start_paramtags, nullptr, &(synth->storage));
pbd->setSkin(currentSkin,bitmapStore);
pbd->altlook = true;
pbd->setControlMode(cm_pbdepth);
Expand All @@ -1705,7 +1705,7 @@ void SurgeGUIEditor::openOrRecreateEditor()
{
CRect rect(0, 0, 43, 14);
rect.offset(p->posx, p->posy);
CNumberField* key = new CNumberField(rect, this, p->id + start_paramtags);
CNumberField* key = new CNumberField(rect, this, p->id + start_paramtags, nullptr, &(synth->storage));
key->setSkin(currentSkin,bitmapStore);
key->setControlMode(cm_polyphony);
// key->setLabel("POLY");
Expand Down Expand Up @@ -4378,7 +4378,7 @@ VSTGUI::COptionMenu* SurgeGUIEditor::makeUIOptionsMenu(VSTGUI::CRect& menuRect)
VSTGUI::COptionMenu::kNoDrawStyle |
VSTGUI::COptionMenu::kMultipleCheckStyle);

// Mouse behavior
// Mouse behavior submenu
int mid = 0;
COptionMenu* mouseSubMenu = new COptionMenu(menuRect, 0, 0, 0, 0,
VSTGUI::COptionMenu::kNoDrawStyle |
Expand All @@ -4396,50 +4396,81 @@ VSTGUI::COptionMenu* SurgeGUIEditor::makeUIOptionsMenu(VSTGUI::CRect& menuRect)
Surge::Storage::updateUserDefaultValue(&(this->synth->storage), "sliderMoveRateState",
CSurgeSlider::sliderMoveRateState);
});
if (menuItem)
menuItem->setChecked((CSurgeSlider::sliderMoveRateState == CSurgeSlider::kClassic));
menuItem->setChecked((CSurgeSlider::sliderMoveRateState == CSurgeSlider::kClassic));
mid++;

menuItem = addCallbackMenu(mouseSubMenu, mouseSlow.c_str(), [this]() {
CSurgeSlider::sliderMoveRateState = CSurgeSlider::kSlow;
Surge::Storage::updateUserDefaultValue(&(this->synth->storage), "sliderMoveRateState",
CSurgeSlider::sliderMoveRateState);
});
if (menuItem)
menuItem->setChecked((CSurgeSlider::sliderMoveRateState == CSurgeSlider::kSlow));
menuItem->setChecked((CSurgeSlider::sliderMoveRateState == CSurgeSlider::kSlow));
mid++;

menuItem = addCallbackMenu(mouseSubMenu, mouseMedium.c_str(), [this]() {
CSurgeSlider::sliderMoveRateState = CSurgeSlider::kMedium;
Surge::Storage::updateUserDefaultValue(&(this->synth->storage), "sliderMoveRateState",
CSurgeSlider::sliderMoveRateState);
});
if (menuItem)
menuItem->setChecked((CSurgeSlider::sliderMoveRateState == CSurgeSlider::kMedium));
menuItem->setChecked((CSurgeSlider::sliderMoveRateState == CSurgeSlider::kMedium));
mid++;

menuItem = addCallbackMenu(mouseSubMenu, mouseExact.c_str(), [this]() {
CSurgeSlider::sliderMoveRateState = CSurgeSlider::kExact;
Surge::Storage::updateUserDefaultValue(&(this->synth->storage), "sliderMoveRateState",
CSurgeSlider::sliderMoveRateState);
});
if (menuItem)
menuItem->setChecked((CSurgeSlider::sliderMoveRateState == CSurgeSlider::kExact));
menuItem->setChecked((CSurgeSlider::sliderMoveRateState == CSurgeSlider::kExact));
mid++;

std::string mouseMenuName = Surge::UI::toOSCaseForMenu("Mouse Behavior");

uiOptionsMenu->addEntry(mouseSubMenu, mouseMenuName.c_str());
mouseSubMenu->forget();

// Middle C submenu
int mcid = 0;
COptionMenu* middleCSubMenu = new COptionMenu(menuRect, 0, 0, 0, 0,
VSTGUI::COptionMenu::kNoDrawStyle |
VSTGUI::COptionMenu::kMultipleCheckStyle);

VSTGUI::CCommandMenuItem* mcItem = nullptr;

auto mcValue = Surge::Storage::getUserDefaultValue(&(this->synth->storage), "middleC", 1);

mcItem = addCallbackMenu(middleCSubMenu, "C3", [this]() {
Surge::Storage::updateUserDefaultValue(&(this->synth->storage), "middleC", 2);
synth->refresh_editor = true;
});
mcItem->setChecked(mcValue == 2);
mcid++;

mcItem = addCallbackMenu(middleCSubMenu, "C4", [this]() {
Surge::Storage::updateUserDefaultValue(&(this->synth->storage), "middleC", 1);
synth->refresh_editor = true;
});
mcItem->setChecked(mcValue == 1);
mcid++;

mcItem = addCallbackMenu(middleCSubMenu, "C5", [this]() {
Surge::Storage::updateUserDefaultValue(&(this->synth->storage), "middleC", 0);
synth->refresh_editor = true;
});
mcItem->setChecked(mcValue == 0);
mcid++;

uiOptionsMenu->addEntry(middleCSubMenu, "Middle C");
middleCSubMenu->forget();


auto precReadout = Surge::Storage::getUserDefaultValue(&(this->synth->storage), "highPrecisionReadouts", 0);
menuItem = addCallbackMenu(uiOptionsMenu, Surge::UI::toOSCaseForMenu("High Precision Value Readouts"),
[this, precReadout]() {Surge::Storage::updateUserDefaultValue(&(this->synth->storage), "highPrecisionReadouts",
precReadout ? 0 : 1);
});

menuItem->setChecked(precReadout);


return uiOptionsMenu;
}

Expand Down Expand Up @@ -5015,8 +5046,9 @@ R"HTML(

for( int i=0; i<128; ++i )
{
int octave = (i / 12) - 1;
char notenames[12][3] = {"C ", "C#", "D ", "D#", "E ", "F ", "F#", "G ", "G#", "A ", "A#", "B "};
int oct_offset = 1;
oct_offset = Surge::Storage::getUserDefaultValue(&(this->synth->storage), "middleC", 1);
char notename[8];

std::string rowstyle="";
std::string tdopen="<td colspan=2>";
Expand All @@ -5026,7 +5058,7 @@ R"HTML(
rowstyle = "style=\"background-color: #dddddd;\"";
tdopen="<td style=\"background-color: #ffffff;\">&nbsp;</td><td>";
}
htmls << "<tr " << rowstyle << ">" << tdopen << i << " (" << notenames[i % 12 ] << octave << ")</td>\n";
htmls << "<tr " << rowstyle << ">" << tdopen << i << " (" << get_notename(notename, i, oct_offset) << ")</td>\n";

auto tn = i - synth->storage.scaleConstantNote();
if( ! synth->storage.isStandardMapping )
Expand Down
6 changes: 3 additions & 3 deletions src/common/unitconversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ inline float seconds_to_envtime(float in) // ff rev2
return v;
}

inline char* get_notename(char* s, int i_value)
inline char* get_notename(char* s, int i_value, int i_offset)
{
int octave = (i_value / 12) - 2;
char notenames[12][3] = {"C ", "C#", "D ", "D#", "E ", "F ", "F#", "G ", "G#", "A ", "A#", "B "};
int octave = (i_value / 12) - i_offset;
char notenames[12][3] = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"};
sprintf(s, "%s%i", notenames[i_value % 12], octave);
return s;
}
Expand Down

0 comments on commit 2b179f5

Please sign in to comment.