diff --git a/build/win32/platform_specific_code/juce_win32_Fonts.cpp b/build/win32/platform_specific_code/juce_win32_Fonts.cpp index bdf47f48ed..f4e39a7170 100644 --- a/build/win32/platform_specific_code/juce_win32_Fonts.cpp +++ b/build/win32/platform_specific_code/juce_win32_Fonts.cpp @@ -40,7 +40,7 @@ static int CALLBACK wfontEnum2 (ENUMLOGFONTEXW* lpelfe, int type, LPARAM lParam) { - if (lpelfe != 0 && type == TRUETYPE_FONTTYPE) + if (lpelfe != 0 && (type & RASTER_FONTTYPE) == 0) { const String fontName (lpelfe->elfLogFont.lfFaceName); @@ -55,8 +55,7 @@ static int CALLBACK wfontEnum1 (ENUMLOGFONTEXW* lpelfe, int type, LPARAM lParam) { - if (lpelfe != 0 - && ((type & (DEVICE_FONTTYPE | RASTER_FONTTYPE)) == 0)) + if (lpelfe != 0 && (type & RASTER_FONTTYPE) == 0) { LOGFONTW lf; zerostruct (lf); diff --git a/extras/audio plugins/wrapper/AU/juce_AU_Wrapper.mm b/extras/audio plugins/wrapper/AU/juce_AU_Wrapper.mm index fbec603cc9..29c7b8733c 100644 --- a/extras/audio plugins/wrapper/AU/juce_AU_Wrapper.mm +++ b/extras/audio plugins/wrapper/AU/juce_AU_Wrapper.mm @@ -55,7 +55,7 @@ //============================================================================== #define juceFilterObjectPropertyID 0x1a45ffe9 -static VoidArray activePlugins; +static VoidArray activePlugins, activeUIs; static const short channelConfigs[][2] = { JucePlugin_PreferredChannelConfigurations }; static const int numChannelConfigs = numElementsInArray (channelConfigs); @@ -108,7 +108,7 @@ public: channels (0), prepared (false) { - if (activePlugins.size() == 0) + if (activePlugins.size() + activeUIs.size() == 0) { #if BUILD_AU_CARBON_UI NSApplicationLoad(); @@ -143,7 +143,7 @@ public: jassert (activePlugins.contains (this)); activePlugins.removeValue (this); - if (activePlugins.size() == 0) + if (activePlugins.size() + activeUIs.size() == 0) shutdownJuce_GUI(); } @@ -993,6 +993,8 @@ public: [self setHidden: NO]; [self setPostsFrameChangedNotifications: YES]; + activeUIs.add (self); + editorComp->addToDesktop (0, (void*) self); editorComp->setVisible (true); @@ -1005,10 +1007,19 @@ public: // is trying to delete our plugin.. jassert (Component::getCurrentlyModalComponent() == 0); - if (editorComp != 0 && editorComp->getChildComponent(0) != 0) - filter->editorBeingDeleted ((AudioProcessorEditor*) editorComp->getChildComponent(0)); + if (editorComp != 0 && editorComp->isValidComponent()) + { + if (editorComp->getChildComponent(0) != 0) + if (activePlugins.contains ((void*) filter)) // plugin may have been deleted before the UI + filter->editorBeingDeleted ((AudioProcessorEditor*) editorComp->getChildComponent(0)); + + deleteAndZero (editorComp); + } - deleteAndZero (editorComp); + jassert (activeUIs.contains (self)); + activeUIs.removeValue (self); + if (activePlugins.size() + activeUIs.size() == 0) + shutdownJuce_GUI(); [super dealloc]; } diff --git a/extras/audio plugins/wrapper/RTAS/juce_RTAS_Wrapper.cpp b/extras/audio plugins/wrapper/RTAS/juce_RTAS_Wrapper.cpp index 45521b8ad0..ff03ac94b2 100644 --- a/extras/audio plugins/wrapper/RTAS/juce_RTAS_Wrapper.cpp +++ b/extras/audio plugins/wrapper/RTAS/juce_RTAS_Wrapper.cpp @@ -1,1002 +1,1002 @@ -/* - ============================================================================== - - This file is part of the JUCE library - "Jules' Utility Class Extensions" - Copyright 2004-7 by Raw Material Software ltd. - - ------------------------------------------------------------------------------ - - JUCE can be redistributed and/or modified under the terms of the - GNU General Public License, as published by the Free Software Foundation; - either version 2 of the License, or (at your option) any later version. - - JUCE is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with JUCE; if not, visit www.gnu.org/licenses or write to the - Free Software Foundation, Inc., 59 Temple Place, Suite 330, - Boston, MA 02111-1307 USA - - ------------------------------------------------------------------------------ - - If you'd like to release a closed-source product which uses JUCE, commercial - licenses are also available: visit www.rawmaterialsoftware.com/juce for - more information. - - ============================================================================== -*/ - -#ifdef _MSC_VER - // (this is a workaround for a build problem in VC9) - #define _DO_NOT_DECLARE_INTERLOCKED_INTRINSICS_IN_MEMORY - #include -#endif - -#include "juce_RTAS_DigiCode_Header.h" - -#if JucePlugin_Build_RTAS - -#ifdef _MSC_VER - #include "Mac2Win.H" -#endif - -/* Note about include paths - ------------------------ - - To be able to include all the Digidesign headers correctly, you'll need to add this - lot to your include path: - - c:\yourdirectory\PT_80_SDK\AlturaPorts\TDMPlugins\PluginLibrary\EffectClasses - c:\yourdirectory\PT_80_SDK\AlturaPorts\TDMPlugins\PluginLibrary\ProcessClasses - c:\yourdirectory\PT_80_SDK\AlturaPorts\TDMPlugins\PluginLibrary\ProcessClasses\Interfaces - c:\yourdirectory\PT_80_SDK\AlturaPorts\TDMPlugins\PluginLibrary\Utilities - c:\yourdirectory\PT_80_SDK\AlturaPorts\TDMPlugins\PluginLibrary\RTASP_Adapt - c:\yourdirectory\PT_80_SDK\AlturaPorts\TDMPlugins\PluginLibrary\CoreClasses - c:\yourdirectory\PT_80_SDK\AlturaPorts\TDMPlugins\PluginLibrary\Controls - c:\yourdirectory\PT_80_SDK\AlturaPorts\TDMPlugins\PluginLibrary\Meters - c:\yourdirectory\PT_80_SDK\AlturaPorts\TDMPlugins\PluginLibrary\ViewClasses - c:\yourdirectory\PT_80_SDK\AlturaPorts\TDMPlugins\PluginLibrary\DSPClasses - c:\yourdirectory\PT_80_SDK\AlturaPorts\TDMPlugins\PluginLibrary\Interfaces - c:\yourdirectory\PT_80_SDK\AlturaPorts\TDMPlugins\common - c:\yourdirectory\PT_80_SDK\AlturaPorts\TDMPlugins\common\Platform - c:\yourdirectory\PT_80_SDK\AlturaPorts\TDMPlugins\SignalProcessing\Public - C:\yourdirectory\PT_80_SDK\AlturaPorts\TDMPlugIns\DSPManager\Interfaces - c:\yourdirectory\PT_80_SDK\AlturaPorts\SADriver\Interfaces - c:\yourdirectory\PT_80_SDK\AlturaPorts\DigiPublic\Interfaces - c:\yourdirectory\PT_80_SDK\AlturaPorts\Fic\Interfaces\DAEClient - c:\yourdirectory\PT_80_SDK\AlturaPorts\NewFileLibs\Cmn - c:\yourdirectory\PT_80_SDK\AlturaPorts\NewFileLibs\DOA - c:\yourdirectory\PT_80_SDK\AlturaPorts\AlturaSource\PPC_H - c:\yourdirectory\PT_80_SDK\AlturaPorts\AlturaSource\AppSupport - c:\yourdirectory\PT_80_SDK\AvidCode\AVX2sdk\AVX\avx2\avx2sdk\inc - C:\yourdirectory\PT_80_SDK\xplat\AVX\avx2\avx2sdk\inc - - NB. If you hit a huge pile of bugs around here, make sure that you've not got the - Apple QuickTime headers before the PT headers in your path, because there are - some filename clashes between them. - -*/ -#include "CEffectGroupMIDI.h" -#include "CEffectProcessMIDI.h" -#include "CEffectProcessRTAS.h" -#include "CCustomView.h" -#include "CEffectTypeRTAS.h" -#include "CPluginControl.h" -#include "CPluginControl_OnOff.h" -#include "FicProcessTokens.h" - -//============================================================================== -#ifdef _MSC_VER - #pragma pack (push, 8) -#endif - -#include "../juce_PluginHeaders.h" - -#ifdef _MSC_VER - #pragma pack (pop) - - #if JUCE_DEBUG - #define PT_LIB_PATH JucePlugin_WinBag_path "\\Debug\\lib\\" - #else - #define PT_LIB_PATH JucePlugin_WinBag_path "\\Release\\lib\\" - #endif - - #pragma comment(lib, PT_LIB_PATH "DAE.lib") - #pragma comment(lib, PT_LIB_PATH "DigiExt.lib") - #pragma comment(lib, PT_LIB_PATH "DSI.lib") - #pragma comment(lib, PT_LIB_PATH "PluginLib.lib") - -#endif - -#undef Component -#undef MemoryBlock - -//============================================================================== -#if JUCE_WIN32 - extern void JUCE_CALLTYPE attachSubWindow (void* hostWindow, int& titleW, int& titleH, JUCE_NAMESPACE::Component* comp); - extern void JUCE_CALLTYPE resizeHostWindow (void* hostWindow, int& titleW, int& titleH, JUCE_NAMESPACE::Component* comp); - #if ! JucePlugin_EditorRequiresKeyboardFocus - extern void JUCE_CALLTYPE passFocusToHostWindow (void* hostWindow); - #endif -#else - extern void* attachSubWindow (void* hostWindowRef, JUCE_NAMESPACE::Component* comp); - extern void removeSubWindow (void* nsWindow, JUCE_NAMESPACE::Component* comp); -#endif - -const int midiBufferSize = 1024; -const OSType juceChunkType = 'juce'; -static const int bypassControlIndex = 1; - -//============================================================================== -/** Somewhere in the codebase of your plugin, you need to implement this function - and make it return a new instance of the filter subclass that you're building. -*/ -extern AudioProcessor* JUCE_CALLTYPE createPluginFilter(); - - -//============================================================================== -static float longToFloat (const long n) throw() -{ - return (float) ((((double) n) + (double) 0x80000000) / (double) 0xffffffff); -} - -static long floatToLong (const float n) throw() -{ - return roundDoubleToInt (jlimit (-(double) 0x80000000, - (double) 0x7fffffff, - n * (double) 0xffffffff - (double) 0x80000000)); -} - -static int numInstances = 0; - -//============================================================================== -class JucePlugInProcess : public CEffectProcessMIDI, - public CEffectProcessRTAS, - public AudioProcessorListener, - public AudioPlayHead, - public AsyncUpdater -{ -public: - //============================================================================== - JucePlugInProcess() - : midiBufferNode (0), - midiTransport (0), - channels (0), - prepared (false), - sampleRate (44100.0) - { - juceFilter = createPluginFilter(); - jassert (juceFilter != 0); - - AddChunk (juceChunkType, "Juce Audio Plugin Data"); - - ++numInstances; - } - - ~JucePlugInProcess() - { - if (mLoggedIn) - MIDILogOut(); - - deleteAndZero (midiBufferNode); - deleteAndZero (midiTransport); - - if (prepared) - juceFilter->releaseResources(); - - delete juceFilter; - juce_free (channels); - - if (--numInstances == 0) - shutdownJuce_GUI(); - } - - //============================================================================== - class JuceCustomUIView : public CCustomView, - public Timer - { - public: - //============================================================================== - JuceCustomUIView (AudioProcessor* const filter_, - JucePlugInProcess* const process_) - : filter (filter_), - process (process_), - wrapper (0), - editorComp (0) - { - // setting the size in here crashes PT for some reason, so keep it simple.. - } - - ~JuceCustomUIView() - { - deleteEditorComp(); - } - - //============================================================================== - void updateSize() - { - if (editorComp == 0) - { - editorComp = filter->createEditorIfNeeded(); - jassert (editorComp != 0); - } - - Rect oldRect; - GetRect (&oldRect); - - Rect r; - r.left = 0; - r.top = 0; - r.right = editorComp->getWidth(); - r.bottom = editorComp->getHeight(); - SetRect (&r); - - if ((oldRect.right != r.right) || (oldRect.bottom != r.bottom)) - startTimer (50); - } - - void timerCallback() - { - if (! JUCE_NAMESPACE::Component::isMouseButtonDownAnywhere()) - { - stopTimer(); - - // Send a token to the host to tell it about the resize - SSetProcessWindowResizeToken token (process->fRootNameId, process->fRootNameId); - FicSDSDispatchToken (&token); - } - } - - void attachToWindow (GrafPtr port) - { - if (port != 0) - { - updateSize(); - -#if JUCE_WIN32 - void* const hostWindow = (void*) ASI_GethWnd ((WindowPtr) port); -#else - void* const hostWindow = (void*) GetWindowFromPort (port); -#endif - deleteAndZero (wrapper); - - wrapper = new EditorCompWrapper (hostWindow, editorComp, this); - } - else - { - deleteEditorComp(); - } - } - - void DrawContents (Rect*) - { -#if JUCE_WIN32 - if (wrapper != 0) - { - ComponentPeer* const peer = wrapper->getPeer(); - - if (peer != 0) - { - // (seems to be required in PT6.4, but not in 7.x) - peer->repaint (0, 0, wrapper->getWidth(), wrapper->getHeight()); - } - } -#endif - } - - void DrawBackground (Rect*) {} - - //============================================================================== - private: - AudioProcessor* const filter; - JucePlugInProcess* const process; - JUCE_NAMESPACE::Component* wrapper; - AudioProcessorEditor* editorComp; - - void deleteEditorComp() - { - if (editorComp != 0 || wrapper != 0) - { -#if JUCE_MAC - const ScopedAutoReleasePool pool; -#endif - PopupMenu::dismissAllActiveMenus(); - - JUCE_NAMESPACE::Component* const modalComponent = JUCE_NAMESPACE::Component::getCurrentlyModalComponent(); - if (modalComponent != 0) - modalComponent->exitModalState (0); - - filter->editorBeingDeleted (editorComp); - - deleteAndZero (editorComp); - deleteAndZero (wrapper); - } - } - - //============================================================================== - // A component to hold the AudioProcessorEditor, and cope with some housekeeping - // chores when it changes or repaints. - class EditorCompWrapper : public JUCE_NAMESPACE::Component -#if ! JUCE_MAC - , public FocusChangeListener -#endif - { - public: - EditorCompWrapper (void* const hostWindow_, - Component* const editorComp, - JuceCustomUIView* const owner_) - : hostWindow (hostWindow_), - owner (owner_), - titleW (0), - titleH (0) - { -#if JucePlugin_EditorRequiresKeyboardFocus - setWantsKeyboardFocus (true); -#else - setComponentProperty ("juce_disallowFocus", true); - setWantsKeyboardFocus (false); -#endif - setOpaque (true); - setBroughtToFrontOnMouseClick (true); - setBounds (editorComp->getBounds()); - editorComp->setTopLeftPosition (0, 0); - addAndMakeVisible (editorComp); - -#if JUCE_WIN32 - attachSubWindow (hostWindow, titleW, titleH, this); -#else - nsWindow = attachSubWindow (hostWindow, this); -#endif - setVisible (true); - -#if JUCE_WIN32 && ! JucePlugin_EditorRequiresKeyboardFocus - Desktop::getInstance().addFocusChangeListener (this); -#endif - } - - ~EditorCompWrapper() - { -#if JUCE_WIN32 && ! JucePlugin_EditorRequiresKeyboardFocus - Desktop::getInstance().removeFocusChangeListener (this); -#endif - -#if JUCE_MAC - removeSubWindow (nsWindow, this); -#endif - } - - void paint (Graphics&) - { - } - - void resized() - { - JUCE_NAMESPACE::Component* const c = getChildComponent (0); - - if (c != 0) - c->setBounds (0, 0, getWidth(), getHeight()); - - repaint(); - } - -#if JUCE_WIN32 - void globalFocusChanged (JUCE_NAMESPACE::Component*) - { - #if ! JucePlugin_EditorRequiresKeyboardFocus - if (hasKeyboardFocus (true)) - passFocusToHostWindow (hostWindow); - #endif - } -#endif - - void childBoundsChanged (JUCE_NAMESPACE::Component* child) - { - setSize (child->getWidth(), child->getHeight()); - child->setTopLeftPosition (0, 0); - -#if JUCE_WIN32 - resizeHostWindow (hostWindow, titleW, titleH, this); -#endif - owner->updateSize(); - } - - void userTriedToCloseWindow() - { - } - - //============================================================================== - juce_UseDebuggingNewOperator - - private: - void* const hostWindow; - void* nsWindow; - JuceCustomUIView* const owner; - int titleW, titleH; - }; - }; - - JuceCustomUIView* getView() const - { - return dynamic_cast (fOurPlugInView); - } - - void GetViewRect (Rect* size) - { - if (getView() != 0) - getView()->updateSize(); - - CEffectProcessRTAS::GetViewRect (size); - } - - CPlugInView* CreateCPlugInView() - { - return new JuceCustomUIView (juceFilter, this); - } - - void SetViewPort (GrafPtr port) - { - CEffectProcessRTAS::SetViewPort (port); - - if (getView() != 0) - getView()->attachToWindow (port); - } - - //============================================================================== -protected: - ComponentResult GetDelaySamplesLong (long* aNumSamples) - { - if (aNumSamples != 0) - *aNumSamples = juceFilter != 0 ? juceFilter->getLatencySamples() : 0; - - return noErr; - } - - //============================================================================== - void EffectInit() - { - SFicPlugInStemFormats stems; - GetProcessType()->GetStemFormats (&stems); - - juceFilter->setPlayConfigDetails (fNumInputs, fNumOutputs, - juceFilter->getSampleRate(), juceFilter->getBlockSize()); - - AddControl (new CPluginControl_OnOff ('bypa', "Master Bypass\nMastrByp\nMByp\nByp", false, true)); - DefineMasterBypassControlIndex (bypassControlIndex); - - for (int i = 0; i < juceFilter->getNumParameters(); ++i) - AddControl (new JucePluginControl (juceFilter, i)); - - // we need to do this midi log-in to get timecode, regardless of whether - // the plugin actually uses midi... - if (MIDILogIn() == noErr) - { -#if JucePlugin_WantsMidiInput - CEffectType* const type = dynamic_cast (this->GetProcessType()); - - if (type != 0) - { - char nodeName [64]; - type->GetProcessTypeName (63, nodeName); - p2cstrcpy (nodeName, reinterpret_cast (nodeName)); - - midiBufferNode = new CEffectMIDIOtherBufferedNode (&mMIDIWorld, - 8192, - eLocalNode, - nodeName, - midiBuffer); - - midiBufferNode->Initialize (1, true); - } -#endif - } - - midiTransport = new CEffectMIDITransport (&mMIDIWorld); - - juceFilter->setPlayHead (this); - juceFilter->addListener (this); - } - - void handleAsyncUpdate() - { - if (! prepared) - { - sampleRate = gProcessGroup->GetSampleRate(); - jassert (sampleRate > 0); - - juce_free (channels); - channels = (float**) juce_calloc (sizeof (float*) * jmax (juceFilter->getNumInputChannels(), - juceFilter->getNumOutputChannels())); - - juceFilter->setPlayConfigDetails (fNumInputs, fNumOutputs, - sampleRate, mRTGlobals->mHWBufferSizeInSamples); - - juceFilter->prepareToPlay (sampleRate, - mRTGlobals->mHWBufferSizeInSamples); - - prepared = true; - } - } - - void RenderAudio (float** inputs, float** outputs, long numSamples) - { - if (! prepared) - { - triggerAsyncUpdate(); - bypassBuffers (inputs, outputs, numSamples); - return; - } - - if (mBypassed) - { - bypassBuffers (inputs, outputs, numSamples); - return; - } - -#if JucePlugin_WantsMidiInput - midiEvents.clear(); - - const Cmn_UInt32 bufferSize = mRTGlobals->mHWBufferSizeInSamples; - - if (midiBufferNode->GetAdvanceScheduleTime() != bufferSize) - midiBufferNode->SetAdvanceScheduleTime (bufferSize); - - if (midiBufferNode->FillMIDIBuffer (mRTGlobals->mRunningTime, numSamples) == noErr) - { - jassert (midiBufferNode->GetBufferPtr() != 0); - const int numMidiEvents = midiBufferNode->GetBufferSize(); - - for (int i = 0; i < numMidiEvents; ++i) - { - const DirectMidiPacket& m = midiBuffer[i]; - - jassert ((int) m.mTimestamp < numSamples); - - midiEvents.addEvent (m.mData, m.mLength, - jlimit (0, (int) numSamples - 1, (int) m.mTimestamp)); - } - } -#endif - -#if defined (JUCE_DEBUG) || JUCE_LOG_ASSERTIONS - const int numMidiEventsComingIn = midiEvents.getNumEvents(); - (void) numMidiEventsComingIn; -#endif - - { - const ScopedLock sl (juceFilter->getCallbackLock()); - - const int numIn = juceFilter->getNumInputChannels(); - const int numOut = juceFilter->getNumOutputChannels(); - const int totalChans = jmax (numIn, numOut); - - if (juceFilter->isSuspended()) - { - for (int i = 0; i < numOut; ++i) - zeromem (outputs [i], sizeof (float) * numSamples); - } - else - { - { - int i; - for (i = 0; i < numOut; ++i) - { - channels[i] = outputs [i]; - - if (i < numIn && inputs != outputs) - memcpy (outputs [i], inputs[i], sizeof (float) * numSamples); - } - - for (; i < numIn; ++i) - channels [i] = inputs [i]; - } - - AudioSampleBuffer chans (channels, totalChans, numSamples); - - juceFilter->processBlock (chans, midiEvents); - } - } - - if (! midiEvents.isEmpty()) - { -#if JucePlugin_ProducesMidiOutput - const juce::uint8* midiEventData; - int midiEventSize, midiEventPosition; - MidiBuffer::Iterator i (midiEvents); - - while (i.getNextEvent (midiEventData, midiEventSize, midiEventPosition)) - { -// jassert (midiEventPosition >= 0 && midiEventPosition < (int) numSamples); - - //xxx - } -#else - // if your plugin creates midi messages, you'll need to set - // the JucePlugin_ProducesMidiOutput macro to 1 in your - // JucePluginCharacteristics.h file - jassert (midiEvents.getNumEvents() <= numMidiEventsComingIn); -#endif - - midiEvents.clear(); - } - } - - //============================================================================== - ComponentResult GetChunkSize (OSType chunkID, long* size) - { - if (chunkID == juceChunkType) - { - tempFilterData.setSize (0); - juceFilter->getStateInformation (tempFilterData); - - *size = sizeof (SFicPlugInChunkHeader) + tempFilterData.getSize(); - return noErr; - } - - return CEffectProcessMIDI::GetChunkSize (chunkID, size); - } - - ComponentResult GetChunk (OSType chunkID, SFicPlugInChunk* chunk) - { - if (chunkID == juceChunkType) - { - if (tempFilterData.getSize() == 0) - juceFilter->getStateInformation (tempFilterData); - - chunk->fSize = sizeof (SFicPlugInChunkHeader) + tempFilterData.getSize(); - tempFilterData.copyTo ((void*) chunk->fData, 0, tempFilterData.getSize()); - - tempFilterData.setSize (0); - - return noErr; - } - - return CEffectProcessMIDI::GetChunk (chunkID, chunk); - } - - ComponentResult SetChunk (OSType chunkID, SFicPlugInChunk* chunk) - { - if (chunkID == juceChunkType) - { - tempFilterData.setSize (0); - - if (chunk->fSize - sizeof (SFicPlugInChunkHeader) > 0) - { - juceFilter->setStateInformation ((void*) chunk->fData, - chunk->fSize - sizeof (SFicPlugInChunkHeader)); - } - - return noErr; - } - - return CEffectProcessMIDI::SetChunk (chunkID, chunk); - } - - //============================================================================== - ComponentResult UpdateControlValue (long controlIndex, long value) - { - if (controlIndex != bypassControlIndex) - juceFilter->setParameter (controlIndex - 2, longToFloat (value)); - else - mBypassed = (value > 0); - - return CProcess::UpdateControlValue (controlIndex, value); - } - - //============================================================================== - bool getCurrentPosition (AudioPlayHead::CurrentPositionInfo& info) - { - // this method can only be called while the plugin is running - jassert (prepared); - - Cmn_Float64 bpm = 120.0; - Cmn_Int32 num = 4, denom = 4; - Cmn_Int64 ticks = 0; - Cmn_Bool isPlaying = false; - - if (midiTransport != 0) - { - midiTransport->GetCurrentTempo (&bpm); - midiTransport->IsTransportPlaying (&isPlaying); - midiTransport->GetCurrentMeter (&num, &denom); - midiTransport->GetCurrentTickPosition (&ticks); - } - - info.bpm = bpm; - info.timeSigNumerator = num; - info.timeSigDenominator = denom; - info.isPlaying = isPlaying; - info.isRecording = false; - info.ppqPosition = ticks / 960000.0; - info.ppqPositionOfLastBarStart = 0; //xxx no idea how to get this correctly.. - - // xxx incorrect if there are tempo changes, but there's no - // other way of getting this info.. - info.timeInSeconds = ticks * (60.0 / 960000.0) / bpm; - - double framesPerSec = 24.0; - - switch (fTimeCodeInfo.mFrameRate) - { - case ficFrameRate_24Frame: - info.frameRate = AudioPlayHead::fps24; - break; - - case ficFrameRate_25Frame: - info.frameRate = AudioPlayHead::fps25; - framesPerSec = 25.0; - break; - - case ficFrameRate_2997NonDrop: - info.frameRate = AudioPlayHead::fps2997; - framesPerSec = 29.97002997; - break; - - case ficFrameRate_2997DropFrame: - info.frameRate = AudioPlayHead::fps2997drop; - framesPerSec = 29.97002997; - break; - - case ficFrameRate_30NonDrop: - info.frameRate = AudioPlayHead::fps30; - framesPerSec = 30.0; - break; - - case ficFrameRate_30DropFrame: - info.frameRate = AudioPlayHead::fps30drop; - framesPerSec = 30.0; - break; - - case ficFrameRate_23976: - // xxx not strictly true.. - info.frameRate = AudioPlayHead::fps24; - framesPerSec = 23.976; - break; - - default: - info.frameRate = AudioPlayHead::fpsUnknown; - break; - } - - info.editOriginTime = fTimeCodeInfo.mFrameOffset / framesPerSec; - - return true; - } - - void audioProcessorParameterChanged (AudioProcessor*, int index, float newValue) - { - SetControlValue (index + 2, floatToLong (newValue)); - } - - void audioProcessorParameterChangeGestureBegin (AudioProcessor*, int index) - { - TouchControl (index + 2); - } - - void audioProcessorParameterChangeGestureEnd (AudioProcessor*, int index) - { - ReleaseControl (index + 2); - } - - void audioProcessorChanged (AudioProcessor*) - { - // xxx is there an RTAS equivalent? - } - - //============================================================================== -private: - AudioProcessor* juceFilter; - MidiBuffer midiEvents; - CEffectMIDIOtherBufferedNode* midiBufferNode; - CEffectMIDITransport* midiTransport; - DirectMidiPacket midiBuffer [midiBufferSize]; - - JUCE_NAMESPACE::MemoryBlock tempFilterData; - float** channels; - bool prepared; - double sampleRate; - - void bypassBuffers (float** const inputs, float** const outputs, const long numSamples) const - { - for (int i = fNumOutputs; --i >= 0;) - { - if (i < fNumInputs) - memcpy (outputs[i], inputs[i], numSamples * sizeof (float)); - else - zeromem (outputs[i], numSamples * sizeof (float)); - } - } - - //============================================================================== - class JucePluginControl : public CPluginControl - { - public: - //============================================================================== - JucePluginControl (AudioProcessor* const juceFilter_, const int index_) - : juceFilter (juceFilter_), - index (index_) - { - } - - ~JucePluginControl() - { - } - - //============================================================================== - OSType GetID() const { return index + 1; } - long GetDefaultValue() const { return floatToLong (0); } - void SetDefaultValue (long) {} - long GetNumSteps() const { return 0xffffffff; } - - long ConvertStringToValue (const char* valueString) const - { - return floatToLong (String (valueString).getFloatValue()); - } - - Cmn_Bool IsKeyValid (long key) const { return true; } - - void GetNameOfLength (char* name, int maxLength, OSType inControllerType) const - { - juceFilter->getParameterName (index).copyToBuffer (name, maxLength); - } - - long GetPriority() const { return kFicCooperativeTaskPriority; } - - long GetOrientation() const - { - return kDAE_LeftMinRightMax | kDAE_BottomMinTopMax - | kDAE_RotarySingleDotMode | kDAE_RotaryLeftMinRightMax; - } - - long GetControlType() const { return kDAE_ContinuousValues; } - - void GetValueString (char* valueString, int maxLength, long value) const - { - juceFilter->getParameterText (index).copyToBuffer (valueString, maxLength); - } - - Cmn_Bool IsAutomatable() const - { - return juceFilter->isParameterAutomatable (index); - } - - private: - //============================================================================== - AudioProcessor* const juceFilter; - const int index; - - JucePluginControl (const JucePluginControl&); - const JucePluginControl& operator= (const JucePluginControl&); - }; -}; - -//============================================================================== -class JucePlugInGroup : public CEffectGroupMIDI -{ -public: - //============================================================================== - JucePlugInGroup() - { - DefineManufacturerNamesAndID (JucePlugin_Manufacturer, JucePlugin_RTASManufacturerCode); - DefinePlugInNamesAndVersion (createRTASName(), JucePlugin_VersionCode); - -#ifndef JUCE_DEBUG - AddGestalt (pluginGestalt_IsCacheable); -#endif - } - - ~JucePlugInGroup() - { - shutdownJuce_GUI(); - shutdownJuce_NonGUI(); - } - - //============================================================================== - void CreateEffectTypes() - { - const short channelConfigs[][2] = { JucePlugin_PreferredChannelConfigurations }; - const int numConfigs = numElementsInArray (channelConfigs); - - // You need to actually add some configurations to the JucePlugin_PreferredChannelConfigurations - // value in your JucePluginCharacteristics.h file.. - jassert (numConfigs > 0); - - for (int i = 0; i < numConfigs; ++i) - { - CEffectType* const type - = new CEffectTypeRTAS ('jcaa' + i, - JucePlugin_RTASProductId, - JucePlugin_RTASCategory); - - type->DefineTypeNames (createRTASName()); - type->DefineSampleRateSupport (eSupports48kAnd96kAnd192k); - - type->DefineStemFormats (getFormatForChans (channelConfigs [i][0]), - getFormatForChans (channelConfigs [i][1])); - - type->AddGestalt (pluginGestalt_CanBypass); - type->AddGestalt (pluginGestalt_SupportsVariableQuanta); - type->AttachEffectProcessCreator (createNewProcess); - - AddEffectType (type); - } - } - - void Initialize() - { - CEffectGroupMIDI::Initialize(); - } - - //============================================================================== -private: - static CEffectProcess* createNewProcess() - { - // Juce setup -#if JUCE_WIN32 - PlatformUtilities::setCurrentModuleInstanceHandle (gThisModule); -#endif - initialiseJuce_GUI(); - - return new JucePlugInProcess(); - } - - static const String createRTASName() - { - return String (JucePlugin_Name) + T("\n") - + String (JucePlugin_Name).substring (0, 4); - } - - static EPlugIn_StemFormat getFormatForChans (const int numChans) throw() - { - switch (numChans) - { - case 0: - return ePlugIn_StemFormat_Generic; - - case 1: - return ePlugIn_StemFormat_Mono; - - case 2: - return ePlugIn_StemFormat_Stereo; - - case 3: - return ePlugIn_StemFormat_LCR; - - case 4: - return ePlugIn_StemFormat_Quad; - - case 5: - return ePlugIn_StemFormat_5dot0; - - case 6: - return ePlugIn_StemFormat_5dot1; - - case 7: - return ePlugIn_StemFormat_6dot1; - - case 8: - return ePlugIn_StemFormat_7dot1; - - default: - jassertfalse // hmm - not a valid number of chans for RTAS.. - break; - } - - return ePlugIn_StemFormat_Generic; - } -}; - -void initialiseMacRTAS(); - -CProcessGroupInterface* CProcessGroup::CreateProcessGroup() -{ -#if JUCE_MAC - initialiseMacRTAS(); -#endif - initialiseJuce_NonGUI(); - return new JucePlugInGroup(); -} - -#endif +/* + ============================================================================== + + This file is part of the JUCE library - "Jules' Utility Class Extensions" + Copyright 2004-7 by Raw Material Software ltd. + + ------------------------------------------------------------------------------ + + JUCE can be redistributed and/or modified under the terms of the + GNU General Public License, as published by the Free Software Foundation; + either version 2 of the License, or (at your option) any later version. + + JUCE is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with JUCE; if not, visit www.gnu.org/licenses or write to the + Free Software Foundation, Inc., 59 Temple Place, Suite 330, + Boston, MA 02111-1307 USA + + ------------------------------------------------------------------------------ + + If you'd like to release a closed-source product which uses JUCE, commercial + licenses are also available: visit www.rawmaterialsoftware.com/juce for + more information. + + ============================================================================== +*/ + +#ifdef _MSC_VER + // (this is a workaround for a build problem in VC9) + #define _DO_NOT_DECLARE_INTERLOCKED_INTRINSICS_IN_MEMORY + #include +#endif + +#include "juce_RTAS_DigiCode_Header.h" + +#if JucePlugin_Build_RTAS + +#ifdef _MSC_VER + #include "Mac2Win.H" +#endif + +/* Note about include paths + ------------------------ + + To be able to include all the Digidesign headers correctly, you'll need to add this + lot to your include path: + + c:\yourdirectory\PT_80_SDK\AlturaPorts\TDMPlugins\PluginLibrary\EffectClasses + c:\yourdirectory\PT_80_SDK\AlturaPorts\TDMPlugins\PluginLibrary\ProcessClasses + c:\yourdirectory\PT_80_SDK\AlturaPorts\TDMPlugins\PluginLibrary\ProcessClasses\Interfaces + c:\yourdirectory\PT_80_SDK\AlturaPorts\TDMPlugins\PluginLibrary\Utilities + c:\yourdirectory\PT_80_SDK\AlturaPorts\TDMPlugins\PluginLibrary\RTASP_Adapt + c:\yourdirectory\PT_80_SDK\AlturaPorts\TDMPlugins\PluginLibrary\CoreClasses + c:\yourdirectory\PT_80_SDK\AlturaPorts\TDMPlugins\PluginLibrary\Controls + c:\yourdirectory\PT_80_SDK\AlturaPorts\TDMPlugins\PluginLibrary\Meters + c:\yourdirectory\PT_80_SDK\AlturaPorts\TDMPlugins\PluginLibrary\ViewClasses + c:\yourdirectory\PT_80_SDK\AlturaPorts\TDMPlugins\PluginLibrary\DSPClasses + c:\yourdirectory\PT_80_SDK\AlturaPorts\TDMPlugins\PluginLibrary\Interfaces + c:\yourdirectory\PT_80_SDK\AlturaPorts\TDMPlugins\common + c:\yourdirectory\PT_80_SDK\AlturaPorts\TDMPlugins\common\Platform + c:\yourdirectory\PT_80_SDK\AlturaPorts\TDMPlugins\SignalProcessing\Public + C:\yourdirectory\PT_80_SDK\AlturaPorts\TDMPlugIns\DSPManager\Interfaces + c:\yourdirectory\PT_80_SDK\AlturaPorts\SADriver\Interfaces + c:\yourdirectory\PT_80_SDK\AlturaPorts\DigiPublic\Interfaces + c:\yourdirectory\PT_80_SDK\AlturaPorts\Fic\Interfaces\DAEClient + c:\yourdirectory\PT_80_SDK\AlturaPorts\NewFileLibs\Cmn + c:\yourdirectory\PT_80_SDK\AlturaPorts\NewFileLibs\DOA + c:\yourdirectory\PT_80_SDK\AlturaPorts\AlturaSource\PPC_H + c:\yourdirectory\PT_80_SDK\AlturaPorts\AlturaSource\AppSupport + c:\yourdirectory\PT_80_SDK\AvidCode\AVX2sdk\AVX\avx2\avx2sdk\inc + C:\yourdirectory\PT_80_SDK\xplat\AVX\avx2\avx2sdk\inc + + NB. If you hit a huge pile of bugs around here, make sure that you've not got the + Apple QuickTime headers before the PT headers in your path, because there are + some filename clashes between them. + +*/ +#include "CEffectGroupMIDI.h" +#include "CEffectProcessMIDI.h" +#include "CEffectProcessRTAS.h" +#include "CCustomView.h" +#include "CEffectTypeRTAS.h" +#include "CPluginControl.h" +#include "CPluginControl_OnOff.h" +#include "FicProcessTokens.h" + +//============================================================================== +#ifdef _MSC_VER + #pragma pack (push, 8) +#endif + +#include "../juce_PluginHeaders.h" + +#ifdef _MSC_VER + #pragma pack (pop) + + #if JUCE_DEBUG + #define PT_LIB_PATH JucePlugin_WinBag_path "\\Debug\\lib\\" + #else + #define PT_LIB_PATH JucePlugin_WinBag_path "\\Release\\lib\\" + #endif + + #pragma comment(lib, PT_LIB_PATH "DAE.lib") + #pragma comment(lib, PT_LIB_PATH "DigiExt.lib") + #pragma comment(lib, PT_LIB_PATH "DSI.lib") + #pragma comment(lib, PT_LIB_PATH "PluginLib.lib") + +#endif + +#undef Component +#undef MemoryBlock + +//============================================================================== +#if JUCE_WIN32 + extern void JUCE_CALLTYPE attachSubWindow (void* hostWindow, int& titleW, int& titleH, JUCE_NAMESPACE::Component* comp); + extern void JUCE_CALLTYPE resizeHostWindow (void* hostWindow, int& titleW, int& titleH, JUCE_NAMESPACE::Component* comp); + #if ! JucePlugin_EditorRequiresKeyboardFocus + extern void JUCE_CALLTYPE passFocusToHostWindow (void* hostWindow); + #endif +#else + extern void* attachSubWindow (void* hostWindowRef, JUCE_NAMESPACE::Component* comp); + extern void removeSubWindow (void* nsWindow, JUCE_NAMESPACE::Component* comp); +#endif + +const int midiBufferSize = 1024; +const OSType juceChunkType = 'juce'; +static const int bypassControlIndex = 1; + +//============================================================================== +/** Somewhere in the codebase of your plugin, you need to implement this function + and make it return a new instance of the filter subclass that you're building. +*/ +extern AudioProcessor* JUCE_CALLTYPE createPluginFilter(); + + +//============================================================================== +static float longToFloat (const long n) throw() +{ + return (float) ((((double) n) + (double) 0x80000000) / (double) 0xffffffff); +} + +static long floatToLong (const float n) throw() +{ + return roundDoubleToInt (jlimit (-(double) 0x80000000, + (double) 0x7fffffff, + n * (double) 0xffffffff - (double) 0x80000000)); +} + +static int numInstances = 0; + +//============================================================================== +class JucePlugInProcess : public CEffectProcessMIDI, + public CEffectProcessRTAS, + public AudioProcessorListener, + public AudioPlayHead, + public AsyncUpdater +{ +public: + //============================================================================== + JucePlugInProcess() + : midiBufferNode (0), + midiTransport (0), + channels (0), + prepared (false), + sampleRate (44100.0) + { + juceFilter = createPluginFilter(); + jassert (juceFilter != 0); + + AddChunk (juceChunkType, "Juce Audio Plugin Data"); + + ++numInstances; + } + + ~JucePlugInProcess() + { + if (mLoggedIn) + MIDILogOut(); + + deleteAndZero (midiBufferNode); + deleteAndZero (midiTransport); + + if (prepared) + juceFilter->releaseResources(); + + delete juceFilter; + juce_free (channels); + + if (--numInstances == 0) + shutdownJuce_GUI(); + } + + //============================================================================== + class JuceCustomUIView : public CCustomView, + public Timer + { + public: + //============================================================================== + JuceCustomUIView (AudioProcessor* const filter_, + JucePlugInProcess* const process_) + : filter (filter_), + process (process_), + wrapper (0), + editorComp (0) + { + // setting the size in here crashes PT for some reason, so keep it simple.. + } + + ~JuceCustomUIView() + { + deleteEditorComp(); + } + + //============================================================================== + void updateSize() + { + if (editorComp == 0) + { + editorComp = filter->createEditorIfNeeded(); + jassert (editorComp != 0); + } + + Rect oldRect; + GetRect (&oldRect); + + Rect r; + r.left = 0; + r.top = 0; + r.right = editorComp->getWidth(); + r.bottom = editorComp->getHeight(); + SetRect (&r); + + if ((oldRect.right != r.right) || (oldRect.bottom != r.bottom)) + startTimer (50); + } + + void timerCallback() + { + if (! JUCE_NAMESPACE::Component::isMouseButtonDownAnywhere()) + { + stopTimer(); + + // Send a token to the host to tell it about the resize + SSetProcessWindowResizeToken token (process->fRootNameId, process->fRootNameId); + FicSDSDispatchToken (&token); + } + } + + void attachToWindow (GrafPtr port) + { + if (port != 0) + { + updateSize(); + +#if JUCE_WIN32 + void* const hostWindow = (void*) ASI_GethWnd ((WindowPtr) port); +#else + void* const hostWindow = (void*) GetWindowFromPort (port); +#endif + deleteAndZero (wrapper); + + wrapper = new EditorCompWrapper (hostWindow, editorComp, this); + } + else + { + deleteEditorComp(); + } + } + + void DrawContents (Rect*) + { +#if JUCE_WIN32 + if (wrapper != 0) + { + ComponentPeer* const peer = wrapper->getPeer(); + + if (peer != 0) + { + // (seems to be required in PT6.4, but not in 7.x) + peer->repaint (0, 0, wrapper->getWidth(), wrapper->getHeight()); + } + } +#endif + } + + void DrawBackground (Rect*) {} + + //============================================================================== + private: + AudioProcessor* const filter; + JucePlugInProcess* const process; + JUCE_NAMESPACE::Component* wrapper; + AudioProcessorEditor* editorComp; + + void deleteEditorComp() + { + if (editorComp != 0 || wrapper != 0) + { +#if JUCE_MAC + const ScopedAutoReleasePool pool; +#endif + PopupMenu::dismissAllActiveMenus(); + + JUCE_NAMESPACE::Component* const modalComponent = JUCE_NAMESPACE::Component::getCurrentlyModalComponent(); + if (modalComponent != 0) + modalComponent->exitModalState (0); + + filter->editorBeingDeleted (editorComp); + + deleteAndZero (editorComp); + deleteAndZero (wrapper); + } + } + + //============================================================================== + // A component to hold the AudioProcessorEditor, and cope with some housekeeping + // chores when it changes or repaints. + class EditorCompWrapper : public JUCE_NAMESPACE::Component +#if ! JUCE_MAC + , public FocusChangeListener +#endif + { + public: + EditorCompWrapper (void* const hostWindow_, + Component* const editorComp, + JuceCustomUIView* const owner_) + : hostWindow (hostWindow_), + owner (owner_), + titleW (0), + titleH (0) + { +#if JucePlugin_EditorRequiresKeyboardFocus + setWantsKeyboardFocus (true); +#else + setComponentProperty ("juce_disallowFocus", true); + setWantsKeyboardFocus (false); +#endif + setOpaque (true); + setBroughtToFrontOnMouseClick (true); + setBounds (editorComp->getBounds()); + editorComp->setTopLeftPosition (0, 0); + addAndMakeVisible (editorComp); + +#if JUCE_WIN32 + attachSubWindow (hostWindow, titleW, titleH, this); +#else + nsWindow = attachSubWindow (hostWindow, this); +#endif + setVisible (true); + +#if JUCE_WIN32 && ! JucePlugin_EditorRequiresKeyboardFocus + Desktop::getInstance().addFocusChangeListener (this); +#endif + } + + ~EditorCompWrapper() + { +#if JUCE_WIN32 && ! JucePlugin_EditorRequiresKeyboardFocus + Desktop::getInstance().removeFocusChangeListener (this); +#endif + +#if JUCE_MAC + removeSubWindow (nsWindow, this); +#endif + } + + void paint (Graphics&) + { + } + + void resized() + { + JUCE_NAMESPACE::Component* const c = getChildComponent (0); + + if (c != 0) + c->setBounds (0, 0, getWidth(), getHeight()); + + repaint(); + } + +#if JUCE_WIN32 + void globalFocusChanged (JUCE_NAMESPACE::Component*) + { + #if ! JucePlugin_EditorRequiresKeyboardFocus + if (hasKeyboardFocus (true)) + passFocusToHostWindow (hostWindow); + #endif + } +#endif + + void childBoundsChanged (JUCE_NAMESPACE::Component* child) + { + setSize (child->getWidth(), child->getHeight()); + child->setTopLeftPosition (0, 0); + +#if JUCE_WIN32 + resizeHostWindow (hostWindow, titleW, titleH, this); +#endif + owner->updateSize(); + } + + void userTriedToCloseWindow() + { + } + + //============================================================================== + juce_UseDebuggingNewOperator + + private: + void* const hostWindow; + void* nsWindow; + JuceCustomUIView* const owner; + int titleW, titleH; + }; + }; + + JuceCustomUIView* getView() const + { + return dynamic_cast (fOurPlugInView); + } + + void GetViewRect (Rect* size) + { + if (getView() != 0) + getView()->updateSize(); + + CEffectProcessRTAS::GetViewRect (size); + } + + CPlugInView* CreateCPlugInView() + { + return new JuceCustomUIView (juceFilter, this); + } + + void SetViewPort (GrafPtr port) + { + CEffectProcessRTAS::SetViewPort (port); + + if (getView() != 0) + getView()->attachToWindow (port); + } + + //============================================================================== +protected: + ComponentResult GetDelaySamplesLong (long* aNumSamples) + { + if (aNumSamples != 0) + *aNumSamples = juceFilter != 0 ? juceFilter->getLatencySamples() : 0; + + return noErr; + } + + //============================================================================== + void EffectInit() + { + SFicPlugInStemFormats stems; + GetProcessType()->GetStemFormats (&stems); + + juceFilter->setPlayConfigDetails (fNumInputs, fNumOutputs, + juceFilter->getSampleRate(), juceFilter->getBlockSize()); + + AddControl (new CPluginControl_OnOff ('bypa', "Master Bypass\nMastrByp\nMByp\nByp", false, true)); + DefineMasterBypassControlIndex (bypassControlIndex); + + for (int i = 0; i < juceFilter->getNumParameters(); ++i) + AddControl (new JucePluginControl (juceFilter, i)); + + // we need to do this midi log-in to get timecode, regardless of whether + // the plugin actually uses midi... + if (MIDILogIn() == noErr) + { +#if JucePlugin_WantsMidiInput + CEffectType* const type = dynamic_cast (this->GetProcessType()); + + if (type != 0) + { + char nodeName [64]; + type->GetProcessTypeName (63, nodeName); + p2cstrcpy (nodeName, reinterpret_cast (nodeName)); + + midiBufferNode = new CEffectMIDIOtherBufferedNode (&mMIDIWorld, + 8192, + eLocalNode, + nodeName, + midiBuffer); + + midiBufferNode->Initialize (1, true); + } +#endif + } + + midiTransport = new CEffectMIDITransport (&mMIDIWorld); + + juceFilter->setPlayHead (this); + juceFilter->addListener (this); + } + + void handleAsyncUpdate() + { + if (! prepared) + { + sampleRate = gProcessGroup->GetSampleRate(); + jassert (sampleRate > 0); + + juce_free (channels); + channels = (float**) juce_calloc (sizeof (float*) * jmax (juceFilter->getNumInputChannels(), + juceFilter->getNumOutputChannels())); + + juceFilter->setPlayConfigDetails (fNumInputs, fNumOutputs, + sampleRate, mRTGlobals->mHWBufferSizeInSamples); + + juceFilter->prepareToPlay (sampleRate, + mRTGlobals->mHWBufferSizeInSamples); + + prepared = true; + } + } + + void RenderAudio (float** inputs, float** outputs, long numSamples) + { + if (! prepared) + { + triggerAsyncUpdate(); + bypassBuffers (inputs, outputs, numSamples); + return; + } + + if (mBypassed) + { + bypassBuffers (inputs, outputs, numSamples); + return; + } + +#if JucePlugin_WantsMidiInput + midiEvents.clear(); + + const Cmn_UInt32 bufferSize = mRTGlobals->mHWBufferSizeInSamples; + + if (midiBufferNode->GetAdvanceScheduleTime() != bufferSize) + midiBufferNode->SetAdvanceScheduleTime (bufferSize); + + if (midiBufferNode->FillMIDIBuffer (mRTGlobals->mRunningTime, numSamples) == noErr) + { + jassert (midiBufferNode->GetBufferPtr() != 0); + const int numMidiEvents = midiBufferNode->GetBufferSize(); + + for (int i = 0; i < numMidiEvents; ++i) + { + const DirectMidiPacket& m = midiBuffer[i]; + + jassert ((int) m.mTimestamp < numSamples); + + midiEvents.addEvent (m.mData, m.mLength, + jlimit (0, (int) numSamples - 1, (int) m.mTimestamp)); + } + } +#endif + +#if defined (JUCE_DEBUG) || JUCE_LOG_ASSERTIONS + const int numMidiEventsComingIn = midiEvents.getNumEvents(); + (void) numMidiEventsComingIn; +#endif + + { + const ScopedLock sl (juceFilter->getCallbackLock()); + + const int numIn = juceFilter->getNumInputChannels(); + const int numOut = juceFilter->getNumOutputChannels(); + const int totalChans = jmax (numIn, numOut); + + if (juceFilter->isSuspended()) + { + for (int i = 0; i < numOut; ++i) + zeromem (outputs [i], sizeof (float) * numSamples); + } + else + { + { + int i; + for (i = 0; i < numOut; ++i) + { + channels[i] = outputs [i]; + + if (i < numIn && inputs != outputs) + memcpy (outputs [i], inputs[i], sizeof (float) * numSamples); + } + + for (; i < numIn; ++i) + channels [i] = inputs [i]; + } + + AudioSampleBuffer chans (channels, totalChans, numSamples); + + juceFilter->processBlock (chans, midiEvents); + } + } + + if (! midiEvents.isEmpty()) + { +#if JucePlugin_ProducesMidiOutput + const juce::uint8* midiEventData; + int midiEventSize, midiEventPosition; + MidiBuffer::Iterator i (midiEvents); + + while (i.getNextEvent (midiEventData, midiEventSize, midiEventPosition)) + { +// jassert (midiEventPosition >= 0 && midiEventPosition < (int) numSamples); + + //xxx + } +#else + // if your plugin creates midi messages, you'll need to set + // the JucePlugin_ProducesMidiOutput macro to 1 in your + // JucePluginCharacteristics.h file + jassert (midiEvents.getNumEvents() <= numMidiEventsComingIn); +#endif + + midiEvents.clear(); + } + } + + //============================================================================== + ComponentResult GetChunkSize (OSType chunkID, long* size) + { + if (chunkID == juceChunkType) + { + tempFilterData.setSize (0); + juceFilter->getStateInformation (tempFilterData); + + *size = sizeof (SFicPlugInChunkHeader) + tempFilterData.getSize(); + return noErr; + } + + return CEffectProcessMIDI::GetChunkSize (chunkID, size); + } + + ComponentResult GetChunk (OSType chunkID, SFicPlugInChunk* chunk) + { + if (chunkID == juceChunkType) + { + if (tempFilterData.getSize() == 0) + juceFilter->getStateInformation (tempFilterData); + + chunk->fSize = sizeof (SFicPlugInChunkHeader) + tempFilterData.getSize(); + tempFilterData.copyTo ((void*) chunk->fData, 0, tempFilterData.getSize()); + + tempFilterData.setSize (0); + + return noErr; + } + + return CEffectProcessMIDI::GetChunk (chunkID, chunk); + } + + ComponentResult SetChunk (OSType chunkID, SFicPlugInChunk* chunk) + { + if (chunkID == juceChunkType) + { + tempFilterData.setSize (0); + + if (chunk->fSize - sizeof (SFicPlugInChunkHeader) > 0) + { + juceFilter->setStateInformation ((void*) chunk->fData, + chunk->fSize - sizeof (SFicPlugInChunkHeader)); + } + + return noErr; + } + + return CEffectProcessMIDI::SetChunk (chunkID, chunk); + } + + //============================================================================== + ComponentResult UpdateControlValue (long controlIndex, long value) + { + if (controlIndex != bypassControlIndex) + juceFilter->setParameter (controlIndex - 2, longToFloat (value)); + else + mBypassed = (value > 0); + + return CProcess::UpdateControlValue (controlIndex, value); + } + + //============================================================================== + bool getCurrentPosition (AudioPlayHead::CurrentPositionInfo& info) + { + // this method can only be called while the plugin is running + jassert (prepared); + + Cmn_Float64 bpm = 120.0; + Cmn_Int32 num = 4, denom = 4; + Cmn_Int64 ticks = 0; + Cmn_Bool isPlaying = false; + + if (midiTransport != 0) + { + midiTransport->GetCurrentTempo (&bpm); + midiTransport->IsTransportPlaying (&isPlaying); + midiTransport->GetCurrentMeter (&num, &denom); + midiTransport->GetCurrentTickPosition (&ticks); + } + + info.bpm = bpm; + info.timeSigNumerator = num; + info.timeSigDenominator = denom; + info.isPlaying = isPlaying; + info.isRecording = false; + info.ppqPosition = ticks / 960000.0; + info.ppqPositionOfLastBarStart = 0; //xxx no idea how to get this correctly.. + + // xxx incorrect if there are tempo changes, but there's no + // other way of getting this info.. + info.timeInSeconds = ticks * (60.0 / 960000.0) / bpm; + + double framesPerSec = 24.0; + + switch (fTimeCodeInfo.mFrameRate) + { + case ficFrameRate_24Frame: + info.frameRate = AudioPlayHead::fps24; + break; + + case ficFrameRate_25Frame: + info.frameRate = AudioPlayHead::fps25; + framesPerSec = 25.0; + break; + + case ficFrameRate_2997NonDrop: + info.frameRate = AudioPlayHead::fps2997; + framesPerSec = 29.97002997; + break; + + case ficFrameRate_2997DropFrame: + info.frameRate = AudioPlayHead::fps2997drop; + framesPerSec = 29.97002997; + break; + + case ficFrameRate_30NonDrop: + info.frameRate = AudioPlayHead::fps30; + framesPerSec = 30.0; + break; + + case ficFrameRate_30DropFrame: + info.frameRate = AudioPlayHead::fps30drop; + framesPerSec = 30.0; + break; + + case ficFrameRate_23976: + // xxx not strictly true.. + info.frameRate = AudioPlayHead::fps24; + framesPerSec = 23.976; + break; + + default: + info.frameRate = AudioPlayHead::fpsUnknown; + break; + } + + info.editOriginTime = fTimeCodeInfo.mFrameOffset / framesPerSec; + + return true; + } + + void audioProcessorParameterChanged (AudioProcessor*, int index, float newValue) + { + SetControlValue (index + 2, floatToLong (newValue)); + } + + void audioProcessorParameterChangeGestureBegin (AudioProcessor*, int index) + { + TouchControl (index + 2); + } + + void audioProcessorParameterChangeGestureEnd (AudioProcessor*, int index) + { + ReleaseControl (index + 2); + } + + void audioProcessorChanged (AudioProcessor*) + { + // xxx is there an RTAS equivalent? + } + + //============================================================================== +private: + AudioProcessor* juceFilter; + MidiBuffer midiEvents; + CEffectMIDIOtherBufferedNode* midiBufferNode; + CEffectMIDITransport* midiTransport; + DirectMidiPacket midiBuffer [midiBufferSize]; + + JUCE_NAMESPACE::MemoryBlock tempFilterData; + float** channels; + bool prepared; + double sampleRate; + + void bypassBuffers (float** const inputs, float** const outputs, const long numSamples) const + { + for (int i = fNumOutputs; --i >= 0;) + { + if (i < fNumInputs) + memcpy (outputs[i], inputs[i], numSamples * sizeof (float)); + else + zeromem (outputs[i], numSamples * sizeof (float)); + } + } + + //============================================================================== + class JucePluginControl : public CPluginControl + { + public: + //============================================================================== + JucePluginControl (AudioProcessor* const juceFilter_, const int index_) + : juceFilter (juceFilter_), + index (index_) + { + } + + ~JucePluginControl() + { + } + + //============================================================================== + OSType GetID() const { return index + 1; } + long GetDefaultValue() const { return floatToLong (0); } + void SetDefaultValue (long) {} + long GetNumSteps() const { return 0xffffffff; } + + long ConvertStringToValue (const char* valueString) const + { + return floatToLong (String (valueString).getFloatValue()); + } + + Cmn_Bool IsKeyValid (long key) const { return true; } + + void GetNameOfLength (char* name, int maxLength, OSType inControllerType) const + { + juceFilter->getParameterName (index).copyToBuffer (name, maxLength); + } + + long GetPriority() const { return kFicCooperativeTaskPriority; } + + long GetOrientation() const + { + return kDAE_LeftMinRightMax | kDAE_BottomMinTopMax + | kDAE_RotarySingleDotMode | kDAE_RotaryLeftMinRightMax; + } + + long GetControlType() const { return kDAE_ContinuousValues; } + + void GetValueString (char* valueString, int maxLength, long value) const + { + juceFilter->getParameterText (index).copyToBuffer (valueString, maxLength); + } + + Cmn_Bool IsAutomatable() const + { + return juceFilter->isParameterAutomatable (index); + } + + private: + //============================================================================== + AudioProcessor* const juceFilter; + const int index; + + JucePluginControl (const JucePluginControl&); + const JucePluginControl& operator= (const JucePluginControl&); + }; +}; + +//============================================================================== +class JucePlugInGroup : public CEffectGroupMIDI +{ +public: + //============================================================================== + JucePlugInGroup() + { + DefineManufacturerNamesAndID (JucePlugin_Manufacturer, JucePlugin_RTASManufacturerCode); + DefinePlugInNamesAndVersion (createRTASName(), JucePlugin_VersionCode); + +#ifndef JUCE_DEBUG + AddGestalt (pluginGestalt_IsCacheable); +#endif + } + + ~JucePlugInGroup() + { + shutdownJuce_GUI(); + shutdownJuce_NonGUI(); + } + + //============================================================================== + void CreateEffectTypes() + { + const short channelConfigs[][2] = { JucePlugin_PreferredChannelConfigurations }; + const int numConfigs = numElementsInArray (channelConfigs); + + // You need to actually add some configurations to the JucePlugin_PreferredChannelConfigurations + // value in your JucePluginCharacteristics.h file.. + jassert (numConfigs > 0); + + for (int i = 0; i < numConfigs; ++i) + { + CEffectType* const type + = new CEffectTypeRTAS ('jcaa' + i, + JucePlugin_RTASProductId, + JucePlugin_RTASCategory); + + type->DefineTypeNames (createRTASName()); + type->DefineSampleRateSupport (eSupports48kAnd96kAnd192k); + + type->DefineStemFormats (getFormatForChans (channelConfigs [i][0] != 0 ? channelConfigs [i][0] : channelConfigs [i][1]), + getFormatForChans (channelConfigs [i][1] != 0 ? channelConfigs [i][1] : channelConfigs [i][0])); + + type->AddGestalt (pluginGestalt_CanBypass); + type->AddGestalt (pluginGestalt_SupportsVariableQuanta); + type->AttachEffectProcessCreator (createNewProcess); + + AddEffectType (type); + } + } + + void Initialize() + { + CEffectGroupMIDI::Initialize(); + } + + //============================================================================== +private: + static CEffectProcess* createNewProcess() + { + // Juce setup +#if JUCE_WIN32 + PlatformUtilities::setCurrentModuleInstanceHandle (gThisModule); +#endif + initialiseJuce_GUI(); + + return new JucePlugInProcess(); + } + + static const String createRTASName() + { + return String (JucePlugin_Name) + T("\n") + + String (JucePlugin_Name).substring (0, 4); + } + + static EPlugIn_StemFormat getFormatForChans (const int numChans) throw() + { + switch (numChans) + { + case 0: + return ePlugIn_StemFormat_Generic; + + case 1: + return ePlugIn_StemFormat_Mono; + + case 2: + return ePlugIn_StemFormat_Stereo; + + case 3: + return ePlugIn_StemFormat_LCR; + + case 4: + return ePlugIn_StemFormat_Quad; + + case 5: + return ePlugIn_StemFormat_5dot0; + + case 6: + return ePlugIn_StemFormat_5dot1; + + case 7: + return ePlugIn_StemFormat_6dot1; + + case 8: + return ePlugIn_StemFormat_7dot1; + + default: + jassertfalse // hmm - not a valid number of chans for RTAS.. + break; + } + + return ePlugIn_StemFormat_Generic; + } +}; + +void initialiseMacRTAS(); + +CProcessGroupInterface* CProcessGroup::CreateProcessGroup() +{ +#if JUCE_MAC + initialiseMacRTAS(); +#endif + initialiseJuce_NonGUI(); + return new JucePlugInGroup(); +} + +#endif diff --git a/extras/audio plugins/wrapper/VST/juce_VST_Wrapper.cpp b/extras/audio plugins/wrapper/VST/juce_VST_Wrapper.cpp index 8123705ed4..1f99cba371 100644 --- a/extras/audio plugins/wrapper/VST/juce_VST_Wrapper.cpp +++ b/extras/audio plugins/wrapper/VST/juce_VST_Wrapper.cpp @@ -221,9 +221,13 @@ class SharedMessageThread : public Thread { public: SharedMessageThread() - : Thread (T("VstMessageThread")) + : Thread (T("VstMessageThread")), + initialised (false) { startThread (7); + + while (! initialised) + sleep (1); } ~SharedMessageThread() @@ -241,6 +245,9 @@ public: const Thread::ThreadID originalThreadId = messageManager->getCurrentMessageThread(); messageManager->setCurrentMessageThread (Thread::getCurrentThreadId()); + initialiseJuce_GUI(); + initialised = true; + while ((! threadShouldExit()) && messageManager->runDispatchLoopUntil (250)) { } @@ -249,8 +256,12 @@ public: } juce_DeclareSingleton (SharedMessageThread, false) + +private: + bool initialised; }; +juce_ImplementSingleton (SharedMessageThread) #endif @@ -446,6 +457,7 @@ public: { if (editorComp == 0) { + const MessageManagerLock mmLock; AudioProcessorEditor* const ed = filter->createEditorIfNeeded(); if (ed != 0) @@ -462,6 +474,7 @@ public: void close() { + const MessageManagerLock mmLock; jassert (! recursionCheck); stopTimer(); @@ -1179,6 +1192,7 @@ public: if (canDeleteLaterIfModal) { shouldDeleteEditor = true; + recursionCheck = false; return; } } @@ -1219,6 +1233,7 @@ public: } else if (opCode == effEditOpen) { + const MessageManagerLock mmLock; jassert (! recursionCheck); deleteEditor (true); @@ -1253,11 +1268,13 @@ public: } else if (opCode == effEditClose) { + const MessageManagerLock mmLock; deleteEditor (true); return 0; } else if (opCode == effEditGetRect) { + const MessageManagerLock mmLock; createEditorComp(); if (editorComp != 0) @@ -1490,7 +1507,6 @@ extern "C" __attribute__ ((visibility("default"))) AEffect* main_macho (audioMas extern "C" AEffect* VSTPluginMain (audioMasterCallback audioMaster) { - initialiseJuce_GUI(); SharedMessageThread::getInstance(); return pluginEntryPoint (audioMaster); diff --git a/extras/browser plugins/wrapper/juce_NPAPI_GlueCode.cpp b/extras/browser plugins/wrapper/juce_NPAPI_GlueCode.cpp index 315246df1a..65367e5155 100644 --- a/extras/browser plugins/wrapper/juce_NPAPI_GlueCode.cpp +++ b/extras/browser plugins/wrapper/juce_NPAPI_GlueCode.cpp @@ -447,7 +447,7 @@ public: { return [[v className] isEqualToString: @"WebNetscapePluginDocumentView"] || [[v className] isEqualToString: @"WebPluginDocumentView"] - || [[v className] isEqualToString: @"ChildView"]; + || ([[v className] isEqualToString: @"ChildView"] && ([v frame].origin.x != 0 && [v frame].origin.y != 0)); } void setWindow (NPWindow* window) diff --git a/juce_amalgamated.cpp b/juce_amalgamated.cpp index 47743a5a9a..fe859535d1 100644 --- a/juce_amalgamated.cpp +++ b/juce_amalgamated.cpp @@ -7965,6 +7965,73 @@ bool URL::isWellFormed() const return url.isNotEmpty(); } +static int findStartOfDomain (const String& url) +{ + int i = 0; + + while (CharacterFunctions::isLetterOrDigit (url[i]) + || CharacterFunctions::indexOfChar (T("+-."), url[i], false) >= 0) + ++i; + + return url[i] == T(':') ? i + 1 : 0; +} + +const String URL::getDomain() const +{ + int start = findStartOfDomain (url); + while (url[start] == T('/')) + ++start; + + const int end1 = url.indexOfChar (start, T('/')); + const int end2 = url.indexOfChar (start, T(':')); + + const int end = (end1 < 0 || end2 < 0) ? jmax (end1, end2) + : jmin (end1, end2); + + return url.substring (start, end); +} + +const String URL::getSubPath() const +{ + int start = findStartOfDomain (url); + while (url[start] == T('/')) + ++start; + + const int startOfPath = url.indexOfChar (start, T('/')) + 1; + + return startOfPath <= 0 ? String::empty + : url.substring (startOfPath); +} + +const String URL::getScheme() const +{ + return url.substring (0, findStartOfDomain (url) - 1); +} + +const URL URL::withNewSubPath (const String& newPath) const +{ + int start = findStartOfDomain (url); + while (url[start] == T('/')) + ++start; + + const int startOfPath = url.indexOfChar (start, T('/')) + 1; + + URL u (*this); + + if (startOfPath > 0) + u.url = url.substring (0, startOfPath); + + if (! u.url.endsWithChar (T('/'))) + u.url << '/'; + + if (newPath.startsWithChar (T('/'))) + u.url << newPath.substring (1); + else + u.url << newPath; + + return u; +} + bool URL::isProbablyAWebsiteURL (const String& possibleURL) { if (possibleURL.startsWithIgnoreCase (T("http:")) @@ -52504,7 +52571,7 @@ public: if (buttonUnderMouse != newItem) { - if (buttonUnderMouse != 0) + if (buttonUnderMouse != 0 && containsItem (buttonUnderMouse)) { const Rectangle r (buttonUnderMouse->getItemPosition (false)); repaint (0, r.getY(), r.getX(), buttonUnderMouse->getItemHeight()); @@ -52588,6 +52655,15 @@ private: item->setSelected ((! cmd) || (! item->isSelected()), ! cmd); } } + + bool containsItem (TreeViewItem* const item) const + { + for (int i = rowComponentItems.size(); --i >= 0;) + if ((TreeViewItem*) rowComponentItems.getUnchecked (i) == item) + return true; + + return false; + } }; class TreeViewport : public Viewport @@ -61074,10 +61150,15 @@ void LookAndFeel::drawButtonBackground (Graphics& g, button.isConnectedOnBottom()); } +const Font LookAndFeel::getFontForTextButton (TextButton& button) +{ + return button.getFont(); +} + void LookAndFeel::drawButtonText (Graphics& g, TextButton& button, bool /*isMouseOverButton*/, bool /*isButtonDown*/) { - g.setFont (button.getFont()); + g.setFont (getFontForTextButton (button)); g.setColour (button.findColour (TextButton::textColourId) .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f)); @@ -70772,7 +70853,8 @@ MagnifierComponent::MagnifierComponent (Component* const content_, : content (content_), scaleFactor (0.0), peer (0), - deleteContent (deleteContentCompWhenNoLongerNeeded) + deleteContent (deleteContentCompWhenNoLongerNeeded), + quality (Graphics::lowResamplingQuality) { holderComp = new PeerHolderComp (this); setScaleFactor (1.0); @@ -70844,7 +70926,7 @@ void MagnifierComponent::paint (Graphics& g) g2.reduceClipRegion (srcX, srcY, srcW, srcH); holderComp->paintEntireComponent (g2); - g.setImageResamplingQuality (Graphics::lowResamplingQuality); + g.setImageResamplingQuality (quality); g.drawImage (&temp, 0, 0, (int) (w * scaleFactor), (int) (h * scaleFactor), 0, 0, w, h, @@ -72256,6 +72338,9 @@ AlertWindow::AlertWindow (const String& title, } } + if (JUCEApplication::getInstance() == 0) + setAlwaysOnTop (true); // for a plugin, make it always-on-top because the host windows are often top-level + lookAndFeelChanged(); constrainer.setMinimumOnscreenAmounts (0x10000, 0x10000, 0x10000, 0x10000); @@ -76602,6 +76687,7 @@ void EdgeTable::addEdgePoint (const int x, const int y, const int winding) throw if (n >= maxEdgesPerLine) { remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine); + jassert (n < maxEdgesPerLine); lineStart = table + lineStrideElements * y; } @@ -80551,11 +80637,9 @@ const AffineTransform RectanglePlacement::getTransformToFit (float x, float y, const float scaleY = dh / h; if ((flags & stretchToFit) != 0) - { return AffineTransform::translation (-x, -y) .scaled (scaleX, scaleY) - .translated (dx - x, dy - y); - } + .translated (dx, dy); float scale = (flags & fillDestination) != 0 ? jmax (scaleX, scaleY) : jmin (scaleX, scaleY); @@ -246621,7 +246705,7 @@ static int CALLBACK wfontEnum2 (ENUMLOGFONTEXW* lpelfe, int type, LPARAM lParam) { - if (lpelfe != 0 && type == TRUETYPE_FONTTYPE) + if (lpelfe != 0 && (type & RASTER_FONTTYPE) == 0) { const String fontName (lpelfe->elfLogFont.lfFaceName); @@ -246636,8 +246720,7 @@ static int CALLBACK wfontEnum1 (ENUMLOGFONTEXW* lpelfe, int type, LPARAM lParam) { - if (lpelfe != 0 - && ((type & (DEVICE_FONTTYPE | RASTER_FONTTYPE)) == 0)) + if (lpelfe != 0 && (type & RASTER_FONTTYPE) == 0) { LOGFONTW lf; zerostruct (lf); diff --git a/juce_amalgamated.h b/juce_amalgamated.h index 9801f3b4b5..166631ecea 100644 --- a/juce_amalgamated.h +++ b/juce_amalgamated.h @@ -12593,6 +12593,32 @@ public: /** True if it seems to be valid. */ bool isWellFormed() const; + /** Returns just the domain part of the URL. + + E.g. for "http://www.xyz.com/foobar", this will return "www.xyz.com". + */ + const String getDomain() const; + + /** Returns the path part of the URL. + + E.g. for "http://www.xyz.com/foo/bar?x=1", this will return "foo/bar". + */ + const String getSubPath() const; + + /** Returns the scheme of the URL. + + E.g. for "http://www.xyz.com/foobar", this will return "http". (It won't + include the colon). + */ + const String getScheme() const; + + /** Returns a new version of this URL that uses a different sub-path. + + E.g. if the URL is "http://www.xyz.com/foo?x=1" and you call this with + "bar", it'll return "http://www.xyz.com/bar?x=1". + */ + const URL withNewSubPath (const String& newPath) const; + /** Returns a copy of this URL, with a GET parameter added to the end. Any control characters in the value will be encoded. @@ -52446,6 +52472,10 @@ public: /** Returns the current zoom factor. */ double getScaleFactor() const throw() { return scaleFactor; } + /** Changes the quality setting used to rescale the graphics. + */ + void setResamplingQuality (Graphics::ResamplingQuality newQuality); + juce_UseDebuggingNewOperator /** @internal */ @@ -52457,6 +52487,7 @@ private: double scaleFactor; ComponentPeer* peer; bool deleteContent; + Graphics::ResamplingQuality quality; void paint (Graphics& g); void mouseDown (const MouseEvent& e); @@ -53803,6 +53834,8 @@ public: bool isMouseOverButton, bool isButtonDown); + virtual const Font getFontForTextButton (TextButton& button); + /** Draws the text for a TextButton. */ virtual void drawButtonText (Graphics& g, TextButton& button, diff --git a/src/juce_appframework/gui/components/controls/juce_TreeView.cpp b/src/juce_appframework/gui/components/controls/juce_TreeView.cpp index 4224bd696e..6bcb20378b 100644 --- a/src/juce_appframework/gui/components/controls/juce_TreeView.cpp +++ b/src/juce_appframework/gui/components/controls/juce_TreeView.cpp @@ -278,7 +278,7 @@ public: if (buttonUnderMouse != newItem) { - if (buttonUnderMouse != 0) + if (buttonUnderMouse != 0 && containsItem (buttonUnderMouse)) { const Rectangle r (buttonUnderMouse->getItemPosition (false)); repaint (0, r.getY(), r.getX(), buttonUnderMouse->getItemHeight()); @@ -363,6 +363,15 @@ private: item->setSelected ((! cmd) || (! item->isSelected()), ! cmd); } } + + bool containsItem (TreeViewItem* const item) const + { + for (int i = rowComponentItems.size(); --i >= 0;) + if ((TreeViewItem*) rowComponentItems.getUnchecked (i) == item) + return true; + + return false; + } }; //============================================================================== diff --git a/src/juce_appframework/gui/components/lookandfeel/juce_LookAndFeel.cpp b/src/juce_appframework/gui/components/lookandfeel/juce_LookAndFeel.cpp index 76cbe9fef3..856c8e2af5 100644 --- a/src/juce_appframework/gui/components/lookandfeel/juce_LookAndFeel.cpp +++ b/src/juce_appframework/gui/components/lookandfeel/juce_LookAndFeel.cpp @@ -365,10 +365,15 @@ void LookAndFeel::drawButtonBackground (Graphics& g, button.isConnectedOnBottom()); } +const Font LookAndFeel::getFontForTextButton (TextButton& button) +{ + return button.getFont(); +} + void LookAndFeel::drawButtonText (Graphics& g, TextButton& button, bool /*isMouseOverButton*/, bool /*isButtonDown*/) { - g.setFont (button.getFont()); + g.setFont (getFontForTextButton (button)); g.setColour (button.findColour (TextButton::textColourId) .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f)); diff --git a/src/juce_appframework/gui/components/lookandfeel/juce_LookAndFeel.h b/src/juce_appframework/gui/components/lookandfeel/juce_LookAndFeel.h index 48aeca3a3e..003ebbf23d 100644 --- a/src/juce_appframework/gui/components/lookandfeel/juce_LookAndFeel.h +++ b/src/juce_appframework/gui/components/lookandfeel/juce_LookAndFeel.h @@ -153,6 +153,8 @@ public: bool isMouseOverButton, bool isButtonDown); + virtual const Font getFontForTextButton (TextButton& button); + /** Draws the text for a TextButton. */ virtual void drawButtonText (Graphics& g, TextButton& button, diff --git a/src/juce_appframework/gui/components/special/juce_MagnifierComponent.cpp b/src/juce_appframework/gui/components/special/juce_MagnifierComponent.cpp index 21869bbeb2..c00596695d 100644 --- a/src/juce_appframework/gui/components/special/juce_MagnifierComponent.cpp +++ b/src/juce_appframework/gui/components/special/juce_MagnifierComponent.cpp @@ -200,7 +200,8 @@ MagnifierComponent::MagnifierComponent (Component* const content_, : content (content_), scaleFactor (0.0), peer (0), - deleteContent (deleteContentCompWhenNoLongerNeeded) + deleteContent (deleteContentCompWhenNoLongerNeeded), + quality (Graphics::lowResamplingQuality) { holderComp = new PeerHolderComp (this); setScaleFactor (1.0); @@ -272,7 +273,7 @@ void MagnifierComponent::paint (Graphics& g) g2.reduceClipRegion (srcX, srcY, srcW, srcH); holderComp->paintEntireComponent (g2); - g.setImageResamplingQuality (Graphics::lowResamplingQuality); + g.setImageResamplingQuality (quality); g.drawImage (&temp, 0, 0, (int) (w * scaleFactor), (int) (h * scaleFactor), 0, 0, w, h, diff --git a/src/juce_appframework/gui/components/special/juce_MagnifierComponent.h b/src/juce_appframework/gui/components/special/juce_MagnifierComponent.h index a5014bace5..709e2a4d4c 100644 --- a/src/juce_appframework/gui/components/special/juce_MagnifierComponent.h +++ b/src/juce_appframework/gui/components/special/juce_MagnifierComponent.h @@ -89,6 +89,9 @@ public: /** Returns the current zoom factor. */ double getScaleFactor() const throw() { return scaleFactor; } + /** Changes the quality setting used to rescale the graphics. + */ + void setResamplingQuality (Graphics::ResamplingQuality newQuality); //============================================================================== juce_UseDebuggingNewOperator @@ -102,6 +105,7 @@ private: double scaleFactor; ComponentPeer* peer; bool deleteContent; + Graphics::ResamplingQuality quality; //============================================================================== void paint (Graphics& g); diff --git a/src/juce_appframework/gui/components/windows/juce_AlertWindow.cpp b/src/juce_appframework/gui/components/windows/juce_AlertWindow.cpp index 0a60d8646e..73e4f9e311 100644 --- a/src/juce_appframework/gui/components/windows/juce_AlertWindow.cpp +++ b/src/juce_appframework/gui/components/windows/juce_AlertWindow.cpp @@ -41,6 +41,7 @@ BEGIN_JUCE_NAMESPACE #include "../juce_Desktop.h" #include "../../../../juce_core/text/juce_LocalisedStrings.h" #include "../../../events/juce_MessageManager.h" +#include "../../../application/juce_Application.h" static const int titleH = 24; static const int iconWidth = 80; @@ -112,6 +113,9 @@ AlertWindow::AlertWindow (const String& title, } } + if (JUCEApplication::getInstance() == 0) + setAlwaysOnTop (true); // for a plugin, make it always-on-top because the host windows are often top-level + lookAndFeelChanged(); constrainer.setMinimumOnscreenAmounts (0x10000, 0x10000, 0x10000, 0x10000); diff --git a/src/juce_appframework/gui/graphics/contexts/juce_EdgeTable.cpp b/src/juce_appframework/gui/graphics/contexts/juce_EdgeTable.cpp index 1bdf5d4d35..a37f97aca6 100644 --- a/src/juce_appframework/gui/graphics/contexts/juce_EdgeTable.cpp +++ b/src/juce_appframework/gui/graphics/contexts/juce_EdgeTable.cpp @@ -135,6 +135,7 @@ void EdgeTable::addEdgePoint (const int x, const int y, const int winding) throw if (n >= maxEdgesPerLine) { remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine); + jassert (n < maxEdgesPerLine); lineStart = table + lineStrideElements * y; } diff --git a/src/juce_appframework/gui/graphics/contexts/juce_RectanglePlacement.cpp b/src/juce_appframework/gui/graphics/contexts/juce_RectanglePlacement.cpp index 4c77bf6b1a..6a6b2452f4 100644 --- a/src/juce_appframework/gui/graphics/contexts/juce_RectanglePlacement.cpp +++ b/src/juce_appframework/gui/graphics/contexts/juce_RectanglePlacement.cpp @@ -105,11 +105,9 @@ const AffineTransform RectanglePlacement::getTransformToFit (float x, float y, const float scaleY = dh / h; if ((flags & stretchToFit) != 0) - { return AffineTransform::translation (-x, -y) .scaled (scaleX, scaleY) - .translated (dx - x, dy - y); - } + .translated (dx, dy); float scale = (flags & fillDestination) != 0 ? jmax (scaleX, scaleY) : jmin (scaleX, scaleY); diff --git a/src/juce_core/io/network/juce_URL.cpp b/src/juce_core/io/network/juce_URL.cpp index 0a4df16996..4742a191e4 100644 --- a/src/juce_core/io/network/juce_URL.cpp +++ b/src/juce_core/io/network/juce_URL.cpp @@ -133,6 +133,73 @@ bool URL::isWellFormed() const return url.isNotEmpty(); } +static int findStartOfDomain (const String& url) +{ + int i = 0; + + while (CharacterFunctions::isLetterOrDigit (url[i]) + || CharacterFunctions::indexOfChar (T("+-."), url[i], false) >= 0) + ++i; + + return url[i] == T(':') ? i + 1 : 0; +} + +const String URL::getDomain() const +{ + int start = findStartOfDomain (url); + while (url[start] == T('/')) + ++start; + + const int end1 = url.indexOfChar (start, T('/')); + const int end2 = url.indexOfChar (start, T(':')); + + const int end = (end1 < 0 || end2 < 0) ? jmax (end1, end2) + : jmin (end1, end2); + + return url.substring (start, end); +} + +const String URL::getSubPath() const +{ + int start = findStartOfDomain (url); + while (url[start] == T('/')) + ++start; + + const int startOfPath = url.indexOfChar (start, T('/')) + 1; + + return startOfPath <= 0 ? String::empty + : url.substring (startOfPath); +} + +const String URL::getScheme() const +{ + return url.substring (0, findStartOfDomain (url) - 1); +} + +const URL URL::withNewSubPath (const String& newPath) const +{ + int start = findStartOfDomain (url); + while (url[start] == T('/')) + ++start; + + const int startOfPath = url.indexOfChar (start, T('/')) + 1; + + URL u (*this); + + if (startOfPath > 0) + u.url = url.substring (0, startOfPath); + + if (! u.url.endsWithChar (T('/'))) + u.url << '/'; + + if (newPath.startsWithChar (T('/'))) + u.url << newPath.substring (1); + else + u.url << newPath; + + return u; +} + //============================================================================== bool URL::isProbablyAWebsiteURL (const String& possibleURL) { diff --git a/src/juce_core/io/network/juce_URL.h b/src/juce_core/io/network/juce_URL.h index 63ab0c1ec2..63398aa669 100644 --- a/src/juce_core/io/network/juce_URL.h +++ b/src/juce_core/io/network/juce_URL.h @@ -75,6 +75,32 @@ public: /** True if it seems to be valid. */ bool isWellFormed() const; + /** Returns just the domain part of the URL. + + E.g. for "http://www.xyz.com/foobar", this will return "www.xyz.com". + */ + const String getDomain() const; + + /** Returns the path part of the URL. + + E.g. for "http://www.xyz.com/foo/bar?x=1", this will return "foo/bar". + */ + const String getSubPath() const; + + /** Returns the scheme of the URL. + + E.g. for "http://www.xyz.com/foobar", this will return "http". (It won't + include the colon). + */ + const String getScheme() const; + + /** Returns a new version of this URL that uses a different sub-path. + + E.g. if the URL is "http://www.xyz.com/foo?x=1" and you call this with + "bar", it'll return "http://www.xyz.com/bar?x=1". + */ + const URL withNewSubPath (const String& newPath) const; + //============================================================================== /** Returns a copy of this URL, with a GET parameter added to the end.