[processing] movie

specify P2D on size():

size(1024, 768, P2D);

otherwise you keep getting this exception on mac:

Exception in thread "Animation Thread" java.lang.ArrayIndexOutOfBoundsException: Coordinate out of bounds!
        at sun.awt.image.IntegerInterleavedRaster.setDataElements(IntegerInterleavedRaster.java:416)
        at processing.core.PGraphicsJava2D$ImageCache.update(PGraphicsJava2D.java:959)
        at processing.core.PGraphicsJava2D.imageImpl(PGraphicsJava2D.java:834)
        at processing.core.PGraphics.image(PGraphics.java:2756)
        at processing.core.PApplet.image(PApplet.java:8637)
        at sketch_may01a.draw(sketch_may01a.java:39)
        at processing.core.PApplet.handleDraw(PApplet.java:1631)
        at processing.core.PApplet.run(PApplet.java:1530)
        at java.lang.Thread.run(Thread.java:680)

via http://processing.org/discourse/yabb2/YaBB.pl?num=1232118515

~/Library/KeyBindings/DefaultKeyBinding.dict

/*
        based on http://gnufoo.org/macosx/macosx.html
        place this at ~/Library/KeyBindings/DefaultKeyBinding.dict
        “^” for Control
        “~” for Option
        “$” for Shift
        “#” for numeric keypad http://developer.apple.com/documentation/Cocoa/Conceptual/EventOverview/index.html
*/ 

{

        "^F"="moveWordForward:";
        "^B"="moveWordBackward:";
        "~f"="moveWordForward:";
        "~b"="moveWordBackward:"; 

        "^D"="deleteWordForward:";
        "^H"="deleteWordBackward:";
        "~d"="deleteWordForward:";
        "~h"="deleteWordBackward:"; 

        /* Escape should really be complete. */
        "\033"="complete:"; /* Escape */

}

what to do & install first for a new mac

install applications

system preference

  • keyboard > modifier key > change Caps Lock to Control
  • keyboard > keyboard shortcuts > add:
    app: "All Applications" / title: "System Preferences" / shortcut: Command + Shift + Comma
  • mouse > set Tracking faster, activate Secondary Button (ie. Right Click)
  • appearance > Click in the scroll bar to: > Jump to the spot that's clicked
  • appearance > check Double-click a window's title bar to minimize
  • expose & spaces > activate corner shortcut
  • (optional) sharing > File / Web / Screen Sharing, Remote Login
  • (optional) network > set fixed IP adress
  • (japanese) keyboard > keyboard shortcuts > set Spotlight to Command+Shift+Space
  • (japanese) language > input method > add Kotoeri Romaji / Kotoeri preference: Windows-like input style

other configuration

transfer from old environment

  • copy HOME>Library>Preferences and HOME>Library>Application Supports

using VBO with PyOpenGL

### to prepare ###

arr = [(float(x)/(size-1),float(y)/(size-1))
            for x in xrange(size)
            for y in xrange(size)]
arr = np.require(arr, 'f')
self.vbo = OpenGL.arrays.vbo.VBO(arr , 'GL_STATIC_DRAW')

### to use ###

self.vbo.bind()
glEnableClientState(GL_VERTEX_ARRAY)
glEnableClientState(GL_TEXTURE_COORD_ARRAY)
glTexCoordPointer(2, GL_FLOAT, 0, None)
glVertexPointer(2, GL_FLOAT, 0, None)
glDrawArrays(GL_POINTS, 0, N_PARTICLE)
glDisableClientState(GL_VERTEX_ARRAY)
glDisableClientState(GL_TEXTURE_COORD_ARRAY)
self.vbo.unbind()

* The last argument for glVertexPointer should be None, not 0.

adding custom property to CAAnimation

* override copyWithZone:

@interface MyLayerAnimation : CABasicAnimation
{
    MyItemLayer *relatedLayer;
}
@property (assign) __weak MyItemLayer *relatedLayer;

@end


@implementation MyLayerAnimation

@synthesize relatedLayer;

- (id)copyWithZone:(NSZone *)zone
{
    MyLayerAnimation *newObj = [super copyWithZone:zone];
    newObj.relatedLayer = self.relatedLayer;
    return newObj;
}

@end

smallest CoreAudio code to grab audio out on iPhone

will generate & play realtime white noise on iphone.

MyAudio.h

#import 

#define MY_AUDIO_BUFFERS_NUM 4
#define MY_AUDIO_BUFFER_FRAMES 256
#define MY_AUDIO_BUFFER_SIZE (MY_AUDIO_BUFFER_FRAMES * 2 * 2)

@interface MyAudio : NSObject {
    AudioQueueRef queueObject;
    AudioQueueBufferRef audioBuffers[MY_AUDIO_BUFFERS_NUM];
    AudioStreamBasicDescription audioFormat;
}

- (IBAction)setupAudio:(id)sender;
- (IBAction)teardownAudio:(id)sender;

@end

MyAudio.m

#import "MyAudio.h"

@interface MyAudio ()
- (void)playbackCallbackWithAudioQueue:(AudioQueueRef)inAudioQueue
                                buffer:(AudioQueueBufferRef)bufferReference;
@end

static void PlaybackCallback (
                              void *inUserData,
                              AudioQueueRef inAudioQueue,
                              AudioQueueBufferRef bufferReference
                              )
{
    [(MyAudio *)inUserData playbackCallbackWithAudioQueue:inAudioQueue
                                                   buffer:bufferReference];

}

@implementation MyAudio

- (void)playbackCallbackWithAudioQueue:(AudioQueueRef)inAudioQueue
                                buffer:(AudioQueueBufferRef)bufferReference;
{
    NSUInteger numBytes = MY_AUDIO_BUFFER_SIZE;
    NSUInteger bytesPerFrame = audioFormat.mBytesPerFrame;
    NSUInteger channlesPerFrame = audioFormat.mChannelsPerFrame;
    NSUInteger bytesPerSample = bytesPerFrame/channlesPerFrame;
    NSUInteger numFrames = numBytes/bytesPerFrame;
    NSUInteger i=0;

    while (imAudioData + dstAddr) = (AudioSampleType)(rand() / (float)RAND_MAX * 10);
        *(AudioSampleType *)(bufferReference->mAudioData + dstAddr + bytesPerSample) = (AudioSampleType)(rand() / (float)RAND_MAX * 10);
        i++;
    }

    bufferReference->mAudioDataByteSize = numBytes;
    AudioQueueEnqueueBuffer (inAudioQueue,
                             bufferReference,
                             0,
                             NULL);
}

- (IBAction)setupAudio:(id)sender
{
    audioFormat.mFormatID = 1819304813;
    audioFormat.mFormatFlags = 14;
    audioFormat.mSampleRate = 44100.0;
    audioFormat.mChannelsPerFrame = 2;
    audioFormat.mFramesPerPacket = 1;
    audioFormat.mBytesPerFrame =  4;
    audioFormat.mBytesPerPacket = 4;
    audioFormat.mBitsPerChannel = 16;
    audioFormat.mReserved = 0;
    OSStatus ret =  AudioQueueNewOutput (
                         &audioFormat,
                         PlaybackCallback,
                         self, 
                         CFRunLoopGetCurrent (),
                         kCFRunLoopCommonModes,
                         0, // run loop flags
                         &queueObject);

    assert(ret == noErr);
    assert(queueObject != NULL);
    assert(audioFormat.mChannelsPerFrame==2);

    Float32 gain = 1.0;
    AudioQueueSetParameter (queueObject,
                            kAudioQueueParam_Volume,
                            gain);

    NSUInteger bufferIndex;
    for (bufferIndex = 0; bufferIndex < MY_AUDIO_BUFFERS_NUM; ++bufferIndex) {
 AudioQueueAllocateBuffer (queueObject,
                                  MY_AUDIO_BUFFER_SIZE,
                                  &audioBuffers[bufferIndex]);
        audioBuffers[bufferIndex]->mAudioDataByteSize = MY_AUDIO_BUFFER_SIZE;
        AudioQueueEnqueueBuffer(queueObject, audioBuffers[bufferIndex], 0, NULL);
    }

    UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
    AudioSessionSetProperty(kAudioSessionProperty_AudioCategory,
                            sizeof (sessionCategory),
                            &sessionCategory);
    AudioSessionSetActive(true);

    ret =  AudioQueueStart (queueObject,
                            NULL);
    assert(ret == noErr);
}

- (void)teardownAudio
{
    AudioQueueStop (queueObject, YES);
    AudioQueueDispose (queueObject, YES);
}

@end

contact: form / email / +33 6 49 52 84 01