From 419aac807478f6883eee0f97aef635cb49dfda59 Mon Sep 17 00:00:00 2001 From: Julian Storer Date: Thu, 10 Jun 2010 12:26:43 +0100 Subject: [PATCH] Minor clean-ups. --- .../formats/juce_AudioUnitPluginFormat.mm | 224 ++++---- src/containers/juce_MemoryBlock.cpp | 3 +- src/containers/juce_MemoryBlock.h | 1 + src/containers/juce_PropertySet.cpp | 1 - src/core/juce_FileLogger.cpp | 1 - src/core/juce_Logger.cpp | 2 +- src/core/juce_Logger.h | 3 + src/core/juce_PerformanceCounter.cpp | 1 - src/core/juce_RelativeTime.cpp | 1 - src/core/juce_SystemStats.cpp | 24 +- src/core/juce_SystemStats.h | 21 +- src/cryptography/juce_MD5.cpp | 1 - src/cryptography/juce_Primes.cpp | 1 - src/cryptography/juce_RSAKey.cpp | 3 +- src/cryptography/juce_RSAKey.h | 3 + .../juce_CPlusPlusCodeTokeniser.cpp | 490 +++++++++--------- src/gui/components/juce_Desktop.cpp | 1 - src/gui/components/mouse/juce_MouseEvent.cpp | 2 +- src/gui/components/mouse/juce_MouseEvent.h | 1 + .../special/juce_ColourSelector.cpp | 5 +- .../special/juce_MidiKeyboardComponent.cpp | 4 +- .../special/juce_MidiKeyboardComponent.h | 3 + .../windows/juce_DocumentWindow.cpp | 1 - .../windows/juce_ResizableWindow.cpp | 1 - .../windows/juce_ThreadWithProgressWindow.cpp | 1 - .../components/windows/juce_TooltipWindow.cpp | 1 - .../windows/juce_TopLevelWindow.cpp | 1 - src/gui/graphics/colour/juce_Colours.cpp | 1 - src/gui/graphics/contexts/juce_Graphics.cpp | 4 +- .../graphics/contexts/juce_Justification.cpp | 1 - .../effects/juce_ReduceOpacityEffect.cpp | 1 - .../geometry/juce_AffineTransform.cpp | 1 - src/gui/graphics/geometry/juce_Path.cpp | 2 +- .../graphics/geometry/juce_PathIterator.cpp | 1 - .../graphics/geometry/juce_PathStrokeType.cpp | 1 - .../image_file_formats/juce_GIFLoader.cpp | 1 - src/gui/graphics/imaging/juce_Image.cpp | 2 - src/io/files/juce_FileSearchPath.cpp | 1 - src/io/files/juce_ZipFile.cpp | 2 +- src/io/network/juce_Socket.cpp | 412 ++++++++------- src/io/network/juce_URL.cpp | 1 - src/io/streams/juce_BufferedInputStream.cpp | 1 - src/io/streams/juce_InputStream.cpp | 1 - src/io/streams/juce_MemoryOutputStream.cpp | 1 - src/io/streams/juce_OutputStream.cpp | 1 - src/io/streams/juce_SubregionStream.cpp | 1 - src/native/linux/juce_linux_SystemStats.cpp | 17 +- src/native/mac/juce_mac_SystemStats.mm | 86 +-- src/native/windows/juce_win32_SystemStats.cpp | 49 +- src/text/juce_LocalisedStrings.cpp | 1 - src/text/juce_StringArray.cpp | 1 - src/text/juce_StringPairArray.cpp | 1 - src/text/juce_XmlElement.cpp | 1 - src/threads/juce_ReadWriteLock.cpp | 1 - src/threads/juce_Thread.cpp | 2 +- src/threads/juce_ThreadPool.cpp | 1 - src/threads/juce_TimeSliceThread.cpp | 1 - src/utilities/juce_UndoManager.cpp | 1 - 58 files changed, 656 insertions(+), 743 deletions(-) diff --git a/src/audio/plugins/formats/juce_AudioUnitPluginFormat.mm b/src/audio/plugins/formats/juce_AudioUnitPluginFormat.mm index b4effaeb3d..eb5c4373e8 100644 --- a/src/audio/plugins/formats/juce_AudioUnitPluginFormat.mm +++ b/src/audio/plugins/formats/juce_AudioUnitPluginFormat.mm @@ -66,127 +66,127 @@ BEGIN_JUCE_NAMESPACE #define log(a) #endif -static int insideCallback = 0; - -//============================================================================== -static const String osTypeToString (OSType type) +namespace AudioUnitFormatHelpers { - char s[4]; - s[0] = (char) (((uint32) type) >> 24); - s[1] = (char) (((uint32) type) >> 16); - s[2] = (char) (((uint32) type) >> 8); - s[3] = (char) ((uint32) type); - return String (s, 4); -} + static int insideCallback = 0; -static OSType stringToOSType (const String& s1) -{ - const String s (s1 + " "); - - return (((OSType) (unsigned char) s[0]) << 24) - | (((OSType) (unsigned char) s[1]) << 16) - | (((OSType) (unsigned char) s[2]) << 8) - | ((OSType) (unsigned char) s[3]); -} - -static const char* auIdentifierPrefix = "AudioUnit:"; - -static const String createAUPluginIdentifier (const ComponentDescription& desc) -{ - jassert (osTypeToString ('abcd') == "abcd"); // agh, must have got the endianness wrong.. - jassert (stringToOSType ("abcd") == (OSType) 'abcd'); // ditto - - String s (auIdentifierPrefix); - - if (desc.componentType == kAudioUnitType_MusicDevice) - s << "Synths/"; - else if (desc.componentType == kAudioUnitType_MusicEffect - || desc.componentType == kAudioUnitType_Effect) - s << "Effects/"; - else if (desc.componentType == kAudioUnitType_Generator) - s << "Generators/"; - else if (desc.componentType == kAudioUnitType_Panner) - s << "Panners/"; - - s << osTypeToString (desc.componentType) << "," - << osTypeToString (desc.componentSubType) << "," - << osTypeToString (desc.componentManufacturer); - - return s; -} - -static void getAUDetails (ComponentRecord* comp, String& name, String& manufacturer) -{ - Handle componentNameHandle = NewHandle (sizeof (void*)); - Handle componentInfoHandle = NewHandle (sizeof (void*)); - - if (componentNameHandle != 0 && componentInfoHandle != 0) + static const String osTypeToString (OSType type) { - ComponentDescription desc; - - if (GetComponentInfo (comp, &desc, componentNameHandle, componentInfoHandle, 0) == noErr) - { - ConstStr255Param nameString = (ConstStr255Param) (*componentNameHandle); - ConstStr255Param infoString = (ConstStr255Param) (*componentInfoHandle); - - if (nameString != 0 && nameString[0] != 0) - { - const String all ((const char*) nameString + 1, nameString[0]); - DBG ("name: "+ all); - - manufacturer = all.upToFirstOccurrenceOf (":", false, false).trim(); - name = all.fromFirstOccurrenceOf (":", false, false).trim(); - } - - if (infoString != 0 && infoString[0] != 0) - { - DBG ("info: " + String ((const char*) infoString + 1, infoString[0])); - } - - if (name.isEmpty()) - name = ""; - } - - DisposeHandle (componentNameHandle); - DisposeHandle (componentInfoHandle); + char s[4]; + s[0] = (char) (((uint32) type) >> 24); + s[1] = (char) (((uint32) type) >> 16); + s[2] = (char) (((uint32) type) >> 8); + s[3] = (char) ((uint32) type); + return String (s, 4); } -} -static bool getComponentDescFromIdentifier (const String& fileOrIdentifier, ComponentDescription& desc, - String& name, String& version, String& manufacturer) -{ - zerostruct (desc); - - if (fileOrIdentifier.startsWithIgnoreCase (auIdentifierPrefix)) + static OSType stringToOSType (const String& s1) { - String s (fileOrIdentifier.substring (jmax (fileOrIdentifier.lastIndexOfChar (':'), - fileOrIdentifier.lastIndexOfChar ('/')) + 1)); + const String s (s1 + " "); - StringArray tokens; - tokens.addTokens (s, ",", String::empty); - tokens.trim(); - tokens.removeEmptyStrings(); + return (((OSType) (unsigned char) s[0]) << 24) + | (((OSType) (unsigned char) s[1]) << 16) + | (((OSType) (unsigned char) s[2]) << 8) + | ((OSType) (unsigned char) s[3]); + } - if (tokens.size() == 3) + static const char* auIdentifierPrefix = "AudioUnit:"; + + static const String createAUPluginIdentifier (const ComponentDescription& desc) + { + jassert (osTypeToString ('abcd') == "abcd"); // agh, must have got the endianness wrong.. + jassert (stringToOSType ("abcd") == (OSType) 'abcd'); // ditto + + String s (auIdentifierPrefix); + + if (desc.componentType == kAudioUnitType_MusicDevice) + s << "Synths/"; + else if (desc.componentType == kAudioUnitType_MusicEffect + || desc.componentType == kAudioUnitType_Effect) + s << "Effects/"; + else if (desc.componentType == kAudioUnitType_Generator) + s << "Generators/"; + else if (desc.componentType == kAudioUnitType_Panner) + s << "Panners/"; + + s << osTypeToString (desc.componentType) << "," + << osTypeToString (desc.componentSubType) << "," + << osTypeToString (desc.componentManufacturer); + + return s; + } + + static void getAUDetails (ComponentRecord* comp, String& name, String& manufacturer) + { + Handle componentNameHandle = NewHandle (sizeof (void*)); + Handle componentInfoHandle = NewHandle (sizeof (void*)); + + if (componentNameHandle != 0 && componentInfoHandle != 0) { - desc.componentType = stringToOSType (tokens[0]); - desc.componentSubType = stringToOSType (tokens[1]); - desc.componentManufacturer = stringToOSType (tokens[2]); + ComponentDescription desc; - ComponentRecord* comp = FindNextComponent (0, &desc); - - if (comp != 0) + if (GetComponentInfo (comp, &desc, componentNameHandle, componentInfoHandle, 0) == noErr) { - getAUDetails (comp, name, manufacturer); + ConstStr255Param nameString = (ConstStr255Param) (*componentNameHandle); + ConstStr255Param infoString = (ConstStr255Param) (*componentInfoHandle); - return true; + if (nameString != 0 && nameString[0] != 0) + { + const String all ((const char*) nameString + 1, nameString[0]); + DBG ("name: "+ all); + + manufacturer = all.upToFirstOccurrenceOf (":", false, false).trim(); + name = all.fromFirstOccurrenceOf (":", false, false).trim(); + } + + if (infoString != 0 && infoString[0] != 0) + { + DBG ("info: " + String ((const char*) infoString + 1, infoString[0])); + } + + if (name.isEmpty()) + name = ""; } + + DisposeHandle (componentNameHandle); + DisposeHandle (componentInfoHandle); } } - return false; -} + static bool getComponentDescFromIdentifier (const String& fileOrIdentifier, ComponentDescription& desc, + String& name, String& version, String& manufacturer) + { + zerostruct (desc); + if (fileOrIdentifier.startsWithIgnoreCase (auIdentifierPrefix)) + { + String s (fileOrIdentifier.substring (jmax (fileOrIdentifier.lastIndexOfChar (':'), + fileOrIdentifier.lastIndexOfChar ('/')) + 1)); + + StringArray tokens; + tokens.addTokens (s, ",", String::empty); + tokens.trim(); + tokens.removeEmptyStrings(); + + if (tokens.size() == 3) + { + desc.componentType = stringToOSType (tokens[0]); + desc.componentSubType = stringToOSType (tokens[1]); + desc.componentManufacturer = stringToOSType (tokens[2]); + + ComponentRecord* comp = FindNextComponent (0, &desc); + + if (comp != 0) + { + getAUDetails (comp, name, manufacturer); + return true; + } + } + } + + return false; + } +} //============================================================================== class AudioUnitPluginWindowCarbon; @@ -205,7 +205,7 @@ public: void fillInPluginDescription (PluginDescription& desc) const { desc.name = pluginName; - desc.fileOrIdentifier = createAUPluginIdentifier (componentDesc); + desc.fileOrIdentifier = AudioUnitFormatHelpers::createAUPluginIdentifier (componentDesc); desc.uid = ((int) componentDesc.componentType) ^ ((int) componentDesc.componentSubType) ^ ((int) componentDesc.componentManufacturer); @@ -375,6 +375,8 @@ AudioUnitPluginInstance::AudioUnitPluginInstance (const String& fileOrIdentifier audioUnit (0), currentBuffer (0) { + using namespace AudioUnitFormatHelpers; + try { ++insideCallback; @@ -406,7 +408,7 @@ AudioUnitPluginInstance::~AudioUnitPluginInstance() { const ScopedLock sl (lock); - jassert (insideCallback == 0); + jassert (AudioUnitFormatHelpers::insideCallback == 0); if (audioUnit != 0) { @@ -420,7 +422,7 @@ bool AudioUnitPluginInstance::getComponentDescFromFile (const String& fileOrIden { zerostruct (componentDesc); - if (getComponentDescFromIdentifier (fileOrIdentifier, componentDesc, pluginName, version, manufacturer)) + if (AudioUnitFormatHelpers::getComponentDescFromIdentifier (fileOrIdentifier, componentDesc, pluginName, version, manufacturer)) return true; const File file (fileOrIdentifier); @@ -1469,7 +1471,7 @@ const StringArray AudioUnitPluginFormat::searchPathsForPlugins (const FileSearch || desc.componentType == kAudioUnitType_Generator || desc.componentType == kAudioUnitType_Panner) { - const String s (createAUPluginIdentifier (desc)); + const String s (AudioUnitFormatHelpers::createAUPluginIdentifier (desc)); DBG (s); result.add (s); } @@ -1483,7 +1485,7 @@ bool AudioUnitPluginFormat::fileMightContainThisPluginType (const String& fileOr ComponentDescription desc; String name, version, manufacturer; - if (getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer)) + if (AudioUnitFormatHelpers::getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer)) return FindNextComponent (0, &desc) != 0; const File f (fileOrIdentifier); @@ -1496,7 +1498,7 @@ const String AudioUnitPluginFormat::getNameOfPluginFromIdentifier (const String& { ComponentDescription desc; String name, version, manufacturer; - getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer); + AudioUnitFormatHelpers::getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer); if (name.isEmpty()) name = fileOrIdentifier; @@ -1506,7 +1508,7 @@ const String AudioUnitPluginFormat::getNameOfPluginFromIdentifier (const String& bool AudioUnitPluginFormat::doesPluginStillExist (const PluginDescription& desc) { - if (desc.fileOrIdentifier.startsWithIgnoreCase (auIdentifierPrefix)) + if (desc.fileOrIdentifier.startsWithIgnoreCase (AudioUnitFormatHelpers::auIdentifierPrefix)) return fileMightContainThisPluginType (desc.fileOrIdentifier); else return File (desc.fileOrIdentifier).exists(); diff --git a/src/containers/juce_MemoryBlock.cpp b/src/containers/juce_MemoryBlock.cpp index 96354a2b3a..273aa5540e 100644 --- a/src/containers/juce_MemoryBlock.cpp +++ b/src/containers/juce_MemoryBlock.cpp @@ -337,8 +337,7 @@ void MemoryBlock::loadFromHexString (const String& hex) throw() } //============================================================================== -static const char* const encodingTable - = ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+"; +const char* const MemoryBlock::encodingTable = ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+"; const String MemoryBlock::toBase64Encoding() const throw() { diff --git a/src/containers/juce_MemoryBlock.h b/src/containers/juce_MemoryBlock.h index b47686d583..02352ace2c 100644 --- a/src/containers/juce_MemoryBlock.h +++ b/src/containers/juce_MemoryBlock.h @@ -237,6 +237,7 @@ private: //============================================================================== HeapBlock data; size_t size; + static const char* const encodingTable; }; diff --git a/src/containers/juce_PropertySet.cpp b/src/containers/juce_PropertySet.cpp index 9bb7706d88..22690ccc88 100644 --- a/src/containers/juce_PropertySet.cpp +++ b/src/containers/juce_PropertySet.cpp @@ -27,7 +27,6 @@ BEGIN_JUCE_NAMESPACE - #include "juce_PropertySet.h" #include "../threads/juce_ScopedLock.h" #include "../text/juce_XmlDocument.h" diff --git a/src/core/juce_FileLogger.cpp b/src/core/juce_FileLogger.cpp index 7fbfc0f51c..4c7df6fe5e 100644 --- a/src/core/juce_FileLogger.cpp +++ b/src/core/juce_FileLogger.cpp @@ -27,7 +27,6 @@ BEGIN_JUCE_NAMESPACE - #include "juce_FileLogger.h" #include "../io/files/juce_FileOutputStream.h" #include "../io/files/juce_FileInputStream.h" diff --git a/src/core/juce_Logger.cpp b/src/core/juce_Logger.cpp index a88af5445e..dd04187112 100644 --- a/src/core/juce_Logger.cpp +++ b/src/core/juce_Logger.cpp @@ -40,7 +40,7 @@ Logger::~Logger() } //============================================================================== -static Logger* currentLogger = 0; +Logger* Logger::currentLogger = 0; void Logger::setCurrentLogger (Logger* const newLogger, const bool deleteOldLogger) diff --git a/src/core/juce_Logger.h b/src/core/juce_Logger.h index 00aae7df8f..42de422324 100644 --- a/src/core/juce_Logger.h +++ b/src/core/juce_Logger.h @@ -88,6 +88,9 @@ protected: @see setCurrentLogger */ virtual void logMessage (const String& message) = 0; + +private: + static Logger* currentLogger; }; diff --git a/src/core/juce_PerformanceCounter.cpp b/src/core/juce_PerformanceCounter.cpp index 7d46ce9e07..7f344becef 100644 --- a/src/core/juce_PerformanceCounter.cpp +++ b/src/core/juce_PerformanceCounter.cpp @@ -27,7 +27,6 @@ BEGIN_JUCE_NAMESPACE - #include "juce_PerformanceCounter.h" #include "juce_Time.h" diff --git a/src/core/juce_RelativeTime.cpp b/src/core/juce_RelativeTime.cpp index 3b1c8ae333..18d622ae52 100644 --- a/src/core/juce_RelativeTime.cpp +++ b/src/core/juce_RelativeTime.cpp @@ -27,7 +27,6 @@ BEGIN_JUCE_NAMESPACE - #include "juce_RelativeTime.h" #include "../text/juce_LocalisedStrings.h" diff --git a/src/core/juce_SystemStats.cpp b/src/core/juce_SystemStats.cpp index 8fe95ad214..a769802261 100644 --- a/src/core/juce_SystemStats.cpp +++ b/src/core/juce_SystemStats.cpp @@ -40,6 +40,8 @@ BEGIN_JUCE_NAMESPACE //============================================================================== +SystemStats::CPUFlags SystemStats::cpuFlags; + const String SystemStats::getJUCEVersion() { return "JUCE v" + String (JUCE_MAJOR_VERSION) @@ -121,6 +123,7 @@ static void juce_testAtomics() } #endif +//============================================================================== void JUCE_PUBLIC_FUNCTION initialiseJuce_NonGUI() { if (! juceInitialisedNonGUI) @@ -194,36 +197,35 @@ void JUCE_PUBLIC_FUNCTION initialiseJuce_NonGUI() } } +//============================================================================== #if JUCE_WINDOWS - // This is imported from the sockets code.. - typedef int (__stdcall juce_CloseWin32SocketLibCall) (void); - extern juce_CloseWin32SocketLibCall* juce_CloseWin32SocketLib; + extern void juce_shutdownWin32Sockets(); // (defined in the sockets code) #endif #if JUCE_DEBUG extern void juce_CheckForDanglingStreams(); #endif +//============================================================================== void JUCE_PUBLIC_FUNCTION shutdownJuce_NonGUI() { if (juceInitialisedNonGUI) { -#if JUCE_MAC || JUCE_IPHONE + #if JUCE_MAC || JUCE_IPHONE const ScopedAutoReleasePool pool; -#endif + #endif -#if JUCE_WINDOWS + #if JUCE_WINDOWS // need to shut down sockets if they were used.. - if (juce_CloseWin32SocketLib != 0) - (*juce_CloseWin32SocketLib)(); -#endif + juce_shutdownWin32Sockets(); + #endif LocalisedStrings::setCurrentMappings (0); Thread::stopAllThreads (3000); -#if JUCE_DEBUG + #if JUCE_DEBUG juce_CheckForDanglingStreams(); -#endif + #endif juceInitialisedNonGUI = false; } diff --git a/src/core/juce_SystemStats.h b/src/core/juce_SystemStats.h index bf2df96541..9318febae1 100644 --- a/src/core/juce_SystemStats.h +++ b/src/core/juce_SystemStats.h @@ -117,20 +117,20 @@ public: static const String getCpuVendor(); /** Checks whether Intel MMX instructions are available. */ - static bool hasMMX(); + static bool hasMMX() throw() { return cpuFlags.hasMMX; } /** Checks whether Intel SSE instructions are available. */ - static bool hasSSE(); + static bool hasSSE() throw() { return cpuFlags.hasSSE; } /** Checks whether Intel SSE2 instructions are available. */ - static bool hasSSE2(); + static bool hasSSE2() throw() { return cpuFlags.hasSSE2; } /** Checks whether AMD 3DNOW instructions are available. */ - static bool has3DNow(); + static bool has3DNow() throw() { return cpuFlags.has3DNow; } /** Returns the number of CPUs. */ - static int getNumCpus(); + static int getNumCpus() throw() { return cpuFlags.numCpus; } //============================================================================== /** Finds out how much RAM is in the machine. @@ -181,6 +181,17 @@ public: static void initialiseStats(); private: + struct CPUFlags + { + int numCpus; + bool hasMMX : 1; + bool hasSSE : 1; + bool hasSSE2 : 1; + bool has3DNow : 1; + }; + + static CPUFlags cpuFlags; + SystemStats(); SystemStats (const SystemStats&); SystemStats& operator= (const SystemStats&); diff --git a/src/cryptography/juce_MD5.cpp b/src/cryptography/juce_MD5.cpp index 2150d777ff..ad27bb6cf5 100644 --- a/src/cryptography/juce_MD5.cpp +++ b/src/cryptography/juce_MD5.cpp @@ -27,7 +27,6 @@ BEGIN_JUCE_NAMESPACE - #include "juce_MD5.h" #include "../io/files/juce_FileInputStream.h" #include "../containers/juce_ScopedPointer.h" diff --git a/src/cryptography/juce_Primes.cpp b/src/cryptography/juce_Primes.cpp index bc7d406b63..440a48d6e3 100644 --- a/src/cryptography/juce_Primes.cpp +++ b/src/cryptography/juce_Primes.cpp @@ -27,7 +27,6 @@ BEGIN_JUCE_NAMESPACE - #include "juce_Primes.h" #include "../core/juce_Random.h" diff --git a/src/cryptography/juce_RSAKey.cpp b/src/cryptography/juce_RSAKey.cpp index 838a7c1e5f..22beb89ab3 100644 --- a/src/cryptography/juce_RSAKey.cpp +++ b/src/cryptography/juce_RSAKey.cpp @@ -27,7 +27,6 @@ BEGIN_JUCE_NAMESPACE - #include "juce_RSAKey.h" #include "juce_Primes.h" @@ -97,7 +96,7 @@ bool RSAKey::applyToValue (BigInteger& value) const return true; } -static const BigInteger findBestCommonDivisor (const BigInteger& p, const BigInteger& q) +const BigInteger RSAKey::findBestCommonDivisor (const BigInteger& p, const BigInteger& q) { // try 3, 5, 9, 17, etc first because these only contain 2 bits and so // are fast to divide + multiply diff --git a/src/cryptography/juce_RSAKey.h b/src/cryptography/juce_RSAKey.h index a4de37613b..3539dce6bd 100644 --- a/src/cryptography/juce_RSAKey.h +++ b/src/cryptography/juce_RSAKey.h @@ -106,6 +106,9 @@ public: protected: BigInteger part1, part2; + +private: + static const BigInteger findBestCommonDivisor (const BigInteger& p, const BigInteger& q); }; diff --git a/src/gui/components/code_editor/juce_CPlusPlusCodeTokeniser.cpp b/src/gui/components/code_editor/juce_CPlusPlusCodeTokeniser.cpp index e6440b9c85..28220d050d 100644 --- a/src/gui/components/code_editor/juce_CPlusPlusCodeTokeniser.cpp +++ b/src/gui/components/code_editor/juce_CPlusPlusCodeTokeniser.cpp @@ -42,299 +42,297 @@ CPlusPlusCodeTokeniser::~CPlusPlusCodeTokeniser() //============================================================================== namespace CppTokeniser { - -static bool isIdentifierStart (const juce_wchar c) throw() -{ - return CharacterFunctions::isLetter (c) - || c == '_' || c == '@'; -} - -static bool isIdentifierBody (const juce_wchar c) throw() -{ - return CharacterFunctions::isLetterOrDigit (c) - || c == '_' || c == '@'; -} - -static bool isReservedKeyword (const juce_wchar* const token, const int tokenLength) throw() -{ - static const juce_wchar* const keywords2Char[] = - { JUCE_T("if"), JUCE_T("do"), JUCE_T("or"), JUCE_T("id"), 0 }; - - static const juce_wchar* const keywords3Char[] = - { JUCE_T("for"), JUCE_T("int"), JUCE_T("new"), JUCE_T("try"), JUCE_T("xor"), JUCE_T("and"), JUCE_T("asm"), JUCE_T("not"), 0 }; - - static const juce_wchar* const keywords4Char[] = - { JUCE_T("bool"), JUCE_T("void"), JUCE_T("this"), JUCE_T("true"), JUCE_T("long"), JUCE_T("else"), JUCE_T("char"), - JUCE_T("enum"), JUCE_T("case"), JUCE_T("goto"), JUCE_T("auto"), 0 }; - - static const juce_wchar* const keywords5Char[] = - { JUCE_T("while"), JUCE_T("bitor"), JUCE_T("break"), JUCE_T("catch"), JUCE_T("class"), JUCE_T("compl"), JUCE_T("const"), JUCE_T("false"), - JUCE_T("float"), JUCE_T("short"), JUCE_T("throw"), JUCE_T("union"), JUCE_T("using"), JUCE_T("or_eq"), 0 }; - - static const juce_wchar* const keywords6Char[] = - { JUCE_T("return"), JUCE_T("struct"), JUCE_T("and_eq"), JUCE_T("bitand"), JUCE_T("delete"), JUCE_T("double"), JUCE_T("extern"), - JUCE_T("friend"), JUCE_T("inline"), JUCE_T("not_eq"), JUCE_T("public"), JUCE_T("sizeof"), JUCE_T("static"), JUCE_T("signed"), - JUCE_T("switch"), JUCE_T("typeid"), JUCE_T("wchar_t"), JUCE_T("xor_eq"), 0}; - - static const juce_wchar* const keywordsOther[] = - { JUCE_T("const_cast"), JUCE_T("continue"), JUCE_T("default"), JUCE_T("explicit"), JUCE_T("mutable"), JUCE_T("namespace"), - JUCE_T("operator"), JUCE_T("private"), JUCE_T("protected"), JUCE_T("register"), JUCE_T("reinterpret_cast"), JUCE_T("static_cast"), - JUCE_T("template"), JUCE_T("typedef"), JUCE_T("typename"), JUCE_T("unsigned"), JUCE_T("virtual"), JUCE_T("volatile"), - JUCE_T("@implementation"), JUCE_T("@interface"), JUCE_T("@end"), JUCE_T("@synthesize"), JUCE_T("@dynamic"), JUCE_T("@public"), - JUCE_T("@private"), JUCE_T("@property"), JUCE_T("@protected"), JUCE_T("@class"), 0 }; - - const juce_wchar* const* k; - - switch (tokenLength) + static bool isIdentifierStart (const juce_wchar c) throw() { - case 2: k = keywords2Char; break; - case 3: k = keywords3Char; break; - case 4: k = keywords4Char; break; - case 5: k = keywords5Char; break; - case 6: k = keywords6Char; break; - - default: - if (tokenLength < 2 || tokenLength > 16) - return false; - - k = keywordsOther; - break; + return CharacterFunctions::isLetter (c) + || c == '_' || c == '@'; } - int i = 0; - while (k[i] != 0) + static bool isIdentifierBody (const juce_wchar c) throw() { - if (k[i][0] == token[0] && CharacterFunctions::compare (k[i], token) == 0) - return true; - - ++i; + return CharacterFunctions::isLetterOrDigit (c) + || c == '_' || c == '@'; } - return false; -} - -static int parseIdentifier (CodeDocument::Iterator& source) throw() -{ - int tokenLength = 0; - juce_wchar possibleIdentifier [19]; - - while (isIdentifierBody (source.peekNextChar())) + static bool isReservedKeyword (const juce_wchar* const token, const int tokenLength) throw() { - const juce_wchar c = source.nextChar(); + static const juce_wchar* const keywords2Char[] = + { JUCE_T("if"), JUCE_T("do"), JUCE_T("or"), JUCE_T("id"), 0 }; - if (tokenLength < numElementsInArray (possibleIdentifier) - 1) - possibleIdentifier [tokenLength] = c; + static const juce_wchar* const keywords3Char[] = + { JUCE_T("for"), JUCE_T("int"), JUCE_T("new"), JUCE_T("try"), JUCE_T("xor"), JUCE_T("and"), JUCE_T("asm"), JUCE_T("not"), 0 }; - ++tokenLength; - } + static const juce_wchar* const keywords4Char[] = + { JUCE_T("bool"), JUCE_T("void"), JUCE_T("this"), JUCE_T("true"), JUCE_T("long"), JUCE_T("else"), JUCE_T("char"), + JUCE_T("enum"), JUCE_T("case"), JUCE_T("goto"), JUCE_T("auto"), 0 }; - if (tokenLength > 1 && tokenLength <= 16) - { - possibleIdentifier [tokenLength] = 0; + static const juce_wchar* const keywords5Char[] = + { JUCE_T("while"), JUCE_T("bitor"), JUCE_T("break"), JUCE_T("catch"), JUCE_T("class"), JUCE_T("compl"), JUCE_T("const"), JUCE_T("false"), + JUCE_T("float"), JUCE_T("short"), JUCE_T("throw"), JUCE_T("union"), JUCE_T("using"), JUCE_T("or_eq"), 0 }; - if (isReservedKeyword (possibleIdentifier, tokenLength)) - return CPlusPlusCodeTokeniser::tokenType_builtInKeyword; - } + static const juce_wchar* const keywords6Char[] = + { JUCE_T("return"), JUCE_T("struct"), JUCE_T("and_eq"), JUCE_T("bitand"), JUCE_T("delete"), JUCE_T("double"), JUCE_T("extern"), + JUCE_T("friend"), JUCE_T("inline"), JUCE_T("not_eq"), JUCE_T("public"), JUCE_T("sizeof"), JUCE_T("static"), JUCE_T("signed"), + JUCE_T("switch"), JUCE_T("typeid"), JUCE_T("wchar_t"), JUCE_T("xor_eq"), 0}; - return CPlusPlusCodeTokeniser::tokenType_identifier; -} + static const juce_wchar* const keywordsOther[] = + { JUCE_T("const_cast"), JUCE_T("continue"), JUCE_T("default"), JUCE_T("explicit"), JUCE_T("mutable"), JUCE_T("namespace"), + JUCE_T("operator"), JUCE_T("private"), JUCE_T("protected"), JUCE_T("register"), JUCE_T("reinterpret_cast"), JUCE_T("static_cast"), + JUCE_T("template"), JUCE_T("typedef"), JUCE_T("typename"), JUCE_T("unsigned"), JUCE_T("virtual"), JUCE_T("volatile"), + JUCE_T("@implementation"), JUCE_T("@interface"), JUCE_T("@end"), JUCE_T("@synthesize"), JUCE_T("@dynamic"), JUCE_T("@public"), + JUCE_T("@private"), JUCE_T("@property"), JUCE_T("@protected"), JUCE_T("@class"), 0 }; -static bool skipNumberSuffix (CodeDocument::Iterator& source) -{ - const juce_wchar c = source.peekNextChar(); - if (c == 'l' || c == 'L' || c == 'u' || c == 'U') - source.skip(); + const juce_wchar* const* k; + + switch (tokenLength) + { + case 2: k = keywords2Char; break; + case 3: k = keywords3Char; break; + case 4: k = keywords4Char; break; + case 5: k = keywords5Char; break; + case 6: k = keywords6Char; break; + + default: + if (tokenLength < 2 || tokenLength > 16) + return false; + + k = keywordsOther; + break; + } + + int i = 0; + while (k[i] != 0) + { + if (k[i][0] == token[0] && CharacterFunctions::compare (k[i], token) == 0) + return true; + + ++i; + } - if (CharacterFunctions::isLetterOrDigit (source.peekNextChar())) return false; - - return true; -} - -static bool isHexDigit (const juce_wchar c) throw() -{ - return (c >= '0' && c <= '9') - || (c >= 'a' && c <= 'f') - || (c >= 'A' && c <= 'F'); -} - -static bool parseHexLiteral (CodeDocument::Iterator& source) throw() -{ - if (source.nextChar() != '0') - return false; - - juce_wchar c = source.nextChar(); - if (c != 'x' && c != 'X') - return false; - - int numDigits = 0; - while (isHexDigit (source.peekNextChar())) - { - ++numDigits; - source.skip(); } - if (numDigits == 0) - return false; - - return skipNumberSuffix (source); -} - -static bool isOctalDigit (const juce_wchar c) throw() -{ - return c >= '0' && c <= '7'; -} - -static bool parseOctalLiteral (CodeDocument::Iterator& source) throw() -{ - if (source.nextChar() != '0') - return false; - - if (! isOctalDigit (source.nextChar())) - return false; - - while (isOctalDigit (source.peekNextChar())) - source.skip(); - - return skipNumberSuffix (source); -} - -static bool isDecimalDigit (const juce_wchar c) throw() -{ - return c >= '0' && c <= '9'; -} - -static bool parseDecimalLiteral (CodeDocument::Iterator& source) throw() -{ - int numChars = 0; - while (isDecimalDigit (source.peekNextChar())) + static int parseIdentifier (CodeDocument::Iterator& source) throw() { - ++numChars; - source.skip(); + int tokenLength = 0; + juce_wchar possibleIdentifier [19]; + + while (isIdentifierBody (source.peekNextChar())) + { + const juce_wchar c = source.nextChar(); + + if (tokenLength < numElementsInArray (possibleIdentifier) - 1) + possibleIdentifier [tokenLength] = c; + + ++tokenLength; + } + + if (tokenLength > 1 && tokenLength <= 16) + { + possibleIdentifier [tokenLength] = 0; + + if (isReservedKeyword (possibleIdentifier, tokenLength)) + return CPlusPlusCodeTokeniser::tokenType_builtInKeyword; + } + + return CPlusPlusCodeTokeniser::tokenType_identifier; } - if (numChars == 0) - return false; - - return skipNumberSuffix (source); -} - -static bool parseFloatLiteral (CodeDocument::Iterator& source) throw() -{ - int numDigits = 0; - - while (isDecimalDigit (source.peekNextChar())) + static bool skipNumberSuffix (CodeDocument::Iterator& source) { - source.skip(); - ++numDigits; + const juce_wchar c = source.peekNextChar(); + if (c == 'l' || c == 'L' || c == 'u' || c == 'U') + source.skip(); + + if (CharacterFunctions::isLetterOrDigit (source.peekNextChar())) + return false; + + return true; } - const bool hasPoint = (source.peekNextChar() == '.'); - - if (hasPoint) + static bool isHexDigit (const juce_wchar c) throw() { - source.skip(); + return (c >= '0' && c <= '9') + || (c >= 'a' && c <= 'f') + || (c >= 'A' && c <= 'F'); + } + + static bool parseHexLiteral (CodeDocument::Iterator& source) throw() + { + if (source.nextChar() != '0') + return false; + + juce_wchar c = source.nextChar(); + if (c != 'x' && c != 'X') + return false; + + int numDigits = 0; + while (isHexDigit (source.peekNextChar())) + { + ++numDigits; + source.skip(); + } + + if (numDigits == 0) + return false; + + return skipNumberSuffix (source); + } + + static bool isOctalDigit (const juce_wchar c) throw() + { + return c >= '0' && c <= '7'; + } + + static bool parseOctalLiteral (CodeDocument::Iterator& source) throw() + { + if (source.nextChar() != '0') + return false; + + if (! isOctalDigit (source.nextChar())) + return false; + + while (isOctalDigit (source.peekNextChar())) + source.skip(); + + return skipNumberSuffix (source); + } + + static bool isDecimalDigit (const juce_wchar c) throw() + { + return c >= '0' && c <= '9'; + } + + static bool parseDecimalLiteral (CodeDocument::Iterator& source) throw() + { + int numChars = 0; + while (isDecimalDigit (source.peekNextChar())) + { + ++numChars; + source.skip(); + } + + if (numChars == 0) + return false; + + return skipNumberSuffix (source); + } + + static bool parseFloatLiteral (CodeDocument::Iterator& source) throw() + { + int numDigits = 0; while (isDecimalDigit (source.peekNextChar())) { source.skip(); ++numDigits; } - } - if (numDigits == 0) - return false; + const bool hasPoint = (source.peekNextChar() == '.'); - juce_wchar c = source.peekNextChar(); - const bool hasExponent = (c == 'e' || c == 'E'); - - if (hasExponent) - { - source.skip(); - - c = source.peekNextChar(); - if (c == '+' || c == '-') - source.skip(); - - int numExpDigits = 0; - while (isDecimalDigit (source.peekNextChar())) + if (hasPoint) { source.skip(); - ++numExpDigits; + + while (isDecimalDigit (source.peekNextChar())) + { + source.skip(); + ++numDigits; + } } - if (numExpDigits == 0) + if (numDigits == 0) return false; - } - c = source.peekNextChar(); - if (c == 'f' || c == 'F') - source.skip(); - else if (! (hasExponent || hasPoint)) - return false; + juce_wchar c = source.peekNextChar(); + const bool hasExponent = (c == 'e' || c == 'E'); - return true; -} - -static int parseNumber (CodeDocument::Iterator& source) -{ - const CodeDocument::Iterator original (source); - - if (parseFloatLiteral (source)) - return CPlusPlusCodeTokeniser::tokenType_floatLiteral; - - source = original; - - if (parseHexLiteral (source)) - return CPlusPlusCodeTokeniser::tokenType_integerLiteral; - - source = original; - - if (parseOctalLiteral (source)) - return CPlusPlusCodeTokeniser::tokenType_integerLiteral; - - source = original; - - if (parseDecimalLiteral (source)) - return CPlusPlusCodeTokeniser::tokenType_integerLiteral; - - source = original; - source.skip(); - - return CPlusPlusCodeTokeniser::tokenType_error; -} - -static void skipQuotedString (CodeDocument::Iterator& source) throw() -{ - const juce_wchar quote = source.nextChar(); - - for (;;) - { - const juce_wchar c = source.nextChar(); - - if (c == quote || c == 0) - break; - - if (c == '\\') + if (hasExponent) + { source.skip(); + + c = source.peekNextChar(); + if (c == '+' || c == '-') + source.skip(); + + int numExpDigits = 0; + while (isDecimalDigit (source.peekNextChar())) + { + source.skip(); + ++numExpDigits; + } + + if (numExpDigits == 0) + return false; + } + + c = source.peekNextChar(); + if (c == 'f' || c == 'F') + source.skip(); + else if (! (hasExponent || hasPoint)) + return false; + + return true; } -} -static void skipComment (CodeDocument::Iterator& source) throw() -{ - bool lastWasStar = false; - - for (;;) + static int parseNumber (CodeDocument::Iterator& source) { - const juce_wchar c = source.nextChar(); + const CodeDocument::Iterator original (source); - if (c == 0 || (c == '/' && lastWasStar)) - break; + if (parseFloatLiteral (source)) + return CPlusPlusCodeTokeniser::tokenType_floatLiteral; - lastWasStar = (c == '*'); + source = original; + + if (parseHexLiteral (source)) + return CPlusPlusCodeTokeniser::tokenType_integerLiteral; + + source = original; + + if (parseOctalLiteral (source)) + return CPlusPlusCodeTokeniser::tokenType_integerLiteral; + + source = original; + + if (parseDecimalLiteral (source)) + return CPlusPlusCodeTokeniser::tokenType_integerLiteral; + + source = original; + source.skip(); + + return CPlusPlusCodeTokeniser::tokenType_error; } -} + static void skipQuotedString (CodeDocument::Iterator& source) throw() + { + const juce_wchar quote = source.nextChar(); + + for (;;) + { + const juce_wchar c = source.nextChar(); + + if (c == quote || c == 0) + break; + + if (c == '\\') + source.skip(); + } + } + + static void skipComment (CodeDocument::Iterator& source) throw() + { + bool lastWasStar = false; + + for (;;) + { + const juce_wchar c = source.nextChar(); + + if (c == 0 || (c == '/' && lastWasStar)) + break; + + lastWasStar = (c == '*'); + } + } } //============================================================================== diff --git a/src/gui/components/juce_Desktop.cpp b/src/gui/components/juce_Desktop.cpp index a43d7676a4..daa8eaaa47 100644 --- a/src/gui/components/juce_Desktop.cpp +++ b/src/gui/components/juce_Desktop.cpp @@ -27,7 +27,6 @@ BEGIN_JUCE_NAMESPACE - #include "juce_Desktop.h" #include "windows/juce_ComponentPeer.h" #include "mouse/juce_MouseInputSource.h" diff --git a/src/gui/components/mouse/juce_MouseEvent.cpp b/src/gui/components/mouse/juce_MouseEvent.cpp index 8234263166..ec13b0a1e3 100644 --- a/src/gui/components/mouse/juce_MouseEvent.cpp +++ b/src/gui/components/mouse/juce_MouseEvent.cpp @@ -168,7 +168,7 @@ const Point MouseEvent::getMouseDownScreenPosition() const } //============================================================================== -static int doubleClickTimeOutMs = 400; +int MouseEvent::doubleClickTimeOutMs = 400; void MouseEvent::setDoubleClickTimeout (const int newTime) throw() { diff --git a/src/gui/components/mouse/juce_MouseEvent.h b/src/gui/components/mouse/juce_MouseEvent.h index 75796bd5ad..1644650b30 100644 --- a/src/gui/components/mouse/juce_MouseEvent.h +++ b/src/gui/components/mouse/juce_MouseEvent.h @@ -320,6 +320,7 @@ private: const Time mouseDownTime; const int numberOfClicks; const bool wasMovedSinceMouseDown; + static int doubleClickTimeOutMs; MouseEvent& operator= (const MouseEvent&); }; diff --git a/src/gui/components/special/juce_ColourSelector.cpp b/src/gui/components/special/juce_ColourSelector.cpp index 47e3ed0970..155574a2b2 100644 --- a/src/gui/components/special/juce_ColourSelector.cpp +++ b/src/gui/components/special/juce_ColourSelector.cpp @@ -33,8 +33,6 @@ BEGIN_JUCE_NAMESPACE #include "../../graphics/imaging/juce_Image.h" #include "../../../text/juce_LocalisedStrings.h" -static const int swatchesPerRow = 8; -static const int swatchHeight = 22; //============================================================================== class ColourComponentSlider : public Slider @@ -515,6 +513,9 @@ void ColourSelector::paint (Graphics& g) void ColourSelector::resized() { + const int swatchesPerRow = 8; + const int swatchHeight = 22; + const int numSliders = ((flags & showAlphaChannel) != 0) ? 4 : 3; const int numSwatches = getNumSwatches(); diff --git a/src/gui/components/special/juce_MidiKeyboardComponent.cpp b/src/gui/components/special/juce_MidiKeyboardComponent.cpp index d459b0003c..ba204e9e95 100644 --- a/src/gui/components/special/juce_MidiKeyboardComponent.cpp +++ b/src/gui/components/special/juce_MidiKeyboardComponent.cpp @@ -248,8 +248,8 @@ int MidiKeyboardComponent::getKeyStartPosition (const int midiNoteNumber) const return x; } -static const uint8 whiteNotes[] = { 0, 2, 4, 5, 7, 9, 11 }; -static const uint8 blackNotes[] = { 1, 3, 6, 8, 10 }; +const uint8 MidiKeyboardComponent::whiteNotes[] = { 0, 2, 4, 5, 7, 9, 11 }; +const uint8 MidiKeyboardComponent::blackNotes[] = { 1, 3, 6, 8, 10 }; int MidiKeyboardComponent::xyToNote (const Point& pos, float& mousePositionVelocity) { diff --git a/src/gui/components/special/juce_MidiKeyboardComponent.h b/src/gui/components/special/juce_MidiKeyboardComponent.h index f2705d4c9f..f27bb47555 100644 --- a/src/gui/components/special/juce_MidiKeyboardComponent.h +++ b/src/gui/components/special/juce_MidiKeyboardComponent.h @@ -404,6 +404,9 @@ private: int keyMappingOctave; int octaveNumForMiddleC; + static const uint8 whiteNotes[]; + static const uint8 blackNotes[]; + void getKeyPos (int midiNoteNumber, int& x, int& w) const; int xyToNote (const Point& pos, float& mousePositionVelocity); int remappedXYToNote (const Point& pos, float& mousePositionVelocity) const; diff --git a/src/gui/components/windows/juce_DocumentWindow.cpp b/src/gui/components/windows/juce_DocumentWindow.cpp index c7c7dd1f69..dcabb69dd4 100644 --- a/src/gui/components/windows/juce_DocumentWindow.cpp +++ b/src/gui/components/windows/juce_DocumentWindow.cpp @@ -27,7 +27,6 @@ BEGIN_JUCE_NAMESPACE - #include "juce_DocumentWindow.h" #include "juce_ComponentPeer.h" #include "../lookandfeel/juce_LookAndFeel.h" diff --git a/src/gui/components/windows/juce_ResizableWindow.cpp b/src/gui/components/windows/juce_ResizableWindow.cpp index 9d665928dc..544f3dbbc5 100644 --- a/src/gui/components/windows/juce_ResizableWindow.cpp +++ b/src/gui/components/windows/juce_ResizableWindow.cpp @@ -27,7 +27,6 @@ BEGIN_JUCE_NAMESPACE - #include "juce_ResizableWindow.h" #include "juce_ComponentPeer.h" #include "../juce_Desktop.h" diff --git a/src/gui/components/windows/juce_ThreadWithProgressWindow.cpp b/src/gui/components/windows/juce_ThreadWithProgressWindow.cpp index c4f464cf15..f65523f5c1 100644 --- a/src/gui/components/windows/juce_ThreadWithProgressWindow.cpp +++ b/src/gui/components/windows/juce_ThreadWithProgressWindow.cpp @@ -27,7 +27,6 @@ BEGIN_JUCE_NAMESPACE - #include "juce_ThreadWithProgressWindow.h" #include "../lookandfeel/juce_LookAndFeel.h" #include "../../../text/juce_LocalisedStrings.h" diff --git a/src/gui/components/windows/juce_TooltipWindow.cpp b/src/gui/components/windows/juce_TooltipWindow.cpp index 3b6163150d..180df52690 100644 --- a/src/gui/components/windows/juce_TooltipWindow.cpp +++ b/src/gui/components/windows/juce_TooltipWindow.cpp @@ -27,7 +27,6 @@ BEGIN_JUCE_NAMESPACE - #include "juce_TooltipWindow.h" #include "../windows/juce_ComponentPeer.h" #include "../../../core/juce_Time.h" diff --git a/src/gui/components/windows/juce_TopLevelWindow.cpp b/src/gui/components/windows/juce_TopLevelWindow.cpp index e4e5fff6a1..90320ebae6 100644 --- a/src/gui/components/windows/juce_TopLevelWindow.cpp +++ b/src/gui/components/windows/juce_TopLevelWindow.cpp @@ -27,7 +27,6 @@ BEGIN_JUCE_NAMESPACE - #include "juce_TopLevelWindow.h" #include "../windows/juce_ComponentPeer.h" #include "../juce_Desktop.h" diff --git a/src/gui/graphics/colour/juce_Colours.cpp b/src/gui/graphics/colour/juce_Colours.cpp index 7247699d6e..024eb44dd9 100644 --- a/src/gui/graphics/colour/juce_Colours.cpp +++ b/src/gui/graphics/colour/juce_Colours.cpp @@ -27,7 +27,6 @@ BEGIN_JUCE_NAMESPACE - #include "juce_Colours.h" diff --git a/src/gui/graphics/contexts/juce_Graphics.cpp b/src/gui/graphics/contexts/juce_Graphics.cpp index 5feee7a68a..6b10452102 100644 --- a/src/gui/graphics/contexts/juce_Graphics.cpp +++ b/src/gui/graphics/contexts/juce_Graphics.cpp @@ -33,8 +33,6 @@ BEGIN_JUCE_NAMESPACE #include "juce_LowLevelGraphicsContext.h" -static const Graphics::ResamplingQuality defaultQuality = Graphics::mediumResamplingQuality; - //============================================================================== template static bool areCoordsSensibleNumbers (Type x, Type y, Type w, Type h) @@ -80,7 +78,7 @@ void Graphics::resetToDefaultState() saveStateIfPending(); context->setFill (FillType()); context->setFont (Font()); - context->setInterpolationQuality (defaultQuality); + context->setInterpolationQuality (Graphics::mediumResamplingQuality); } bool Graphics::isVectorDevice() const diff --git a/src/gui/graphics/contexts/juce_Justification.cpp b/src/gui/graphics/contexts/juce_Justification.cpp index e6c31ed728..c4f15ad787 100644 --- a/src/gui/graphics/contexts/juce_Justification.cpp +++ b/src/gui/graphics/contexts/juce_Justification.cpp @@ -27,7 +27,6 @@ BEGIN_JUCE_NAMESPACE - #include "juce_Justification.h" diff --git a/src/gui/graphics/effects/juce_ReduceOpacityEffect.cpp b/src/gui/graphics/effects/juce_ReduceOpacityEffect.cpp index 670ad43569..e67612a89b 100644 --- a/src/gui/graphics/effects/juce_ReduceOpacityEffect.cpp +++ b/src/gui/graphics/effects/juce_ReduceOpacityEffect.cpp @@ -27,7 +27,6 @@ BEGIN_JUCE_NAMESPACE - #include "juce_ReduceOpacityEffect.h" diff --git a/src/gui/graphics/geometry/juce_AffineTransform.cpp b/src/gui/graphics/geometry/juce_AffineTransform.cpp index f1830a417e..d6cf64398f 100644 --- a/src/gui/graphics/geometry/juce_AffineTransform.cpp +++ b/src/gui/graphics/geometry/juce_AffineTransform.cpp @@ -27,7 +27,6 @@ BEGIN_JUCE_NAMESPACE - #include "juce_AffineTransform.h" diff --git a/src/gui/graphics/geometry/juce_Path.cpp b/src/gui/graphics/geometry/juce_Path.cpp index 37804cf925..972edbc031 100644 --- a/src/gui/graphics/geometry/juce_Path.cpp +++ b/src/gui/graphics/geometry/juce_Path.cpp @@ -27,13 +27,13 @@ BEGIN_JUCE_NAMESPACE - #include "juce_PathIterator.h" #include "juce_Line.h" #include "../../../io/streams/juce_MemoryInputStream.h" #include "../../../io/streams/juce_MemoryOutputStream.h" #include "../imaging/juce_Image.h" + // tests that some co-ords aren't NaNs #define CHECK_COORDS_ARE_VALID(x, y) \ jassert (x == x && y == y); diff --git a/src/gui/graphics/geometry/juce_PathIterator.cpp b/src/gui/graphics/geometry/juce_PathIterator.cpp index 08d3193311..a276c25d52 100644 --- a/src/gui/graphics/geometry/juce_PathIterator.cpp +++ b/src/gui/graphics/geometry/juce_PathIterator.cpp @@ -27,7 +27,6 @@ BEGIN_JUCE_NAMESPACE - #include "juce_PathIterator.h" #if JUCE_MSVC && JUCE_DEBUG diff --git a/src/gui/graphics/geometry/juce_PathStrokeType.cpp b/src/gui/graphics/geometry/juce_PathStrokeType.cpp index 789c7c5331..76753f0213 100644 --- a/src/gui/graphics/geometry/juce_PathStrokeType.cpp +++ b/src/gui/graphics/geometry/juce_PathStrokeType.cpp @@ -27,7 +27,6 @@ BEGIN_JUCE_NAMESPACE - #include "juce_PathStrokeType.h" #include "juce_PathIterator.h" diff --git a/src/gui/graphics/imaging/image_file_formats/juce_GIFLoader.cpp b/src/gui/graphics/imaging/image_file_formats/juce_GIFLoader.cpp index 086842dcc9..3dc5b50498 100644 --- a/src/gui/graphics/imaging/image_file_formats/juce_GIFLoader.cpp +++ b/src/gui/graphics/imaging/image_file_formats/juce_GIFLoader.cpp @@ -27,7 +27,6 @@ BEGIN_JUCE_NAMESPACE - #include "juce_GIFLoader.h" #include "../../colour/juce_PixelFormats.h" diff --git a/src/gui/graphics/imaging/juce_Image.cpp b/src/gui/graphics/imaging/juce_Image.cpp index e84081081c..59ed38fdd8 100644 --- a/src/gui/graphics/imaging/juce_Image.cpp +++ b/src/gui/graphics/imaging/juce_Image.cpp @@ -27,14 +27,12 @@ BEGIN_JUCE_NAMESPACE - #include "juce_Image.h" #include "../contexts/juce_Graphics.h" #include "../contexts/juce_LowLevelGraphicsSoftwareRenderer.h" #include "../colour/juce_PixelFormats.h" #include "../../../containers/juce_SparseSet.h" -static const int fullAlphaThreshold = 253; //============================================================================== Image::SharedImage::SharedImage (const PixelFormat format_, const int width_, const int height_) diff --git a/src/io/files/juce_FileSearchPath.cpp b/src/io/files/juce_FileSearchPath.cpp index 471986b945..0c390bc9d1 100644 --- a/src/io/files/juce_FileSearchPath.cpp +++ b/src/io/files/juce_FileSearchPath.cpp @@ -27,7 +27,6 @@ BEGIN_JUCE_NAMESPACE - #include "juce_FileSearchPath.h" diff --git a/src/io/files/juce_ZipFile.cpp b/src/io/files/juce_ZipFile.cpp index 1901e03979..2fee334c04 100644 --- a/src/io/files/juce_ZipFile.cpp +++ b/src/io/files/juce_ZipFile.cpp @@ -27,7 +27,6 @@ BEGIN_JUCE_NAMESPACE - #include "juce_ZipFile.h" #include "../streams/juce_GZIPDecompressorInputStream.h" #include "../streams/juce_BufferedInputStream.h" @@ -36,6 +35,7 @@ BEGIN_JUCE_NAMESPACE #include "juce_FileOutputStream.h" #include "../../threads/juce_ScopedLock.h" + //============================================================================== class ZipFile::ZipEntryInfo { diff --git a/src/io/network/juce_Socket.cpp b/src/io/network/juce_Socket.cpp index 9d1fd6f966..45abe249c0 100644 --- a/src/io/network/juce_Socket.cpp +++ b/src/io/network/juce_Socket.cpp @@ -68,236 +68,248 @@ BEGIN_JUCE_NAMESPACE //============================================================================== #if JUCE_WINDOWS -typedef int (__stdcall juce_CloseWin32SocketLibCall) (void); -juce_CloseWin32SocketLibCall* juce_CloseWin32SocketLib = 0; +namespace SocketHelpers +{ + typedef int (__stdcall juce_CloseWin32SocketLibCall) (void); + static juce_CloseWin32SocketLibCall* juce_CloseWin32SocketLib = 0; +} static void initWin32Sockets() { static CriticalSection lock; const ScopedLock sl (lock); - if (juce_CloseWin32SocketLib == 0) + if (SocketHelpers::juce_CloseWin32SocketLib == 0) { WSADATA wsaData; const WORD wVersionRequested = MAKEWORD (1, 1); WSAStartup (wVersionRequested, &wsaData); - juce_CloseWin32SocketLib = &WSACleanup; + SocketHelpers::juce_CloseWin32SocketLib = &WSACleanup; } } +void juce_shutdownWin32Sockets() +{ + if (SocketHelpers::juce_CloseWin32SocketLib != 0) + (*SocketHelpers::juce_CloseWin32SocketLib)(); +} + #endif //============================================================================== -static bool resetSocketOptions (const int handle, const bool isDatagram, const bool allowBroadcast) throw() +namespace SocketHelpers { - const int sndBufSize = 65536; - const int rcvBufSize = 65536; - const int one = 1; - - return handle > 0 - && setsockopt (handle, SOL_SOCKET, SO_RCVBUF, (const char*) &rcvBufSize, sizeof (rcvBufSize)) == 0 - && setsockopt (handle, SOL_SOCKET, SO_SNDBUF, (const char*) &sndBufSize, sizeof (sndBufSize)) == 0 - && (isDatagram ? ((! allowBroadcast) || setsockopt (handle, SOL_SOCKET, SO_BROADCAST, (const char*) &one, sizeof (one)) == 0) - : (setsockopt (handle, IPPROTO_TCP, TCP_NODELAY, (const char*) &one, sizeof (one)) == 0)); -} - -static bool bindSocketToPort (const int handle, const int port) throw() -{ - if (handle <= 0 || port <= 0) - return false; - - struct sockaddr_in servTmpAddr; - zerostruct (servTmpAddr); - servTmpAddr.sin_family = PF_INET; - servTmpAddr.sin_addr.s_addr = htonl (INADDR_ANY); - servTmpAddr.sin_port = htons ((uint16) port); - - return bind (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)) >= 0; -} - -static int readSocket (const int handle, - void* const destBuffer, const int maxBytesToRead, - bool volatile& connected, - const bool blockUntilSpecifiedAmountHasArrived) throw() -{ - int bytesRead = 0; - - while (bytesRead < maxBytesToRead) + static bool resetSocketOptions (const int handle, const bool isDatagram, const bool allowBroadcast) throw() { - int bytesThisTime; + const int sndBufSize = 65536; + const int rcvBufSize = 65536; + const int one = 1; -#if JUCE_WINDOWS - bytesThisTime = recv (handle, ((char*) destBuffer) + bytesRead, maxBytesToRead - bytesRead, 0); -#else - while ((bytesThisTime = (int) ::read (handle, ((char*) destBuffer) + bytesRead, maxBytesToRead - bytesRead)) < 0 - && errno == EINTR - && connected) - { - } -#endif - - if (bytesThisTime <= 0 || ! connected) - { - if (bytesRead == 0) - bytesRead = -1; - - break; - } - - bytesRead += bytesThisTime; - - if (! blockUntilSpecifiedAmountHasArrived) - break; + return handle > 0 + && setsockopt (handle, SOL_SOCKET, SO_RCVBUF, (const char*) &rcvBufSize, sizeof (rcvBufSize)) == 0 + && setsockopt (handle, SOL_SOCKET, SO_SNDBUF, (const char*) &sndBufSize, sizeof (sndBufSize)) == 0 + && (isDatagram ? ((! allowBroadcast) || setsockopt (handle, SOL_SOCKET, SO_BROADCAST, (const char*) &one, sizeof (one)) == 0) + : (setsockopt (handle, IPPROTO_TCP, TCP_NODELAY, (const char*) &one, sizeof (one)) == 0)); } - return bytesRead; -} - -static int waitForReadiness (const int handle, const bool forReading, - const int timeoutMsecs) throw() -{ - struct timeval timeout; - struct timeval* timeoutp; - - if (timeoutMsecs >= 0) + static bool bindSocketToPort (const int handle, const int port) throw() { - timeout.tv_sec = timeoutMsecs / 1000; - timeout.tv_usec = (timeoutMsecs % 1000) * 1000; - timeoutp = &timeout; - } - else - { - timeoutp = 0; + if (handle <= 0 || port <= 0) + return false; + + struct sockaddr_in servTmpAddr; + zerostruct (servTmpAddr); + servTmpAddr.sin_family = PF_INET; + servTmpAddr.sin_addr.s_addr = htonl (INADDR_ANY); + servTmpAddr.sin_port = htons ((uint16) port); + + return bind (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)) >= 0; } - fd_set rset, wset; - FD_ZERO (&rset); - FD_SET (handle, &rset); - FD_ZERO (&wset); - FD_SET (handle, &wset); - - fd_set* const prset = forReading ? &rset : 0; - fd_set* const pwset = forReading ? 0 : &wset; - -#if JUCE_WINDOWS - if (select (handle + 1, prset, pwset, 0, timeoutp) < 0) - return -1; -#else + static int readSocket (const int handle, + void* const destBuffer, const int maxBytesToRead, + bool volatile& connected, + const bool blockUntilSpecifiedAmountHasArrived) throw() { - int result; - while ((result = select (handle + 1, prset, pwset, 0, timeoutp)) < 0 - && errno == EINTR) + int bytesRead = 0; + + while (bytesRead < maxBytesToRead) { + int bytesThisTime; + + #if JUCE_WINDOWS + bytesThisTime = recv (handle, ((char*) destBuffer) + bytesRead, maxBytesToRead - bytesRead, 0); + #else + while ((bytesThisTime = (int) ::read (handle, ((char*) destBuffer) + bytesRead, maxBytesToRead - bytesRead)) < 0 + && errno == EINTR + && connected) + { + } + #endif + + if (bytesThisTime <= 0 || ! connected) + { + if (bytesRead == 0) + bytesRead = -1; + + break; + } + + bytesRead += bytesThisTime; + + if (! blockUntilSpecifiedAmountHasArrived) + break; } - if (result < 0) + return bytesRead; + } + + static int waitForReadiness (const int handle, const bool forReading, + const int timeoutMsecs) throw() + { + struct timeval timeout; + struct timeval* timeoutp; + + if (timeoutMsecs >= 0) + { + timeout.tv_sec = timeoutMsecs / 1000; + timeout.tv_usec = (timeoutMsecs % 1000) * 1000; + timeoutp = &timeout; + } + else + { + timeoutp = 0; + } + + fd_set rset, wset; + FD_ZERO (&rset); + FD_SET (handle, &rset); + FD_ZERO (&wset); + FD_SET (handle, &wset); + + fd_set* const prset = forReading ? &rset : 0; + fd_set* const pwset = forReading ? 0 : &wset; + + #if JUCE_WINDOWS + if (select (handle + 1, prset, pwset, 0, timeoutp) < 0) return -1; - } -#endif + #else + { + int result; + while ((result = select (handle + 1, prset, pwset, 0, timeoutp)) < 0 + && errno == EINTR) + { + } - { - int opt; - juce_socklen_t len = sizeof (opt); + if (result < 0) + return -1; + } + #endif - if (getsockopt (handle, SOL_SOCKET, SO_ERROR, (char*) &opt, &len) < 0 - || opt != 0) - return -1; + { + int opt; + juce_socklen_t len = sizeof (opt); + + if (getsockopt (handle, SOL_SOCKET, SO_ERROR, (char*) &opt, &len) < 0 + || opt != 0) + return -1; + } + + if ((forReading && FD_ISSET (handle, &rset)) + || ((! forReading) && FD_ISSET (handle, &wset))) + return 1; + + return 0; } - if ((forReading && FD_ISSET (handle, &rset)) - || ((! forReading) && FD_ISSET (handle, &wset))) - return 1; - - return 0; -} - -static bool setSocketBlockingState (const int handle, const bool shouldBlock) throw() -{ -#if JUCE_WINDOWS - u_long nonBlocking = shouldBlock ? 0 : 1; - - if (ioctlsocket (handle, FIONBIO, &nonBlocking) != 0) - return false; -#else - int socketFlags = fcntl (handle, F_GETFL, 0); - - if (socketFlags == -1) - return false; - - if (shouldBlock) - socketFlags &= ~O_NONBLOCK; - else - socketFlags |= O_NONBLOCK; - - if (fcntl (handle, F_SETFL, socketFlags) != 0) - return false; -#endif - - return true; -} - -static bool connectSocket (int volatile& handle, - const bool isDatagram, - void** serverAddress, - const String& hostName, - const int portNumber, - const int timeOutMillisecs) throw() -{ - struct hostent* const hostEnt = gethostbyname (hostName.toUTF8()); - - if (hostEnt == 0) - return false; - - struct in_addr targetAddress; - memcpy (&targetAddress.s_addr, - *(hostEnt->h_addr_list), - sizeof (targetAddress.s_addr)); - - struct sockaddr_in servTmpAddr; - zerostruct (servTmpAddr); - servTmpAddr.sin_family = PF_INET; - servTmpAddr.sin_addr = targetAddress; - servTmpAddr.sin_port = htons ((uint16) portNumber); - - if (handle < 0) - handle = (int) socket (AF_INET, isDatagram ? SOCK_DGRAM : SOCK_STREAM, 0); - - if (handle < 0) - return false; - - if (isDatagram) + static bool setSocketBlockingState (const int handle, const bool shouldBlock) throw() { - *serverAddress = new struct sockaddr_in(); - *((struct sockaddr_in*) *serverAddress) = servTmpAddr; + #if JUCE_WINDOWS + u_long nonBlocking = shouldBlock ? 0 : 1; + + if (ioctlsocket (handle, FIONBIO, &nonBlocking) != 0) + return false; + #else + int socketFlags = fcntl (handle, F_GETFL, 0); + + if (socketFlags == -1) + return false; + + if (shouldBlock) + socketFlags &= ~O_NONBLOCK; + else + socketFlags |= O_NONBLOCK; + + if (fcntl (handle, F_SETFL, socketFlags) != 0) + return false; + #endif return true; } - setSocketBlockingState (handle, false); - - const int result = ::connect (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)); - - if (result < 0) + static bool connectSocket (int volatile& handle, + const bool isDatagram, + void** serverAddress, + const String& hostName, + const int portNumber, + const int timeOutMillisecs) throw() { -#if JUCE_WINDOWS - if (result == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK) -#else - if (errno == EINPROGRESS) -#endif + struct hostent* const hostEnt = gethostbyname (hostName.toUTF8()); + + if (hostEnt == 0) + return false; + + struct in_addr targetAddress; + memcpy (&targetAddress.s_addr, + *(hostEnt->h_addr_list), + sizeof (targetAddress.s_addr)); + + struct sockaddr_in servTmpAddr; + zerostruct (servTmpAddr); + servTmpAddr.sin_family = PF_INET; + servTmpAddr.sin_addr = targetAddress; + servTmpAddr.sin_port = htons ((uint16) portNumber); + + if (handle < 0) + handle = (int) socket (AF_INET, isDatagram ? SOCK_DGRAM : SOCK_STREAM, 0); + + if (handle < 0) + return false; + + if (isDatagram) { - if (waitForReadiness (handle, false, timeOutMillisecs) != 1) + *serverAddress = new struct sockaddr_in(); + *((struct sockaddr_in*) *serverAddress) = servTmpAddr; + + return true; + } + + setSocketBlockingState (handle, false); + + const int result = ::connect (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)); + + if (result < 0) + { + #if JUCE_WINDOWS + if (result == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK) + #else + if (errno == EINPROGRESS) + #endif { - setSocketBlockingState (handle, true); - return false; + if (waitForReadiness (handle, false, timeOutMillisecs) != 1) + { + setSocketBlockingState (handle, true); + return false; + } } } + + setSocketBlockingState (handle, true); + resetSocketOptions (handle, false, false); + + return true; } - - setSocketBlockingState (handle, true); - resetSocketOptions (handle, false, false); - - return true; } //============================================================================== @@ -325,7 +337,7 @@ StreamingSocket::StreamingSocket (const String& hostName_, initWin32Sockets(); #endif - resetSocketOptions (handle_, false, false); + SocketHelpers::resetSocketOptions (handle_, false, false); } StreamingSocket::~StreamingSocket() @@ -336,7 +348,7 @@ StreamingSocket::~StreamingSocket() //============================================================================== int StreamingSocket::read (void* destBuffer, const int maxBytesToRead, const bool blockUntilSpecifiedAmountHasArrived) { - return (connected && ! isListener) ? readSocket (handle, destBuffer, maxBytesToRead, connected, blockUntilSpecifiedAmountHasArrived) + return (connected && ! isListener) ? SocketHelpers::readSocket (handle, destBuffer, maxBytesToRead, connected, blockUntilSpecifiedAmountHasArrived) : -1; } @@ -363,14 +375,14 @@ int StreamingSocket::write (const void* sourceBuffer, const int numBytesToWrite) int StreamingSocket::waitUntilReady (const bool readyForReading, const int timeoutMsecs) const { - return connected ? waitForReadiness (handle, readyForReading, timeoutMsecs) + return connected ? SocketHelpers::waitForReadiness (handle, readyForReading, timeoutMsecs) : -1; } //============================================================================== bool StreamingSocket::bindToPort (const int port) { - return bindSocketToPort (handle, port); + return SocketHelpers::bindSocketToPort (handle, port); } bool StreamingSocket::connect (const String& remoteHostName, @@ -390,10 +402,10 @@ bool StreamingSocket::connect (const String& remoteHostName, portNumber = remotePortNumber; isListener = false; - connected = connectSocket (handle, false, 0, remoteHostName, - remotePortNumber, timeOutMillisecs); + connected = SocketHelpers::connectSocket (handle, false, 0, remoteHostName, + remotePortNumber, timeOutMillisecs); - if (! (connected && resetSocketOptions (handle, false, false))) + if (! (connected && SocketHelpers::resetSocketOptions (handle, false, false))) { close(); return false; @@ -526,7 +538,7 @@ DatagramSocket::DatagramSocket (const String& hostName_, const int portNumber_, initWin32Sockets(); #endif - resetSocketOptions (handle_, true, allowBroadcast); + SocketHelpers::resetSocketOptions (handle_, true, allowBroadcast); bindToPort (localPortNumber); } @@ -555,7 +567,7 @@ void DatagramSocket::close() bool DatagramSocket::bindToPort (const int port) { - return bindSocketToPort (handle, port); + return SocketHelpers::bindSocketToPort (handle, port); } bool DatagramSocket::connect (const String& remoteHostName, @@ -568,11 +580,11 @@ bool DatagramSocket::connect (const String& remoteHostName, hostName = remoteHostName; portNumber = remotePortNumber; - connected = connectSocket (handle, true, &serverAddress, - remoteHostName, remotePortNumber, - timeOutMillisecs); + connected = SocketHelpers::connectSocket (handle, true, &serverAddress, + remoteHostName, remotePortNumber, + timeOutMillisecs); - if (! (connected && resetSocketOptions (handle, true, allowBroadcast))) + if (! (connected && SocketHelpers::resetSocketOptions (handle, true, allowBroadcast))) { close(); return false; @@ -605,13 +617,13 @@ DatagramSocket* DatagramSocket::waitForNextConnection() const int DatagramSocket::waitUntilReady (const bool readyForReading, const int timeoutMsecs) const { - return connected ? waitForReadiness (handle, readyForReading, timeoutMsecs) + return connected ? SocketHelpers::waitForReadiness (handle, readyForReading, timeoutMsecs) : -1; } int DatagramSocket::read (void* destBuffer, const int maxBytesToRead, const bool blockUntilSpecifiedAmountHasArrived) { - return connected ? readSocket (handle, destBuffer, maxBytesToRead, connected, blockUntilSpecifiedAmountHasArrived) + return connected ? SocketHelpers::readSocket (handle, destBuffer, maxBytesToRead, connected, blockUntilSpecifiedAmountHasArrived) : -1; } diff --git a/src/io/network/juce_URL.cpp b/src/io/network/juce_URL.cpp index 25c4a879b4..e53c611e9c 100644 --- a/src/io/network/juce_URL.cpp +++ b/src/io/network/juce_URL.cpp @@ -27,7 +27,6 @@ BEGIN_JUCE_NAMESPACE - #include "juce_URL.h" #include "../../core/juce_Random.h" #include "../../core/juce_PlatformUtilities.h" diff --git a/src/io/streams/juce_BufferedInputStream.cpp b/src/io/streams/juce_BufferedInputStream.cpp index 7fa0ea12a3..83c340fbb3 100644 --- a/src/io/streams/juce_BufferedInputStream.cpp +++ b/src/io/streams/juce_BufferedInputStream.cpp @@ -27,7 +27,6 @@ BEGIN_JUCE_NAMESPACE - #include "juce_BufferedInputStream.h" diff --git a/src/io/streams/juce_InputStream.cpp b/src/io/streams/juce_InputStream.cpp index ff0734131f..40d27e4076 100644 --- a/src/io/streams/juce_InputStream.cpp +++ b/src/io/streams/juce_InputStream.cpp @@ -27,7 +27,6 @@ BEGIN_JUCE_NAMESPACE - #include "juce_InputStream.h" diff --git a/src/io/streams/juce_MemoryOutputStream.cpp b/src/io/streams/juce_MemoryOutputStream.cpp index 39c51b650a..a16ae4e45f 100644 --- a/src/io/streams/juce_MemoryOutputStream.cpp +++ b/src/io/streams/juce_MemoryOutputStream.cpp @@ -27,7 +27,6 @@ BEGIN_JUCE_NAMESPACE - #include "juce_MemoryOutputStream.h" diff --git a/src/io/streams/juce_OutputStream.cpp b/src/io/streams/juce_OutputStream.cpp index 6ed0d007c9..96492a1727 100644 --- a/src/io/streams/juce_OutputStream.cpp +++ b/src/io/streams/juce_OutputStream.cpp @@ -27,7 +27,6 @@ BEGIN_JUCE_NAMESPACE - #include "juce_OutputStream.h" #include "../../threads/juce_ScopedLock.h" #include "../../containers/juce_Array.h" diff --git a/src/io/streams/juce_SubregionStream.cpp b/src/io/streams/juce_SubregionStream.cpp index daa7781189..fb911f1029 100644 --- a/src/io/streams/juce_SubregionStream.cpp +++ b/src/io/streams/juce_SubregionStream.cpp @@ -27,7 +27,6 @@ BEGIN_JUCE_NAMESPACE - #include "juce_SubregionStream.h" diff --git a/src/native/linux/juce_linux_SystemStats.cpp b/src/native/linux/juce_linux_SystemStats.cpp index a6e307ec48..37bb439908 100644 --- a/src/native/linux/juce_linux_SystemStats.cpp +++ b/src/native/linux/juce_linux_SystemStats.cpp @@ -68,11 +68,6 @@ static const String juce_getCpuInfo (const char* const key) return String::empty; } -bool SystemStats::hasMMX() { return juce_getCpuInfo ("flags").contains ("mmx"); } -bool SystemStats::hasSSE() { return juce_getCpuInfo ("flags").contains ("sse"); } -bool SystemStats::hasSSE2() { return juce_getCpuInfo ("flags").contains ("sse2"); } -bool SystemStats::has3DNow() { return juce_getCpuInfo ("flags").contains ("3dnow"); } - const String SystemStats::getCpuVendor() { return juce_getCpuInfo ("vendor_id"); @@ -98,11 +93,6 @@ int SystemStats::getPageSize() return sysconf (_SC_PAGESIZE); } -int SystemStats::getNumCpus() -{ - return juce_getCpuInfo ("processor").getIntValue() + 1; -} - //============================================================================== const String SystemStats::getLogonName() { @@ -126,6 +116,13 @@ const String SystemStats::getFullUserName() //============================================================================== void SystemStats::initialiseStats() { + const String flags (juce_getCpuInfo ("flags")); + cpuFlags.hasMMX = flags.contains ("mmx"); + cpuFlags.hasSSE = flags.contains ("sse"); + cpuFlags.hasSSE2 = flags.contains ("sse2"); + cpuFlags.has3DNow = flags.contains ("3dnow"); + + cpuFlags.numCpus = juce_getCpuInfo ("processor").getIntValue() + 1; } void PlatformUtilities::fpuReset() diff --git a/src/native/mac/juce_mac_SystemStats.mm b/src/native/mac/juce_mac_SystemStats.mm index 2b721e93b8..1805c52909 100644 --- a/src/native/mac/juce_mac_SystemStats.mm +++ b/src/native/mac/juce_mac_SystemStats.mm @@ -65,16 +65,6 @@ namespace SystemStatsHelpers return cpu; } - struct CPUFlags - { - bool hasMMX : 1; - bool hasSSE : 1; - bool hasSSE2 : 1; - bool has3DNow : 1; - }; - - static CPUFlags cpuFlags; - #endif } @@ -88,16 +78,15 @@ void SystemStats::initialiseStats() { initialised = true; -#if JUCE_MAC - // extremely annoying: adding this line stops the apple menu items from working. Of - // course, not adding it means that carbon windows (e.g. in plugins) won't get - // any events. - //NSApplicationLoad(); - [NSApplication sharedApplication]; -#endif + #if JUCE_MAC + // extremely annoying: adding this line stops the apple menu items from working. Of + // course, not adding it means that carbon windows (e.g. in plugins) won't get + // any events. + //NSApplicationLoad(); + [NSApplication sharedApplication]; + #endif -#if JUCE_INTEL - { + #if JUCE_INTEL unsigned int familyModel, extFeatures; const unsigned int features = getCPUIDWord (familyModel, extFeatures); @@ -105,8 +94,18 @@ void SystemStats::initialiseStats() cpuFlags.hasSSE = ((features & (1 << 25)) != 0); cpuFlags.hasSSE2 = ((features & (1 << 26)) != 0); cpuFlags.has3DNow = ((extFeatures & (1 << 31)) != 0); - } -#endif + #else + cpuFlags.hasMMX = false; + cpuFlags.hasSSE = false; + cpuFlags.hasSSE2 = false; + cpuFlags.has3DNow = false; + #endif + + #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5) + cpuFlags.numCpus = (int) [[NSProcessInfo processInfo] activeProcessorCount]; + #else + cpuFlags.numCpus = (int) MPProcessors(); + #endif mach_timebase_info_data_t timebase; (void) mach_timebase_info (&timebase); @@ -152,42 +151,6 @@ int SystemStats::getMemorySizeInMegabytes() return (int) (mem / (1024 * 1024)); } -bool SystemStats::hasMMX() -{ -#if JUCE_INTEL - return SystemStatsHelpers::cpuFlags.hasMMX; -#else - return false; -#endif -} - -bool SystemStats::hasSSE() -{ -#if JUCE_INTEL - return SystemStatsHelpers::cpuFlags.hasSSE; -#else - return false; -#endif -} - -bool SystemStats::hasSSE2() -{ -#if JUCE_INTEL - return SystemStatsHelpers::cpuFlags.hasSSE2; -#else - return false; -#endif -} - -bool SystemStats::has3DNow() -{ -#if JUCE_INTEL - return SystemStatsHelpers::cpuFlags.has3DNow; -#else - return false; -#endif -} - const String SystemStats::getCpuVendor() { #if JUCE_INTEL @@ -213,15 +176,6 @@ int SystemStats::getCpuSpeedInMegaherz() return (int) (speedHz / 1000000); } -int SystemStats::getNumCpus() -{ -#if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5) - return (int) [[NSProcessInfo processInfo] activeProcessorCount]; -#else - return MPProcessors(); -#endif -} - //============================================================================== const String SystemStats::getLogonName() { diff --git a/src/native/windows/juce_win32_SystemStats.cpp b/src/native/windows/juce_win32_SystemStats.cpp index 0ac79bb436..0c55e2318c 100644 --- a/src/native/windows/juce_win32_SystemStats.cpp +++ b/src/native/windows/juce_win32_SystemStats.cpp @@ -113,36 +113,6 @@ const String SystemStats::getCpuVendor() //============================================================================== -struct CPUFlags -{ - bool hasMMX : 1; - bool hasSSE : 1; - bool hasSSE2 : 1; - bool has3DNow : 1; -}; - -static CPUFlags cpuFlags; - -bool SystemStats::hasMMX() -{ - return cpuFlags.hasMMX; -} - -bool SystemStats::hasSSE() -{ - return cpuFlags.hasSSE; -} - -bool SystemStats::hasSSE2() -{ - return cpuFlags.hasSSE2; -} - -bool SystemStats::has3DNow() -{ - return cpuFlags.has3DNow; -} - void SystemStats::initialiseStats() { juce_initialiseThreadEvents(); @@ -156,6 +126,12 @@ void SystemStats::initialiseStats() cpuFlags.has3DNow = IsProcessorFeaturePresent (PF_3DNOW_INSTRUCTIONS_AVAILABLE) != 0; #endif + { + SYSTEM_INFO systemInfo; + GetSystemInfo (&systemInfo); + cpuFlags.numCpus = systemInfo.dwNumberOfProcessors; + } + LARGE_INTEGER f; QueryPerformanceFrequency (&f); hiResTicksPerSecond = f.QuadPart; @@ -163,12 +139,9 @@ void SystemStats::initialiseStats() String s (SystemStats::getJUCEVersion()); -#if JUCE_DEBUG const MMRESULT res = timeBeginPeriod (1); + (void) res; jassert (res == TIMERR_NOERROR); -#else - timeBeginPeriod (1); -#endif #if JUCE_DEBUG && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS _CrtSetDbgFlag (_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); @@ -244,14 +217,6 @@ int SystemStats::getMemorySizeInMegabytes() return (int) (mem.ullTotalPhys / (1024 * 1024)) + 1; } -int SystemStats::getNumCpus() -{ - SYSTEM_INFO systemInfo; - GetSystemInfo (&systemInfo); - - return systemInfo.dwNumberOfProcessors; -} - //============================================================================== uint32 juce_millisecondsSinceStartup() throw() { diff --git a/src/text/juce_LocalisedStrings.cpp b/src/text/juce_LocalisedStrings.cpp index 348bf1d5a0..348747a72d 100644 --- a/src/text/juce_LocalisedStrings.cpp +++ b/src/text/juce_LocalisedStrings.cpp @@ -27,7 +27,6 @@ BEGIN_JUCE_NAMESPACE - #include "juce_LocalisedStrings.h" diff --git a/src/text/juce_StringArray.cpp b/src/text/juce_StringArray.cpp index 9bc04c40d9..045f4f470e 100644 --- a/src/text/juce_StringArray.cpp +++ b/src/text/juce_StringArray.cpp @@ -27,7 +27,6 @@ BEGIN_JUCE_NAMESPACE - #include "juce_StringArray.h" diff --git a/src/text/juce_StringPairArray.cpp b/src/text/juce_StringPairArray.cpp index 59e247ca6a..a35f09c98d 100644 --- a/src/text/juce_StringPairArray.cpp +++ b/src/text/juce_StringPairArray.cpp @@ -27,7 +27,6 @@ BEGIN_JUCE_NAMESPACE - #include "juce_StringPairArray.h" diff --git a/src/text/juce_XmlElement.cpp b/src/text/juce_XmlElement.cpp index a7953569ad..e6c01f4e52 100644 --- a/src/text/juce_XmlElement.cpp +++ b/src/text/juce_XmlElement.cpp @@ -27,7 +27,6 @@ BEGIN_JUCE_NAMESPACE - #include "juce_XmlElement.h" #include "../io/streams/juce_MemoryOutputStream.h" #include "../io/files/juce_TemporaryFile.h" diff --git a/src/threads/juce_ReadWriteLock.cpp b/src/threads/juce_ReadWriteLock.cpp index 2f3638f8a1..25977302ad 100644 --- a/src/threads/juce_ReadWriteLock.cpp +++ b/src/threads/juce_ReadWriteLock.cpp @@ -27,7 +27,6 @@ BEGIN_JUCE_NAMESPACE - #include "juce_ReadWriteLock.h" #include "juce_ScopedLock.h" #include "juce_Thread.h" diff --git a/src/threads/juce_Thread.cpp b/src/threads/juce_Thread.cpp index cab7c999d8..a432ff50ee 100644 --- a/src/threads/juce_Thread.cpp +++ b/src/threads/juce_Thread.cpp @@ -27,11 +27,11 @@ BEGIN_JUCE_NAMESPACE - #include "juce_Thread.h" #include "juce_ScopedLock.h" #include "../core/juce_Time.h" + // these functions are implemented in the platform-specific code. void* juce_createThread (void* userData); void juce_killThread (void* handle); diff --git a/src/threads/juce_ThreadPool.cpp b/src/threads/juce_ThreadPool.cpp index 81c2b35e76..5b78567ae9 100644 --- a/src/threads/juce_ThreadPool.cpp +++ b/src/threads/juce_ThreadPool.cpp @@ -27,7 +27,6 @@ BEGIN_JUCE_NAMESPACE - #include "juce_ThreadPool.h" #include "../core/juce_Time.h" diff --git a/src/threads/juce_TimeSliceThread.cpp b/src/threads/juce_TimeSliceThread.cpp index 2b53e60242..49a537fba6 100644 --- a/src/threads/juce_TimeSliceThread.cpp +++ b/src/threads/juce_TimeSliceThread.cpp @@ -27,7 +27,6 @@ BEGIN_JUCE_NAMESPACE - #include "juce_TimeSliceThread.h" #include "juce_ScopedLock.h" diff --git a/src/utilities/juce_UndoManager.cpp b/src/utilities/juce_UndoManager.cpp index 3bbb9caa69..fa6f76c10a 100644 --- a/src/utilities/juce_UndoManager.cpp +++ b/src/utilities/juce_UndoManager.cpp @@ -27,7 +27,6 @@ BEGIN_JUCE_NAMESPACE - #include "juce_UndoManager.h" #include "../application/juce_Application.h"