Cocoa!

I might have compiled the library in Xcode 2.5 under 10.4. I had to make some modifications to juce_mac_NSViewComponentPeer.mm to eliminate property access on NSEvent* e(e.modifierFlags & …)

Specifically

[code]static void updateModifiers (NSEvent* e)
{
int m = currentModifiers & ~(ModifierKeys::shiftModifier | ModifierKeys::ctrlModifier
| ModifierKeys::altModifier | ModifierKeys::commandModifier);

if (([e modifierFlags] & NSShiftKeyMask) != 0)
    m |= ModifierKeys::shiftModifier;

if (([e modifierFlags] & NSControlKeyMask) != 0)
    m |= ModifierKeys::ctrlModifier;

if (([e modifierFlags] & NSAlternateKeyMask) != 0)
    m |= ModifierKeys::altModifier;

if (([e modifierFlags] & NSCommandKeyMask) != 0)
    m |= ModifierKeys::commandModifier;

currentModifiers = m;

}[/code]

&

[code]

  • (void) keyDown: (NSEvent*) ev
    {
    bool used = false;

    if (owner != 0)
    {
    updateKeysDown (ev, true);
    used = owner->handleKeyEvent (ev, true);

      if (([ev modifierFlags] & NSCommandKeyMask) != 0)
      {
          // for command keys, the key-up event is thrown away, so simulate one..
          updateKeysDown (ev, false);
          used = owner->handleKeyEvent (ev, false) || used;
      }
    

    }

    if (! used)
    [super keyDown: ev];
    }[/code]

Also for some reason the AvailabilityMacros for 10.4 wasn’t being picked up so I got frustrated and just

#define MACOS_10_4_OR_EARLIER 1

before
#include “…/…/…/src/juce_core/basics/juce_StandardHeader.h”

in

juce_mac_NativeIncludes.h

I haven’t actually linked it in yet…:slight_smile:

And a suggestion for Julian below…

/******************************************/

[quote] Using POSIX Threads in Cocoa

NSThreads are built upon POSIX threads (pthreads). You can create your
own pthreads, but you must be cautious about using Cocoa from them.
When you detach an NSThread, Cocoa enters a multithreaded mode, which
activates greater thread safety measures. When you create your own
pthreads, Cocoa does not know to change modes. To force Cocoa into its
multithreaded mode, you must detach an NSThread, which could
immediately exit. To identify whether Cocoa is already in
multithreaded mode, use the NSThread class method isMultiThreaded.[/quote]

I think 10.5 handles all this automatically. But in 10.4 I make sure my app is multithreaded(as I use a variety of NSThread and pthreads)

Here is my code I call when my app init’s

@interface MTCocoaSafe : NSObject
{
	
}
+ (id)initializeCocoaThreads;
@end


@implementation MTCocoaSafe
+ (id)initializeCocoaThreads
{
	id instance=[[self alloc]init];
	if (!instance)
		return nil;
	if (![NSThread isMultiThreaded])
		[NSThread detachNewThreadSelector:@selector(goMultiThreaded) toTarget:instance withObject:nil];
	return [instance autorelease];
}
- (void)goMultiThreaded
{
	NSAutoreleasePool *pool=[[NSAutoreleasePool alloc]init];
	[pool release];
}
@end
[MTCocoaSafe initializeCocoaThreads];

[/b]

Just a graphical thing but…

If I create a window and…
setUsingNativeTitleBar(true);

It flashes a few times in the lower left hand part of my screen before moving into position.

Perhaps its the order of my calls but this seems to show it…

[code]SMTestWindow::SMTestWindow () : DocumentWindow(TRANS(“Test Window”),Colour(51,53,68),DocumentWindow::allButtons, true)
{

setUsingNativeTitleBar(true);
ContentController *contentComp=new ContentController();
setContentComponent(contentComp,false,true);


setResizable(true,false);

setResizeLimits(600,500,1024,1000);
centreWithSize(ApplicationProperties::getInstance()->getUserSettings()->getIntValue(L"mainWindowWidth",800),
			   ApplicationProperties::getInstance()->getUserSettings()->getIntValue(L"mainWindowHeight",550));
setVisible(true);

}[/code]

Excellent stuff - thanks for that, I’ve checked in some changes that should sort you out.

I’ve also added a small change that I think should sort out the flashing window position thing, though I don’t see it on my machine, so can’t be 100% sure it’s what you’re seeing.

Stepping through, the window is invisible until

setContentComponent(contentComp,false,true); At which point it pops down in my lower left.

Only on those windows with native title bars of course!

I’ll check out the latest and see if it fixes anything…Thanks…looks like an absurd amount of work you’ve done!

setResizeLimits on Native Title Bar appears broken as well…I can resize my window to anything. A JUCE window works fine.

Moving my setContentComponent to after my resizing and before my setVisible call fixes the flash

centreWithSize(ApplicationProperties::getInstance()->getUserSettings()->getIntValue(L"mainWindowWidth",800),
				   ApplicationProperties::getInstance()->getUserSettings()->getIntValue(L"mainWindowHeight",550));
	setContentComponent(contentComp,false,false);
	setVisible(true);

In Xcode 2.5 - 10.4 - JUCEApplication…is anyone else seeing their main menu contents duplicated?

In other words the contents created by createStandardAppMenu() appear twice(once with the key commands that work) and again(although none of these items work)

Julian - I checked out your fix, and it still flashes lower left, so I just moved my setContentComponent after the window sizing and it appears to work just fine.

Yes! It compiled in XCode2.5 with 10.4.11 with #define MACOS_10_4_OR_EARLIER 1.

But: Cannot compile my code because MessageManager::dispatchPendingMessages() is gone! Why is that? It’s very important I can use this function to flush all messages before going on in my code.

i think Julian have introduced a much more efficient:

I noticed that too, also the MessageManager .h and .cpp files seems they have not correctly gained the juce style and are a bit messy. But i’m sure the fearless leader will clean that before a proper release.

As a notice, why now the vst hosting code have been disabled for LINUX ? that is a pita imho. If you need i can make sure it works so you can throw back in the support.

The compiling of my code finished, but then I got the following problem:

Building target “Quad2” of project “quad2COCOA” with configuration “Release” — (1 error, 2 warnings)
Checking Dependencieswarning: skipping file ‘/Volumes/Untitled/juce/PROJECTS/QUAD2/Release/gfx/background.png’ (unexpected file type ‘image.png’ in Frameworks & Libraries build phase)
warning: skipping file ‘/Volumes/Untitled/juce/PROJECTS/QUAD2/Release/gfx/background.png’ (unexpected file type ‘image.png’ in Frameworks & Libraries build phase)
warning: skipping file ‘/Volumes/Untitled/juce/PROJECTS/QUAD2/Release/gfx/background.png’ (unexpected file type ‘image.png’ in Frameworks & Libraries build phase)
warning: skipping file ‘/Volumes/Untitled/juce/PROJECTS/QUAD2/Release/gfx/background.png’ (unexpected file type ‘image.png’ in Frameworks & Libraries build phase)
cd “/Users/theman/Desktop/CODING/PROJECTS/QUAD2 COCOA”
/Developer/usr/bin/g+±4.0 -o /Users/theman/Desktop/CODING/PROJECTS/QUAD2\ COCOA/build/quad2COCOA.build/Release/Quad2.build/Objects-normal/i386/Quad2 -L/Users/theman/Desktop/CODING/PROJECTS/QUAD2\ COCOA/build/Release -L…/…/…/juce/bin -L/opt/local/var/macports/software/id3lib/3.8.3_0/opt/local/lib -L/Volumes/Untitled/juce/bin -L/Users/theman/Desktop/CODING/PROJECTS/QUAD2\ COCOA/…/…/…/id3lib\ compilation/id3lib/build/Release -L/opt/local/lib -L/Users/theman/Desktop/CODING/PROJECTS/QUAD2\ COCOA/…/…/…/…/juce/trunk/bin -F/Users/theman/Desktop/CODING/PROJECTS/QUAD2\ COCOA/build/Release -F/Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks -filelist /Users/theman/Desktop/CODING/PROJECTS/QUAD2\ COCOA/build/quad2COCOA.build/Release/Quad2.build/Objects-normal/i386/Quad2.LinkFileList -framework Carbon -framework CoreAudio -framework AGL -framework QuickTime -framework CoreMIDI -framework IOKit -framework AudioToolbox -framework OpenGL -lid3lib -framework AudioUnit -ljuce -arch i386 -Wl,-Y,1455
/Developer/usr/bin/…/libexec/gcc/i686-apple-darwin8/4.0.1/ld: warning -L: directory name (…/…/…/juce/bin) does not exist
/Developer/usr/bin/…/libexec/gcc/i686-apple-darwin8/4.0.1/ld: multiple definitions of symbol _bitreverse
/Users/theman/Desktop/CODING/PROJECTS/QUAD2 COCOA/build/quad2COCOA.build/Release/Quad2.build/Objects-normal/i386/ID3DataBase.o private external definition of _bitreverse in section (__TEXT,__text)
/Users/theman/Desktop/CODING/PROJECTS/QUAD2 COCOA/build/quad2COCOA.build/Release/Quad2.build/Objects-normal/i386/CEngine.o private external definition of _bitreverse in section (__TEXT,__text)
/Developer/usr/bin/…/libexec/gcc/i686-apple-darwin8/4.0.1/ld: multiple definitions of symbol _bitreverse.eh
/Users/theman/Desktop/CODING/PROJECTS/QUAD2 COCOA/build/quad2COCOA.build/Release/Quad2.build/Objects-normal/i386/ID3DataBase.o private external definition of absolute _bitreverse.eh (value 0x0)
/Users/theman/Desktop/CODING/PROJECTS/QUAD2 COCOA/build/quad2COCOA.build/Release/Quad2.build/Objects-normal/i386/CEngine.o private external definition of absolute _bitreverse.eh (value 0x0)
/Users/theman/Desktop/CODING/PROJECTS/QUAD2 COCOA/build/quad2COCOA.build/Release/Quad2.build/Objects-normal/i386/OggVorbisTagger.o private external definition of _bitreverse in section (__TEXT,__text)
/Users/theman/Desktop/CODING/PROJECTS/QUAD2 COCOA/build/quad2COCOA.build/Release/Quad2.build/Objects-normal/i386/OggVorbisTagger.o private external definition of absolute _bitreverse.eh (value 0x0)
collect2: ld returned 1 exit status
collect2: ld returned 1 exit status
collect2: ld returned 1 exit status
collect2: ld returned 1 exit status
collect2: ld returned 1 exit status
collect2: ld returned 1 exit status
collect2: ld returned 1 exit status
collect2: ld returned 1 exit status
collect2: ld returned 1 exit status
collect2: ld returned 1 exit status
collect2: ld returned 1 exit status
collect2: ld returned 1 exit status
Build failed (1 error, 2 warnings)

What’s up with this bitreverse stuff?

I still have the same bottom cropping if I use native titlebars (my app is not hidden behind the menubar like zamrate though)

Whoops! Forgot to do that bit. Will get it sorted pronto…

[quote]
In Xcode 2.5 - 10.4 - JUCEApplication…is anyone else seeing their main menu contents duplicated?[/quote]

Can’t think why that would be… The jucer and jucedemo work ok, right?

Yes - there was no mac equivalent that could easily dispatch just the pending messages, so I changed that method. Will tidy up the classes and add proper comments shortly.

The bitreverse things look like a naming clash - it’s a function used in the ogg code, so I’ll rename it to something else to avoid it clashing with other libs…

Hmm, I changed every occurence of bitreverse to bitreverseEX and still get the same problem,…

Well, looking at your error list, it looks like you’re linking some of your own stuff - maybe this has nothing to do with juce?

Sorry, I wasn’t aware that I’d changed it! Sure, if you can let me know what I broke, I’ll fix it right away!

Nope, it’s the same project I used before, just linking with the new JUCE. I got that error away, but then come others.

When I try to compile the example “juce_application”, I get a compiler error. Seems like the amalgamated version is too big for XCode2.5 to handle.
So I remove it, and get lots of errors like many JUCE symbols are not found.

I’m giving it up now, lost too much time trying this.

yeah i think i’ll give up too. it seems there is a lot of cocoa powder in the middle of every gear in the core and the engine stopped working.

i’m getting lots of free related problems (sigabort, double free) when i shutdown the application with this version:

*** glibc detected *** /usr/local/bin/jost_debug: free(): invalid next size (fast): 0x08378d00 ***
======= Backtrace: =========
/lib/libc.so.6[0x4a187a00]
/lib/libc.so.6(cfree+0x89)[0x4a1896f9]
/usr/local/bin/jost_debug[0x8098bf4]
/usr/local/bin/jost_debug[0x82426ab]
/usr/local/bin/jost_debug[0x8242cab]
/usr/local/bin/jost_debug[0x82447c4]
/usr/local/bin/jost_debug[0x824346f]
/usr/local/bin/jost_debug[0x8244cab]
/usr/local/bin/jost_debug[0x813c64c]
/usr/local/bin/jost_debug[0x81cbf57]
/usr/local/bin/jost_debug[0x81cc021]
/usr/local/bin/jost_debug[0x82418ad]
/lib/libc.so.6(__libc_start_main+0xdc)[0x4a137fdc]
/usr/local/bin/jost_debug[0x804f051]
======= Memory map: ========
08048000-0835c000 r-xp 00000000 08:03 4628335    /usr/local/bin/jost_debug
0835c000-0835d000 r--p 00313000 08:03 4628335    /usr/local/bin/jost_debug
0835d000-0835e000 rw-p 00314000 08:03 4628335    /usr/local/bin/jost_debug
0835e000-0843e000 rw-p 0835e000 00:00 0          [heap]
41ece000-41edd000 r-xp 00000000 08:03 4551516    /usr/lib/libjack.so.0.0.28
41edd000-41ede000 r--p 0000e000 08:03 4551516    /usr/lib/libjack.so.0.0.28
41ede000-41ee0000 rw-p 0000f000 08:03 4551516    /usr/lib/libjack.so.0.0.28
41ee0000-41ee8000 rw-p 41ee0000 00:00 0 
4299c000-4299d000 r-xp 00000000 08:03 4645565    /usr/lib/opengl/nvidia/tls/libnvidia-tls.so.177.80
4299d000-4299e000 rw-p 00000000 08:03 4645565    /usr/lib/opengl/nvidia/tls/libnvidia-tls.so.177.80
43244000-432d6000 r-xp 00000000 08:03 4668130    /usr/lib/opengl/nvidia/lib/libGL.so.177.80
432d6000-432f0000 rwxp 00092000 08:03 4668130    /usr/lib/opengl/nvidia/lib/libGL.so.177.80
432f0000-432f2000 rwxp 432f0000 00:00 0 
432f4000-43370000 r-xp 00000000 08:03 4548518    /usr/lib/libGLU.so.1.3.060502
43370000-43371000 rw-p 0007c000 08:03 4548518    /usr/lib/libGLU.so.1.3.060502
4585a000-46518000 r-xp 00000000 08:03 4668111    /usr/lib/opengl/nvidia/lib/libGLcore.so.177.80
46518000-466bc000 rwxp 00cbe000 08:03 4668111    /usr/lib/opengl/nvidia/lib/libGLcore.so.177.80
466bc000-466c7000 rwxp 466bc000 00:00 0 
48183000-4826b000 r-xp 00000000 08:03 4549145    /usr/lib/libX11.so.6.2.0
4826b000-4826c000 r--p 000e7000 08:03 4549145    /usr/lib/libX11.so.6.2.0
4826c000-4826f000 rw-p 000e8000 08:03 4549145    /usr/lib/libX11.so.6.2.0
4833e000-483b8000 r-xp 00000000 08:03 4549047    /usr/lib/libfreetype.so.6.3.18
483b8000-483bc000 r--p 00079000 08:03 4549047    /usr/lib/libfreetype.so.6.3.18
483bc000-483bd000 rw-p 0007d000 08:03 4549047    /usr/lib/libfreetype.so.6.3.18
483bf000-483cb000 r-xp 00000000 08:03 4549150    /usr/lib/libXext.so.6.4.0
483cb000-483cc000 rw-p 0000c000 08:03 4549150    /usr/lib/libXext.so.6.4.0
48435000-4843c000 r-xp 00000000 08:03 4549152    /usr/lib/libXrender.so.1.3.0
4843c000-4843d000 rw-p 00006000 08:03 4549152    /usr/lib/libXrender.so.1.3.0
4843f000-48443000 r-xp 00000000 08:03 4549180    /usr/lib/libXfixes.so.3.1.0
48443000-48444000 rw-p 00003000 08:03 4549180    /usr/lib/libXfixes.so.3.1.0
48460000-48468000 r-xp 00000000 08:03 4549183    /usr/lib/libXcursor.so.1.0.2
48468000-48469000 r--p 00007000 08:03 4549183    /usr/lib/libXcursor.so.1.0.2
48469000-4846a000 rw-p 00008000 08:03 4549183    /usr/lib/libXcursor.so.1.0.2
49563000-4957d000 r-xp 00000000 08:03 4856546    /lib/ld-2.6.1.so
4957d000-4957e000 r--p 00019000 08:03 4856546    /lib/ld-2.6.1.so
4957e000-4957f000 rw-p 0001a000 08:03 4856546    /lib/ld-2.6.1.so
4a122000-4a24c000 r-xp 00000000 08:03 4856547    /lib/libc-2.6.1.so
4a24c000-4a24e000 r--p 0012a000 08:03 4856547    /lib/libc-2.6.1.so
4a24e000-4a24f000 rw-p 0012c000 08:03 4856547    /lib/libc-2.6.1.so
4a24f000-4a252000 rw-p 4a24f000 00:00 0 
4a254000-4a256000 r-xp 00000000 08:03 4856593    /lib/libdl-2.6.1.so
4a256000-4a257000 r--p 00001000 08:03 4856593    /lib/libdl-2.6.1.so
4a257000-4a258000 rw-p 00002000 08:03 4856593    /lib/libdl-2.6.1.so
4a25a000-4a27e000 r-xp 00000000 08:03 4857842    /lib/libm-2.6.1.so
4a27e000-4a27f000 r--p 00023000 08:03 4857842    /lib/libm-2.6.1.so
4a27f000-4a280000 rw-p 00024000 08:03 4857842    /lib/libm-2.6.1.so
4a282000-4a295000 r-xp 00000000 08:03 4857895    /lib/libpthread-2.6.1.so

Program received signal SIGABRT, Aborted.
[Switching to Thread 0xb7ef16f0 (LWP 7467)]
0xffffe424 in __kernel_vsyscall ()
(gdb) bt
#0  0xffffe424 in __kernel_vsyscall ()
#1  0x4a14b101 in raise () from /lib/libc.so.6
#2  0x4a14c8e8 in abort () from /lib/libc.so.6
#3  0x4a181cbb in ?? () from /lib/libc.so.6
#4  0x0000000a in ?? ()
#5  0xbfa24e50 in ?? ()
#6  0x00000400 in ?? ()
#7  0xbfa25330 in ?? ()
#8  0x4a15df79 in vfprintf () from /lib/libc.so.6
#9  0x4a187a00 in ?? () from /lib/libc.so.6
#10 0x00000002 in ?? ()
#11 0x4a236968 in ?? () from /lib/libc.so.6
#12 0xbfa25e77 in ?? ()
#13 0x4a2369b4 in ?? () from /lib/libc.so.6
#14 0xbfa25387 in ?? ()
#15 0x4a2369b4 in ?? () from /lib/libc.so.6
#16 0x30000000 in ?? ()
#17 0x38373338 in ?? ()
#18 0x00303064 in ?? ()
#19 0x4a24dff4 in ?? () from /lib/libc.so.6
#20 0x4a24f120 in ?? () from /lib/libc.so.6
#21 0x08378d00 in ?? ()
#22 0xbfa253b8 in ?? ()
#23 0x4a1896f9 in free () from /lib/libc.so.6
Backtrace stopped: frame did not save the PC

i don’t say it never happened before, but now it happens EVERY TIME i close my application…

now some things hunted:

  • in MessageManager this should be like this (now that you changed thread id from int to int64).
  • in juce_VstWrapper.cpp there are a bunch of stuff:
class SharedMessageThread : public Thread
{
public:
    SharedMessageThread()
      : Thread (T("VstMessageThread"))
    {
        startThread (7);
    }

    ~SharedMessageThread()
    {
        signalThreadShouldExit ();

        JUCEApplication::quit ();

        waitForThreadToExit (5000);

        clearSingletonInstance();
    }

    void run()
    {
        MessageManager* const messageManager = MessageManager::getInstance();

        const int64 originalThreadId = messageManager->getCurrentMessageThread();
        messageManager->setCurrentMessageThread (Thread::getCurrentThreadId());

        while (! threadShouldExit()
               && messageManager->runDispatchLoopUntil(250))
        {
        }

        messageManager->setCurrentMessageThread (originalThreadId);
    }

    juce_DeclareSingleton (SharedMessageThread, false)
};

and you introduced dynamic editor allocation, but you forgot to lock the MessageManager and to call editorBeingDeleted (assert hit)


    void open()
    {
        if (editorComp == 0)
        {
#if JUCE_LINUX
            const MessageManagerLock mml;
#endif

            AudioProcessorEditor* const ed = filter->createEditorIfNeeded();

            if (ed != 0)
                cEffect.flags |= effFlagsHasEditor;
            else
                cEffect.flags &= ~effFlagsHasEditor;

            filter->editorBeingDeleted (ed);

            delete ed;
        }

Thanks for those! Will check in shortly…

Really can’t think what’d be causing the problems on shutdown, but haven’t spent much time playing with linux recently. I’ll have a think…

Well i don’t think it’s linux only. I’ve seen some things that are a bit suspicious, and i wouldn’t expect that from you, the fearless leader.

Look here, you touched the AudioSampleBuffer stuff cause people asked for dynamic allocation of channels, but the old version was working and the new version is untested and broken.

AudioSampleBuffer::AudioSampleBuffer (const int numChannels_,

                                      const int numSamples) throw()

  : numChannels (numChannels_),

    size (numSamples)

{

    jassert (numSamples >= 0);

    jassert (numChannels_ > 0);



    allocatedBytes = numChannels * numSamples * sizeof (float) + 32;

    allocatedData = (float*) juce_malloc (allocatedBytes);

    channels = (float**) juce_malloc (numChannels_ * sizeof (float*));



    float* chan = allocatedData;

    for (int i = 0; i < numChannels_; ++i)

    {

        channels[i] = chan;

        chan += numSamples;

    }



    channels [numChannels_] = 0;

}

You don’t see anyting suspicious ? writing 0 out of bounds for instance ?
This adrove me nuts… i don’t apreciate the idea of debugging things inside core classes already established and well working just to discover the new versions broke.

I’ll do more sanity check all over the library. But please, try to focus on stability first rather than new features.

p.s. i want to be a little critical but not with arse :slight_smile:

cheers !

With the AudioSampleBuffer fixes all is going slick as usual.

Anyway i valgrinded my plugins massively and the jucedemo and i discovered some definately memory loss and strange things that i will post here, but now i’m too tired to do that… tomorrow !

night :wink:

Just tried that new cocoa juce on my standalone application, and I did not notice any bug that have not been already reported in this thread: I got caught by the AudioSampleBuffer bug; My dialogs with native tible bar are cropped at the bottom , and I also see them flashing in the upper left corner before they appear. Everything else looks fine !