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.

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