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.

135 lines
4.1KB

  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 "../globals.h"
  20. #include "XMLwrapper.h"
  21. #define MAX_OCTAVE_SIZE 128
  22. #define MICROTONAL_MAX_NAME_LEN 120
  23. #include <stdio.h>
  24. /**Tuning settings and microtonal capabilities*/
  25. class Microtonal
  26. {
  27. public:
  28. /**Constructor*/
  29. Microtonal();
  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. unsigned char *Pname;
  81. /**Comment about the tuning*/
  82. unsigned char *Pcomment;
  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. private:
  91. int linetotunings(unsigned int nline, const char *line);
  92. int loadline(FILE *file, char *line); //loads a line from the text file, while ignoring the lines beggining with "!"
  93. unsigned char octavesize;
  94. struct {
  95. unsigned char type; //1 for cents or 2 for division
  96. // the real tuning (eg. +1.05946f for one halftone)
  97. // or 2.0f for one octave
  98. float tuning;
  99. //the real tunning is x1/x2
  100. unsigned int x1, x2;
  101. } octave[MAX_OCTAVE_SIZE], tmpoctave[MAX_OCTAVE_SIZE];
  102. };
  103. #endif