From 8a43de5b5b62e9985880a8b7ffb4feb3d1a7c0ff Mon Sep 17 00:00:00 2001 From: Louis-Joseph Fournier Date: Sun, 3 Jan 2016 20:05:28 +0100 Subject: [PATCH] Temperaments: class interface and code begin --- Tuner.pro | 6 ++- data/Temperaments.csv | 87 ++++++++++++++++++++++++++++++++++++++ harbour-sailtuner.pro | 6 ++- src/scale/Scale.cpp | 8 ++++ src/scale/Scale.hpp | 4 +- src/scale/Temperaments.cpp | 76 +++++++++++++++++++++++++++++++++ src/scale/Temperaments.hpp | 64 ++++++++++++++++++++++++++++ 7 files changed, 246 insertions(+), 5 deletions(-) create mode 100644 data/Temperaments.csv create mode 100644 src/scale/Temperaments.cpp create mode 100644 src/scale/Temperaments.hpp diff --git a/Tuner.pro b/Tuner.pro index 2a325ed..3f30835 100644 --- a/Tuner.pro +++ b/Tuner.pro @@ -10,13 +10,15 @@ SOURCES += \ src/Tuner.cpp \ src/audio/LinearFilter.cpp \ src/audio/ZeroCross.cpp \ - src/scale/Scale.cpp + src/scale/Scale.cpp \ + src/scale/Temperaments.cpp HEADERS += \ src/Tuner.hpp \ src/audio/LinearFilter.hpp \ src/audio/ZeroCross.hpp \ - src/scale/Scale.hpp + src/scale/Scale.hpp \ + src/scale/Temperaments.hpp RESOURCES += \ qml/desktop.qrc diff --git a/data/Temperaments.csv b/data/Temperaments.csv new file mode 100644 index 0000000..5a4b6c0 --- /dev/null +++ b/data/Temperaments.csv @@ -0,0 +1,87 @@ +Werckmeister III;263.40;277.50;294.33;312.18;330.00;351.21;369.99;393.77;416.24;440.00;468.27;495.00 +Kirnberger I;264.00;278.12;297.00;312.89;330.00;352.00;371.25;396.00;417.19;440.00;469.33;495.00 +Kirnberger II;262.36;276.40;295.16;310.95;327.95;349.81;368.94;393.54;414.59;440.00;466.42;491.93 +Kirnberger III;263.18;277.26;294.25;311.92;328.98;350.91;370.10;393.55;415.89;440.00;467.88;493.47 +Kirnberger III unequal;263.10;277.18;294.50;311.82;328.88;350.80;369.98;393.80;415.76;440.00;467.73;493.31 +Kelletat;262.82;276.97;294.33;311.49;328.65;350.43;369.29;393.81;415.32;440.00;467.24;492.39 +Kellner;262.87;276.93;294.13;311.55;329.11;350.49;369.24;393.24;415.40;440.00;467.32;493.66 +Billeter;262.40;276.71;294.50;311.29;328.70;350.20;368.95;393.10;415.07;440.00;466.93;492.50 +Equal temperature;261.63;277.18;293.66;311.13;329.63;349.23;369.99;392.00;415.30;440.00;466.16;493.88 +Lehman 1/6 Pyth.;262.53;277.82;294.00;311.85;329.25;350.85;370.42;392.90;416.27;440.00;467.24;493.88 +Lehman 1/6 Synt.;262.35;277.89;293.94;311.92;329.32;350.52;370.51;392.72;416.36;440.00;467.35;494.00 +Fritz (1756 - Equal Beat);261.76;277.33;293.73;311.25;329.70;349.41;370.17;392.04;415.39;440.00;466.27;493.96 +Pythagoras H.A. van ZWOLLE;260.74;274.69;293.33;309.03;330.00;347.65;366.25;391.11;412.03;440.00;463.54;495.00 +Meantone;263.18;275.00;294.25;314.84;328.98;352.00;367.81;393.55;411.22;440.00;470.79;491.93 +GRMMATEUS / Von WIESE-i-A;260.74;276.56;293.33;311.13;330.00;347.65;368.74;391.11;414.84;440.00;466.69;495.03 +Von WIESE-II-d;262.51;276.56;293.33;311.13;330.00;350.02;368.74;391.11;414.84;440.00;466.69;491.61 +Von WIESE-II-b;262.51;276.56;295.33;311.13;327.77;350.02;368.74;393.77;414.84;440.00;466.69;491.61 +BENDELER-I;263.11;277.18;293.33;311.83;330.00;350.81;369.58;392.88;415.77;440.00;467.75;495.03 +YOUNG / Van BIEZEN;262.51;276.56;294.00;311.13;329.26;350.02;368.74;392.88;414.84;440.00;466.69;492.74 +ASSELIN;262.07;277.03;293.83;311.65;329.44;350.02;369.37;392.44;415.54;440.00;467.48;493.31 +RAMIS de PAREJA;264.00;278.44;293.33;312.89;330.00;352.00;371.25;396.00;417.19;440.00;469.33;495.03 +AGRICOLA;260.74;275.00;293.33;309.38;330.00;347.65;366.67;391.11;412.50;440.00;463.54;495.03 +BARCA;262.37;276.71;293.94;311.30;329.32;349.82;368.95;392.73;415.07;440.00;466.43;492.91 +NEIDHARDT-1 d-1724 ks-1732;262.51;277.18;294.00;311.48;329.26;350.02;369.58;392.88;415.77;440.00;466.69;493.31 +NEIDHARDT 2 ks-1724 GS-1732;262.51;277.50;294.00;311.83;329.63;350.41;370.41;392.88;415.77;440.00;467.75;494.45 +NEIDHARDT-3 GS-1724;262.51;277.50;294.00;311.83;329.63;350.02;370.41;392.88;415.77;440.00;467.22;494.45 +NEIDHARDT-4 d-1732;262.51;277.18;294.33;311.48;328.88;350.02;369.58;393.33;415.30;440.00;467.22;493.31 +SALINAS;264.00;273.86;294.55;316.80;328.64;353.46;366.67;394.36;409.10;440.00;473.24;490.90 +ROSSI / SAUVEUR Middentoon;262.69;275.68;294.06;313.67;329.18;351.13;368.49;393.06;412.50;440.00;469.33;492.55 +ROMIEU;262.37;276.14;293.94;312.89;329.32;350.54;368.95;392.74;413.37;440.00;468.38;492.97 +GABLER (Weingarten ±1750);262.69;275.90;294.00;313.29;329.25;350.85;368.93;393.13;413.39;440.00;468.86;492.46 +SILBERMANN;262.52;275.94;294.00;313.25;329.27;350.83;368.76;392.88;412.98;440.00;468.81;492.77 +DUPONT / SCHLICK;263.19;275.00;294.26;314.85;330.89;352.00;367.82;393.56;416.15;440.00;470.79;491.95 +LAMBERT / CHAUMONT;263.18;275.00;294.25;311.34;328.98;352.00;367.81;393.55;411.22;440.00;468.17;491.93 +CORRETTE;263.19;275.00;294.26;312.89;328.98;352.00;367.82;393.56;412.51;440.00;469.35;491.95 +ANON. De CAEN;263.19;275.00;294.26;311.92;328.98;352.00;367.82;393.56;413.80;440.00;469.35;491.95 +VINCENT;263.19;275.00;294.26;309.60;328.98;350.04;367.82;393.56;411.22;440.00;465.57;491.95 +RAMEAU;263.18;276.71;294.25;312.58;328.98;352.00;368.95;393.55;415.07;440.00;470.79;491.93 +RAMEAU-MERCADIER;263.18;275.00;294.25;310.57;328.98;350.91;367.81;393.55;411.99;440.00;467.30;491.93 +MARPURG;263.18;276.31;294.25;311.87;328.98;352.00;367.81;393.55;415.14;440.00;468.57;491.93 +LEGROS (3 R.T.);263.18;275.86;294.25;311.13;328.98;350.91;367.81;393.55;413.78;440.00;467.88;491.93 +LEGROS (2 R.T.);263.18;276.71;294.25;311.30;328.98;350.91;368.95;393.55;415.07;440.00;467.88;491.93 +d'ALEMBERT / ROUSSEAU;263.19;276.64;294.26;311.13;328.98;350.62;369.27;393.56;414.49;440.00;467.11;492.91 +de BETHISY;263.19;276.64;294.26;310.88;328.98;350.52;369.27;393.56;414.49;440.00;466.84;492.91 +VOGEL;262.87;276.18;294.12;311.54;329.11;351.43;368.25;393.24;414.27;440.00;468.59;492.32 +WERCKMEISTER IV;263.11;275.93;294.66;311.83;330.00;350.81;369.58;392.88;413.90;440.00;469.86;492.77 +WERCKMEISTER V;261.63;276.56;294.33;311.13;328.88;350.02;369.99;392.44;413.43;440.00;466.69;493.33 +MARPURG (3);260.74;271.60;293.33;312.89;325.93;347.65;366.67;391.11;407.41;440.00;463.54;488.89 +KEPLER / MARPURG (2);260.74;275.00;293.33;312.89;325.93;347.65;366.67;391.11;412.50;440.00;469.33;488.89 +WERCKMEISTER-VI;262.76;276.81;292.77;312.03;329.99;350.34;370.53;393.38;415.23;440.00;468.03;495.00 +OTHEL / NIEDERBOBRITZSCH;261.63;276.86;294.09;310.77;329.44;349.93;370.10;391.77;414.83;440.00;466.57;492.17 +GEIB / NEU-BAMBERG;262.53;276.70;294.34;313.11;328.68;350.85;368.08;393.81;412.91;440.00;469.14;492.17 +VON WIESE-II-a;260.74;274.69;293.33;309.03;330.00;347.65;368.74;391.11;412.03;440.00;463.54;495.00 +VON WIESE-II-c;260.74;276.56;293.33;311.13;330.00;347.65;368.74;391.11;414.84;440.00;463.54;495.00 +BENDELER-II;263.40;277.50;294.33;312.18;330.00;351.21;371.25;393.77;416.24;440.00;468.27;495.00 +BENDELER-III;262.51;277.50;293.33;311.13;330.00;350.02;369.99;392.44;416.24;440.00;466.69;493.33 +SIEVERS;263.11;277.18;294.66;311.83;329.26;350.81;369.58;393.77;415.77;440.00;467.75;492.77 +VALLOTTI - TARTINI;262.51;277.18;294.00;311.83;329.26;350.81;369.58;392.88;415.77;440.00;467.75;492.77 +BARNES;262.51;277.18;294.00;311.83;329.26;350.81;369.58;392.88;415.77;440.00;467.75;493.88 +LAMBERT;262.26;276.83;293.90;311.43;329.36;350.36;369.10;392.63;415.24;440.00;467.14;493.09 +SCHIASSI;264.00;278.44;297.00;313.24;330.00;352.00;371.25;396.00;417.66;440.00;469.33;495.00 +MICHELIN;261.04;275.00;293.66;309.38;330.00;348.05;371.25;391.55;412.50;440.00;464.06;495.00 +STANHOPE;262.91;277.13;294.55;311.77;328.64;350.55;369.51;394.36;415.70;440.00;467.39;492.95 +BARCA - interpr. DEVIE;262.37;277.29;293.94;311.95;329.32;350.55;369.72;392.73;415.93;440.00;467.39;492.95 +SORGE 1744;262.51;277.18;294.00;311.83;330.00;350.02;369.99;392.88;415.77;440.00;467.22;493.88 +SORGE 1758;262.51;277.50;294.00;311.83;329.63;350.02;370.41;392.88;416.24;440.00;467.22;494.44 +YOUNG;262.51;277.18;294.00;311.83;329.26;350.41;369.58;392.88;415.77;440.00;467.75;493.33 +MERCADIER;262.51;277.10;294.00;311.48;329.26;350.41;369.79;392.88;415.30;440.00;467.22;493.47 +MIDDENTOON -2/7 C;263.53;274.51;294.38;315.68;328.83;352.63;367.32;393.90;410.31;440.00;471.84;491.50 +MIDDENTOON -1/7 C;262.13;276.47;293.85;312.33;329.41;350.13;369.28;392.50;413.97;440.00;467.67;493.25 +MIDDENTOON -1/8 C;261.96;276.71;293.79;311.92;329.49;349.82;369.52;392.33;414.43;440.00;467.15;493.47 +MIDDENTOON -1/9 C;261.82;276.90;293.74;311.60;329.54;349.58;369.72;392.19;414.78;440.00;466.75;493.64 +WEINGARTEN;262.38;277.18;293.50;312.21;329.44;350.04;369.14;392.68;416.02;440.00;467.78;492.74 +RAMEAU in C;263.18;275.00;294.25;309.38;328.98;349.47;367.81;393.55;412.50;440.00;464.06;491.93 +RAMEAU in F;263.18;275.86;294.25;310.34;328.98;352.00;367.81;393.55;413.78;440.00;467.42;491.93 +RAMEAU volg. KLOP;263.18;276.71;294.25;310.34;328.98;352.00;368.95;393.55;415.07;440.00;467.42;491.93 +RAMEAU volg. TLA;263.37;276.54;294.34;311.13;328.87;352.37;368.71;393.81;414.83;440.00;468.32;491.61 +VOGEL (STADE);262.87;277.68;294.13;311.55;329.11;351.44;369.24;393.24;415.40;440.00;467.32;492.32 +LOUET;262.69;276.37;294.06;311.71;329.18;351.13;368.95;393.06;414.04;440.00;469.33;492.55 +SALOMON de CAUS;264.00;275.00;293.33;309.38;330.00;352.00;371.25;396.00;412.50;440.00;464.06;495.00 +MARPURG (1) ZARLINO;264.00;275.00;297.00;316.80;330.00;352.00;371.25;396.00;412.50;440.00;475.20;495.00 +MARPURG (4) LOULIE;264.00;275.00;293.33;316.80;330.00;352.00;366.67;396.00;412.50;440.00;475.20;495.00 +FOGLIANO;264.00;275.00;293.33;316.80;330.00;352.00;366.67;396.00;412.50;440.00;469.33;495.00 +Malcolm (vlg. Kelletat);264.00;280.50;297.00;313.50;330.00;352.00;374.00;396.00;418.00;440.00;467.50;495.00 +Anoniem (vlg. Kelletat);260.74;271.60;293.33;305.56;325.93;347.65;366.67;391.11;407.41;440.00;463.54;488.89 +Euler (vlg. Kelletat);264.00;275.00;297.00;309.38;330.00;352.00;371.25;396.00;412.50;440.00;464.06;495.00 +Mattheson (vlg. Kelletat);264.00;275.00;297.00;309.38;330.00;352.00;371.25;396.00;412.50;440.00;475.20;495.00 diff --git a/harbour-sailtuner.pro b/harbour-sailtuner.pro index 2fe49ec..88de359 100644 --- a/harbour-sailtuner.pro +++ b/harbour-sailtuner.pro @@ -14,10 +14,12 @@ SOURCES += \ src/Tuner.cpp \ src/audio/LinearFilter.cpp \ src/audio/ZeroCross.cpp \ - src/scale/Scale.cpp + src/scale/Scale.cpp \ + src/scale/Temperaments.cpp HEADERS += \ src/Tuner.hpp \ src/audio/LinearFilter.hpp \ src/audio/ZeroCross.hpp \ - src/scale/Scale.hpp + src/scale/Scale.hpp \ + src/scale/Temperaments.hpp diff --git a/src/scale/Scale.cpp b/src/scale/Scale.cpp index 4836f38..6c22d27 100644 --- a/src/scale/Scale.cpp +++ b/src/scale/Scale.cpp @@ -18,6 +18,8 @@ #include #include #include +#include + #include "Scale.hpp" const char * Scale::noteNames[] = { @@ -114,6 +116,12 @@ double Scale::GetLa() return actualLa; } +void Scale::SetNotesFrequencies(double freq[nbNote]) +{ + memcpy(noteFreq, freq, sizeof(double) * nbNote); + updateScale(); +} + void Scale::SetLa(double la) { assert(la > 0); diff --git a/src/scale/Scale.hpp b/src/scale/Scale.hpp index 02ff162..5847539 100644 --- a/src/scale/Scale.hpp +++ b/src/scale/Scale.hpp @@ -51,6 +51,9 @@ class Scale { void ConstructEqualTemperament(); + /// Set notes frequencies from a temperament + void SetNotesFrequencies(double freq[nbNote]); + double GetLa(); void SetLa(double la); @@ -59,7 +62,6 @@ class Scale { */ int FindNote(double freq, int &octave, double &deviation); - static const char * NoteName(int note); }; diff --git a/src/scale/Temperaments.cpp b/src/scale/Temperaments.cpp new file mode 100644 index 0000000..38cc84a --- /dev/null +++ b/src/scale/Temperaments.cpp @@ -0,0 +1,76 @@ +/* Copyright 2016 (C) Louis-Joseph Fournier + * louisjoseph.fournier@gmail.com + * + * This file is part of SailTuner. + * + * SailTuner is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * SailTuner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#include +#include +#include +#include + +#include "Temperaments.hpp" + +using namespace std; + +Temperaments::Temperaments(const char * dirname) : current(0) +{ + GetDir(dirname); +} + +void Temperaments::GetDir(const char * dirname) +{ + DIR *pdir = opendir(dirname); + struct dirent *pent = NULL; + struct stat filestat; + string filepath; + + if (!pdir) { + cerr << __func__ << ": impossible to open dir " << dirname << endl; + return; + } + while((pent = readdir(pdir))) { + // get only files + if (pent->d_name[0] == '.') continue; + filepath = dirname; + filepath += "/"; + filepath += pent->d_name; + if (stat(filepath.c_str(), &filestat )) continue; + if (S_ISDIR( filestat.st_mode )) continue; + + CheckFile(filepath); + } +} + +void Temperaments::CheckFile(string filename) +{ + cout << __func__ << " " << filename << endl; +} + +string Temperaments::GetCurrentName() const +{ + if (current >= list.size()) return ""; + return list[current].name; +} + +string Temperaments::GetName(unsigned int n) const +{ + if (n < list.size()) return ""; + return list[n].name; +} + +const double * Temperaments::NotesFrequencies() const +{ + return notes; +} diff --git a/src/scale/Temperaments.hpp b/src/scale/Temperaments.hpp new file mode 100644 index 0000000..e0a9827 --- /dev/null +++ b/src/scale/Temperaments.hpp @@ -0,0 +1,64 @@ +/* Copyright 2016 (C) Louis-Joseph Fournier + * louisjoseph.fournier@gmail.com + * + * This file is part of SailTuner. + * + * SailTuner is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * SailTuner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#ifndef __TEMPERAMENTS_HPP +#define __TEMPERAMENTS_HPP + +#include +#include + +/** + * Temperament management + * + * Check temperaments in files in a dir + * Get list and temperements + */ +class Temperaments { + private: + /// describe internal a temperament + struct temp_t { + std::string name; ///< temperament name + std::string file; ///< file name + int seek; ///< position in file + }; + + static const int nb_notes = 12; + + unsigned int current; + std::vector list; + double notes[nb_notes]; + + void GetDir(const char *dirname); + void CheckFile(std::string filename); + void GetTemperament(const temp_t temperament); + + public: + /// constructor with dir name to find data files + Temperaments(const char * dirname); + ~Temperaments(); + + /// set current temperament + bool SetTemperament(std::string name); + /// get the name of current temperament + std::string GetCurrentName() const; + /// get the name of temperament number n + std::string GetName(unsigned int n) const; + /// get notes frequencies as double[nb_notes] + const double * NotesFrequencies() const; +}; + +#endif