Skip to content

Commit

Permalink
A variety of tuning fixups (#1022)
Browse files Browse the repository at this point in the history
1. The system knows if it is in tuning mode
2. You can see the tuning details (opens in a browser)
3. Menus work based on tuning state
4. Remove the experimental tag

Addresses #828
  • Loading branch information
baconpaul authored Aug 13, 2019
1 parent df90134 commit 1cf1f39
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/common/SurgeStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,7 @@ double shafted_tanh(double x)

void SurgeStorage::init_tables()
{
isStandardTuning = true;
float db60 = powf(10.f, 0.05f * -60.f);
for (int i = 0; i < 512; i++)
{
Expand Down Expand Up @@ -1233,6 +1234,9 @@ float envelope_rate_linear(float x)

void SurgeStorage::retuneToScale(const Surge::Storage::Scale& s)
{
currentScale = s;
isStandardTuning = false;

float pitches[512];
int pos0 = 256 + scaleConstantNote();
float pitchMod = log(scaleConstantPitch())/log(2) - 1;
Expand Down
3 changes: 3 additions & 0 deletions src/common/SurgeStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,9 @@ class alignas(16) SurgeStorage
void retuneToScale(const Surge::Storage::Scale& s);
inline int scaleConstantNote() { return 48; }
inline float scaleConstantPitch() { return 16.0; }

Surge::Storage::Scale currentScale;
bool isStandardTuning;

private:
TiXmlDocument snapshotloader;
Expand Down
94 changes: 94 additions & 0 deletions src/common/Tunings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <fstream>
#include <cstdlib>
#include <math.h>
#include <sstream>

/*
From: http://huygens-fokker.org/scala/scl_format.html
Expand Down Expand Up @@ -45,8 +46,10 @@ Surge::Storage::Scale Surge::Storage::readSCLFile(std::string fname)

Scale res;
res.name = fname;
std::ostringstream rawOSS;
while (std::getline(inf, line))
{
rawOSS << line << "\n";
if (line[0] == '!')
{
continue;
Expand Down Expand Up @@ -96,6 +99,7 @@ Surge::Storage::Scale Surge::Storage::readSCLFile(std::string fname)
}
}

res.rawText = rawOSS.str();
return res;
}

Expand All @@ -118,3 +122,93 @@ std::ostream& Surge::Storage::operator<<(std::ostream& os, const Surge::Storage:
os << " - " << t << "\n";
return os;
}

std::string Surge::Storage::Scale::toHtml()
{
std::ostringstream htmls;

htmls <<
R"HTML(
<html>
<head>
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Lato" />
<style>
table {
border-collapse: collapse;
}
td {
border: 1px solid #CDCED4;
padding: 2pt;
}
th {
padding: 4pt;
color: #123463;
background: #CDCED4;
border: 1px solid #123463;
}
</style>
</head>
<body style="margin: 0pt; background: #CDCED4;">
<div style="border-bottom: 1px solid #123463; background: #ff9000; padding: 2pt;">
<div style="font-size: 20pt; font-family: Lato; padding: 2pt; color:#123463;">
Surge Tuning
</div>
<div style="font-size: 12pt; font-family: Lato; padding: 2pt;">
)HTML"
<< description <<
R"HTML(
</div>
</div>
<div style="margin:10pt; padding: 5pt; border: 1px solid #123463; background: #fafbff;">
<div style="font-size: 12pt; margin-bottom: 10pt; font-family: Lato; color: #123463;">
Tuning Information
</div>
<div style="font-size: 12pt; font-family: Lato;">
<div style="padding-bottom: 10pt;">
)HTML" << count << " tones" <<
R"HTML(
</div>
<table>
<tr>
<th>#</th><th>Datum</th><th>Cents</th><th>Float</th>
</tr>
<tr>
<td>1</td><td>1</td><td>0</td><td>1</td>
</tr>
)HTML";

int ct = 2;
for( auto & t : tones )
{
htmls << "<tr><td> " << ct++ << "</td><td>";
if (t.type == Tone::kToneCents)
htmls << t.cents;
else
htmls << t.ratio_n << " / " << t.ratio_d;

htmls << "</td><td>" << t.cents << "</td><td>" << t.floatValue << "</td></tr>\n";
};

htmls << R"HTML(
</table>
</div>
</div>
<div style="margin:10pt; padding: 5pt; border: 1px solid #123463; background: #fafbff;">
<div style="font-size: 12pt; font-family: Lato; color: #123463;">
Raw File:
)HTML" << name << "</div>\n<pre>\n" << rawText << R"HTML(
</pre>
</div>
</body>
</html>
)HTML";

return htmls.str();

}
5 changes: 4 additions & 1 deletion src/common/Tunings.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ struct Scale
{
std::string name;
std::string description;
std::string rawText;
int count;
std::vector<Tone> tones;

Scale() : name("empty scale"), description(""), count(0)
Scale() : name("empty scale"), description(""), rawText(""), count(0)
{
}

std::string toHtml();
};

std::ostream& operator<<(std::ostream& os, const Tone& sc);
Expand Down
1 change: 1 addition & 0 deletions src/common/UserInteractions.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ MessageResult promptOKCancel(const std::string &message, const std::string &titl

// Open a URL in a user-appropriate fashion
void openURL(const std::string &url);
void showHTML(const std::string &html);

// Open a folder in the system appropriate file browser (finder on macOS, explorer on win,
// etc)
Expand Down
17 changes: 15 additions & 2 deletions src/common/gui/SurgeGUIEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2806,12 +2806,13 @@ void SurgeGUIEditor::showSettingsMenu(CRect &menuRect)
VSTGUI::COptionMenu::kNoDrawStyle |
VSTGUI::COptionMenu::kMultipleCheckStyle);

addCallbackMenu(tuningSubMenu, "Set to Standard Tuning",
auto *st = addCallbackMenu(tuningSubMenu, "Set to Standard Tuning",
[this]()
{
this->synth->storage.init_tables();
}
);
st->setEnabled(! this->synth->storage.isStandardTuning);
tid++;

addCallbackMenu(tuningSubMenu, "Apply .scl file tuning",
Expand All @@ -2838,6 +2839,17 @@ void SurgeGUIEditor::showSettingsMenu(CRect &menuRect)
}
);
tid++;

auto *sct = addCallbackMenu(tuningSubMenu, "Show current tuning",
[this]()
{
// Surge::UserInteractions::promptOKCancel( "Surge tuning is NONstandard tuning", "Tuning Info" );
Surge::UserInteractions::showHTML( this->synth->storage.currentScale.toHtml() );
}
);
sct->setEnabled(! this->synth->storage.isStandardTuning );

/*
tuningSubMenu->addSeparator(tid++);
addCallbackMenu(tuningSubMenu, "Apply .kbm file mapping",
Expand All @@ -2848,8 +2860,9 @@ void SurgeGUIEditor::showSettingsMenu(CRect &menuRect)
this);
}
);
*/

settingsMenu->addEntry(tuningSubMenu, "Tunings (experimental)");
settingsMenu->addEntry(tuningSubMenu, "Tuning" );
eid++;
tuningSubMenu->forget();

Expand Down
4 changes: 4 additions & 0 deletions src/headless/UserInteractionsHeadless.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ MessageResult promptOKCancel(const std::string &message, const std::string &titl
void openURL(const std::string &url)
{
}
void showHTML( const std::string &html)
{
std::cerr << "SURGE HTML: " << html << std::endl;
}

void promptFileOpenDialog(const std::string& initialDirectory,
const std::string& filterSuffix,
Expand Down
16 changes: 16 additions & 0 deletions src/linux/UserInteractionsLinux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,22 @@ void openURL(const std::string &url)
}
}

void showHTML( const std::string &html )
{
// FIXME - there's proper APIs for this that crash on MacOS
std::ostringstream fns;
fns << "/tmp/surge-tuning." << rand() << ".html";

FILE *f = fopen(fns.str().c_str(), "w" );
if( f )
{
fprintf( f, "%s", html.c_str());
fclose(f);
std::string url = std::string("file://") + fns.str();
openURL(url);
}
}

void openFolderInFileBrowser(const std::string& folder)
{
std::string url = "file://" + folder;
Expand Down
20 changes: 20 additions & 0 deletions src/mac/UserInteractionsMac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#include <ApplicationServices/ApplicationServices.h>
#include <AppKit/AppKit.h>

#include <iostream>
#include <sstream>
#include <unistd.h>

namespace Surge
{

Expand Down Expand Up @@ -70,6 +74,22 @@ void openURL(const std::string& url_str)
CFRelease(url);
}

void showHTML( const std::string &html )
{
// Why does mktemp crash on macos I wonder?
std::ostringstream fns;
fns << "/var/tmp/surge-tuning." << rand() << ".html";

FILE *f = fopen(fns.str().c_str(), "w" );
if( f )
{
fprintf( f, "%s", html.c_str());
fclose(f);
std::string url = std::string("file://") + fns.str();
openURL(url);
}
}

void openFolderInFileBrowser(const std::string& folder)
{
std::string url = "file://" + folder;
Expand Down
18 changes: 18 additions & 0 deletions src/windows/UserInteractionsWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,24 @@ void openURL(const std::string &url)
ShellExecute(NULL, "open", url.c_str(), NULL, NULL, SW_SHOWNORMAL);
}

void showHTML( const std::string &html )
{
TCHAR lpTempPathBuffer[MAX_PATH];

auto dwRetVal = GetTempPath(MAX_PATH, lpTempPathBuffer);
std::ostringstream fns;
fns << lpTempPathBuffer << "surge-tuning." << rand() << ".html";

FILE *f = fopen(fns.str().c_str(), "w" );
if( f )
{
fprintf( f, "%s", html.c_str());
fclose(f);
std::string url = std::string("file:///") + fns.str();
openURL(url);
}
}

void openFolderInFileBrowser(const std::string& folder)
{
std::string url = "file://" + folder;
Expand Down

0 comments on commit 1cf1f39

Please sign in to comment.