diff --git a/extras/audio plugins/wrapper/AU/juce_AU_Wrapper.mm b/extras/audio plugins/wrapper/AU/juce_AU_Wrapper.mm index 84c58bfb11..8d4c600d81 100644 --- a/extras/audio plugins/wrapper/AU/juce_AU_Wrapper.mm +++ b/extras/audio plugins/wrapper/AU/juce_AU_Wrapper.mm @@ -324,8 +324,7 @@ public: CFDictionaryRef dict = (CFDictionaryRef) inData; CFDataRef data = 0; - if (CFDictionaryGetValueIfPresent (dict, CFSTR("jucePluginState"), - (const void**) &data)) + if (CFDictionaryGetValueIfPresent (dict, CFSTR("jucePluginState"), (const void**) &data)) { if (data != 0) { @@ -452,7 +451,7 @@ public: } //============================================================================== - #if BUILD_AU_CARBON_UI + #if BUILD_AU_CARBON_UI int GetNumCustomUIComponents() { return 1; } void GetUIComponentDescs (ComponentDescription* inDescArray) @@ -463,7 +462,7 @@ public: inDescArray[0].componentFlags = 0; inDescArray[0].componentFlagsMask = 0; } - #endif + #endif //============================================================================== bool getCurrentPosition (AudioPlayHead::CurrentPositionInfo& info) @@ -478,35 +477,15 @@ public: switch (lastSMPTETime.mType) { - case kSMPTETimeType24: - info.frameRate = AudioPlayHead::fps24; - break; - - case kSMPTETimeType25: - info.frameRate = AudioPlayHead::fps25; - break; - - case kSMPTETimeType30Drop: - info.frameRate = AudioPlayHead::fps30drop; - break; - - case kSMPTETimeType30: - info.frameRate = AudioPlayHead::fps30; - break; - - case kSMPTETimeType2997: - info.frameRate = AudioPlayHead::fps2997; - break; - - case kSMPTETimeType2997Drop: - info.frameRate = AudioPlayHead::fps2997drop; - break; - + case kSMPTETimeType24: info.frameRate = AudioPlayHead::fps24; break; + case kSMPTETimeType25: info.frameRate = AudioPlayHead::fps25; break; + case kSMPTETimeType30Drop: info.frameRate = AudioPlayHead::fps30drop; break; + case kSMPTETimeType30: info.frameRate = AudioPlayHead::fps30; break; + case kSMPTETimeType2997: info.frameRate = AudioPlayHead::fps2997; break; + case kSMPTETimeType2997Drop: info.frameRate = AudioPlayHead::fps2997drop; break; //case kSMPTETimeType60: //case kSMPTETimeType5994: - default: - info.frameRate = AudioPlayHead::fpsUnknown; - break; + default: info.frameRate = AudioPlayHead::fpsUnknown; break; } if (CallHostBeatAndTempo (&info.ppqPosition, &info.bpm) != noErr) @@ -555,7 +534,7 @@ public: } } - void audioProcessorParameterChanged (AudioProcessor*, int index, float newValue) + void audioProcessorParameterChanged (AudioProcessor*, int index, float /*newValue*/) { sendAUEvent (kAudioUnitEvent_ParameterValueChange, index); } @@ -575,7 +554,7 @@ public: // xxx is there an AU equivalent? } - bool StreamFormatWritable (AudioUnitScope inScope, AudioUnitElement element) + bool StreamFormatWritable (AudioUnitScope, AudioUnitElement) { return ! IsInitialized(); } @@ -588,9 +567,9 @@ public: //============================================================================== ComponentResult Initialize() { - #if ! JucePlugin_IsSynth + #if ! JucePlugin_IsSynth const int numIns = GetInput(0) != 0 ? GetInput(0)->GetStreamFormat().mChannelsPerFrame : 0; - #endif + #endif const int numOuts = GetOutput(0) != 0 ? GetOutput(0)->GetStreamFormat().mChannelsPerFrame : 0; bool isValidChannelConfig = false; @@ -639,20 +618,20 @@ public: { if (juceFilter != 0) { - #if ! JucePlugin_IsSynth - juceFilter->setPlayConfigDetails (GetInput(0)->GetStreamFormat().mChannelsPerFrame, - #else - juceFilter->setPlayConfigDetails (0, - #endif - GetOutput(0)->GetStreamFormat().mChannelsPerFrame, - GetSampleRate(), - GetMaxFramesPerSlice()); + juceFilter->setPlayConfigDetails ( + #if ! JucePlugin_IsSynth + GetInput(0)->GetStreamFormat().mChannelsPerFrame, + #else + 0, + #endif + GetOutput(0)->GetStreamFormat().mChannelsPerFrame, + GetSampleRate(), + GetMaxFramesPerSlice()); bufferSpace.setSize (juceFilter->getNumInputChannels() + juceFilter->getNumOutputChannels(), GetMaxFramesPerSlice() + 32); - juceFilter->prepareToPlay (GetSampleRate(), - GetMaxFramesPerSlice()); + juceFilter->prepareToPlay (GetSampleRate(), GetMaxFramesPerSlice()); midiEvents.ensureSize (2048); midiEvents.clear(); @@ -672,15 +651,15 @@ public: { lastSMPTETime = inTimeStamp.mSMPTETime; - #if ! JucePlugin_IsSynth + #if ! JucePlugin_IsSynth return JuceAUBaseClass::Render (ioActionFlags, inTimeStamp, nFrames); - #else + #else // synths can't have any inputs.. AudioBufferList inBuffer; inBuffer.mNumberBuffers = 0; return ProcessBufferLists (ioActionFlags, inBuffer, GetOutput(0)->GetBufferList(), nFrames); - #endif + #endif } OSStatus ProcessBufferLists (AudioUnitRenderActionFlags& ioActionFlags, @@ -837,44 +816,40 @@ public: } } - #if ! JucePlugin_SilenceInProducesSilenceOut + #if ! JucePlugin_SilenceInProducesSilenceOut ioActionFlags &= ~kAudioUnitRenderAction_OutputIsSilence; - #endif + #endif } return noErr; } protected: - OSStatus HandleMidiEvent (UInt8 nStatus, - UInt8 inChannel, - UInt8 inData1, - UInt8 inData2, - #if defined(MAC_OS_X_VERSION_10_5) + OSStatus HandleMidiEvent (UInt8 nStatus, UInt8 inChannel, UInt8 inData1, UInt8 inData2, + #if defined (MAC_OS_X_VERSION_10_5) UInt32 inStartFrame) - #else + #else long inStartFrame) - #endif + #endif { - #if JucePlugin_WantsMidiInput + #if JucePlugin_WantsMidiInput const ScopedLock sl (incomingMidiLock); - JUCE_NAMESPACE::uint8 data [4]; - data[0] = nStatus | inChannel; - data[1] = inData1; - data[2] = inData2; + const JUCE_NAMESPACE::uint8 data[] = { (JUCE_NAMESPACE::uint8) (nStatus | inChannel), + (JUCE_NAMESPACE::uint8) inData1, + (JUCE_NAMESPACE::uint8) inData2 }; incomingEvents.addEvent (data, 3, inStartFrame); - #endif + #endif return noErr; } OSStatus HandleSysEx (const UInt8* inData, UInt32 inLength) { - #if JucePlugin_WantsMidiInput + #if JucePlugin_WantsMidiInput const ScopedLock sl (incomingMidiLock); incomingEvents.addEvent (inData, inLength, 0); - #endif + #endif return noErr; } @@ -921,23 +896,20 @@ protected: return noErr; } - void componentMovedOrResized (Component& component, bool wasMoved, bool wasResized) + void componentMovedOrResized (Component& component, bool /*wasMoved*/, bool /*wasResized*/) { - //if (wasResized) - { - NSView* view = (NSView*) component.getWindowHandle(); - NSRect r = [[view superview] frame]; - r.origin.y = r.origin.y + r.size.height - component.getHeight(); - r.size.width = component.getWidth(); - r.size.height = component.getHeight(); - [[view superview] setFrame: r]; - [view setFrame: NSMakeRect (0, 0, component.getWidth(), component.getHeight())]; - [view setNeedsDisplay: YES]; - } + NSView* view = (NSView*) component.getWindowHandle(); + NSRect r = [[view superview] frame]; + r.origin.y = r.origin.y + r.size.height - component.getHeight(); + r.size.width = component.getWidth(); + r.size.height = component.getHeight(); + [[view superview] setFrame: r]; + [view setFrame: NSMakeRect (0, 0, component.getWidth(), component.getHeight())]; + [view setNeedsDisplay: YES]; } - //============================================================================== private: + //============================================================================== ScopedPointer juceFilter; AudioSampleBuffer bufferSpace; HeapBlock channels; @@ -948,6 +920,8 @@ private: AudioUnitEvent auEvent; mutable MemoryBlock presetsArray; CriticalSection incomingMidiLock; + + JUCE_DECLARE_NON_COPYABLE (JuceAU); }; //============================================================================== @@ -1152,9 +1126,6 @@ private: //============================================================================== class JuceAUView : public AUCarbonViewBase { - AudioProcessor* juceFilter; - ScopedPointer windowComp; - public: JuceAUView (AudioUnitCarbonView auview) : AUCarbonViewBase (auview), @@ -1206,6 +1177,9 @@ public: void* getEventListenerUserData() const { return mEventListenerUserData; } private: + //============================================================================== + AudioProcessor* juceFilter; + ScopedPointer windowComp; FakeMouseMoveGenerator fakeMouseGenerator; void deleteUI() @@ -1214,8 +1188,13 @@ private: { PopupMenu::dismissAllActiveMenus(); - // there's some kind of component currently modal, but the host - // is trying to delete our plugin.. + /* This assertion is triggered when there's some kind of modal component active, and the + host is trying to delete our plugin. + If you must use modal components, always use them in a non-blocking way, by never + calling runModalLoop(), but instead using enterModalState() with a callback that + will be performed on completion. (Note that this assertion could actually trigger + a false alarm even if you're doing it correctly, but is here to catch people who + aren't so careful) */ jassert (Component::getCurrentlyModalComponent() == 0); if (windowComp != 0 && windowComp->getChildComponent(0) != 0) @@ -1319,11 +1298,12 @@ private: void resized() { - if (getChildComponent(0) != 0) - getChildComponent(0)->setBounds (0, 0, getWidth(), getHeight()); + Component* const child = getChildComponent (0); + if (child != 0) + child->setBounds (getLocalBounds()); } - void paint (Graphics& g) {} + void paint (Graphics&) {} void childBoundsChanged (Component*) { @@ -1368,6 +1348,7 @@ private: } private: + //============================================================================== HIViewRef parentView; NSWindow* hostWindow; EditorCompHolder editor; diff --git a/extras/audio plugins/wrapper/RTAS/juce_RTAS_WinUtilities.cpp b/extras/audio plugins/wrapper/RTAS/juce_RTAS_WinUtilities.cpp index f20bd11c0b..3c32f76cda 100644 --- a/extras/audio plugins/wrapper/RTAS/juce_RTAS_WinUtilities.cpp +++ b/extras/audio plugins/wrapper/RTAS/juce_RTAS_WinUtilities.cpp @@ -107,10 +107,8 @@ namespace break; } - RECT windowPos; + RECT windowPos, parentPos; GetWindowRect (w, &windowPos); - - RECT parentPos; GetWindowRect (parent, &parentPos); int dw = (parentPos.right - parentPos.left) - (windowPos.right - windowPos.left); diff --git a/extras/audio plugins/wrapper/VST/juce_VST_Wrapper.cpp b/extras/audio plugins/wrapper/VST/juce_VST_Wrapper.cpp index 58fc7d50cf..4eda300bd9 100644 --- a/extras/audio plugins/wrapper/VST/juce_VST_Wrapper.cpp +++ b/extras/audio plugins/wrapper/VST/juce_VST_Wrapper.cpp @@ -28,19 +28,19 @@ #endif #ifdef _WIN32 - #include + #include #elif defined (LINUX) - #include - #include - #include - #undef KeyPress + #include + #include + #include + #undef KeyPress #else - #include + #include #endif #ifdef PRAGMA_ALIGN_SUPPORTED - #undef PRAGMA_ALIGN_SUPPORTED - #define PRAGMA_ALIGN_SUPPORTED 1 + #undef PRAGMA_ALIGN_SUPPORTED + #define PRAGMA_ALIGN_SUPPORTED 1 #endif #include "../juce_IncludeCharacteristics.h" @@ -69,7 +69,7 @@ #include #if ! VST_2_4_EXTENSIONS - #error // You're probably trying to include the wrong VSTSDK version - make sure your include path matches the JUCE_USE_VSTSDK_2_4 flag + #error "You're probably trying to include the wrong VSTSDK version - make sure your include path matches the JUCE_USE_VSTSDK_2_4 flag" #endif #else @@ -80,7 +80,7 @@ #include #if (! VST_2_3_EXTENSIONS) || VST_2_4_EXTENSIONS - #error // You're probably trying to include the wrong VSTSDK version - make sure your include path matches the JUCE_USE_VSTSDK_2_4 flag + #error "You're probably trying to include the wrong VSTSDK version - make sure your include path matches the JUCE_USE_VSTSDK_2_4 flag" #endif #define __aeffect__ // (needed for juce_VSTMidiEventList.h to work) @@ -89,39 +89,39 @@ typedef long VstIntPtr; enum Vst2StringConstants { - kVstMaxNameLen = 64, - kVstMaxLabelLen = 64, - kVstMaxShortLabelLen = 8, - kVstMaxCategLabelLen = 24, - kVstMaxFileNameLen = 100 + kVstMaxNameLen = 64, + kVstMaxLabelLen = 64, + kVstMaxShortLabelLen = 8, + kVstMaxCategLabelLen = 24, + kVstMaxFileNameLen = 100 }; enum VstSmpteFrameRate { - kVstSmpte24fps = 0, ///< 24 fps - kVstSmpte25fps = 1, ///< 25 fps - kVstSmpte2997fps = 2, ///< 29.97 fps - kVstSmpte30fps = 3, ///< 30 fps - kVstSmpte2997dfps = 4, ///< 29.97 drop - kVstSmpte30dfps = 5, ///< 30 drop - kVstSmpteFilm16mm = 6, ///< Film 16mm - kVstSmpteFilm35mm = 7, ///< Film 35mm - kVstSmpte239fps = 10, ///< HDTV: 23.976 fps - kVstSmpte249fps = 11, ///< HDTV: 24.976 fps - kVstSmpte599fps = 12, ///< HDTV: 59.94 fps - kVstSmpte60fps = 13 ///< HDTV: 60 fps + kVstSmpte24fps = 0, // 24 fps + kVstSmpte25fps = 1, // 25 fps + kVstSmpte2997fps = 2, // 29.97 fps + kVstSmpte30fps = 3, // 30 fps + kVstSmpte2997dfps = 4, // 29.97 drop + kVstSmpte30dfps = 5, // 30 drop + kVstSmpteFilm16mm = 6, // Film 16mm + kVstSmpteFilm35mm = 7, // Film 35mm + kVstSmpte239fps = 10, // HDTV: 23.976 fps + kVstSmpte249fps = 11, // HDTV: 24.976 fps + kVstSmpte599fps = 12, // HDTV: 59.94 fps + kVstSmpte60fps = 13 // HDTV: 60 fps }; struct VstMidiSysexEvent { - VstInt32 type; ///< #kVstSysexType - VstInt32 byteSize; ///< sizeof (VstMidiSysexEvent) - VstInt32 deltaFrames; ///< sample frames related to the current block start sample position - VstInt32 flags; ///< none defined yet (should be zero) - VstInt32 dumpBytes; ///< byte size of sysexDump - VstIntPtr resvd1; ///< zero (Reserved for future use) - char* sysexDump; ///< sysex dump - VstIntPtr resvd2; ///< zero (Reserved for future use) + VstInt32 type; // #kVstSysexType + VstInt32 byteSize; // sizeof (VstMidiSysexEvent) + VstInt32 deltaFrames; // sample frames related to the current block start sample position + VstInt32 flags; // none defined yet (should be zero) + VstInt32 dumpBytes; // byte size of sysexDump + VstIntPtr resvd1; // zero (Reserved for future use) + char* sysexDump; // sysex dump + VstIntPtr resvd2; // zero (Reserved for future use) }; typedef int VstSpeakerArrangementType; @@ -129,15 +129,14 @@ //============================================================================== #ifdef _MSC_VER - #pragma pack (push, 8) + #pragma pack (push, 8) #endif #include "../juce_PluginHeaders.h" #include "../juce_PluginHostType.h" - #ifdef _MSC_VER - #pragma pack (pop) + #pragma pack (pop) #endif #undef MemoryBlock @@ -274,8 +273,7 @@ public: MessageManager::getInstance()->setCurrentThreadAsMessageThread(); while ((! threadShouldExit()) && MessageManager::getInstance()->runDispatchLoopUntil (250)) - { - } + {} } juce_DeclareSingleton (SharedMessageThread, false) @@ -292,7 +290,7 @@ static Array activePlugins; //============================================================================== /** - This wraps an AudioProcessor as an AudioEffectX... + This is an AudioEffectX object that holds and wraps our AudioProcessor... */ class JuceVSTWrapper : public AudioEffectX, private Timer, @@ -301,50 +299,42 @@ class JuceVSTWrapper : public AudioEffectX, { public: //============================================================================== - JuceVSTWrapper (audioMasterCallback audioMaster, - AudioProcessor* const filter_) - : AudioEffectX (audioMaster, - filter_->getNumPrograms(), - filter_->getNumParameters()), - filter (filter_) + JuceVSTWrapper (audioMasterCallback audioMaster, AudioProcessor* const filter_) + : AudioEffectX (audioMaster, filter_->getNumPrograms(), filter_->getNumParameters()), + filter (filter_), + chunkMemoryTime (0), + speakerIn (kSpeakerArrEmpty), + speakerOut (kSpeakerArrEmpty), + numInChans (JucePlugin_MaxNumInputChannels), + numOutChans (JucePlugin_MaxNumOutputChannels), + isProcessing (false) + hasShutdown (false) + firstProcessCallback (true), + shouldDeleteEditor (false), + hostWindow (0) { - chunkMemoryTime = 0; - isProcessing = false; - hasShutdown = false; - firstProcessCallback = true; - shouldDeleteEditor = false; - speakerIn = kSpeakerArrEmpty; - speakerOut = kSpeakerArrEmpty; - numInChans = JucePlugin_MaxNumInputChannels; - numOutChans = JucePlugin_MaxNumOutputChannels; - -#if JUCE_MAC || JUCE_LINUX - hostWindow = 0; -#endif - filter->setPlayConfigDetails (numInChans, numOutChans, 0, 0); - - filter_->setPlayHead (this); - filter_->addListener (this); + filter->setPlayHead (this); + filter->addListener (this); cEffect.flags |= effFlagsHasEditor; cEffect.version = (long) (JucePlugin_VersionCode); setUniqueID ((int) (JucePlugin_VSTUniqueID)); -#if JucePlugin_WantsMidiInput && ! JUCE_USE_VSTSDK_2_4 + #if JucePlugin_WantsMidiInput && ! JUCE_USE_VSTSDK_2_4 wantEvents(); -#endif + #endif setNumInputs (numInChans); setNumOutputs (numOutChans); canProcessReplacing (true); -#if ! JUCE_USE_VSTSDK_2_4 + #if ! JUCE_USE_VSTSDK_2_4 hasVu (false); hasClip (false); -#endif + #endif isSynth ((JucePlugin_IsSynth) != 0); noTail (((JucePlugin_SilenceInProducesSilenceOut) != 0) && (JucePlugin_TailLengthSeconds <= 0)); @@ -359,9 +349,9 @@ public: JUCE_AUTORELEASEPOOL { - #if JUCE_LINUX + #if JUCE_LINUX MessageManagerLock mmLock; - #endif + #endif stopTimer(); deleteEditor (false); @@ -381,9 +371,9 @@ public: if (activePlugins.size() == 0) { - #if JUCE_LINUX + #if JUCE_LINUX SharedMessageThread::deleteInstance(); - #endif + #endif shutdownJuce_GUI(); } } @@ -419,20 +409,10 @@ public: return true; } - bool getProductString (char* text) - { - return getEffectName (text); - } - - VstInt32 getVendorVersion() - { - return JucePlugin_VersionCode; - } - - VstPlugCategory getPlugCategory() - { - return JucePlugin_VSTCategory; - } + bool getProductString (char* text) { return getEffectName (text); } + VstInt32 getVendorVersion() { return JucePlugin_VersionCode; } + VstPlugCategory getPlugCategory() { return JucePlugin_VSTCategory; } + bool keysRequired() { return (JucePlugin_EditorRequiresKeyboardFocus) != 0; } VstInt32 canDo (char* text) { @@ -442,21 +422,21 @@ public: || strcmp (text, "receiveVstMidiEvent") == 0 || strcmp (text, "receiveVstMidiEvents") == 0) { -#if JucePlugin_WantsMidiInput + #if JucePlugin_WantsMidiInput result = 1; -#else + #else result = -1; -#endif + #endif } else if (strcmp (text, "sendVstEvents") == 0 || strcmp (text, "sendVstMidiEvent") == 0 || strcmp (text, "sendVstMidiEvents") == 0) { -#if JucePlugin_ProducesMidiOutput + #if JucePlugin_ProducesMidiOutput result = 1; -#else + #else result = -1; -#endif + #endif } else if (strcmp (text, "receiveVstTimeInfo") == 0 || strcmp (text, "conformsToWindowRules") == 0) @@ -473,36 +453,13 @@ public: return result; } - bool keysRequired() - { - return (JucePlugin_EditorRequiresKeyboardFocus) != 0; - } - bool getInputProperties (VstInt32 index, VstPinProperties* properties) { if (filter == 0 || index >= JucePlugin_MaxNumInputChannels) return false; - const String name (filter->getInputChannelName ((int) index)); - - name.copyToUTF8 (properties->label, kVstMaxLabelLen - 1); - name.copyToUTF8 (properties->shortLabel, kVstMaxShortLabelLen - 1); - - if (speakerIn != kSpeakerArrEmpty) - { - properties->flags = kVstPinUseSpeaker; - properties->arrangementType = speakerIn; - } - else - { - properties->flags = kVstPinIsActive; - - if (filter->isInputChannelStereoPair ((int) index)) - properties->flags |= kVstPinIsStereo; - - properties->arrangementType = 0; - } - + setPinProperties (*properties, filter->getInputChannelName ((int) index), + speakerIn, filter->isInputChannelStereoPair ((int) index)); return true; } @@ -511,38 +468,41 @@ public: if (filter == 0 || index >= JucePlugin_MaxNumOutputChannels) return false; - const String name (filter->getOutputChannelName ((int) index)); + setPinProperties (*properties, filter->getOutputChannelName ((int) index), + speakerOut, filter->isOutputChannelStereoPair ((int) index)); + return true; + } - name.copyToUTF8 (properties->label, kVstMaxLabelLen - 1); - name.copyToUTF8 (properties->shortLabel, kVstMaxShortLabelLen - 1); + static void setPinProperties (VstPinProperties& properties, const String& name, + VstSpeakerArrangementType type, const bool isPair) + { + name.copyToUTF8 (properties.label, kVstMaxLabelLen - 1); + name.copyToUTF8 (properties.shortLabel, kVstMaxShortLabelLen - 1); - if (speakerOut != kSpeakerArrEmpty) + if (type != kSpeakerArrEmpty) { - properties->flags = kVstPinUseSpeaker; - properties->arrangementType = speakerOut; + properties.flags = kVstPinUseSpeaker; + properties.arrangementType = type; } else { - properties->flags = kVstPinIsActive; + properties.flags = kVstPinIsActive; + properties.arrangementType = 0; - if (filter->isOutputChannelStereoPair ((int) index)) - properties->flags |= kVstPinIsStereo; - - properties->arrangementType = 0; + if (isPair) + properties.flags |= kVstPinIsStereo; } - - return true; } //============================================================================== VstInt32 processEvents (VstEvents* events) { -#if JucePlugin_WantsMidiInput + #if JucePlugin_WantsMidiInput VSTMidiEventList::addEventsToMidiBuffer (events, midiEvents); return 1; -#else + #else return 0; -#endif + #endif } void process (float** inputs, float** outputs, VstInt32 numSamples) @@ -579,16 +539,16 @@ public: filter->setNonRealtime (getCurrentProcessLevel() == 4 /* kVstProcessLevelOffline */); -#if JUCE_WINDOWS + #if JUCE_WINDOWS if (GetThreadPriority (GetCurrentThread()) <= THREAD_PRIORITY_NORMAL && GetThreadPriority (GetCurrentThread()) >= THREAD_PRIORITY_LOWEST) filter->setNonRealtime (true); -#endif + #endif } -#if JUCE_DEBUG && ! JucePlugin_ProducesMidiOutput + #if JUCE_DEBUG && ! JucePlugin_ProducesMidiOutput const int numMidiEventsComingIn = midiEvents.getNumEvents(); -#endif + #endif jassert (activePlugins.contains (this)); @@ -645,7 +605,7 @@ public: if (! midiEvents.isEmpty()) { -#if JucePlugin_ProducesMidiOutput + #if JucePlugin_ProducesMidiOutput const int numEvents = midiEvents.getNumEvents(); outgoingEvents.ensureSize (numEvents); @@ -663,7 +623,7 @@ public: } sendVstEventsToHost (outgoingEvents.events); -#else + #else /* This assertion is caused when you've added some events to the midiMessages array in your processBlock() method, which usually means that you're trying to send them somewhere. But in this case they're @@ -679,92 +639,82 @@ public: to the output. */ jassert (midiEvents.getNumEvents() <= numMidiEventsComingIn); -#endif + #endif midiEvents.clear(); } } //============================================================================== - VstInt32 startProcess () { return 0; } - VstInt32 stopProcess () { return 0;} + VstInt32 startProcess() { return 0; } + VstInt32 stopProcess() { return 0; } void resume() { - if (filter == 0) - return; + if (filter != 0) + { + isProcessing = true; + channels.calloc (numInChans + numOutChans); - isProcessing = true; - channels.calloc (numInChans + numOutChans); + double rate = getSampleRate(); + jassert (rate > 0); + if (rate <= 0.0) + rate = 44100.0; - double rate = getSampleRate(); - jassert (rate > 0); - if (rate <= 0.0) - rate = 44100.0; + const int blockSize = getBlockSize(); + jassert (blockSize > 0); - const int blockSize = getBlockSize(); - jassert (blockSize > 0); + firstProcessCallback = true; - firstProcessCallback = true; + filter->setNonRealtime (getCurrentProcessLevel() == 4 /* kVstProcessLevelOffline */); + filter->setPlayConfigDetails (numInChans, numOutChans, rate, blockSize); - filter->setNonRealtime (getCurrentProcessLevel() == 4 /* kVstProcessLevelOffline */); + deleteTempChannels(); - filter->setPlayConfigDetails (numInChans, numOutChans, - rate, blockSize); + filter->prepareToPlay (rate, blockSize); - deleteTempChannels(); + midiEvents.ensureSize (2048); + midiEvents.clear(); - filter->prepareToPlay (rate, blockSize); + setInitialDelay (filter->getLatencySamples()); - midiEvents.ensureSize (2048); - midiEvents.clear(); + AudioEffectX::resume(); - setInitialDelay (filter->getLatencySamples()); + #if JucePlugin_ProducesMidiOutput + outgoingEvents.ensureSize (512); + #endif - AudioEffectX::resume(); - -#if JucePlugin_ProducesMidiOutput - outgoingEvents.ensureSize (512); -#endif - -#if JucePlugin_WantsMidiInput && ! JUCE_USE_VSTSDK_2_4 - wantEvents(); -#endif + #if JucePlugin_WantsMidiInput && ! JUCE_USE_VSTSDK_2_4 + wantEvents(); + #endif + } } void suspend() { - if (filter == 0) - return; + if (filter != 0) + { + AudioEffectX::suspend(); - AudioEffectX::suspend(); + filter->releaseResources(); + outgoingEvents.freeEvents(); - filter->releaseResources(); - outgoingEvents.freeEvents(); + isProcessing = false; + channels.free(); - isProcessing = false; - channels.free(); - - deleteTempChannels(); + deleteTempChannels(); + } } bool getCurrentPosition (AudioPlayHead::CurrentPositionInfo& info) { - const VstTimeInfo* const ti = getTimeInfo (kVstPpqPosValid - | kVstTempoValid - | kVstBarsValid - //| kVstCyclePosValid - | kVstTimeSigValid - | kVstSmpteValid - | kVstClockValid); + const VstTimeInfo* const ti = getTimeInfo (kVstPpqPosValid | kVstTempoValid | kVstBarsValid //| kVstCyclePosValid + | kVstTimeSigValid | kVstSmpteValid | kVstClockValid); if (ti == 0 || ti->sampleRate <= 0) return false; - if ((ti->flags & kVstTempoValid) != 0) - info.bpm = ti->tempo; - else - info.bpm = 0.0; + info.bpm = (ti->flags & kVstTempoValid) != 0 ? ti->tempo : 0.0; if ((ti->flags & kVstTimeSigValid) != 0) { @@ -778,16 +728,8 @@ public: } info.timeInSeconds = ti->samplePos / ti->sampleRate; - - if ((ti->flags & kVstPpqPosValid) != 0) - info.ppqPosition = ti->ppqPos; - else - info.ppqPosition = 0.0; - - if ((ti->flags & kVstBarsValid) != 0) - info.ppqPositionOfLastBarStart = ti->barStartPos; - else - info.ppqPositionOfLastBarStart = 0.0; + info.ppqPosition = (ti->flags & kVstPpqPosValid) != 0 ? ti->ppqPos : 0.0; + info.ppqPositionOfLastBarStart = (ti->flags & kVstBarsValid) != 0 ? ti->barStartPos : 0.0; if ((ti->flags & kVstSmpteValid) != 0) { @@ -906,15 +848,8 @@ public: setParameterAutomated (index, newValue); } - void audioProcessorParameterChangeGestureBegin (AudioProcessor*, int index) - { - beginEdit (index); - } - - void audioProcessorParameterChangeGestureEnd (AudioProcessor*, int index) - { - endEdit (index); - } + void audioProcessorParameterChangeGestureBegin (AudioProcessor*, int index) { beginEdit (index); } + void audioProcessorParameterChangeGestureEnd (AudioProcessor*, int index) { endEdit (index); } void audioProcessorChanged (AudioProcessor*) { @@ -929,16 +864,12 @@ public: class ChannelConfigComparator { public: - static int compareElements (const short* const first, const short* const second) + static int compareElements (const short* const first, const short* const second) throw() { - if (first[0] < second[0]) - return -1; - else if (first[0] > second[0]) - return 1; - else if (first[1] < second[1]) - return -1; - else if (first[1] > second[1]) - return 1; + if (first[0] < second[0]) return -1; + else if (first[0] > second[0]) return 1; + else if (first[1] < second[1]) return -1; + else if (first[1] > second[1]) return 1; return 0; } @@ -1034,18 +965,17 @@ public: chunkMemory.setSize (0); } -#if JUCE_MAC + #if JUCE_MAC if (hostWindow != 0) checkWindowVisibility (hostWindow, editorComp); -#endif + #endif tryMasterIdle(); } void tryMasterIdle() { - if (Component::isMouseButtonDownAnywhere() - && ! recursionCheck) + if (Component::isMouseButtonDownAnywhere() && ! recursionCheck) { const JUCE_NAMESPACE::uint32 now = JUCE_NAMESPACE::Time::getMillisecondCounter(); @@ -1127,13 +1057,13 @@ public: } } -#if JUCE_MAC + #if JUCE_MAC if (hostWindow != 0) { detachComponentFromWindowRef (editorComp, hostWindow); hostWindow = 0; } -#endif + #endif filter->editorBeingDeleted (editorComp->getEditorComp()); @@ -1144,9 +1074,9 @@ public: jassert (Component::getCurrentlyModalComponent() == 0); } -#if JUCE_LINUX + #if JUCE_LINUX hostWindow = 0; -#endif + #endif recursionCheck = false; } @@ -1233,12 +1163,14 @@ public: if (! (canHostDo (const_cast ("sizeWindow")) && sizeWindow (newWidth, newHeight))) { // some hosts don't support the sizeWindow call, so do it manually.. -#if JUCE_MAC + #if JUCE_MAC setNativeHostWindowSize (hostWindow, editorComp, newWidth, newHeight, getHostType()); -#elif JUCE_LINUX + + #elif JUCE_LINUX // (Currently, all linux hosts support sizeWindow, so this should never need to happen) editorComp->setSize (newWidth, newHeight); -#else + + #else int dw = 0; int dh = 0; const int frameThickness = GetSystemMetrics (SM_CYFIXEDFRAME); @@ -1258,15 +1190,11 @@ public: if (String (windowType).equalsIgnoreCase ("MDIClient")) break; - RECT windowPos; + RECT windowPos, parentPos; GetWindowRect (w, &windowPos); - - RECT parentPos; GetWindowRect (parent, &parentPos); - SetWindowPos (w, 0, 0, 0, - newWidth + dw, - newHeight + dh, + SetWindowPos (w, 0, 0, 0, newWidth + dw, newHeight + dh, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER); dw = (parentPos.right - parentPos.left) - (windowPos.right - windowPos.left); @@ -1282,11 +1210,9 @@ public: } if (w != 0) - SetWindowPos (w, 0, 0, 0, - newWidth + dw, - newHeight + dh, + SetWindowPos (w, 0, 0, 0, newWidth + dw, newHeight + dh, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER); -#endif + #endif } if (editorComp->getPeer() != 0) @@ -1346,7 +1272,7 @@ public: triggerAsyncUpdate(); } - #if JUCE_MAC + #if JUCE_MAC bool keyPressed (const KeyPress& kp) { // If we have an unused keypress, move the key-focus to a host window @@ -1354,7 +1280,7 @@ public: forwardCurrentKeyEventToHost (this); return true; } - #endif + #endif AudioProcessorEditor* getEditorComp() const { @@ -1378,15 +1304,15 @@ public: wrapper.resizeHostWindow (cw, ch); - #if ! JUCE_LINUX // setSize() on linux causes renoise and energyxt to fail. + #if ! JUCE_LINUX // setSize() on linux causes renoise and energyxt to fail. setSize (cw, ch); - #else + #else XResizeWindow (display, (Window) getWindowHandle(), cw, ch); - #endif + #endif - #if JUCE_MAC + #if JUCE_MAC wrapper.resizeHostWindow (cw, ch); // (doing this a second time seems to be necessary in tracktion) - #endif + #endif } void handleAsyncUpdate() @@ -1394,7 +1320,7 @@ public: wrapper.tryMasterIdle(); } - #if JUCE_WINDOWS + #if JUCE_WINDOWS void mouseDown (const MouseEvent&) { broughtToFront(); @@ -1409,7 +1335,7 @@ public: if (parent != 0) SetWindowPos (parent, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); } - #endif + #endif private: //============================================================================== @@ -1428,18 +1354,22 @@ private: ERect editorSize; MidiBuffer midiEvents; VSTMidiEventList outgoingEvents; - bool isProcessing; - bool hasShutdown; - bool firstProcessCallback; - int diffW, diffH; VstSpeakerArrangementType speakerIn, speakerOut; int numInChans, numOutChans; - HeapBlock channels; - Array tempChannels; // see note in processReplacing() - bool shouldDeleteEditor; + bool isProcessing, hasShutdown, firstProcessCallback, shouldDeleteEditor; + HeapBlock channels; + Array tempChannels; // see note in processReplacing() + + #if JUCE_MAC + void* hostWindow; + #elif JUCE_LINUX + Window hostWindow; + #else + HWND hostWindow; + #endif //============================================================================== -#if JUCE_WINDOWS + #if JUCE_WINDOWS // Workarounds for Wavelab's happy-go-lucky use of threads. static void checkWhetherMessageThreadIsCorrect() { @@ -1469,9 +1399,9 @@ private: } } } -#else + #else static void checkWhetherMessageThreadIsCorrect() {} -#endif + #endif //============================================================================== void deleteTempChannels() @@ -1485,21 +1415,6 @@ private: tempChannels.insertMultiple (0, 0, filter->getNumInputChannels() + filter->getNumOutputChannels()); } - const String getHostName() - { - char host[256] = { 0 }; - getHostProductString (host); - return host; - } - - #if JUCE_MAC - void* hostWindow; - #elif JUCE_LINUX - Window hostWindow; - #else - HWND hostWindow; - #endif - JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (JuceVSTWrapper); }; @@ -1522,9 +1437,9 @@ namespace { if (audioMaster (0, audioMasterVersion, 0, 0, 0, 0) != 0) { - #if JUCE_LINUX + #if JUCE_LINUX MessageManagerLock mmLock; - #endif + #endif AudioProcessor* const filter = createPluginFilter(); @@ -1588,18 +1503,18 @@ namespace return pluginEntryPoint (audioMaster); } - #ifndef _WIN64 // (can't compile this on win64, but it's not needed anyway with VST2.4) + #ifndef _WIN64 // (can't compile this on win64, but it's not needed anyway with VST2.4) extern "C" __declspec (dllexport) void* main (audioMasterCallback audioMaster) { return (void*) pluginEntryPoint (audioMaster); } - #endif + #endif - #if JucePlugin_Build_RTAS + #if JucePlugin_Build_RTAS BOOL WINAPI DllMainVST (HINSTANCE instance, DWORD dwReason, LPVOID) - #else + #else extern "C" BOOL WINAPI DllMain (HINSTANCE instance, DWORD dwReason, LPVOID) - #endif + #endif { if (dwReason == DLL_PROCESS_ATTACH) PlatformUtilities::setCurrentModuleInstanceHandle (instance); diff --git a/juce_amalgamated.cpp b/juce_amalgamated.cpp index 8ae7c293c6..5cd0c7d047 100644 --- a/juce_amalgamated.cpp +++ b/juce_amalgamated.cpp @@ -9183,47 +9183,45 @@ namespace SocketHelpers const int portNumber, const int timeOutMillisecs) throw() { - struct hostent* const hostEnt = gethostbyname (hostName.toUTF8()); + struct addrinfo hints; + zerostruct (hints); + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = isDatagram ? SOCK_DGRAM : SOCK_STREAM; - if (hostEnt == 0) + struct addrinfo* result = 0; + if (getaddrinfo (hostName.toUTF8(), 0, &hints, &result) != 0 || result == 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) + handle = (int) socket (result->ai_family, result->ai_socktype, 0); if (handle < 0) + { + freeaddrinfo (result); return false; + } if (isDatagram) { - *serverAddress = new struct sockaddr_in(); - *((struct sockaddr_in*) *serverAddress) = servTmpAddr; + struct sockaddr* s = new struct sockaddr(); + *s = *(result->ai_addr); + *serverAddress = s; + freeaddrinfo (result); return true; } - setSocketBlockingState (handle, false); + freeaddrinfo (result); - const int result = ::connect (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)); + setSocketBlockingState (handle, false); if (result < 0) { - #if JUCE_WINDOWS + #if JUCE_WINDOWS if (result == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK) - #else + #else if (errno == EINPROGRESS) - #endif + #endif { if (waitForReadiness (handle, false, timeOutMillisecs) != 1) { @@ -9466,7 +9464,7 @@ DatagramSocket::~DatagramSocket() { close(); - delete static_cast (serverAddress); + delete static_cast (serverAddress); serverAddress = 0; } @@ -259532,57 +259530,60 @@ private: if (! decomposeURL (address, hostName, hostPath, hostPort)) return; - const struct hostent* host = 0; + String serverName, proxyName, proxyPath; + int proxyPort = 0; int port = 0; - String proxyName, proxyPath; - int proxyPort = 0; - - String proxyURL (getenv ("http_proxy")); + const String proxyURL (getenv ("http_proxy")); if (proxyURL.startsWithIgnoreCase ("http://")) { if (! decomposeURL (proxyURL, proxyName, proxyPath, proxyPort)) return; - host = gethostbyname (proxyName.toUTF8()); + serverName = proxyName; port = proxyPort; } else { - host = gethostbyname (hostName.toUTF8()); + serverName = hostName; port = hostPort; } - if (host == 0) + struct addrinfo hints; + zerostruct (hints); + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + hints.ai_flags = AI_NUMERICSERV; + + struct addrinfo* result = 0; + if (getaddrinfo (serverName.toUTF8(), String (port).toUTF8(), &hints, &result) != 0 || result == 0) return; + socketHandle = socket (result->ai_family, result->ai_socktype, 0); + + if (socketHandle == -1) { - struct sockaddr_in socketAddress; - zerostruct (socketAddress); - memcpy (&socketAddress.sin_addr, host->h_addr, host->h_length); - socketAddress.sin_family = host->h_addrtype; - socketAddress.sin_port = htons (port); - - socketHandle = socket (host->h_addrtype, SOCK_STREAM, 0); - - if (socketHandle == -1) - return; - - int receiveBufferSize = 16384; - setsockopt (socketHandle, SOL_SOCKET, SO_RCVBUF, (char*) &receiveBufferSize, sizeof (receiveBufferSize)); - setsockopt (socketHandle, SOL_SOCKET, SO_KEEPALIVE, 0, 0); - - #if JUCE_MAC - setsockopt (socketHandle, SOL_SOCKET, SO_NOSIGPIPE, 0, 0); - #endif - - if (connect (socketHandle, (struct sockaddr*) &socketAddress, sizeof (socketAddress)) == -1) - { - closeSocket(); - return; - } + freeaddrinfo (result); + return; } + int receiveBufferSize = 16384; + setsockopt (socketHandle, SOL_SOCKET, SO_RCVBUF, (char*) &receiveBufferSize, sizeof (receiveBufferSize)); + setsockopt (socketHandle, SOL_SOCKET, SO_KEEPALIVE, 0, 0); + + #if JUCE_MAC + setsockopt (socketHandle, SOL_SOCKET, SO_NOSIGPIPE, 0, 0); + #endif + + if (connect (socketHandle, result->ai_addr, result->ai_addrlen) == -1) + { + closeSocket(); + freeaddrinfo (result); + return; + } + + freeaddrinfo (result); + { const MemoryBlock requestHeader (createRequestHeader (hostName, hostPort, proxyName, proxyPort, hostPath, address, headers, postData, isPost)); @@ -283431,6 +283432,7 @@ BEGIN_JUCE_NAMESPACE // List of basic required classes #define JUCE_JNI_CLASSES_ESSENTIAL(JAVACLASS) \ JAVACLASS (activityClass, "com/juce/JuceAppActivity") \ + JAVACLASS (httpStreamClass, "com/juce/JuceAppActivity$HTTPStream") \ JAVACLASS (componentPeerViewClass, "com/juce/ComponentPeerView") \ JAVACLASS (fileClass, "java/io/File") \ JAVACLASS (systemClass, "java/lang/System") \ @@ -283472,6 +283474,14 @@ BEGIN_JUCE_NAMESPACE METHOD (activityClass, setClipboardContent, "setClipboardContent", "(Ljava/lang/String;)V") \ METHOD (activityClass, excludeClipRegion, "excludeClipRegion", "(Landroid/graphics/Canvas;FFFF)V") \ METHOD (activityClass, renderGlyph, "renderGlyph", "(CLandroid/graphics/Paint;Landroid/graphics/Matrix;Landroid/graphics/Rect;)[I") \ + STATICMETHOD (activityClass, createHTTPStream, "createHTTPStream", "(Ljava/lang/String;Z[BLjava/lang/String;ILjava/lang/StringBuffer;)Lcom/juce/JuceAppActivity$HTTPStream;") \ +\ + METHOD (httpStreamClass, httpStreamRelease, "release", "()V") \ + METHOD (httpStreamClass, httpStreamRead, "read", "([BI)I") \ + METHOD (httpStreamClass, getPosition, "getPosition", "()J") \ + METHOD (httpStreamClass, getTotalLength, "getTotalLength", "()J") \ + METHOD (httpStreamClass, isExhausted, "isExhausted", "()Z") \ + METHOD (httpStreamClass, setPosition, "setPosition", "(J)Z") \ \ METHOD (fileClass, fileExists, "exists", "()Z") \ STATICMETHOD (systemClass, getProperty, "getProperty", "(Ljava/lang/String;)Ljava/lang/String;") \ diff --git a/juce_amalgamated.h b/juce_amalgamated.h index dabe0ca8ac..7b98cf1067 100644 --- a/juce_amalgamated.h +++ b/juce_amalgamated.h @@ -73,7 +73,7 @@ namespace JuceDummyNamespace {} */ #define JUCE_MAJOR_VERSION 1 #define JUCE_MINOR_VERSION 53 -#define JUCE_BUILDNUMBER 41 +#define JUCE_BUILDNUMBER 42 /** Current Juce version number. diff --git a/src/core/juce_StandardHeader.h b/src/core/juce_StandardHeader.h index 88eca743e6..ae07e5e327 100644 --- a/src/core/juce_StandardHeader.h +++ b/src/core/juce_StandardHeader.h @@ -33,7 +33,7 @@ */ #define JUCE_MAJOR_VERSION 1 #define JUCE_MINOR_VERSION 53 -#define JUCE_BUILDNUMBER 41 +#define JUCE_BUILDNUMBER 42 /** Current Juce version number. diff --git a/src/io/network/juce_Socket.cpp b/src/io/network/juce_Socket.cpp index 7ebfaaccc6..ca56a953bf 100644 --- a/src/io/network/juce_Socket.cpp +++ b/src/io/network/juce_Socket.cpp @@ -254,47 +254,45 @@ namespace SocketHelpers const int portNumber, const int timeOutMillisecs) throw() { - struct hostent* const hostEnt = gethostbyname (hostName.toUTF8()); + struct addrinfo hints; + zerostruct (hints); + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = isDatagram ? SOCK_DGRAM : SOCK_STREAM; - if (hostEnt == 0) + struct addrinfo* result = 0; + if (getaddrinfo (hostName.toUTF8(), 0, &hints, &result) != 0 || result == 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) + handle = (int) socket (result->ai_family, result->ai_socktype, 0); if (handle < 0) + { + freeaddrinfo (result); return false; + } if (isDatagram) { - *serverAddress = new struct sockaddr_in(); - *((struct sockaddr_in*) *serverAddress) = servTmpAddr; + struct sockaddr* s = new struct sockaddr(); + *s = *(result->ai_addr); + *serverAddress = s; + freeaddrinfo (result); return true; } - setSocketBlockingState (handle, false); + freeaddrinfo (result); - const int result = ::connect (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)); + setSocketBlockingState (handle, false); if (result < 0) { - #if JUCE_WINDOWS + #if JUCE_WINDOWS if (result == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK) - #else + #else if (errno == EINPROGRESS) - #endif + #endif { if (waitForReadiness (handle, false, timeOutMillisecs) != 1) { @@ -545,7 +543,7 @@ DatagramSocket::~DatagramSocket() { close(); - delete static_cast (serverAddress); + delete static_cast (serverAddress); serverAddress = 0; } diff --git a/src/native/android/java/JuceAppActivity.java b/src/native/android/java/JuceAppActivity.java index 9a62a05175..37a94199a0 100644 --- a/src/native/android/java/JuceAppActivity.java +++ b/src/native/android/java/JuceAppActivity.java @@ -38,6 +38,7 @@ import android.graphics.RectF; import android.graphics.Rect; import android.text.ClipboardManager; import com.juce.ComponentPeerView; +import java.net.URL; //============================================================================== @@ -196,4 +197,56 @@ public final class JuceAppActivity extends Activity } private int[] cachedRenderArray = new int [256]; + + //============================================================================== + public static class HTTPStream + { + public HTTPStream() + { + } + + public final void release() + { + } + + public final int read (byte[] buffer, int numBytes) + { + return 0; + } + + public final long getPosition() + { + return 0; + } + + public final long getTotalLength() + { + return 0; + } + + public final boolean isExhausted() + { + return false; + } + + public final boolean setPosition (long newPos) + { + return false; + } + } + + public static final HTTPStream createHTTPStream (String address, boolean isPost, byte[] postData, + String headers, int timeOutMs, java.lang.StringBuffer responseHeaders) + { + try + { + URL u = new URL (address); + + return new HTTPStream (); + } + catch (java.net.MalformedURLException e) + {} + + return null; + } } diff --git a/src/native/android/juce_android_NativeCode.cpp b/src/native/android/juce_android_NativeCode.cpp index 861c8ec916..6e1c98b29d 100644 --- a/src/native/android/juce_android_NativeCode.cpp +++ b/src/native/android/juce_android_NativeCode.cpp @@ -100,6 +100,7 @@ BEGIN_JUCE_NAMESPACE // List of basic required classes #define JUCE_JNI_CLASSES_ESSENTIAL(JAVACLASS) \ JAVACLASS (activityClass, "com/juce/JuceAppActivity") \ + JAVACLASS (httpStreamClass, "com/juce/JuceAppActivity$HTTPStream") \ JAVACLASS (componentPeerViewClass, "com/juce/ComponentPeerView") \ JAVACLASS (fileClass, "java/io/File") \ JAVACLASS (systemClass, "java/lang/System") \ @@ -144,6 +145,14 @@ BEGIN_JUCE_NAMESPACE METHOD (activityClass, setClipboardContent, "setClipboardContent", "(Ljava/lang/String;)V") \ METHOD (activityClass, excludeClipRegion, "excludeClipRegion", "(Landroid/graphics/Canvas;FFFF)V") \ METHOD (activityClass, renderGlyph, "renderGlyph", "(CLandroid/graphics/Paint;Landroid/graphics/Matrix;Landroid/graphics/Rect;)[I") \ + STATICMETHOD (activityClass, createHTTPStream, "createHTTPStream", "(Ljava/lang/String;Z[BLjava/lang/String;ILjava/lang/StringBuffer;)Lcom/juce/JuceAppActivity$HTTPStream;") \ +\ + METHOD (httpStreamClass, httpStreamRelease, "release", "()V") \ + METHOD (httpStreamClass, httpStreamRead, "read", "([BI)I") \ + METHOD (httpStreamClass, getPosition, "getPosition", "()J") \ + METHOD (httpStreamClass, getTotalLength, "getTotalLength", "()J") \ + METHOD (httpStreamClass, isExhausted, "isExhausted", "()Z") \ + METHOD (httpStreamClass, setPosition, "setPosition", "(J)Z") \ \ METHOD (fileClass, fileExists, "exists", "()Z") \ STATICMETHOD (systemClass, getProperty, "getProperty", "(Ljava/lang/String;)Ljava/lang/String;") \ diff --git a/src/native/linux/juce_linux_Network.cpp b/src/native/linux/juce_linux_Network.cpp index f661ac9244..7bff70486d 100644 --- a/src/native/linux/juce_linux_Network.cpp +++ b/src/native/linux/juce_linux_Network.cpp @@ -195,57 +195,60 @@ private: if (! decomposeURL (address, hostName, hostPath, hostPort)) return; - const struct hostent* host = 0; + String serverName, proxyName, proxyPath; + int proxyPort = 0; int port = 0; - String proxyName, proxyPath; - int proxyPort = 0; - - String proxyURL (getenv ("http_proxy")); + const String proxyURL (getenv ("http_proxy")); if (proxyURL.startsWithIgnoreCase ("http://")) { if (! decomposeURL (proxyURL, proxyName, proxyPath, proxyPort)) return; - host = gethostbyname (proxyName.toUTF8()); + serverName = proxyName; port = proxyPort; } else { - host = gethostbyname (hostName.toUTF8()); + serverName = hostName; port = hostPort; } - if (host == 0) + struct addrinfo hints; + zerostruct (hints); + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + hints.ai_flags = AI_NUMERICSERV; + + struct addrinfo* result = 0; + if (getaddrinfo (serverName.toUTF8(), String (port).toUTF8(), &hints, &result) != 0 || result == 0) return; + socketHandle = socket (result->ai_family, result->ai_socktype, 0); + + if (socketHandle == -1) { - struct sockaddr_in socketAddress; - zerostruct (socketAddress); - memcpy (&socketAddress.sin_addr, host->h_addr, host->h_length); - socketAddress.sin_family = host->h_addrtype; - socketAddress.sin_port = htons (port); - - socketHandle = socket (host->h_addrtype, SOCK_STREAM, 0); - - if (socketHandle == -1) - return; - - int receiveBufferSize = 16384; - setsockopt (socketHandle, SOL_SOCKET, SO_RCVBUF, (char*) &receiveBufferSize, sizeof (receiveBufferSize)); - setsockopt (socketHandle, SOL_SOCKET, SO_KEEPALIVE, 0, 0); - - #if JUCE_MAC - setsockopt (socketHandle, SOL_SOCKET, SO_NOSIGPIPE, 0, 0); - #endif - - if (connect (socketHandle, (struct sockaddr*) &socketAddress, sizeof (socketAddress)) == -1) - { - closeSocket(); - return; - } + freeaddrinfo (result); + return; } + int receiveBufferSize = 16384; + setsockopt (socketHandle, SOL_SOCKET, SO_RCVBUF, (char*) &receiveBufferSize, sizeof (receiveBufferSize)); + setsockopt (socketHandle, SOL_SOCKET, SO_KEEPALIVE, 0, 0); + + #if JUCE_MAC + setsockopt (socketHandle, SOL_SOCKET, SO_NOSIGPIPE, 0, 0); + #endif + + if (connect (socketHandle, result->ai_addr, result->ai_addrlen) == -1) + { + closeSocket(); + freeaddrinfo (result); + return; + } + + freeaddrinfo (result); + { const MemoryBlock requestHeader (createRequestHeader (hostName, hostPort, proxyName, proxyPort, hostPath, address, headers, postData, isPost));