Skip to content

Commit

Permalink
Display the Tuning Frequency Table (#1454)
Browse files Browse the repository at this point in the history
Display the full tuning frequency table in the HTML

Part of #1041
  • Loading branch information
baconpaul authored Jan 6, 2020
1 parent 7b9b120 commit 72dec2f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
30 changes: 29 additions & 1 deletion src/common/Tunings.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

#include "Tunings.h"
#include "SurgeStorage.h"

#include <iostream>
#include <fstream>
Expand Down Expand Up @@ -146,7 +147,7 @@ bool Surge::Storage::Scale::isValid() const
return true;
}

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

Expand Down Expand Up @@ -216,6 +217,33 @@ R"HTML(
htmls << "</td><td>" << t.cents << "</td><td>" << t.floatValue << "</td></tr>\n";
};

htmls << R"HTML(
</table>
<p>
<table>
<tr>
<th>Midi Note</th><th>Scale Position</th><th>Frequency</th>
</tr>
)HTML";

for( int i=0; i<127; ++i )
{
int octave = (i / 12) - 1;
char notenames[12][3] = {"C ", "C#", "D ", "D#", "E ", "F ", "F#", "G ", "G#", "A ", "A#", "B "};

htmls << "<tr><td>" << i << " (" << notenames[i % 12 ] << octave << ")</td>\n";

auto tn = i - storage->scaleConstantNote();
while( tn < 0 ) tn += count;

auto p = storage->note_to_pitch(i);
htmls << "<td>" << (tn % count + 1) << "</td><td>" << 8.175798915 * p << " hz</td>";
htmls << "</tr>\n";
}

htmls << R"HTML(
</table>
</div>
Expand Down
4 changes: 3 additions & 1 deletion src/common/Tunings.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <vector>
#include <iostream>

class SurgeStorage;

namespace Surge
{
namespace Storage
Expand Down Expand Up @@ -40,7 +42,7 @@ struct Scale

bool isValid() const;

std::string toHtml();
std::string toHtml(SurgeStorage *storage);
};

std::ostream& operator<<(std::ostream& os, const Tone& sc);
Expand Down
4 changes: 2 additions & 2 deletions src/common/gui/SurgeGUIEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3494,8 +3494,8 @@ VSTGUI::COptionMenu *SurgeGUIEditor::makeTuningMenu(VSTGUI::CRect &menuRect)
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() );
// Surge::UserInteractions::promptOKCancel( "Surge tuning is NONstandard tuning", "Tuning Info" );
Surge::UserInteractions::showHTML( this->synth->storage.currentScale.toHtml(&(this->synth->storage)) );
}
);
sct->setEnabled(! this->synth->storage.isStandardTuning );
Expand Down

0 comments on commit 72dec2f

Please sign in to comment.