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.

308 lines
7.3KB

  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. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  24. // compiled on its own).
  25. #ifdef JUCE_INCLUDED_FILE
  26. static int64 highResTimerFrequency;
  27. #if JUCE_INTEL
  28. static void juce_getCpuVendor (char* const v) throw()
  29. {
  30. int vendor[4];
  31. zerostruct (vendor);
  32. int dummy = 0;
  33. asm ("mov %%ebx, %%esi \n\t"
  34. "cpuid \n\t"
  35. "xchg %%esi, %%ebx"
  36. : "=a" (dummy), "=S" (vendor[0]), "=c" (vendor[2]), "=d" (vendor[1]) : "a" (0));
  37. memcpy (v, vendor, 16);
  38. }
  39. static unsigned int getCPUIDWord (unsigned int& familyModel, unsigned int& extFeatures) throw()
  40. {
  41. unsigned int cpu = 0;
  42. unsigned int ext = 0;
  43. unsigned int family = 0;
  44. unsigned int dummy = 0;
  45. asm ("mov %%ebx, %%esi \n\t"
  46. "cpuid \n\t"
  47. "xchg %%esi, %%ebx"
  48. : "=a" (family), "=S" (ext), "=c" (dummy), "=d" (cpu) : "a" (1));
  49. familyModel = family;
  50. extFeatures = ext;
  51. return cpu;
  52. }
  53. struct CPUFlags
  54. {
  55. bool hasMMX : 1;
  56. bool hasSSE : 1;
  57. bool hasSSE2 : 1;
  58. bool has3DNow : 1;
  59. };
  60. static CPUFlags cpuFlags;
  61. #endif
  62. //==============================================================================
  63. void SystemStats::initialiseStats() throw()
  64. {
  65. static bool initialised = false;
  66. if (! initialised)
  67. {
  68. initialised = true;
  69. // etremely annoying: adding this line stops the apple menu items from working. Of
  70. // course, not adding it means that carbon windows (e.g. in plugins) won't get
  71. // any events.
  72. //NSApplicationLoad();
  73. [NSApplication sharedApplication];
  74. #if JUCE_INTEL
  75. {
  76. unsigned int familyModel, extFeatures;
  77. const unsigned int features = getCPUIDWord (familyModel, extFeatures);
  78. cpuFlags.hasMMX = ((features & (1 << 23)) != 0);
  79. cpuFlags.hasSSE = ((features & (1 << 25)) != 0);
  80. cpuFlags.hasSSE2 = ((features & (1 << 26)) != 0);
  81. cpuFlags.has3DNow = ((extFeatures & (1 << 31)) != 0);
  82. }
  83. #endif
  84. highResTimerFrequency = (int64) AudioGetHostClockFrequency();
  85. String s (SystemStats::getJUCEVersion());
  86. rlimit lim;
  87. getrlimit (RLIMIT_NOFILE, &lim);
  88. lim.rlim_cur = lim.rlim_max = RLIM_INFINITY;
  89. setrlimit (RLIMIT_NOFILE, &lim);
  90. }
  91. }
  92. static const String getCpuInfo (const char* key, bool lastOne = false) throw()
  93. {
  94. String info;
  95. char buf [256];
  96. FILE* f = fopen ("/proc/cpuinfo", "r");
  97. while (f != 0 && fgets (buf, sizeof(buf), f))
  98. {
  99. if (strncmp (buf, key, strlen (key)) == 0)
  100. {
  101. char* p = buf;
  102. while (*p && *p != '\n')
  103. ++p;
  104. if (*p != 0)
  105. *p = 0;
  106. p = buf;
  107. while (*p != 0 && *p != ':')
  108. ++p;
  109. if (*p != 0 && *(p + 1) != 0)
  110. info = p + 2;
  111. if (! lastOne)
  112. break;
  113. }
  114. }
  115. fclose (f);
  116. return info;
  117. }
  118. //==============================================================================
  119. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  120. {
  121. return MacOSX;
  122. }
  123. const String SystemStats::getOperatingSystemName() throw()
  124. {
  125. return T("Mac OS X");
  126. }
  127. bool SystemStats::isOperatingSystem64Bit() throw()
  128. {
  129. #if JUCE_64BIT
  130. return true;
  131. #else
  132. //xxx not sure how to find this out?..
  133. return false;
  134. #endif
  135. }
  136. int SystemStats::getMemorySizeInMegabytes() throw()
  137. {
  138. #if MACOS_10_4_OR_EARLIER
  139. long bytes;
  140. if (Gestalt (gestaltPhysicalRAMSize, &bytes) == noErr)
  141. return (int) (((unsigned long) bytes) / (1024 * 1024));
  142. return 0;
  143. #else
  144. return (int) ([[NSProcessInfo processInfo] physicalMemory] / (1024 * 1024));
  145. #endif
  146. }
  147. bool SystemStats::hasMMX() throw()
  148. {
  149. #if JUCE_INTEL
  150. return cpuFlags.hasMMX;
  151. #else
  152. return false;
  153. #endif
  154. }
  155. bool SystemStats::hasSSE() throw()
  156. {
  157. #if JUCE_INTEL
  158. return cpuFlags.hasSSE;
  159. #else
  160. return false;
  161. #endif
  162. }
  163. bool SystemStats::hasSSE2() throw()
  164. {
  165. #if JUCE_INTEL
  166. return cpuFlags.hasSSE2;
  167. #else
  168. return false;
  169. #endif
  170. }
  171. bool SystemStats::has3DNow() throw()
  172. {
  173. #if JUCE_INTEL
  174. return cpuFlags.has3DNow;
  175. #else
  176. return false;
  177. #endif
  178. }
  179. const String SystemStats::getCpuVendor() throw()
  180. {
  181. #if JUCE_INTEL
  182. char v [16];
  183. juce_getCpuVendor (v);
  184. return String (v, 16);
  185. #else
  186. return String::empty;
  187. #endif
  188. }
  189. int SystemStats::getCpuSpeedInMegaherz() throw()
  190. {
  191. #if MACOS_10_4_OR_EARLIER
  192. return GetCPUSpeed();
  193. #else
  194. return roundDoubleToInt (getCpuInfo ("cpu MHz").getDoubleValue());
  195. #endif
  196. }
  197. int SystemStats::getNumCpus() throw()
  198. {
  199. #if MACOS_10_4_OR_EARLIER
  200. return MPProcessors();
  201. #else
  202. return [[NSProcessInfo processInfo] activeProcessorCount];
  203. #endif
  204. }
  205. //==============================================================================
  206. static int64 juce_getMicroseconds() throw()
  207. {
  208. UnsignedWide t;
  209. Microseconds (&t);
  210. return (((int64) t.hi) << 32) | t.lo;
  211. }
  212. uint32 juce_millisecondsSinceStartup() throw()
  213. {
  214. return (uint32) (juce_getMicroseconds() / 1000);
  215. }
  216. double Time::getMillisecondCounterHiRes() throw()
  217. {
  218. // xxx might be more accurate to use a scaled AudioGetCurrentHostTime?
  219. return juce_getMicroseconds() * 0.001;
  220. }
  221. int64 Time::getHighResolutionTicks() throw()
  222. {
  223. return (int64) AudioGetCurrentHostTime();
  224. }
  225. int64 Time::getHighResolutionTicksPerSecond() throw()
  226. {
  227. return highResTimerFrequency;
  228. }
  229. int64 SystemStats::getClockCycleCounter() throw()
  230. {
  231. return (int64) AudioGetCurrentHostTime();
  232. }
  233. bool Time::setSystemTimeToThisTime() const throw()
  234. {
  235. jassertfalse
  236. return false;
  237. }
  238. //==============================================================================
  239. int SystemStats::getPageSize() throw()
  240. {
  241. return NSPageSize();
  242. }
  243. void PlatformUtilities::fpuReset()
  244. {
  245. }
  246. #endif