/* void IdleTimerAction (EventLoopTimerRef inTimer, void *inUserData, EventIdleAction inAction ); */ SEXP R_carbonInstallIdle(R_IdleFunc f, void *userData) { EventLoopRef loop = GetCurrentEventLoop(); EventTimerInterval delay, time; EventLoopTimerUPP proc; EventLoopTimerRef out; OSSStatus status; delay = 0; time = 0; /* This is not quite what we want. It will not detect other events such as input onf streams, etc. And it is only available on OS X 10.2. */ status = InstallEventLoopIdleTimer(loop, delay, time, proc, userData, &out); if(status != noErr) { PROBLEM "Can't register idle task" ERROR; } return(createRCarbonTimer(out)); }
static void Initialize( void ) { EventLoopTimerRef timerRef; EventTypeSpec eventTypeSpec = { kEventClassWindow, kEventWindowClose }; Rect bounds; WindowRef window; InitCursor(); // Create a window and install an event handler to handle the close button. SetRect( &bounds, 50, 50, 600, 200 ); CreateNewWindow( kDocumentWindowClass, kWindowCloseBoxAttribute + kWindowStandardHandlerAttribute, &bounds, &window ); SetWTitle( window, "\pPlugIn Host -- Close Window To Quit" ); InstallWindowEventHandler( window, NewEventHandlerUPP( MyCloseHandler ), 1, &eventTypeSpec, NULL, NULL ); // Create a timer to handle ball-drawing in the window. InstallEventLoopTimer( GetCurrentEventLoop(), kEventDurationSecond, kEventDurationSecond, NewEventLoopTimerUPP( MyTimerHandler ), window, &timerRef ); ShowWindow( window ); }
void Tk_MacOSXSetupTkNotifier() { ThreadSpecificData *tsdPtr = Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); if (!tsdPtr->initialized) { /* HACK ALERT: There is a bug in Jaguar where when it goes to make * the event queue for the Main Event Loop, it stores the Current * event loop rather than the Main Event Loop in the Queue structure. * So we have to make sure that the Main Event Queue gets set up on * the main thread. Calling GetMainEventQueue will force this to * happen. */ GetMainEventQueue(); tsdPtr->initialized = 1; /* Install Carbon events event source in main event loop thread. */ if (GetCurrentEventLoop() == GetMainEventLoop()) { if (!pthread_main_np()) { /* * Panic if the Carbon main event loop thread (i.e. the * thread where HIToolbox was first loaded) is not the * main application thread, as Carbon does not support * this properly. */ Tcl_Panic("Tk_MacOSXSetupTkNotifier: %s", "first [load] of TkAqua has to occur in the main thread!"); } Tcl_CreateEventSource(CarbonEventsSetupProc, CarbonEventsCheckProc, GetMainEventQueue()); TkCreateExitHandler(TkMacOSXNotifyExitHandler, NULL); } } }
void StartHIDInput (void) { EndHIDInput (); // ensure we are overwriting an earlier set up // setup inputs if (SetupHIDInputs ()) InstallEventLoopTimer (GetCurrentEventLoop(), 0, 0.01, GetHIDTimerUPP (), NULL, &gHIDTimer); // start timer 100 hz else printf ("No 2 DOF device found.\n"); }
bool8 NPServerDialog (void) { OSStatus err; IBNibRef nibRef; npserver.dialogcancel = true; err = CreateNibReference(kMacS9XCFString, &nibRef); if (err == noErr) { WindowRef tWindowRef; err = CreateWindowFromNib(nibRef, CFSTR("ClientList"), &tWindowRef); if (err == noErr) { EventHandlerRef eref; EventLoopTimerRef tref; EventHandlerUPP eventUPP; EventLoopTimerUPP timerUPP; EventTypeSpec windowEvents[] = { { kEventClassCommand, kEventCommandProcess }, { kEventClassCommand, kEventCommandUpdateStatus } }; HIViewRef ctl; HIViewID cid = { 'Chse', 0 }; npserver.dialogprocess = kNPSDialogInit; eventUPP = NewEventHandlerUPP(NPServerDialogEventHandler); err = InstallWindowEventHandler(tWindowRef, eventUPP, GetEventTypeCount(windowEvents), windowEvents, (void *) tWindowRef, &eref); timerUPP = NewEventLoopTimerUPP(NPServerDialogTimerHandler); err = InstallEventLoopTimer(GetCurrentEventLoop(), 0.0f, 0.1f, timerUPP, (void *) tWindowRef, &tref); HIViewFindByID(HIViewGetRoot(tWindowRef), cid, &ctl); HIViewSetVisible(ctl, false); MoveWindowPosition(tWindowRef, kWindowServer, false); ShowWindow(tWindowRef); err = RunAppModalLoopForWindow(tWindowRef); HideWindow(tWindowRef); SaveWindowPosition(tWindowRef, kWindowServer); err = RemoveEventLoopTimer(tref); DisposeEventLoopTimerUPP(timerUPP); err = RemoveEventHandler(eref); DisposeEventHandlerUPP(eventUPP); CFRelease(tWindowRef); } DisposeNibReference(nibRef); } return (!npserver.dialogcancel); }
void InstallTimer( void ) { EventLoopTimerRef timer; InstallEventLoopTimer( GetCurrentEventLoop(), 0, kEventDurationMillisecond * 20, NewEventLoopTimerUPP( MyTimerProc ), gWindow, &timer ); }
void InstallTimer( void ) { EventLoopTimerRef timer; InstallEventLoopTimer( GetCurrentEventLoop(), 0, kEventDurationMillisecond * 8, // Roughly 125 times per second NewEventLoopTimerUPP( MyTimerProc ), NULL, &timer ); }
int main(int argc, char* argv[]) { IBNibRef nibRef; OSStatus err; InitCursor(); // check the correct BASS was loaded if (HIWORD(BASS_GetVersion())!=BASSVERSION) { Error("An incorrect version of BASS.DLL was loaded (2.4 is required)"); return 0; } // check the correct BASS_FX was loaded if (HIWORD(BASS_FX_GetVersion())!=BASSVERSION) { Error("An incorrect version of BASS_FX.DLL was loaded (2.4 is required)"); return 0; } // initialize default output device if(!BASS_Init(-1,44100,0,NULL,NULL)) { Error("Can't initialize device"); return 0; } // Create Window and Stuff err = CreateNibReference(CFSTR("reverse"), &nibRef); if (err) return err; err = CreateWindowFromNib(nibRef, CFSTR("MainWindow"), &win); if (err) return err; DisposeNibReference(nibRef); SetupControlHandler(10,kEventControlHit,OpenEventHandler); SetControlAction(GetControl(11),NewControlActionUPP(VolEventHandler)); SetControlAction(GetControl(13),NewControlActionUPP(TempoEventHandler)); SetControlAction(GetControl(15),NewControlActionUPP(PosEventHandler)); SetupControlHandler(16,kEventControlHit,DirEventHandler); EventLoopTimerRef timer; InstallEventLoopTimer(GetCurrentEventLoop(),kEventDurationNoWait,kEventDurationSecond/2,TimerProc,0,&timer); // The window was created hidden so show it. ShowWindow(win); // Call the event loop RunApplicationEventLoop(); // Close output BASS_Free(); return 0; }
void WindowBase::MainLoop() { OSXWindowData *windowData = (OSXWindowData*) GetWRefCon (mWindowHandle); windowData->StartedApplicationLoop = true; windowData->MainLoopEventHandler = NewEventLoopTimerUPP(MainLoopEventHandler); PRCORE_ASSERT_EXCEPTION( noErr != InstallEventLoopTimer (GetCurrentEventLoop(), 0, mMainFreq, windowData->MainLoopEventHandler, (void *) windowData, &windowData->EventMainLoopReference )); RunApplicationEventLoop(); }
int prHIDRunEventLoop(VMGlobals *g, int numArgsPushed) { PyrSlot *a = g->sp - 1; //class PyrSlot *b = g->sp; //num double eventtime; int err = slotDoubleVal(b, &eventtime); if (err) return err; if(gTimer) { RemoveEventLoopTimer(gTimer); gTimer = NULL; } InstallEventLoopTimer (GetCurrentEventLoop(), 0, (EventTimerInterval) eventtime, GetTimerUPP (), 0, &gTimer); //HIDSetQueueCallback(pCurrentHIDDevice, callback); return errNone; }
void windowCaptureFrames(GLWindow *glw) { // This routine is what we'll use to capture frames for building a movie // We need an array of GWorld to hold the image data we're reading out of OpenGL // Then we'll process that buffer with another thread char fBuffer[256], tBuffer[256], frBuffer[256]; Size dataSize; // bail if we're already in the middle of a snapshot sequence if(snapshotTimerUPP) return; // Get the desired frame rate GetControlData(movieFrameRate, kControlEditTextPart, kControlStaticTextTextTag, 256, frBuffer, &dataSize); fps = atoi(frBuffer); if(fps <= 0) fps = 32; if(movieUseTimeLimit) { GetControlData(movieTimeLimit, kControlEditTextPart, kControlStaticTextTextTag, 256, fBuffer, &dataSize); seqTimeInt = atoi(fBuffer); } if(movieUseFrameLimit) { GetControlData(movieFrameCount, kControlEditTextPart, kControlStaticTextTextTag, 256, tBuffer, &dataSize); seqFrameCount = atoi(tBuffer); } if(movTimeLimit <= 0) movTimeLimit = 10; if(movFrameCount <= 0) movFrameCount = 300; // now kick off our sequence timer snapshotTimerUPP = NewEventLoopTimerUPP(MovieCaptureTimedEventProcessor); InstallEventLoopTimer(GetCurrentEventLoop(), 0, kEventDurationSecond / fps, snapshotTimerUPP, NULL, // User Data &snapshotTimer); }
void windowSnapshotSequence(GLWindow *glw) { // Get the values from the controls (time and number of frames) // I think we need to pass a count along to the snapshot function // in order to figure out when to remove the damned thing. // There's no other way to do it without creating my own API. char buffer[256]; Size dataSize; // If our UPP is valid, we've already got a timer going if(snapshotTimerUPP) return; GetControlData(sequenceTimeInterval, kControlEditTextPart, kControlStaticTextTextTag, 256, buffer, &dataSize); seqTimeInt = atoi(buffer); GetControlData(sequenceFrameCount, kControlEditTextPart, kControlStaticTextTextTag, 256, buffer, &dataSize); seqFrameCount = atoi(buffer); if(seqTimeInt <= 0) seqTimeInt = 1; if(seqFrameCount <= 0) seqFrameCount = 1; // Now allocate memory for our GWorld buffer if(gwBuffer) { free(gwBuffer); gwBuffer = NULL; } gwBuffer = malloc(seqFrameCount * sizeof(GWorldPtr)); // Remember, we need to use NewGWorldFromPtr() on EACH of these elements as we create them // Now we kick off a new timer to create our snapshots snapshotTimerUPP = NewEventLoopTimerUPP(SnapshotTimedEventProcessor); InstallEventLoopTimer(GetCurrentEventLoop(), 0, kEventDurationMillisecond * seqTimeInt, snapshotTimerUPP, NULL, // User Data &snapshotTimer); }
SEXP R_carbonInstallTimer(int interval, R_TimerFunc f, void *userData) { EventLoopRef loop = GetCurrentEventLoop(); EventTimerInterval delay, time; EventLoopTimerUPP proc; EventLoopTimerRef out; OSStatus status; delay = 0; time = interval * kEventDurationSecond; /* Is this milli sceonds */ status = InstallEventLoopTimer(loop, delay, time, NewEventLoopTimerUPP(proc), userData, &out); if(status != noErr) { PROBLEM "Can't register timer task" ERROR; } return(createRCarbonTimer(out)); }
IdleList::IdleList(mdaLooplex *effect, IdleList *next) : effect(effect), next(next), remove(false) { if(effect && !timer) //start timer { #if WIN32 timer = SetTimer(NULL, 0, IDLE_MSEC, TimerCallback); #elif __linux__ timer = 1; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 16 * 1024); int policy; if (pthread_attr_getschedpolicy(&attr, &policy) == 0) { struct sched_param param; param.sched_priority = sched_get_priority_min(policy); pthread_attr_setschedpolicy(&attr, SCHED_OTHER); pthread_attr_setschedparam(&attr, ¶m); } pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, 0); if (pthread_create(&thread, &attr, &ThreadCallback, 0) != 0) { thread = 0; timer = 0; fprintf(stderr, "Error: mdaLooplex.cpp (line %d)\n", __LINE__); } pthread_attr_destroy(&attr); #else //OSX double ms = kEventDurationMillisecond * (double)IDLE_MSEC; InstallEventLoopTimer(GetCurrentEventLoop(), ms, ms, NewEventLoopTimerUPP(TimerCallback), 0, &timer); #endif } }
void MusicBoxDialog(void) { OSStatus err; IBNibRef nibRef; if (!cartOpen) return; err = CreateNibReference(kMacS9XCFString, &nibRef); if (err == noErr) { CFURLRef iconURL; FSRef iconFSRef; IconRef actIcon; WindowRef tWindowRef; actIcon = nil; if (musicboxmode == kMBXSoundEmulation) iconURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("musicbox_ledoff"), CFSTR("icns"), nil); else iconURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("musicbox_ledon" ), CFSTR("icns"), nil); if (iconURL) { if (CFURLGetFSRef(iconURL, &iconFSRef)) err = RegisterIconRefFromFSRef('~9X~', 'micn', &iconFSRef, &actIcon); CFRelease(iconURL); } err = CreateWindowFromNib(nibRef, CFSTR("MusicBox"), &tWindowRef); if (err == noErr) { EventHandlerRef mboxRef, paneRef; EventHandlerUPP mboxUPP, paneUPP; EventLoopTimerRef timeRef; EventLoopTimerUPP timeUPP; EventTypeSpec mboxEvents[] = { { kEventClassCommand, kEventCommandProcess }, { kEventClassCommand, kEventCommandUpdateStatus } }, paneEvents[] = { { kEventClassControl, kEventControlDraw } }; CFStringRef sref; CGDataProviderRef prov; CGImageRef ipng; CFURLRef iurl; HIViewRef ctl, root, paneView, imageView, contentView; HIViewID cid; HIRect bounds; Rect windowRect, barRect; char drive[_MAX_DRIVE], dir[_MAX_DIR], fname[_MAX_FNAME], ext[_MAX_EXT]; mboxPause = false; mbxFinished = false; showIndicator = false; so.stereo_switch = ~0; for (int i = 0; i < MAC_MAX_PLAYERS; i++) controlPad[i] = 0; switch (drawingMethod) { case kDrawingOpenGL: Settings.OpenGLEnable = true; break; case kDrawingDirect: case kDrawingBlitGL: Settings.OpenGLEnable = false; } // 107's enhanced SPC player root = HIViewGetRoot(tWindowRef); cid.id = 0; if (musicboxmode == kMBXSoundEmulation) { cid.signature = 'HEAD'; HIViewFindByID(root, cid, &ctl); EnableControl(ctl); StoredAPU = new SAPU; StoredAPURegisters = new SAPURegisters; StoredSoundData = new SSoundData; StoredIAPURAM = new uint8 [0x10000]; SPCPlayFreeze(); } else MusicBoxForceFreeze(); cid.signature = 'Kart'; HIViewFindByID(root, cid, &ctl); SetStaticTextTrunc(ctl, truncEnd, false); _splitpath(Memory.ROMFilename, drive, dir, fname, ext); sref = CFStringCreateWithCString(kCFAllocatorDefault, fname, MAC_PATH_ENCODING); if (sref) { SetStaticTextCFString(ctl, sref, false); CFRelease(sref); } ipng = nil; iurl = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("musicbox_indicator"), CFSTR("png"), nil); if (iurl) { prov = CGDataProviderCreateWithURL(iurl); if (prov) { ipng = CGImageCreateWithPNGDataProvider(prov, nil, false, kCGRenderingIntentDefault); CGDataProviderRelease(prov); } CFRelease(iurl); } imageView = nil; if (ipng) { HIViewFindByID(root, kHIViewWindowContentID, &contentView); err = HIImageViewCreate(ipng, &imageView); if (err == noErr) { bounds = CGRectMake(30, 64, CGImageGetWidth(ipng), CGImageGetHeight(ipng)); HIViewSetFrame(imageView, &bounds); HIImageViewSetOpaque(imageView, false); HIViewSetVisible(imageView, true); HIViewAddSubview(contentView, imageView); cid.signature = 'iMaG'; SetControlID(imageView, &cid); } CGImageRelease(ipng); } cid.signature = 'Pane'; HIViewFindByID(root, cid, &paneView); HIViewGetBounds(paneView, &bounds); mbxViewWidth = bounds.size.width; mbxViewHeight = bounds.size.height; mbxMarginY = (mbxViewHeight - mbxBarHeight) / 2.0; mbxMarginX = (mbxViewWidth - ((mbxBarWidth * 8.0 + mbxBarSpace * 7.0) * 2.0 + mbxLRSpace)) / 2.0; if (imageView) { HIViewSetZOrder(imageView, kHIViewZOrderBelow, paneView); HIViewAddSubview(imageView, paneView); } cid.signature = 'Tr_i'; HIViewFindByID(root, cid, &ctl); HIViewGetFrame(ctl, &bounds); GetWindowBounds(tWindowRef, kWindowTitleBarRgn, &barRect); mbxClosedHeight = (short) (bounds.origin.y + bounds.size.height + 7.0) + (barRect.bottom - barRect.top); GetWindowBounds(tWindowRef, kWindowStructureRgn, &windowRect); mbxOpenedHeight = windowRect.bottom - windowRect.top; windowRect.bottom = windowRect.top + mbxClosedHeight; SetWindowBounds(tWindowRef, kWindowStructureRgn, &windowRect); paneUPP = NewEventHandlerUPP(IndicatorEventHandler); err = InstallControlEventHandler(paneView, paneUPP, GetEventTypeCount(paneEvents), paneEvents, (void *) paneView, &paneRef); mboxUPP = NewEventHandlerUPP(MusicBoxEventHandler); err = InstallWindowEventHandler(tWindowRef, mboxUPP, GetEventTypeCount(mboxEvents), mboxEvents, (void *) tWindowRef, &mboxRef); timeUPP = NewEventLoopTimerUPP(MusicBoxTimerHandler); err = InstallEventLoopTimer(GetCurrentEventLoop(), kEventDurationNoWait, kEventDurationSecond * 2.0 / (double) Memory.ROMFramesPerSecond, timeUPP, (void *) paneView, &timeRef); MusicBoxInitIndicator(); stopNow = false; MacStartSound(); pthread_create(&mbxThread, nil, SoundTask, nil); MoveWindowPosition(tWindowRef, kWindowMusicBox, true); GetWindowBounds(tWindowRef, kWindowStructureRgn, &windowRect); if (windowRect.bottom - windowRect.top > mbxClosedHeight) { showIndicator = true; SetControl32BitValue(ctl, 1); // Tr_i } ShowWindow(tWindowRef); err = RunAppModalLoopForWindow(tWindowRef); HideWindow(tWindowRef); SaveWindowPosition(tWindowRef, kWindowMusicBox); stopNow = true; pthread_join(mbxThread, nil); MacStopSound(); err = RemoveEventLoopTimer(timeRef); DisposeEventLoopTimerUPP(timeUPP); err = RemoveEventHandler(mboxRef); DisposeEventHandlerUPP(mboxUPP); err = RemoveEventHandler(paneRef); DisposeEventHandlerUPP(paneUPP); ReleaseWindow(tWindowRef); so.stereo_switch = ~0; mbxFinished = true; if (musicboxmode == kMBXSoundEmulation) { SPCPlayDefrost(); delete StoredAPU; delete StoredAPURegisters; delete StoredSoundData; delete [] StoredIAPURAM; } else MusicBoxForceDefrost(); Settings.OpenGLEnable = false; } if (actIcon) err = UnregisterIconRef('~9X~', 'micn'); DisposeNibReference(nibRef); } }
/*----------------------------------------------------------------------------------------------------------*/ pascal OSStatus ScrollingTextViewHandler(EventHandlerCallRef inCaller, EventRef inEvent, void* inRefcon) { OSStatus result = eventNotHandledErr; ScrollingTextBoxData* myData = (ScrollingTextBoxData*)inRefcon; switch (GetEventClass(inEvent)) { case kEventClassHIObject: switch (GetEventKind(inEvent)) { case kEventHIObjectConstruct: { // allocate some instance data myData = (ScrollingTextBoxData*) calloc(1, sizeof(ScrollingTextBoxData)); // get our superclass instance HIViewRef epView; GetEventParameter(inEvent, kEventParamHIObjectInstance, typeHIObjectRef, NULL, sizeof(epView), NULL, &epView); // remember our superclass in our instance data and initialize other fields myData->view = epView; // set the control ID so that we can find it later with HIViewFindByID result = SetControlID(myData->view, &kScrollingTextBoxViewID); // store our instance data into the event result = SetEventParameter(inEvent, kEventParamHIObjectInstance, typeVoidPtr, sizeof(myData), &myData); break; } case kEventHIObjectDestruct: { if (myData->theTimer != NULL) RemoveEventLoopTimer(myData->theTimer); CFRelease(myData->theText); free(myData); result = noErr; break; } case kEventHIObjectInitialize: { // always begin kEventHIObjectInitialize by calling through to the previous handler result = CallNextEventHandler(inCaller, inEvent); // if that succeeded, do our own initialization if (result == noErr) { GetEventParameter(inEvent, kEventParamScrollingText, typeCFStringRef, NULL, sizeof(myData->theText), NULL, &myData->theText); CFRetain(myData->theText); GetEventParameter(inEvent, kEventParamAutoScroll, typeBoolean, NULL, sizeof(myData->autoScroll), NULL, &myData->autoScroll); GetEventParameter(inEvent, kEventParamDelayBeforeAutoScroll, typeUInt32, NULL, sizeof(myData->delayBeforeAutoScroll), NULL, &myData->delayBeforeAutoScroll); GetEventParameter(inEvent, kEventParamDelayBetweenAutoScroll, typeUInt32, NULL, sizeof(myData->delayBetweenAutoScroll), NULL, &myData->delayBetweenAutoScroll); GetEventParameter(inEvent, kEventParamAutoScrollAmount, typeSInt16, NULL, sizeof(myData->autoScrollAmount), NULL, &myData->autoScrollAmount); myData->theTimer = NULL; } break; } default: break; } break; case kEventClassScrollable: switch (GetEventKind(inEvent)) { case kEventScrollableGetInfo: { // we're being asked to return information about the scrolled view that we set as Event Parameters HISize imageSize = {50.0, myData->height}; SetEventParameter(inEvent, kEventParamImageSize, typeHISize, sizeof(imageSize), &imageSize); HISize lineSize = {50.0, 20.0}; SetEventParameter(inEvent, kEventParamLineSize, typeHISize, sizeof(lineSize), &lineSize); HIRect bounds; HIViewGetBounds(myData->view, &bounds); SetEventParameter(inEvent, kEventParamViewSize, typeHISize, sizeof(bounds.size), &bounds.size); SetEventParameter(inEvent, kEventParamOrigin, typeHIPoint, sizeof(myData->originPoint), &myData->originPoint); result = noErr; break; } case kEventScrollableScrollTo: { // we're being asked to scroll, we just do a sanity check and ask for a redraw HIPoint where; GetEventParameter(inEvent, kEventParamOrigin, typeHIPoint, NULL, sizeof(where), NULL, &where); HIViewSetNeedsDisplay(myData->view, true); myData->originPoint.y = (where.y < 0.0)?0.0:where.y; HIViewSetBoundsOrigin(myData->view, 0, myData->originPoint.y); break; } default: break; } break; case kEventClassControl: switch (GetEventKind(inEvent)) { // sets the feature of the view. case kEventControlInitialize: { result = CallNextEventHandler(inCaller, inEvent); if (result != noErr) break; UInt32 features = 0; result = GetEventParameter(inEvent, kEventParamControlFeatures, typeUInt32, NULL, sizeof(features), NULL, &features); if (result == noErr) features |= kControlSupportsEmbedding; else features = kControlSupportsEmbedding; result = SetEventParameter(inEvent, kEventParamControlFeatures, typeUInt32, sizeof features, &features); break; } // Our parent view just changed dimensions, so we determined our new height. case kEventControlSetData: CFRelease(myData->theText); CFStringRef *p; GetEventParameter(inEvent, kEventParamControlDataBuffer, typePtr, NULL, sizeof(p), NULL, &p); myData->theText = *p; CFRetain(myData->theText); // fallthrough case kEventControlBoundsChanged: { HIRect bounds; HIViewGetBounds(myData->view, &bounds); // // If we're building on Panther (or later) then HIThemeGetTextDimensions is available, else we use GetThemeTextDimensions // #if PANTHER_BUILD // // Furthermore, if we're running on Panther then we can call HIThemeGetTextDimensions else we call GetThemeTextDimensions // if (GetHIToolboxVersion() >= Panther_HIToolbox_Version) { HIThemeTextInfo textInfo = {0, kThemeStateActive, kScrollingTextBoxFontID, kHIThemeTextHorizontalFlushLeft, kHIThemeTextVerticalFlushTop, kHIThemeTextBoxOptionStronglyVertical, kHIThemeTextTruncationNone, 0, false}; HIThemeGetTextDimensions(myData->theText, bounds.size.width - kMargin - kMargin, &textInfo, NULL, &myData->height, NULL); } else #endif { Point pointBounds; pointBounds.h = (int)(bounds.size.width - kMargin - kMargin); GetThemeTextDimensions(myData->theText, kScrollingTextBoxFontID, kThemeStateActive, true, &pointBounds, NULL); myData->height = pointBounds.v; } myData->height += 2.0 * kMargin; HIViewSetNeedsDisplay(myData->view, true); result = eventNotHandledErr; break; } // Draw the view. case kEventControlDraw: { CGContextRef context; result = GetEventParameter(inEvent, kEventParamCGContextRef, typeCGContextRef, NULL, sizeof(context), NULL, &context); HIRect bounds; HIViewGetBounds(myData->view, &bounds); CGContextSaveGState(context); CGAffineTransform transform = CGAffineTransformIdentity; // adjust the transform so the text doesn't draw upside down transform = CGAffineTransformScale(transform, 1, -1); CGContextSetTextMatrix(context, transform); // now that the proper parameters and configurations have been dealt with, let's draw result = ScrollingTextBoxDraw(context, &bounds, myData); CGContextRestoreGState(context); if (myData->autoScroll) CGContextStrokeRect(context, bounds); // we postpone starting the autoscroll timer until after we do our first drawing if ( (myData->autoScroll) && (myData->theTimer == NULL) ) InstallEventLoopTimer(GetCurrentEventLoop(), TicksToEventTime(myData->delayBeforeAutoScroll), TicksToEventTime(myData->delayBetweenAutoScroll), myScrollingTextTimeProc, myData, &myData->theTimer); result = noErr; break; } default: break; } break; default: break; } return result; }
bool8 NPClientDialog (void) { OSStatus err; IBNibRef nibRef; npclient.dialogcancel = true; npclient.dialogsheet = false; npclient.configsaved = false; err = CreateNibReference(kMacS9XCFString, &nibRef); if (err == noErr) { err = CreateWindowFromNib(nibRef, CFSTR("Connect"), &mRef); if (err == noErr) { err = CreateWindowFromNib(nibRef, CFSTR("PlayerList"), &sRef); if (err == noErr) { EventHandlerRef eref, seref; EventLoopTimerRef tref; EventHandlerUPP eventUPP, sheetUPP; EventLoopTimerUPP timerUPP; EventTypeSpec windowEvents[] = { { kEventClassCommand, kEventCommandProcess }, { kEventClassCommand, kEventCommandUpdateStatus } }; CFStringRef ref; HIViewRef ctl, root; HIViewID cid; npclient.dialogprocess = kNPCDialogInit; eventUPP = NewEventHandlerUPP(NPClientDialogEventHandler); err = InstallWindowEventHandler(mRef, eventUPP, GetEventTypeCount(windowEvents), windowEvents, (void *) mRef, &eref); timerUPP = NewEventLoopTimerUPP(NPClientDialogTimerHandler); err = InstallEventLoopTimer(GetCurrentEventLoop(), 0.0f, 0.1f, timerUPP, (void *) mRef, &tref); sheetUPP = NewEventHandlerUPP(NPClientSheetEventHandler); err = InstallWindowEventHandler(sRef, sheetUPP, GetEventTypeCount(windowEvents), windowEvents, (void *) sRef, &seref); root = HIViewGetRoot(mRef); cid.id = 0; cid.signature = 'CHAS'; HIViewFindByID(root, cid, &ctl); HIViewSetVisible(ctl, false); cid.signature = 'SVIP'; HIViewFindByID(root, cid, &ctl); SetEditTextCStr(ctl, npServerIP, false); cid.signature = 'CLNM'; HIViewFindByID(root, cid, &ctl); ref = CFStringCreateWithCString(kCFAllocatorDefault, npName, kCFStringEncodingUTF8); if (ref) { SetEditTextCFString(ctl, ref, false); CFRelease(ref); } else SetEditTextCFString(ctl, CFSTR("unknown"), false); MoveWindowPosition(mRef, kWindowClient, false); ShowWindow(mRef); err = HIViewAdvanceFocus(root, 0); err = RunAppModalLoopForWindow(mRef); HideWindow(mRef); SaveWindowPosition(mRef, kWindowClient); err = RemoveEventHandler(seref); DisposeEventHandlerUPP(sheetUPP); err = RemoveEventLoopTimer(tref); DisposeEventLoopTimerUPP(timerUPP); err = RemoveEventHandler(eref); DisposeEventHandlerUPP(eventUPP); CFRelease(sRef); } CFRelease(mRef); } DisposeNibReference(nibRef); } return (!npclient.dialogcancel); }
int main(int argc, char* argv[]) { IBNibRef nibRef; OSStatus err; glob_t g; // check the correct BASS was loaded if (HIWORD(BASS_GetVersion())!=BASSVERSION) { Error("An incorrect version of BASS was loaded"); return 0; } // initialize default output device if (!BASS_Init(-1,44100,0,NULL,NULL)) { Error("Can't initialize device"); return 0; } // Create Window and stuff err = CreateNibReference(CFSTR("plugins"), &nibRef); if (err) return err; err = CreateWindowFromNib(nibRef, CFSTR("Window"), &win); if (err) return err; DisposeNibReference(nibRef); DataBrowserCallbacks dbc; dbc.version=kDataBrowserLatestCallbacks; InitDataBrowserCallbacks(&dbc); dbc.u.v1.itemDataCallback=MyDataBrowserItemDataCallback; ControlRef list=GetControl(20); SetDataBrowserCallbacks(list,&dbc); { // look for plugins (in the executable directory) char path[300]; DWORD l=sizeof(path); _NSGetExecutablePath(path,&l); strcpy(strrchr(path,'/')+1,"libbass*.dylib"); if (!glob(path,0,0,&g)) { int a; for (a=0;a<g.gl_pathc;a++) { if (BASS_PluginLoad(g.gl_pathv[a],0)) { // plugin loaded, add it to the list... char *p=strrchr(g.gl_pathv[a],'/')+1; AddDataBrowserItems(list,kDataBrowserNoItem,1,(DataBrowserItemID*)&p,kDataBrowserItemNoProperty); } } } DWORD c; GetDataBrowserItemCount(list,kDataBrowserNoItem,FALSE,kDataBrowserItemNoState,(DataBrowserItemState*)&c); if (!c) { // no plugins... static const char *noplugins="no plugins - visit the BASS webpage to get some"; AddDataBrowserItems(list,kDataBrowserNoItem,1,(DataBrowserItemID*)&noplugins,kDataBrowserItemNoProperty); } } SetupControlHandler(10,kEventControlHit,OpenEventHandler); SetControlAction(GetControl(12),NewControlActionUPP(PosEventHandler)); EventLoopTimerRef timer; InstallEventLoopTimer(GetCurrentEventLoop(),kEventDurationNoWait,kEventDurationSecond/2,NewEventLoopTimerUPP(TimerProc),0,&timer); ShowWindow(win); RunApplicationEventLoop(); globfree(&g); // "free" the output device and all plugins BASS_Free(); BASS_PluginFree(0); return 0; }
int main(int argc, char* argv[]) { // check the correct BASS was loaded if (HIWORD(BASS_GetVersion())!=BASSVERSION) { Error("An incorrect version of BASS was loaded"); return 0; } // initialize BASS if (!BASS_Init(-1,44100,0,win,NULL)) { Error("Can't initialize device"); return 0; } if (!PlayFile()) { // start a file playing BASS_Free(); return 0; } // create the window Rect wr; wr.left=200; wr.right=wr.left+SPECWIDTH; wr.top=200; wr.bottom=wr.top+SPECHEIGHT; CreateNewWindow(kMovableModalWindowClass,kWindowStandardHandlerAttribute,&wr,&win); SetWindowTitleWithCFString(win,CFSTR("BASS spectrum example (click to toggle mode)")); ChangeWindowAttributes(win,kWindowAsyncDragAttribute,kWindowNoAttributes); { EventTypeSpec etype={kEventClassWindow,kEventWindowDrawContent}; InstallWindowEventHandler(win,NewEventHandlerUPP(EventWindowDrawContent),1,&etype,0,NULL); etype.eventKind=kEventWindowHandleContentClick; InstallWindowEventHandler(win,NewEventHandlerUPP(EventWindowClick),1,&etype,0,NULL); } // create the bitmap CGColorSpaceRef colorSpace=CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); specdc=CGBitmapContextCreate(specbuf,SPECWIDTH,SPECHEIGHT,8,SPECWIDTH*4,colorSpace,kCGImageAlphaNoneSkipLast); CGColorSpaceRelease(colorSpace); { // setup palette RGBQUAD *pal=(RGBQUAD*)palette; int a; memset(palette,0,sizeof(palette)); for (a=1;a<128;a++) { pal[a].rgbGreen=256-2*a; pal[a].rgbRed=2*a; } for (a=0;a<32;a++) { pal[128+a].rgbBlue=8*a; pal[128+32+a].rgbBlue=255; pal[128+32+a].rgbRed=8*a; pal[128+64+a].rgbRed=255; pal[128+64+a].rgbBlue=8*(31-a); pal[128+64+a].rgbGreen=8*a; pal[128+96+a].rgbRed=255; pal[128+96+a].rgbGreen=255; pal[128+96+a].rgbBlue=8*a; } } ShowWindow(win); // setup update timer (40hz) EventLoopTimerRef timer; InstallEventLoopTimer(GetCurrentEventLoop(),kEventDurationNoWait,kEventDurationSecond/40,NewEventLoopTimerUPP(UpdateSpectrum),0,&timer); RunApplicationEventLoop(); CGContextRelease(specdc); DisposeWindow(win); BASS_Free(); return 0; }
//------------------------------------------------------------------------------------------------------- bool checkEffectEditor (AEffect* effect) { if ((effect->flags & effFlagsHasEditor) == 0) { printf ("This plug does not have an editor!\n"); return false; } #if _WIN32 theEffect = effect; MyDLGTEMPLATE t; t.style = WS_POPUPWINDOW|WS_DLGFRAME|DS_MODALFRAME|DS_CENTER; t.cx = 100; t.cy = 100; DialogBoxIndirectParam (GetModuleHandle (0), &t, 0, (DLGPROC)EditorProc, (LPARAM)effect); theEffect = 0; #elif _LINUX Display *dpy; Window win; XEvent e; char effect_name[256]; // arbitrary, vst GetEffectName is max 32 chars Atom wmDeleteMessage, prop_atom, val_atom; // create the window dpy = XOpenDisplay(NULL); win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0, 300, 300, 0, 0, 0); // we want an event when the window is being closed wmDeleteMessage = XInternAtom(dpy, "WM_DELETE_WINDOW", false); XSetWMProtocols(dpy, win, &wmDeleteMessage, 1); // Make the window a Dialog, maybe the window manager will place it centered prop_atom = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False); val_atom = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DIALOG", False); XChangeProperty(dpy, win, prop_atom, XA_ATOM, 32, PropModeReplace, (unsigned char *)&val_atom, 1); // prepare the plugin name in the title bar effect->dispatcher(effect, effGetEffectName, 0, 0, effect_name, 0); strcat(effect_name, " [minihost]"); XStoreName(dpy, win, effect_name); // Get and prepare editor size ERect* eRect = 0; printf ("HOST> Get editor rect..\n"); effect->dispatcher (effect, effEditGetRect, 0, 0, &eRect, 0); if (eRect) { int width = eRect->right - eRect->left; int height = eRect->bottom - eRect->top; printf("GetRect -> %d, %d\n", width, height); XResizeWindow(dpy, win, width, height); } // ? Is it correct to effEditGetRect above, before effEditOpen ? // Display the window, let the plugin populate it printf ("HOST> Open editor...\n"); XMapWindow(dpy, win); XFlush(dpy); effect->dispatcher (effect, effEditOpen, 0, (VstIntPtr) dpy, (void*) win, 0); // Needs adjusting according to events we want to handle in the loop below XSelectInput(dpy, win, SubstructureNotifyMask | ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | ExposureMask | KeyPressMask); while (true) { XNextEvent(dpy, &e); // handle events as needed if (e.type == ClientMessage && e.xclient.data.l[0] == wmDeleteMessage) { break; } } printf ("HOST> Close editor..\n"); effect->dispatcher (effect, effEditClose, 0, 0, 0, 0); XCloseDisplay(dpy); #elif TARGET_API_MAC_CARBON WindowRef window; Rect mRect = {0, 0, 300, 300}; OSStatus err = CreateNewWindow (kDocumentWindowClass, kWindowCloseBoxAttribute | kWindowCompositingAttribute | kWindowAsyncDragAttribute | kWindowStandardHandlerAttribute, &mRect, &window); if (err != noErr) { printf ("HOST> Could not create mac window !\n"); return false; } static EventTypeSpec eventTypes[] = { { kEventClassWindow, kEventWindowClose } }; InstallWindowEventHandler (window, windowHandler, GetEventTypeCount (eventTypes), eventTypes, window, NULL); printf ("HOST> Open editor...\n"); effect->dispatcher (effect, effEditOpen, 0, 0, window, 0); ERect* eRect = 0; printf ("HOST> Get editor rect..\n"); effect->dispatcher (effect, effEditGetRect, 0, 0, &eRect, 0); if (eRect) { int width = eRect->right - eRect->left; int height = eRect->bottom - eRect->top; Rect bounds; GetWindowBounds (window, kWindowContentRgn, &bounds); bounds.right = bounds.left + width; bounds.bottom = bounds.top + height; SetWindowBounds (window, kWindowContentRgn, &bounds); } RepositionWindow (window, NULL, kWindowCenterOnMainScreen); ShowWindow (window); EventLoopTimerRef idleEventLoopTimer; InstallEventLoopTimer (GetCurrentEventLoop (), kEventDurationSecond / 25., kEventDurationSecond / 25., idleTimerProc, effect, &idleEventLoopTimer); RunAppModalLoopForWindow (window); RemoveEventLoopTimer (idleEventLoopTimer); printf ("HOST> Close editor..\n"); effect->dispatcher (effect, effEditClose, 0, 0, 0, 0); ReleaseWindow (window); #endif return true; }
bool dialog_animation_settings_run(int animate_idx) { int i,pose_move_idx; ControlRef ctrl; ControlID ctrl_id; DataBrowserItemID itemID; DataBrowserCallbacks dbcall; DataBrowserItemDataUPP pose_list_item_upp,particle_list_item_upp,ring_list_item_upp; DataBrowserItemNotificationUPP pose_list_notify_upp,particle_list_notify_upp,ring_list_notify_upp; EventHandlerUPP event_upp,tab_event_upp; EventLoopTimerRef timer_event; EventLoopTimerUPP timer_upp; EventTypeSpec event_list[]={{kEventClassCommand,kEventProcessCommand}}, tab_event_list[]={{kEventClassCommand,kEventProcessCommand}, {kEventClassControl,kEventControlHit}}; // backup animation for cancel memmove(&animate_backup,&model.animates[animate_idx],sizeof(model_animate_type)); // if there is no pose moves or new animation, // then we need to add a default pose pose_move_idx=0; if (model.animates[animate_idx].npose_move==0) { pose_move_idx=model_animate_pose_insert(&model,animate_idx,-1,0); } // open the dialog dialog_open(&dialog_animation_settings_wind,"AnimationSettings"); // tab dialog_set_tab(dialog_animation_settings_wind,kAnimationPoseTab,0,0,kAnimationPoseTabCount); ctrl_id.signature=kAnimationPoseTab; ctrl_id.id=0; GetControlByID(dialog_animation_settings_wind,&ctrl_id,&ctrl); tab_event_upp=NewEventHandlerUPP(pose_move_setting_tab_proc); InstallControlEventHandler(ctrl,tab_event_upp,GetEventTypeCount(tab_event_list),tab_event_list,dialog_animation_settings_wind,NULL); // set pose list dialog_animate_idx=animate_idx; dialog_pose_move_idx=pose_move_idx; ctrl_id.signature=kAnimationPoseList; ctrl_id.id=0; GetControlByID(dialog_animation_settings_wind,&ctrl_id,&dialog_pose_move_list); dbcall.version=kDataBrowserLatestCallbacks; InitDataBrowserCallbacks(&dbcall); pose_list_item_upp=NewDataBrowserItemDataUPP(&pose_list_item_proc); dbcall.u.v1.itemDataCallback=pose_list_item_upp; pose_list_notify_upp=NewDataBrowserItemNotificationUPP(&pose_list_notify_proc); dbcall.u.v1.itemNotificationCallback=pose_list_notify_upp; SetDataBrowserCallbacks(dialog_pose_move_list,&dbcall); AddDataBrowserItems(dialog_pose_move_list,kDataBrowserNoItem,model.animates[dialog_animate_idx].npose_move,NULL,kDataBrowserItemNoProperty); dialog_pose_move_change_ok=FALSE; itemID=pose_move_idx+1; SetDataBrowserSelectedItems(dialog_pose_move_list,1,&itemID,kDataBrowserItemsAssign); dialog_pose_move_change_ok=TRUE; // setup particle list ctrl_id.signature=kAnimationParticleList; ctrl_id.id=0; GetControlByID(dialog_animation_settings_wind,&ctrl_id,&dialog_particle_list); dbcall.version=kDataBrowserLatestCallbacks; InitDataBrowserCallbacks(&dbcall); particle_list_item_upp=NewDataBrowserItemDataUPP(&particle_list_item_proc); dbcall.u.v1.itemDataCallback=particle_list_item_upp; particle_list_notify_upp=NewDataBrowserItemNotificationUPP(&particle_list_notify_proc); dbcall.u.v1.itemNotificationCallback=particle_list_notify_upp; SetDataBrowserCallbacks(dialog_particle_list,&dbcall); // setup ring list ctrl_id.signature=kAnimationRingList; ctrl_id.id=0; GetControlByID(dialog_animation_settings_wind,&ctrl_id,&dialog_ring_list); dbcall.version=kDataBrowserLatestCallbacks; InitDataBrowserCallbacks(&dbcall); ring_list_item_upp=NewDataBrowserItemDataUPP(&ring_list_item_proc); dbcall.u.v1.itemDataCallback=ring_list_item_upp; ring_list_notify_upp=NewDataBrowserItemNotificationUPP(&ring_list_notify_proc); dbcall.u.v1.itemNotificationCallback=ring_list_notify_upp; SetDataBrowserCallbacks(dialog_ring_list,&dbcall); // fill pose combo dialog_clear_combo(dialog_animation_settings_wind,kAnimationPosePose,0); for (i=0;i!=model.npose;i++) { dialog_add_combo_item(dialog_animation_settings_wind,kAnimationPosePose,0,model.poses[i].name,FOUR_CHAR_CODE('\?\?\?\?')); } // fill mesh combo (leave none in list) for (i=0;i!=model.nmesh;i++) { dialog_add_combo_item(dialog_animation_settings_wind,kAnimationMeshName,0,model.meshes[i].name,FOUR_CHAR_CODE('\?\?\?\?')); } // load setting data dialog_set_text(dialog_animation_settings_wind,kAnimationName,0,model.animates[animate_idx].name); dialog_set_boolean(dialog_animation_settings_wind,kAnimationLoop,0,model.animates[animate_idx].loop); dialog_set_focus(dialog_animation_settings_wind,kAnimationName,0); // load pose move data dialog_pose_move_settings_load(); dialog_animation_settings_cancel=FALSE; // show window ShowWindow(dialog_animation_settings_wind); // install event handler event_upp=NewEventHandlerUPP(animation_settings_event_proc); InstallWindowEventHandler(dialog_animation_settings_wind,event_upp,GetEventTypeCount(event_list),event_list,NULL,NULL); // modal window and timer timer_upp=NewEventLoopTimerUPP(pose_move_timer); InstallEventLoopTimer(GetCurrentEventLoop(),0,0.01,timer_upp,NULL,&timer_event); RunAppModalLoopForWindow(dialog_animation_settings_wind); RemoveEventLoopTimer(timer_event); DisposeEventLoopTimerUPP(timer_upp); // dialog to data dialog_get_text(dialog_animation_settings_wind,kAnimationName,0,model.animates[animate_idx].name,name_str_len); model.animates[animate_idx].loop=dialog_get_boolean(dialog_animation_settings_wind,kAnimationLoop,0); dialog_pose_move_settings_save(); // close window DisposeDataBrowserItemDataUPP(pose_list_item_upp); DisposeDataBrowserItemNotificationUPP(pose_list_notify_upp); DisposeDataBrowserItemDataUPP(particle_list_item_upp); DisposeDataBrowserItemNotificationUPP(particle_list_notify_upp); DisposeDataBrowserItemDataUPP(ring_list_item_upp); DisposeDataBrowserItemNotificationUPP(ring_list_notify_upp); DisposeWindow(dialog_animation_settings_wind); // if cancel, reset animation if (dialog_animation_settings_cancel) { memmove(&model.animates[animate_idx],&animate_backup,sizeof(model_animate_type)); } reset_animate_list(); return(!dialog_animation_settings_cancel); }