The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

284 lines
6.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-7 by Raw Material Software ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the
  7. GNU General Public License, as published by the Free Software Foundation;
  8. either version 2 of the License, or (at your option) any later version.
  9. JUCE 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 for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with JUCE; if not, visit www.gnu.org/licenses or write to the
  15. Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  16. Boston, MA 02111-1307 USA
  17. ------------------------------------------------------------------------------
  18. If you'd like to release a closed-source product which uses JUCE, commercial
  19. licenses are also available: visit www.rawmaterialsoftware.com/juce for
  20. more information.
  21. ==============================================================================
  22. */
  23. #include "juce_mac_NativeHeaders.h"
  24. #include <AppKit/AppKit.h>
  25. #include <CoreAudio/HostTime.h>
  26. #include <ctime>
  27. #include <sys/resource.h>
  28. BEGIN_JUCE_NAMESPACE
  29. #include "../../../src/juce_appframework/application/juce_Application.h"
  30. #include "../../../src/juce_core/basics/juce_SystemStats.h"
  31. #include "../../../src/juce_core/basics/juce_Time.h"
  32. #include "../../../src/juce_core/misc/juce_PlatformUtilities.h"
  33. static int64 highResTimerFrequency;
  34. #if JUCE_INTEL
  35. static void juce_getCpuVendor (char* const v) throw()
  36. {
  37. int vendor[4];
  38. zerostruct (vendor);
  39. int dummy = 0;
  40. asm ("mov %%ebx, %%esi \n\t"
  41. "cpuid \n\t"
  42. "xchg %%esi, %%ebx"
  43. : "=a" (dummy), "=S" (vendor[0]), "=c" (vendor[2]), "=d" (vendor[1]) : "a" (0));
  44. memcpy (v, vendor, 16);
  45. }
  46. static unsigned int getCPUIDWord (unsigned int& familyModel, unsigned int& extFeatures) throw()
  47. {
  48. unsigned int cpu = 0;
  49. unsigned int ext = 0;
  50. unsigned int family = 0;
  51. unsigned int dummy = 0;
  52. asm ("mov %%ebx, %%esi \n\t"
  53. "cpuid \n\t"
  54. "xchg %%esi, %%ebx"
  55. : "=a" (family), "=S" (ext), "=c" (dummy), "=d" (cpu) : "a" (1));
  56. familyModel = family;
  57. extFeatures = ext;
  58. return cpu;
  59. }
  60. struct CPUFlags
  61. {
  62. bool hasMMX : 1;
  63. bool hasSSE : 1;
  64. bool hasSSE2 : 1;
  65. bool has3DNow : 1;
  66. };
  67. static CPUFlags cpuFlags;
  68. #endif
  69. //==============================================================================
  70. void Logger::outputDebugString (const String& text) throw()
  71. {
  72. String withLineFeed (text + T("\n"));
  73. const char* const utf8 = withLineFeed.toUTF8();
  74. fwrite (utf8, strlen (utf8), 1, stdout);
  75. }
  76. void Logger::outputDebugPrintf (const tchar* format, ...) throw()
  77. {
  78. String text;
  79. va_list args;
  80. va_start (args, format);
  81. text.vprintf(format, args);
  82. outputDebugString (text);
  83. }
  84. int SystemStats::getMemorySizeInMegabytes() throw()
  85. {
  86. long bytes;
  87. if (Gestalt (gestaltPhysicalRAMSize, &bytes) == noErr)
  88. return (int) (((unsigned long) bytes) / (1024 * 1024));
  89. return 0;
  90. }
  91. //==============================================================================
  92. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  93. {
  94. return MacOSX;
  95. }
  96. const String SystemStats::getOperatingSystemName() throw()
  97. {
  98. return T("Mac OS X");
  99. }
  100. bool SystemStats::isOperatingSystem64Bit() throw()
  101. {
  102. #if JUCE_64BIT
  103. return true;
  104. #else
  105. //xxx not sure how to find this out?..
  106. return false;
  107. #endif
  108. }
  109. //==============================================================================
  110. void SystemStats::initialiseStats() throw()
  111. {
  112. static bool initialised = false;
  113. if (! initialised)
  114. {
  115. initialised = true;
  116. //[NSApplication sharedApplication];
  117. NSApplicationLoad();
  118. #if JUCE_INTEL
  119. {
  120. unsigned int familyModel, extFeatures;
  121. const unsigned int features = getCPUIDWord (familyModel, extFeatures);
  122. cpuFlags.hasMMX = ((features & (1 << 23)) != 0);
  123. cpuFlags.hasSSE = ((features & (1 << 25)) != 0);
  124. cpuFlags.hasSSE2 = ((features & (1 << 26)) != 0);
  125. cpuFlags.has3DNow = ((extFeatures & (1 << 31)) != 0);
  126. }
  127. #endif
  128. highResTimerFrequency = (int64) AudioGetHostClockFrequency();
  129. String s (SystemStats::getJUCEVersion());
  130. rlimit lim;
  131. getrlimit (RLIMIT_NOFILE, &lim);
  132. lim.rlim_cur = lim.rlim_max = RLIM_INFINITY;
  133. setrlimit (RLIMIT_NOFILE, &lim);
  134. }
  135. }
  136. bool SystemStats::hasMMX() throw()
  137. {
  138. #if JUCE_INTEL
  139. return cpuFlags.hasMMX;
  140. #else
  141. return false;
  142. #endif
  143. }
  144. bool SystemStats::hasSSE() throw()
  145. {
  146. #if JUCE_INTEL
  147. return cpuFlags.hasSSE;
  148. #else
  149. return false;
  150. #endif
  151. }
  152. bool SystemStats::hasSSE2() throw()
  153. {
  154. #if JUCE_INTEL
  155. return cpuFlags.hasSSE2;
  156. #else
  157. return false;
  158. #endif
  159. }
  160. bool SystemStats::has3DNow() throw()
  161. {
  162. #if JUCE_INTEL
  163. return cpuFlags.has3DNow;
  164. #else
  165. return false;
  166. #endif
  167. }
  168. const String SystemStats::getCpuVendor() throw()
  169. {
  170. #if JUCE_INTEL
  171. char v [16];
  172. juce_getCpuVendor (v);
  173. return String (v, 16);
  174. #else
  175. return String::empty;
  176. #endif
  177. }
  178. int SystemStats::getCpuSpeedInMegaherz() throw()
  179. {
  180. return GetCPUSpeed();
  181. }
  182. int SystemStats::getNumCpus() throw()
  183. {
  184. return MPProcessors();
  185. }
  186. //==============================================================================
  187. static int64 juce_getMicroseconds() throw()
  188. {
  189. UnsignedWide t;
  190. Microseconds (&t);
  191. return (((int64) t.hi) << 32) | t.lo;
  192. }
  193. uint32 juce_millisecondsSinceStartup() throw()
  194. {
  195. return (uint32) (juce_getMicroseconds() / 1000);
  196. }
  197. double Time::getMillisecondCounterHiRes() throw()
  198. {
  199. // xxx might be more accurate to use a scaled AudioGetCurrentHostTime?
  200. return juce_getMicroseconds() * 0.001;
  201. }
  202. int64 Time::getHighResolutionTicks() throw()
  203. {
  204. return (int64) AudioGetCurrentHostTime();
  205. }
  206. int64 Time::getHighResolutionTicksPerSecond() throw()
  207. {
  208. return highResTimerFrequency;
  209. }
  210. int64 SystemStats::getClockCycleCounter() throw()
  211. {
  212. jassertfalse
  213. return 0;
  214. }
  215. bool Time::setSystemTimeToThisTime() const throw()
  216. {
  217. jassertfalse
  218. return false;
  219. }
  220. //==============================================================================
  221. int SystemStats::getPageSize() throw()
  222. {
  223. jassertfalse
  224. return 512; //xxx
  225. }
  226. void PlatformUtilities::fpuReset()
  227. {
  228. }
  229. END_JUCE_NAMESPACE