lmms_basics.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 <limits>
  27. #include "lmmsconfig.h"
  28. #ifdef LMMS_HAVE_STDINT_H
  29. #include <cstdint>
  30. #endif
  31. typedef int32_t bar_t;
  32. typedef int32_t tick_t;
  33. typedef uint8_t volume_t;
  34. typedef int8_t panning_t;
  35. typedef float sample_t; // standard sample-type
  36. typedef int16_t int_sample_t; // 16-bit-int-sample
  37. typedef uint32_t sample_rate_t; // sample-rate
  38. typedef int16_t fpp_t; // frames per period (0-16384)
  39. typedef int32_t f_cnt_t; // standard frame-count
  40. typedef uint8_t ch_cnt_t; // channel-count (0-SURROUND_CHANNELS)
  41. typedef uint16_t bpm_t; // tempo (MIN_BPM to MAX_BPM)
  42. typedef uint16_t bitrate_t; // bitrate in kbps
  43. typedef uint16_t fx_ch_t; // FX-channel (0 to MAX_EFFECT_CHANNEL)
  44. typedef uint32_t jo_id_t; // (unique) ID of a journalling object
  45. // use for improved branch prediction
  46. #define likely(x) Q_LIKELY(x)
  47. #define unlikely(x) Q_UNLIKELY(x)
  48. // windows headers define "min" and "max" macros, breaking the methods bwloe
  49. #undef min
  50. #undef max
  51. template<typename T>
  52. struct typeInfo
  53. {
  54. static inline T min()
  55. {
  56. return std::numeric_limits<T>::min();
  57. }
  58. static inline T max()
  59. {
  60. return std::numeric_limits<T>::max();
  61. }
  62. static inline T minEps()
  63. {
  64. return 1;
  65. }
  66. static inline bool isEqual( T x, T y )
  67. {
  68. return x == y;
  69. }
  70. static inline T absVal( T t )
  71. {
  72. return t >= 0 ? t : -t;
  73. }
  74. } ;
  75. template<>
  76. inline float typeInfo<float>::minEps()
  77. {
  78. return 1.0e-10f;
  79. }
  80. template<>
  81. inline bool typeInfo<float>::isEqual( float x, float y )
  82. {
  83. if( x == y )
  84. {
  85. return true;
  86. }
  87. return absVal( x - y ) < minEps();
  88. }
  89. const ch_cnt_t DEFAULT_CHANNELS = 2;
  90. const ch_cnt_t SURROUND_CHANNELS =
  91. #define LMMS_DISABLE_SURROUND
  92. #ifndef LMMS_DISABLE_SURROUND
  93. 4;
  94. #else
  95. 2;
  96. #endif
  97. #ifdef LMMS_BUILD_WIN32
  98. #define LADSPA_PATH_SEPERATOR ';'
  99. #else
  100. #define LADSPA_PATH_SEPERATOR ':'
  101. #endif
  102. typedef sample_t sampleFrame[DEFAULT_CHANNELS];
  103. typedef sample_t surroundSampleFrame[SURROUND_CHANNELS];
  104. #define ALIGN_SIZE 16
  105. #if __GNUC__
  106. typedef sample_t sampleFrameA[DEFAULT_CHANNELS] __attribute__((__aligned__(ALIGN_SIZE)));
  107. #endif
  108. #define STRINGIFY(s) STR(s)
  109. #define STR(PN) #PN
  110. // Abstract away GUI CTRL key (linux/windows) vs ⌘ (apple)
  111. #ifdef LMMS_BUILD_APPLE
  112. # define UI_CTRL_KEY "⌘"
  113. #else
  114. # define UI_CTRL_KEY "Ctrl"
  115. #endif
  116. #endif