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.

Microtonal.h 4.3KB

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