From da340b4d2f73addac6cc6355202fa2c7052912be Mon Sep 17 00:00:00 2001 From: jules Date: Tue, 24 Mar 2009 18:43:08 +0000 Subject: [PATCH] added a CD-eject method for the mac; fixed a small CoreAudio bug; sorted out some minor message loop problems on the mac and windows; added a PlatformUtilities method to add an item to the OSX dock. --- .../juce_mac_AudioCDBurner.mm | 9 +++ .../juce_mac_CoreAudio.cpp | 5 +- .../juce_mac_MessageManager.mm | 2 +- .../juce_mac_MiscUtilities.mm | 16 ++++ .../juce_mac_NativeCode.mm | 1 + .../juce_posix_SharedCode.h | 20 +++++ juce_amalgamated.cpp | 74 +++++++++++++++++-- juce_amalgamated.h | 2 + .../events/juce_MessageManager.cpp | 8 +- .../gui/components/controls/juce_Label.cpp | 2 +- .../lookandfeel/juce_LookAndFeel.cpp | 2 + src/juce_core/misc/juce_PlatformUtilities.h | 2 + 12 files changed, 129 insertions(+), 14 deletions(-) diff --git a/build/macosx/platform_specific_code/juce_mac_AudioCDBurner.mm b/build/macosx/platform_specific_code/juce_mac_AudioCDBurner.mm index 1506ceb30b..291062f4a5 100644 --- a/build/macosx/platform_specific_code/juce_mac_AudioCDBurner.mm +++ b/build/macosx/platform_specific_code/juce_mac_AudioCDBurner.mm @@ -431,4 +431,13 @@ const String AudioCDBurner::burn (JUCE_NAMESPACE::AudioCDBurner::BurnProgressLis return error; } + +//============================================================================== +void AudioCDReader::ejectDisk() +{ + const ScopedAutoReleasePool p; + [[NSWorkspace sharedWorkspace] unmountAndEjectDeviceAtPath: juceStringToNS (volumeDir.getFullPathName())]; +} + + #endif diff --git a/build/macosx/platform_specific_code/juce_mac_CoreAudio.cpp b/build/macosx/platform_specific_code/juce_mac_CoreAudio.cpp index 62644c4534..2863a2f8e6 100644 --- a/build/macosx/platform_specific_code/juce_mac_CoreAudio.cpp +++ b/build/macosx/platform_specific_code/juce_mac_CoreAudio.cpp @@ -166,7 +166,6 @@ public: { if (activeInputChans[chanNum]) { - inputChannelInfo [activeChans].sourceChannelNum = chanNum; inputChannelInfo [activeChans].streamNum = i; inputChannelInfo [activeChans].dataOffsetSamples = j; inputChannelInfo [activeChans].dataStrideSamples = b.mNumberChannels; @@ -180,7 +179,6 @@ public: { if (activeOutputChans[chanNum]) { - outputChannelInfo [activeChans].sourceChannelNum = chanNum; outputChannelInfo [activeChans].streamNum = i; outputChannelInfo [activeChans].dataOffsetSamples = j; outputChannelInfo [activeChans].dataStrideSamples = b.mNumberChannels; @@ -583,7 +581,7 @@ public: for (i = numInputChans; --i >= 0;) { const CallbackDetailsForChannel& info = inputChannelInfo[i]; - float* dest = tempInputBuffers [info.sourceChannelNum]; + float* dest = tempInputBuffers [i]; const float* src = ((const float*) inInputData->mBuffers[info.streamNum].mData) + info.dataOffsetSamples; const int stride = info.dataStrideSamples; @@ -755,7 +753,6 @@ private: struct CallbackDetailsForChannel { - int sourceChannelNum; int streamNum; int dataOffsetSamples; int dataStrideSamples; diff --git a/build/macosx/platform_specific_code/juce_mac_MessageManager.mm b/build/macosx/platform_specific_code/juce_mac_MessageManager.mm index e6cb31ed92..750e504055 100644 --- a/build/macosx/platform_specific_code/juce_mac_MessageManager.mm +++ b/build/macosx/platform_specific_code/juce_mac_MessageManager.mm @@ -279,7 +279,7 @@ bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor) uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor; NSDate* endDate = [NSDate dateWithTimeIntervalSinceNow: millisecondsToRunFor * 0.001]; - while (Time::getMillisecondCounter() < endTime) + while (Time::getMillisecondCounter() < endTime && ! quitMessagePosted) { const ScopedAutoReleasePool pool; diff --git a/build/macosx/platform_specific_code/juce_mac_MiscUtilities.mm b/build/macosx/platform_specific_code/juce_mac_MiscUtilities.mm index 2471b21ffb..5001614f35 100644 --- a/build/macosx/platform_specific_code/juce_mac_MiscUtilities.mm +++ b/build/macosx/platform_specific_code/juce_mac_MiscUtilities.mm @@ -51,6 +51,21 @@ void PlatformUtilities::beep() NSBeep(); } +//============================================================================== +void PlatformUtilities::addItemToDock (const File& file) +{ + // check that it's not already there... + if (! juce_getOutputFromCommand ("defaults read com.apple.dock persistent-apps") + .containsIgnoreCase (file.getFullPathName())) + { + juce_runSystemCommand ("defaults write com.apple.dock persistent-apps -array-add \"tile-datafile-data_CFURLString" + + file.getFullPathName() + "_CFURLStringType0\""); + + juce_runSystemCommand ("osascript -e \"tell application \\\"Dock\\\" to quit\""); + } +} + + //============================================================================== #if ! JUCE_ONLY_BUILD_CORE_LIBRARY @@ -243,6 +258,7 @@ void juce_updateMultiMonitorInfo (Array & monitorCoords, const bool c jassert (monitorCoords.size() > 0); } + #endif #endif diff --git a/build/macosx/platform_specific_code/juce_mac_NativeCode.mm b/build/macosx/platform_specific_code/juce_mac_NativeCode.mm index f4fffb2cfd..5fe952dada 100644 --- a/build/macosx/platform_specific_code/juce_mac_NativeCode.mm +++ b/build/macosx/platform_specific_code/juce_mac_NativeCode.mm @@ -70,6 +70,7 @@ BEGIN_JUCE_NAMESPACE #include "../../../src/juce_appframework/gui/components/special/juce_WebBrowserComponent.h" #include "../../../src/juce_appframework/gui/components/filebrowser/juce_FileChooser.h" #include "../../../src/juce_appframework/audio/audio_file_formats/juce_AudioCDBurner.h" +#include "../../../src/juce_appframework/audio/audio_file_formats/juce_AudioCDReader.h" #include "../../../src/juce_appframework/audio/audio_sources/juce_AudioSource.h" #include "../../../src/juce_appframework/audio/dsp/juce_AudioDataConverters.h" #include "../../../src/juce_appframework/audio/devices/juce_AudioIODeviceType.h" diff --git a/build/macosx/platform_specific_code/juce_posix_SharedCode.h b/build/macosx/platform_specific_code/juce_posix_SharedCode.h index e3d5afea02..606533a33b 100644 --- a/build/macosx/platform_specific_code/juce_posix_SharedCode.h +++ b/build/macosx/platform_specific_code/juce_posix_SharedCode.h @@ -390,6 +390,26 @@ const String juce_getVolumeLabel (const String& filenameOnVolume, return String::empty; } + +//============================================================================== +void juce_runSystemCommand (const String& command) +{ + system ((const char*) command.toUTF8()); +} + +const String juce_getOutputFromCommand (const String& command) +{ + // slight bodge here, as we just pipe the output into a temp file and read it... + const File tempFile (File::getSpecialLocation (File::tempDirectory) + .getNonexistentChildFile (String::toHexString (Random::getSystemRandom().nextInt()), ".tmp", false)); + + juce_runSystemCommand (command + " > " + tempFile.getFullPathName()); + + String result (tempFile.loadFileAsString()); + tempFile.deleteFile(); + return result; +} + //============================================================================== #if JUCE_64BIT #define filedesc ((long long) internal) diff --git a/juce_amalgamated.cpp b/juce_amalgamated.cpp index 19cc5db379..d82b386106 100644 --- a/juce_amalgamated.cpp +++ b/juce_amalgamated.cpp @@ -36933,7 +36933,13 @@ bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor) { JUCE_TRY { - juce_dispatchNextMessageOnSystemQueue (millisecondsToRunFor >= 0); + if (! juce_dispatchNextMessageOnSystemQueue (millisecondsToRunFor >= 0)) + { + const int msToWait = (int) (endTime - Time::currentTimeMillis()); + + if (msToWait > 0) + Thread::sleep (jmin (5, msToWait)); + } } JUCE_CATCH_EXCEPTION } @@ -43768,7 +43774,7 @@ void Label::showEditor() if (editor == 0) { addAndMakeVisible (editor = createEditorComponent()); - editor->setText (getText()); + editor->setText (getText(), false); editor->addListener (this); editor->grabKeyboardFocus(); editor->setHighlightedRegion (0, text.length()); @@ -60972,8 +60978,10 @@ void LookAndFeel::drawPopupMenuBackground (Graphics& g, int width, int height) for (int i = 0; i < height; i += 3) g.fillRect (0, i, width, 1); +#if ! JUCE_MAC g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.6f)); g.drawRect (0, 0, width, height); +#endif } void LookAndFeel::drawPopupMenuUpDownArrow (Graphics& g, @@ -255314,6 +255322,24 @@ const String juce_getVolumeLabel (const String& filenameOnVolume, return String::empty; } +void juce_runSystemCommand (const String& command) +{ + system ((const char*) command.toUTF8()); +} + +const String juce_getOutputFromCommand (const String& command) +{ + // slight bodge here, as we just pipe the output into a temp file and read it... + const File tempFile (File::getSpecialLocation (File::tempDirectory) + .getNonexistentChildFile (String::toHexString (Random::getSystemRandom().nextInt()), ".tmp", false)); + + juce_runSystemCommand (command + " > " + tempFile.getFullPathName()); + + String result (tempFile.loadFileAsString()); + tempFile.deleteFile(); + return result; +} + #if JUCE_64BIT #define filedesc ((long long) internal) #else @@ -265350,6 +265376,24 @@ const String juce_getVolumeLabel (const String& filenameOnVolume, return String::empty; } +void juce_runSystemCommand (const String& command) +{ + system ((const char*) command.toUTF8()); +} + +const String juce_getOutputFromCommand (const String& command) +{ + // slight bodge here, as we just pipe the output into a temp file and read it... + const File tempFile (File::getSpecialLocation (File::tempDirectory) + .getNonexistentChildFile (String::toHexString (Random::getSystemRandom().nextInt()), ".tmp", false)); + + juce_runSystemCommand (command + " > " + tempFile.getFullPathName()); + + String result (tempFile.loadFileAsString()); + tempFile.deleteFile(); + return result; +} + #if JUCE_64BIT #define filedesc ((long long) internal) #else @@ -266036,6 +266080,19 @@ void PlatformUtilities::beep() NSBeep(); } +void PlatformUtilities::addItemToDock (const File& file) +{ + // check that it's not already there... + if (! juce_getOutputFromCommand ("defaults read com.apple.dock persistent-apps") + .containsIgnoreCase (file.getFullPathName())) + { + juce_runSystemCommand ("defaults write com.apple.dock persistent-apps -array-add \"tile-datafile-data_CFURLString" + + file.getFullPathName() + "_CFURLStringType0\""); + + juce_runSystemCommand ("osascript -e \"tell application \\\"Dock\\\" to quit\""); + } +} + #if ! JUCE_ONLY_BUILD_CORE_LIBRARY bool AlertWindow::showNativeDialogBox (const String& title, @@ -269801,6 +269858,12 @@ const String AudioCDBurner::burn (JUCE_NAMESPACE::AudioCDBurner::BurnProgressLis return error; } +void AudioCDReader::ejectDisk() +{ + const ScopedAutoReleasePool p; + [[NSWorkspace sharedWorkspace] unmountAndEjectDeviceAtPath: juceStringToNS (volumeDir.getFullPathName())]; +} + #endif /********* End of inlined file: juce_mac_AudioCDBurner.mm *********/ @@ -270378,7 +270441,7 @@ bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor) uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor; NSDate* endDate = [NSDate dateWithTimeIntervalSinceNow: millisecondsToRunFor * 0.001]; - while (Time::getMillisecondCounter() < endTime) + while (Time::getMillisecondCounter() < endTime && ! quitMessagePosted) { const ScopedAutoReleasePool pool; @@ -270850,7 +270913,6 @@ public: { if (activeInputChans[chanNum]) { - inputChannelInfo [activeChans].sourceChannelNum = chanNum; inputChannelInfo [activeChans].streamNum = i; inputChannelInfo [activeChans].dataOffsetSamples = j; inputChannelInfo [activeChans].dataStrideSamples = b.mNumberChannels; @@ -270864,7 +270926,6 @@ public: { if (activeOutputChans[chanNum]) { - outputChannelInfo [activeChans].sourceChannelNum = chanNum; outputChannelInfo [activeChans].streamNum = i; outputChannelInfo [activeChans].dataOffsetSamples = j; outputChannelInfo [activeChans].dataStrideSamples = b.mNumberChannels; @@ -271265,7 +271326,7 @@ public: for (i = numInputChans; --i >= 0;) { const CallbackDetailsForChannel& info = inputChannelInfo[i]; - float* dest = tempInputBuffers [info.sourceChannelNum]; + float* dest = tempInputBuffers [i]; const float* src = ((const float*) inInputData->mBuffers[info.streamNum].mData) + info.dataOffsetSamples; const int stride = info.dataStrideSamples; @@ -271436,7 +271497,6 @@ private: struct CallbackDetailsForChannel { - int sourceChannelNum; int streamNum; int dataOffsetSamples; int dataStrideSamples; diff --git a/juce_amalgamated.h b/juce_amalgamated.h index 2209682289..522b9c5161 100644 --- a/juce_amalgamated.h +++ b/juce_amalgamated.h @@ -13121,6 +13121,8 @@ public: /** MAC ONLY - Returns true if this file is actually a bundle. */ static bool isBundle (const String& filename); + /** MAC ONLY - Adds an item to the dock */ + static void addItemToDock (const File& file); #endif #if JUCE_WIN32 || DOXYGEN diff --git a/src/juce_appframework/events/juce_MessageManager.cpp b/src/juce_appframework/events/juce_MessageManager.cpp index d5a7173dff..79e14eeca1 100644 --- a/src/juce_appframework/events/juce_MessageManager.cpp +++ b/src/juce_appframework/events/juce_MessageManager.cpp @@ -163,7 +163,13 @@ bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor) { JUCE_TRY { - juce_dispatchNextMessageOnSystemQueue (millisecondsToRunFor >= 0); + if (! juce_dispatchNextMessageOnSystemQueue (millisecondsToRunFor >= 0)) + { + const int msToWait = (int) (endTime - Time::currentTimeMillis()); + + if (msToWait > 0) + Thread::sleep (jmin (5, msToWait)); + } } JUCE_CATCH_EXCEPTION } diff --git a/src/juce_appframework/gui/components/controls/juce_Label.cpp b/src/juce_appframework/gui/components/controls/juce_Label.cpp index 0d942a6275..08f86684ee 100644 --- a/src/juce_appframework/gui/components/controls/juce_Label.cpp +++ b/src/juce_appframework/gui/components/controls/juce_Label.cpp @@ -203,7 +203,7 @@ void Label::showEditor() if (editor == 0) { addAndMakeVisible (editor = createEditorComponent()); - editor->setText (getText()); + editor->setText (getText(), false); editor->addListener (this); editor->grabKeyboardFocus(); editor->setHighlightedRegion (0, text.length()); diff --git a/src/juce_appframework/gui/components/lookandfeel/juce_LookAndFeel.cpp b/src/juce_appframework/gui/components/lookandfeel/juce_LookAndFeel.cpp index e9ba38d0aa..cc8dbd02c4 100644 --- a/src/juce_appframework/gui/components/lookandfeel/juce_LookAndFeel.cpp +++ b/src/juce_appframework/gui/components/lookandfeel/juce_LookAndFeel.cpp @@ -961,8 +961,10 @@ void LookAndFeel::drawPopupMenuBackground (Graphics& g, int width, int height) for (int i = 0; i < height; i += 3) g.fillRect (0, i, width, 1); +#if ! JUCE_MAC g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.6f)); g.drawRect (0, 0, width, height); +#endif } void LookAndFeel::drawPopupMenuUpDownArrow (Graphics& g, diff --git a/src/juce_core/misc/juce_PlatformUtilities.h b/src/juce_core/misc/juce_PlatformUtilities.h index eed17849f8..4584a0220f 100644 --- a/src/juce_core/misc/juce_PlatformUtilities.h +++ b/src/juce_core/misc/juce_PlatformUtilities.h @@ -77,6 +77,8 @@ public: /** MAC ONLY - Returns true if this file is actually a bundle. */ static bool isBundle (const String& filename); + /** MAC ONLY - Adds an item to the dock */ + static void addItemToDock (const File& file); #endif