lmms_basics.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * lmms_basics.h - typedefs for common types that are used in the whole app
  3. *
  4. * Copyright (c) 2004-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
  5. *
  6. * This file is part of LMMS - https://lmms.io
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public
  19. * License along with this program (see COPYING); if not, write to the
  20. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. * Boston, MA 02110-1301 USA.
  22. *
  23. */
  24. #ifndef TYPES_H
  25. #define TYPES_H
  26. #include <cstddef>
  27. #include <limits>
  28. #include "lmmsconfig.h"
  29. #ifdef LMMS_HAVE_STDINT_H
  30. #include <cstdint>
  31. #include <array>
  32. #endif
  33. typedef int32_t bar_t;
  34. typedef int32_t tick_t;
  35. typedef uint8_t volume_t;
  36. typedef int8_t panning_t;
  37. typedef float sample_t; // standard sample-type
  38. typedef int16_t int_sample_t; // 16-bit-int-sample
  39. typedef uint32_t sample_rate_t; // sample-rate
  40. typedef int16_t fpp_t; // frames per period (0-16384)
  41. typedef int32_t f_cnt_t; // standard frame-count
  42. typedef uint8_t ch_cnt_t; // channel-count (0-SURROUND_CHANNELS)
  43. typedef uint16_t bpm_t; // tempo (MIN_BPM to MAX_BPM)
  44. typedef uint16_t bitrate_t; // bitrate in kbps
  45. typedef uint16_t mix_ch_t; // Mixer-channel (0 to MAX_CHANNEL)
  46. typedef uint32_t jo_id_t; // (unique) ID of a journalling object
  47. // windows headers define "min" and "max" macros, breaking the methods bwloe
  48. #undef min
  49. #undef max
  50. template<typename T>
  51. struct typeInfo
  52. {
  53. static inline T min()
  54. {
  55. return std::numeric_limits<T>::min();
  56. }
  57. static inline T max()
  58. {
  59. return std::numeric_limits<T>::max();
  60. }
  61. static inline T minEps()
  62. {
  63. return 1;
  64. }
  65. static inline bool isEqual( T x, T y )
  66. {
  67. return x == y;
  68. }
  69. static inline T absVal( T t )
  70. {
  71. return t >= 0 ? t : -t;
  72. }
  73. } ;
  74. template<>
  75. inline float typeInfo<float>::minEps()
  76. {
  77. return 1.0e-10f;
  78. }
  79. template<>
  80. inline bool typeInfo<float>::isEqual( float x, float y )
  81. {
  82. if( x == y )
  83. {
  84. return true;
  85. }
  86. return absVal( x - y ) < minEps();
  87. }
  88. constexpr ch_cnt_t DEFAULT_CHANNELS = 2;
  89. constexpr ch_cnt_t SURROUND_CHANNELS =
  90. #define LMMS_DISABLE_SURROUND
  91. #ifndef LMMS_DISABLE_SURROUND
  92. 4;
  93. #else
  94. 2;
  95. #endif
  96. constexpr char LADSPA_PATH_SEPERATOR =
  97. #ifdef LMMS_BUILD_WIN32
  98. ';';
  99. #else
  100. ':';
  101. #endif
  102. using sampleFrame = std::array<sample_t, DEFAULT_CHANNELS>;
  103. using surroundSampleFrame = std::array<sample_t, SURROUND_CHANNELS>;
  104. constexpr std::size_t LMMS_ALIGN_SIZE = 16;
  105. #define STRINGIFY(s) STR(s)
  106. #define STR(PN) #PN
  107. // Abstract away GUI CTRL key (linux/windows) vs ⌘ (apple)
  108. constexpr const char* UI_CTRL_KEY =
  109. #ifdef LMMS_BUILD_APPLE
  110. "⌘";
  111. #else
  112. "Ctrl";
  113. #endif
  114. #endif