Audio plugin host https://kx.studio/carla
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.

166 lines
4.8KB

  1. /*
  2. ZynAddSubFX - a software synthesizer
  3. Microtonal.h - Tuning settings and microtonal capabilities
  4. Copyright (C) 2002-2005 Nasca Octavian Paul
  5. Author: Nasca Octavian Paul
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of version 2 of the GNU General Public License
  8. as published by the Free Software Foundation.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License (version 2 or later) for more details.
  13. You should have received a copy of the GNU General Public License (version 2)
  14. along with this program; if not, write to the Free Software Foundation,
  15. Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. */
  17. #ifndef MICROTONAL_H
  18. #define MICROTONAL_H
  19. #include <cstdio>
  20. #include <stdint.h>
  21. #include "../globals.h"
  22. #define MAX_OCTAVE_SIZE 128
  23. #define MICROTONAL_MAX_NAME_LEN 120
  24. class XMLwrapper;
  25. struct KbmInfo
  26. {
  27. uint8_t Pmapsize;
  28. uint8_t Pfirstkey;
  29. uint8_t Plastkey;
  30. uint8_t Pmiddlenote;
  31. uint8_t PAnote;
  32. float PAfreq;
  33. uint8_t Pmappingenabled;
  34. short int Pmapping[128];
  35. };
  36. struct OctaveTuning {
  37. unsigned char type; //1 for cents or 2 for division
  38. // the real tuning (eg. +1.05946f for one halftone)
  39. // or 2.0f for one octave
  40. float tuning;
  41. //the real tunning is x1/x2
  42. unsigned int x1, x2;
  43. };
  44. struct SclInfo
  45. {
  46. char Pname[MICROTONAL_MAX_NAME_LEN];
  47. char Pcomment[MICROTONAL_MAX_NAME_LEN];
  48. unsigned char octavesize;
  49. OctaveTuning octave[MAX_OCTAVE_SIZE];
  50. };
  51. /**Tuning settings and microtonal capabilities*/
  52. class Microtonal
  53. {
  54. public:
  55. /**Constructor*/
  56. Microtonal(const int& gzip_compression);
  57. /**Destructor*/
  58. ~Microtonal();
  59. void defaults();
  60. /**Calculates the frequency for a given note
  61. */
  62. float getnotefreq(int note, int keyshift) const;
  63. //Parameters
  64. /**if the keys are inversed (the pitch is lower to keys from the right direction)*/
  65. unsigned char Pinvertupdown;
  66. /**the central key of the inversion*/
  67. unsigned char Pinvertupdowncenter;
  68. /**0 for 12 key temperate scale, 1 for microtonal*/
  69. unsigned char Penabled;
  70. /**the note of "A" key*/
  71. unsigned char PAnote;
  72. /**the frequency of the "A" note*/
  73. float PAfreq;
  74. /**if the scale is "tuned" to a note, you can tune to other note*/
  75. unsigned char Pscaleshift;
  76. //first and last key (to retune)
  77. unsigned char Pfirstkey;
  78. unsigned char Plastkey;
  79. /**The middle note where scale degree 0 is mapped to*/
  80. unsigned char Pmiddlenote;
  81. /**Map size*/
  82. unsigned char Pmapsize;
  83. /**Mapping ON/OFF*/
  84. unsigned char Pmappingenabled;
  85. /**Mapping (keys)*/
  86. short int Pmapping[128];
  87. /**Fine detune to be applied to all notes*/
  88. unsigned char Pglobalfinedetune;
  89. // Functions
  90. /** Return the current octave size*/
  91. unsigned char getoctavesize() const;
  92. /**Convert tunning to string*/
  93. void tuningtoline(int n, char *line, int maxn);
  94. /**load the tunnings from a .scl file*/
  95. static int loadscl(SclInfo &scl, const char *filename);
  96. /**load the mapping from .kbm file*/
  97. static int loadkbm(KbmInfo &kbm, const char *filename);
  98. /**Load text into the internal tunings
  99. *
  100. *\todo better description*/
  101. int texttotunings(const char *text);
  102. /**Load text into the internal mappings
  103. *
  104. *\todo better description*/
  105. void texttomapping(const char *text);
  106. /**Name of Microtonal tuning*/
  107. char Pname[MICROTONAL_MAX_NAME_LEN];
  108. /**Comment about the tuning*/
  109. char Pcomment[MICROTONAL_MAX_NAME_LEN];
  110. void add2XML(XMLwrapper& xml) const;
  111. void getfromXML(XMLwrapper& xml);
  112. int saveXML(const char *filename) const;
  113. int loadXML(const char *filename);
  114. //simple operators primarily for debug
  115. bool operator==(const Microtonal &micro) const;
  116. bool operator!=(const Microtonal &micro) const;
  117. void clone(Microtonal &m);
  118. static const rtosc::Ports ports;
  119. //only paste handler should access there (quasi-private)
  120. unsigned char octavesize;
  121. OctaveTuning octave[MAX_OCTAVE_SIZE];
  122. private:
  123. //loads a line from the text file, while ignoring the lines beggining with "!"
  124. static int loadline(FILE *file, char *line);
  125. //Grab a 0..127 integer from the provided descriptor
  126. static int linetotunings(struct OctaveTuning &tune, const char *line);
  127. const int& gzip_compression;
  128. };
  129. #endif