You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.5KB

  1. /* Copyright 2013-2019 Matt Tytel
  2. *
  3. * vital is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 3 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * vital is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with vital. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #pragma once
  17. #include "JuceHeader.h"
  18. #include "common.h"
  19. #include "json/json.h"
  20. using json = nlohmann::json;
  21. class Tuning {
  22. public:
  23. static constexpr int kTuningSize = 2 * vital::kMidiSize;
  24. static constexpr int kTuningCenter = vital::kMidiSize;
  25. static Tuning getTuningForFile(File file);
  26. static String allFileExtensions();
  27. static int noteToMidiKey(const String& note);
  28. Tuning();
  29. Tuning(File file);
  30. void loadScale(std::vector<float> scale);
  31. void loadFile(File file);
  32. void setConstantTuning(float note);
  33. void setDefaultTuning();
  34. vital::mono_float convertMidiNote(int note) const;
  35. void setStartMidiNote(int start_midi_note) { scale_start_midi_note_ = start_midi_note; }
  36. void setReferenceNote(int reference_note) { reference_midi_note_ = reference_note; }
  37. void setReferenceFrequency(float frequency);
  38. void setReferenceNoteFrequency(int midi_note, float frequency);
  39. void setReferenceRatio(float ratio);
  40. std::string getName() const {
  41. if (mapping_name_.size() == 0)
  42. return tuning_name_;
  43. if (tuning_name_.size() == 0)
  44. return mapping_name_;
  45. return tuning_name_ + " / " + mapping_name_;
  46. }
  47. void setName(const std::string& name) {
  48. mapping_name_ = "";
  49. tuning_name_ = name;
  50. }
  51. bool isDefault() const { return default_; }
  52. json stateToJson() const;
  53. void jsonToState(const json& data);
  54. void loadScalaFile(const StringArray& scala_lines);
  55. private:
  56. void loadScalaFile(File scala_file);
  57. void loadKeyboardMapFile(File kbm_file);
  58. void loadTunFile(File tun_file);
  59. int scale_start_midi_note_;
  60. float reference_midi_note_;
  61. std::vector<float> scale_;
  62. std::vector<int> keyboard_mapping_;
  63. vital::mono_float tuning_[kTuningSize];
  64. std::string tuning_name_;
  65. std::string mapping_name_;
  66. bool default_;
  67. JUCE_LEAK_DETECTOR(Tuning)
  68. };