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.

157 lines
4.4KB

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