home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-03-08 | 26.5 KB | 765 lines | [TEXT/MPS ] |
- {••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••}
- {• BAR GRAPH •}
- {•------------------------------------------------------------------------------•}
- {• •}
- {• Le programme BARGRAPH présenté ici, fait partie d'une série d'exemples à •}
- {• caractère pédagogique (enfin j'espère !) sur la façon d'utiliser MIDISHARE. •}
- {• •}
- {• BARGRAPH permet de visualiser l'activité Midi. Il comporte deux séries de 16 •}
- {• afficheurs à L.E.D. sensibles à la vélocité des notes reçues. •}
- {• •}
- {•------------------------------------------------------------------------------•}
- {• Release 1.1 (Mars 90) (pour MPW 3.1) •}
- {• •}
- {• - ajout du menu Edit pour DA ouvert dans l'application elle-même •}
- {• - correction de bugs sous MultiFinder et/ou avec DA dans l'application •}
- {• •}
- {•------------------------------------------------------------------------------•}
- {• © GRAME 1989, Yann Orlarey et Hervé Lequay •}
- {••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••}
-
- {$D+} { MacsBug symbols on }
- {$R-} { No range checking }
-
- program BarGraph;
-
- uses Memtypes, Quickdraw, OSIntf, ToolIntf, PackIntf, Traps, MIDIShareUnit;
-
- const
- AppleID = 128; AppleMenu = 1;
- FileID = 129; FileMenu = 2;
- EditID = 130; EditMenu = 3;
- UndoI = 1; CutI = 3; CopyI = 4; PasteI = 5; ClearI = 6;
-
- WindowId = 128; { ID fenêtre de l'application }
- AboutID = 129; { ID fenêtre de About }
- AlertID = 500; { ID Alerte erreurs }
-
- resumeMask = $01; { suspend/resume mask }
-
- type
- TBarGraph = record { infos nécessaires à l'affichage }
- portVal : array [0..1] of integer;
- portTarg : array [0..1] of integer;
- value : array [0..1, 0..15] of integer;
- target : array [0..1, 0..15] of integer;
- end;
-
- var
- myWindow : WindowPtr; { ma fenêtre (qui est un Dialog) }
- dragRect : Rect; { limite les mouvmnt de la fenêtre }
- myMenus : array [AppleMenu..EditMenu] of MenuHandle;
-
- gMac : SysEnvRec; { machine… }
- eventPending : boolean; { vrai si événement en attente }
- hasWNE : boolean; { vrai si WaitNextEvent implémenté }
- foreGround : boolean; { vrai si en foreGround }
-
- doneFlag : boolean; { signale la fin de l'application }
- myEvent : EventRecord; { événement Macintosh }
-
- whichChar : char; { caractère clavier Macintosh }
- myNum : integer; { ID unique de l'appl. donné par MS }
- myBarGraph : TBarGraph; { Afficheurs BarGraphs }
-
- {*******************************************************************************}
- { UTILITAIRES }
- {-------------------------------------------------------------------------------}
- { }
- {*******************************************************************************}
-
- {$S Initialize}
- Procedure PullToFront;
- var i : integer;
- begin
- for i := 1 TO 3 DO
- IF EventAvail(everyEvent,myEvent) THEN; { pull application to front }
- end;
-
- {$S Initialize}
- function TrapAvailable(tNumber: integer; tType: trapType): boolean;
- { Vérification de l'implémentation d'une trappe }
- begin
- TrapAvailable := NGetTrapAddress(tNumber, tType) <> GetTrapAddress(_Unimplemented)
- end;
-
- {$S Main}
- function IsAppWindow(aWind: WindowPtr): boolean;
- { vérifie si la fenêtre appartient à l'application }
-
- begin
- if aWind = nil then
- IsAppWindow := false
- else
- IsAppWindow := windowPeek(aWind)^.windowKind >= 0
- end;
-
- {$S Main}
- function IsDAWindow(aWind: WindowPtr): boolean;
- { vérifie si la fenêtre appartient à un accessoire de bureau }
- begin
- if aWind = nil then
- IsDAWindow := false
- else
- IsDAWindow := windowPeek(aWind)^.windowKind < 0
- end;
-
- {$S Main}
- Procedure CenterRectOnScreen (var aRect: Rect);
- { aRect rectangle global à centrer sur écran (dragRect) }
- var screenSize : Point;
- rectSize : Point;
- begin
- with dragRect do
- SetPt(screenSize,right - left,bottom - top);
- with aRect do begin
- SetPt(rectSize,right - left,bottom - top);
- left:= dragRect.left + (screenSize.h - rectSize.h) div 2;
- top:= dragRect.top + (screenSize.v - rectSize.v) div 5;
- topLeft:= point(PinRect(dragRect,topLeft));
- right:= left + rectSize.h;
- bottom:= top + rectSize.v;
- end;
- end;
-
- {$S Main}
- Function GetNewCenteredDialog (dialogID: integer): DialogPtr;
- var dlogTemplate : DialogTHndl;
- begin
- GetNewCenteredDialog := nil;
- dlogTemplate := DialogTHndl(GetResource('DLOG', dialogID));
- if dlogTemplate <> nil then begin
- CenterRectOnScreen(dlogTemplate^^.boundsRect);
- GetNewCenteredDialog:= GetNewDialog(dialogID, nil, pointer(-1));
- end
- else SysBeep(2) { At least give some indication }
- end;
-
- {$S Main}
- Procedure AlertUser (alertID: integer);
- var alrtTemplate : AlertTHndl;
- temp : integer;
- begin
- alrtTemplate := AlertTHndl(GetResource('ALRT', alertID));
- if alrtTemplate <> nil then begin
- SetCursor(arrow);
- CenterRectOnScreen(alrtTemplate^^.boundsRect);
- temp:= Alert(alertID,nil)
- end
- else SysBeep(2) { At least give some indication }
- end;
-
-
- {*******************************************************************************}
- { INIT BAR GRAPH }
- {-------------------------------------------------------------------------------}
- { Prépare les barGraphs en leur donnant un objectif maximal pour "allumer" }
- { toutes les LEDs au démarrage de l'application. }
- { }
- { Les paramètres de l'appel : }
- { --------------------------- }
- { }
- { aucun paramètre. }
- { }
- {*******************************************************************************}
-
- {$ Initialize}
- procedure InitBarGraph;
- var
- p, i : integer;
- begin
- with myBarGraph do
- for p := 0 to 1 do begin { Pour chaque ports Midi }
- portVal[p] := 0; { LED actuellement éteinte }
- portTarg[p] := 1; { objectif, allumée. }
- for i := 0 to 15 do begin { Pour chaque canal }
- value[p, i] := 0; { LEDs actuellement éteintes }
- target[p, i] := 8; { objectif, les 8 allumées. }
- end
- end
- end;
-
- {*******************************************************************************}
- { DOWN BAR GRAPH }
- {-------------------------------------------------------------------------------}
- { Cette procédure a pour objectif de "rendre vivants" les barGraphs en les }
- { ramenant doucement vers la valeur zéro à chaque fois qu'ils sont activés. }
- { }
- { DownBarGraph fonctionne comme une tâche de fond qui se réactive périodi- }
- { quement toutes les 100 ms par le biais d'un MidiCall. Le premier lancement }
- { est effectué à l'initialisation de l'application (voir MIDI SET UP). }
- { }
- { Comme DownBarGraph est appelée sous interruptions, elle ne fait aucun affi- }
- { chage directement, mais elle prépare le travail pour RefreshBarGraph. }
- { }
- { Les paramètres d'un appel par le biais d'un MidiCall sont imposés, et sont }
- { au nombre de cinq : la date de l'appel (longint), le numéro de référence de }
- { l'application (integer), et trois paramètres dont l'usage est libre sous }
- { réserve qu'ils soient de la taille d'un longint ou d'un pointeur. }
- { }
- { Les paramètres de l'appel : }
- { --------------------------- }
- { }
- { d: date de l'appel (longint, en ms) }
- { myNum: numéro de référence unique de l'application (integer) }
- { delay: delai entre les activations successives. }
- { a2,a3: paramètres obligatoires, mais non utilisés ici. }
- { }
- {*******************************************************************************}
-
- {$ Main}
- procedure downBarGraph(date: longint; refNum: integer; delay, a2, a3: longint);
- var
- p, i : integer;
- begin
- with myBarGraph do
- for p := 0 to 1 do begin { Pour chaque port Midi }
- if (portTarg[p] > 0) & { Si la LED a un objectif et }
- (portVal[p] >= portTarg[p]) then { Si elle l'a atteint : }
- portTarg[p] := portTarg[p] - 1; { diminuer son objectif }
- for i := 0 to 15 do { Pour tous les canaux Midi }
- if (target[p, i] > 0) & { Si le BarGraph à un objectif et }
- (value[p, i] >= target[p, i]) then { Si il l'a atteint : }
- target[p, i] := target[p, i] - 1; { diminuer son objectif }
- end;
- midiCall(@downBarGraph,date + delay,refNum,delay,a2,a3) { DownBarGraph se relance }
- end; { elle-même dans <Delay> ms }
-
-
- {*******************************************************************************}
- { REFRESH BAR GRAPH }
- {-------------------------------------------------------------------------------}
- { Cette procédure met à jour l'affichage de tous les objets qui doivent chan- }
- { ger de valeur en dessinant les différences entre valeur courante et valeur }
- { objectif. }
- { }
- { Les paramètres de l'appel : }
- { --------------------------- }
- { }
- { aucun paramètre. }
- { }
- {*******************************************************************************}
-
- {$ Main}
- procedure refreshBarGraph;
- var
- x0, y0, x1, y1: integer;
- i, p, n, v, t: integer;
- r : Rect;
- begin
- SetPort(myWindow);
- with myBarGraph do
- for p := 0 to 1 do begin { Pour chaque ports Midi }
- x0 := 10 + p * (16 * 13 + 5); y0 := 50; { calcule la position du groupe, }
- x1 := x0 + 130; y1 := y0 - 42; { celle de la LED du port Midi }
- setRect(r, x1, y1, x1 + 8, y1 + 3); { ainsi que son rectangle. }
- if (portVal[p] = 0) & (portTarg[p] <> 0) then { s'il faut allumer la LED }
- paintRect(r) { dessine la LED }
- else if (portVal[p] <> 0) & (portTarg[p] = 0) then { s'il faut éteindre la LED }
- eraseRect(r); { efface la LED }
- portVal[p] := portTarg[p]; { l'objectif est réalisé }
-
- for i := 0 to 15 do begin { Pour chaque canal Midi }
- v := value[p, i]; { v est la valeur du BarGraph }
- t := target[p, i]; { t est son objectif }
- if v < t then { s'il faut monter la valeur }
- for n := 1 + v to t do begin { on dessine les LED en plus }
- x1 := x0 + 13 * i; y1 := y0 - 4 * n;
- setRect(r, x1, y1, x1 + 8, y1 + 3);
- if n > 5 then ForeColor(redColor)
- else ForeColor(greenColor);
- paintRect(r);
- end
- else if v > t then { s'il faut descendre la valeur }
- for n := v downto 1 + t do begin { on efface les LED en trop }
- x1 := x0 + 13 * i; y1 := y0 - 4 * n;
- setRect(r, x1, y1, x1 + 8, y1 + 3);
- eraseRect(r);
- end;
- value[p, i] := t; { l'objectif est réalisé }
- end;
- ForeColor(blackColor)
- end
- end;
-
- {*******************************************************************************}
- { DRAW BAR GRAPH }
- {-------------------------------------------------------------------------------}
- { Cette procédure redessine tous les objets. }
- { }
- { Les paramètres de l'appel : }
- { --------------------------- }
- { }
- { aucun paramètre. }
- { }
- {*******************************************************************************}
-
- {$ Main}
-
- procedure drawBarGraph;
- var
- x0, y0, x1, y1: integer;
- i, p, n : integer;
- r : Rect;
- begin
- with myBarGraph do
- for p := 0 to 1 do begin { Pour chaque port Midi }
- x0 := 10 + p * (16 * 13 + 5); y0 := 50; { calcule la position du groupe, }
- if portVal[p] > 0 then begin { Si la LED est allumée : }
- x1 := x0 + 130; y1 := y0 - 42; { calcule sa position }
- setRect(r, x1, y1, x1 + 8, y1 + 3); { calcule son rectangle }
- paintRect(r); { et la dessine. }
- end;
- for i := 0 to 15 do { Pour chaque canal Midi }
- for n := 1 to value[p, i] do begin { Pour chaque LED allumée }
- x1 := x0 + 13 * i; y1 := y0 - 4 * n; { calcule sa position }
- setRect(r, x1, y1, x1 + 8, y1 + 3); { calcule son rectangle }
- if n > 5 then ForeColor(redColor)
- else ForeColor(greenColor);
- paintRect(r); { et la dessine }
- end;
- ForeColor(blackColor)
- end;
- end;
-
- {*******************************************************************************}
- { DRAW MY WINDOW }
- {-------------------------------------------------------------------------------}
- { Affiche la fenêtre (qui est un Dialog) avec son contenu. }
- { }
- { Les paramètres de l'appel : }
- { --------------------------- }
- { }
- { aucun paramètre. }
- { }
- {*******************************************************************************}
-
- {$ Main}
- procedure DrawMyWindow;
- begin
- DrawDialog(myWindow);
- drawBarGraph;
- end;
-
- {*******************************************************************************}
- { TREAT MIDI EVENTS }
- {-------------------------------------------------------------------------------}
- { La procedure de réception des événements Midi. Elle est appelée automatique- }
- { ment par MidiShare, sous interruptions, chaque fois que l'application }
- { reçoit de nouveaux événements. }
- { }
- { Pour ce faire, l'adresse de cette routine à été fournie à MidiShare à }
- { l'ouverture de l'application par un MidiSetRcvAlarm. }
- { }
- { Cette procédure doit obligatoirement comporter un paramètre, qui est le }
- { numéro de référence unique de l'application (integer). }
- { }
- { Le principe de cette procédure est d'aller récupérer les événements reçus. }
- { Lorsque ce sont des KeyOn, TreatMidiEvents ce sert de leur vélocité pour }
- { assigner un objectif au BarGraph du canal correspondant. Dans les autres cas }
- { TreatMidiEvents se contente de faire clignoter la LED du port de provenance. }
- { }
- { Les paramètres de l'appel : }
- { --------------------------- }
- { }
- { myNum: numéro de référence Midi de l'application. }
- { }
- {*******************************************************************************}
-
- {$ Main}
- procedure TreatMidiEvents(refNum: integer);
- var
- e : midiEvPtr;
- v : integer;
- n : longint;
- begin
- n := midiCountEvs(myNum); { compte les événements reçus }
- while n > 0 do begin { Pour chaque événement : }
- e := midiGetEv(refNum); { on récupère l'événement reçu }
- with e^, myBarGraph do begin
- portTarg[port] := 2; { on fixe à la LED l'objectif allumée }
- if evType <= typeKeyOn then begin { Si l'événement est une note ou un KeyOn: }
- v := (vel + 15) div 16; { on calcul un objectif d'aprés sa vel. }
- if v > target[port, chan] then { Si cet objectif est sup. à l'ancien : }
- target[port, chan] := v; { il devient le nouvel objectif }
- end;
- end;
- midiFreeEv(e); { on n'a plus besoin de l'événement }
- n := n - 1; { un de moins à traiter }
- end
- end;
-
- {*******************************************************************************}
- { SET UP MIDI }
- {-------------------------------------------------------------------------------}
- { Cette procédure définit les différents paramètres necessaires au fonction- }
- { nement Midi de l'application. Tout d'abord, le MidiOpen de l'application }
- { qui lui permet de se signaler à MidiShare, et d'obtenir un numèro de réfé- }
- { rence unique pour la suite des opérations. La chaine de caractères passée en }
- { argument sert au catalogue des applications ouvertes que maintient MidiShare. }
- { Ensuite la définition de l'alarme de réception, une procédure appelée auto- }
- { matiquement par MidiShare, à chaque fois que l'application va recevoir de }
- { nouveaux événements. Troisièmement, le lancement d'une tâche de fond qui est }
- { chargée, toutes les 100 ms, de faire descendre les BarGraphs. Enfin l'éta- }
- { blissement d'une connection entre l'application et les port Midi d'entrées. }
- { }
- { Les paramètres de l'appel : }
- { --------------------------- }
- { }
- { aucun paramètre. }
- { }
- {*******************************************************************************}
-
- {$ Initialize}
- procedure SetUpMidi;
- var name: str255;
- apRefNum: integer;
- apParam: Handle;
- aRefNum: integer;
-
- Procedure FAILSETUP (strIndex: integer);
- var msgStr: str255;
- begin
- GetIndString (msgStr,AlertID,strIndex); { message d'alerte suivant erreur }
- ParamText(name,msgStr,'','');
- AlertUser(AlertID);
- ExitToShell { et quitte }
- end;
-
- begin
- GetAppParms(name,apRefNum,apParam); { récupérer le nom d'application }
- if not MidiShare then FailSetUp(1); { MidiShare n'est pas installé }
-
- myNum:= MidiOpen(name); { ouverture en Midi }
- if myNum = MidiErrSpace then FailSetUp(2); { impossible, plus de place }
-
- midiCall(@downBarGraph, midiGetTime + 400, myNum, 100, 0, 0); { appel à la tâche downBarGraph }
- midiSetRcvAlarm(myNum, @TreatMidiEvents); { définit la tâche temps-réel de réception }
-
- midiConnect(0, myNum, true); { connection avec les ports Midi d'entrées }
- end;
-
- {*******************************************************************************}
- { SET UP WINDOWS }
- {-------------------------------------------------------------------------------}
- { Procédure chargé d'ouvrir la fenêtre et de réaliser les initialisations }
- { nécessaires. }
- { }
- { Les paramètres de l'appel : }
- { --------------------------- }
- { }
- { aucun paramètre. }
- { }
- {*******************************************************************************}
-
- {$ Initialize}
- procedure SetUpWindows;
- var r : rect;
- begin
- with screenBits.bounds do { rect max de déplacmt de fenêtre }
- SetRect(dragRect, 4, 24, right - 4, bottom - 4);
- myWindow := GetNewDialog(WindowID,nil,pointer(-1));
- SetPort(myWindow);
- r:= myWindow^.portRect;
- with r do begin
- LocalToGlobal(topLeft);
- LocalToGlobal(botRight)
- end;
- if not RectInRgn(r,GetGrayRgn) then begin
- CenterRectOnScreen(r);
- MoveWindow(myWindow,r.left,r.top,true)
- end;
- InitBarGraph;
-
- ShowWindow(myWindow)
- end;
-
-
- {$S Main}
- Procedure SaveWindowPos;
- type rectPtr = ^rect;
- rectHdle = ^rectPtr;
- var windHdle: handle;
- begin
- windHdle:= Get1Resource('DLOG',WindowID);
- rectHdle(windHdle)^^:= windowPeek(myWindow)^.contRgn^^.rgnBBox;
- ChangedResource(windHdle);
- if ResError = noErr then
- WriteResource(windHdle)
- end;
-
-
- {*******************************************************************************}
- { SET UP MENUS }
- {-------------------------------------------------------------------------------}
- { Définition de la barre des menus. }
- { }
- { Les paramètres de l'appel : }
- { --------------------------- }
- { }
- { aucun paramètre. }
- { }
- {*******************************************************************************}
-
- {$ Initialize}
- procedure SetUpMenus;
- var
- i : integer;
- begin
- myMenus[AppleMenu] := GetMenu(AppleID);
- AddResMenu(myMenus[AppleMenu], 'DRVR');
- myMenus[FileMenu] := GetMenu(FileID);
- myMenus[EditMenu] := GetMenu(EditID);
- for i := AppleMenu to EditMenu do InsertMenu(myMenus[i], 0);
- DrawMenuBar
- end;
-
- {*******************************************************************************}
- { INITIALIZE }
- {-------------------------------------------------------------------------------}
- { Initialisations générales (hasWNE, foreGround, managers, fenêtre, Midi) }
- { }
- { Les paramètres de l'appel : }
- { --------------------------- }
- { }
- { aucun }
- { }
- {*******************************************************************************}
-
- {$ Initialize}
- procedure Initialize;
- var
- err : OSErr;
- begin
- err := SysEnvirons(1, gMac);
- hasWNE := (gMac.machineType >= 0) & TrapAvailable(_WaitNextEvent, ToolTrap);
-
- InitGraf(@thePort); { initialisations standard }
- InitFonts;
- InitWindows;
- InitMenus;
- TEInit;
- InitDialogs(nil);
- InitCursor;
- SetUpMenus; { mise en place menus }
- PullToFront;
- SetUpMidi; { ouverture MidiShare }
- SetUpWindows; { initialisations fenêtre }
- end;
-
- {*******************************************************************************}
- { DO COMMAND }
- {-------------------------------------------------------------------------------}
- { Execution des commandes du menu. }
- { }
- { Les paramètres de l'appel : }
- { --------------------------- }
- { }
- { mResult : le menu et l'item sélectionnés }
- { }
- {*******************************************************************************}
-
- {$ Main}
- procedure DoCommand(mResult: longint);
- var
- theItem : integer;
- name : str255;
- sysEdit : boolean;
-
- Procedure SHOWABOUT;
- var myDialog : dialogPtr;
- hit : integer;
- begin
- myDialog:= GetNewCenteredDialog(AboutID);
- if myDialog <> nil then begin
- ModalDialog(nil,hit);
- DisposDialog(myDialog);
- end
- end;
-
- begin
- theItem := LoWord(mResult);
- case HiWord(mResult) of
- AppleID:
- if theItem <> 1 then begin
- GetItem(myMenus[AppleMenu], theItem, name);
- theItem := OpenDeskAcc(name)
- end
- else
- ShowAbout;
- FileID:
- doneFlag := true;
- EditID: { menu Edit: uniquement pour DAs }
- sysEdit := SystemEdit(theItem - 1);
- end;
- HiliteMenu(0)
- end;
-
- {*******************************************************************************}
- { ADJUST MENUS }
- {-------------------------------------------------------------------------------}
- { Ajustement de la barre de menus suivant la fenêtre de premier plan, juste }
- { lors d'un click dans la barre des menus }
- { }
- { Les paramètres de l'appel : }
- { --------------------------- }
- { }
- { aucun }
- { }
- {*******************************************************************************}
-
- {$S Main}
- procedure AdjustMenus;
- begin
- if IsAppWindow(FrontWindow) then begin
- DisableItem(myMenus[EditMenu], UndoI);
- DisableItem(myMenus[EditMenu], CutI);
- DisableItem(myMenus[EditMenu], CopyI);
- DisableItem(myMenus[EditMenu], PasteI);
- DisableItem(myMenus[EditMenu], ClearI)
- end
- else if IsDAWindow(FrontWindow) then begin
- EnableItem(myMenus[EditMenu], UndoI);
- EnableItem(myMenus[EditMenu], CutI);
- EnableItem(myMenus[EditMenu], CopyI);
- EnableItem(myMenus[EditMenu], PasteI);
- EnableItem(myMenus[EditMenu], ClearI)
- end
- end;
-
- {*******************************************************************************}
- { DO MOUSE DOWN }
- {-------------------------------------------------------------------------------}
- { Gère les clicks souris }
- { }
- { Les paramètres de l'appel : }
- { --------------------------- }
- { }
- { anEvent: l'événement }
- { }
- {*******************************************************************************}
-
- {$ Main}
-
- procedure DoMouseDown(anEvent: EventRecord);
- var
- whichWind : WindowPtr;
- part : integer;
- begin
- part := FindWindow(anEvent.where, whichWind);
- case part of
- inMenuBar: begin
- AdjustMenus;
- DoCommand(MenuSelect(anEvent.where))
- end;
- inSysWindow: SystemClick(anEvent, whichWind);
- inDrag: DragWindow(whichWind, anEvent.where, dragRect);
- inGoAway: if IsAppWindow(whichWind) then
- doneFlag := TrackGoAway(whichWind, anEvent.where);
- inContent: if whichWind <> FrontWindow then
- SelectWindow(whichWind);
- end
- end;
-
- {*******************************************************************************}
- { ADJUST CURSOR }
- {-------------------------------------------------------------------------------}
- { Ajuste le curseur suivant région et fenêtre }
- { }
- {*******************************************************************************}
-
- {$S Main}
- procedure AdjustCursor;
- begin
- if foreGround & IsAppWindow(FrontWindow) then SetCursor(arrow)
- end;
-
- {*******************************************************************************}
- { CLOSE WINDOWS }
- {-------------------------------------------------------------------------------}
- { Pour terminer correctement l'application: fermeture de toutes les fenêtres }
- { (application et DA's) }
- { }
- {*******************************************************************************}
-
- {$S Main}
- procedure CloseWind(aWind: WindowPtr);
- { ferme une fenêtre }
- begin
- if IsDAWindow(aWind) then
- CloseDeskAcc(windowPeek(aWind)^.windowKind)
- else
- if IsAppWindow(aWind) then DisposeWindow(aWind)
- end;
-
- Procedure CLOSEALLWINDS;
- { ferme toutes les fenêtres }
- var window: windowPtr;
- begin
- repeat
- window:= FrontWindow;
- if window <> nil then
- CloseWind(window);
- until window = nil;
- end;
-
-
- procedure _DataInit; external;
-
- {*******************************************************************************}
- { Corps principal du programme }
- {-------------------------------------------------------------------------------}
- { Ouverture des différents managers, Initialisations diverses et boucle prin- }
- { cipale typique d'une application Macintosh. }
- {*******************************************************************************}
-
- {$ Main}
- begin
- UnLoadSeg(@_DataInit);
- MaxApplZone;
- Initialize;
- UnLoadSeg(@Initialize);
-
- doneFlag := false; { flag de terminaison }
- repeat
- if hasWNE then
- eventPending := WaitNextEvent(everyEvent, myEvent, 0, nil)
- else begin
- SystemTask;
- eventPending := GetNextEvent(everyEvent, myEvent)
- end;
- AdjustCursor;
- with myEvent do
- case what of
- nullEvent:
- refreshBarGraph; { redessine les BarGraphs qui ont bougés }
- osEvt:
- case BSR(message, 24) of
- suspendResumeMessage: foreGround := BAnd(message, resumeMask) <> 0;
- mouseMovedMessage: refreshBarGraph;
- end;
- keyDown, autoKey:
- if IsAppWindow(FrontWindow) then begin
- whichChar := CHR(BAnd(myEvent.message, charCodeMask));
- if BAnd(myEvent.modifiers, cmdKey) <> 0 then
- DoCommand(MenuKey(whichChar))
- end;
- mouseDown:
- DoMouseDown(myEvent);
- updateEvt:
- if IsAppWindow(WindowPtr(message)) then begin
- BeginUpdate(WindowPtr(message));
- if not EmptyRgn(WindowPtr(message)^.visRgn) then begin
- SetPort(WindowPtr(message));
- DrawMyWindow
- end;
- EndUpdate(WindowPtr(message))
- end
- end
- until doneFlag;
- MidiClose(myNum); { fermeture MidiShare }
- SaveWindowPos;
- CloseAllWinds;
- ExitToShell
- end.
-