Initial commit.
[amiga/xmodule.git] / ClearWin.c
1 /*
2 **      ClearWin.c
3 **
4 **      Copyright (C) 1994,95,96 Bernardo Innocenti
5 **
6 **      Clear panel handling functions.
7 */
8
9 #include <intuition/intuition.h>
10 #include <intuition/gadgetclass.h>
11 #include <libraries/gadtools.h>
12
13 #include <proto/exec.h>
14 #include <proto/intuition.h>
15 #include <proto/gadtools.h>
16 #include <proto/xmodule.h>
17
18 #include "XModulePriv.h"
19 #include "Gui.h"
20
21
22
23 /* Gadgets IDs */
24
25 enum {
26         GD_ClearGroup0,
27                 GD_ClearGroup1,
28                         GD_ClearSequence,
29                         GD_ClearInstruments,
30                         GD_ClearPatterns,
31                 GD_ClearPerform,
32
33         Clear_CNT
34 };
35
36
37 /*****************************/
38 /* Local function prototypes */
39 /*****************************/
40
41 static void ClearPerformClicked (struct WinUserData *wud);
42
43
44
45
46 XDEF struct ClearSwitches ClearSwitches = { 1, 1, 1 };
47
48
49
50 static LONG ClearArgs[] =
51 {
52         VGROUP_KIND, BBFT_RIDGE,
53                 CHECKBOX_KIND,  NULL,   MSG_CLR_SEQUENCE_GAD,           (LONG)&ClearSwitches.ClearSeq,          TAG_DONE,
54                 CHECKBOX_KIND,  NULL,   MSG_CLR_INSTRUMENTS_GAD,        (LONG)&ClearSwitches.ClearInstr,        TAG_DONE,
55                 CHECKBOX_KIND,  NULL,   MSG_CLR_PATTERNS_GAD,           (LONG)&ClearSwitches.ClearPatt, TAG_DONE,
56                 ENDGROUP_KIND,
57         BUTTON_KIND,    (LONG)ClearPerformClicked,      MSG_CLEARMOD_GAD,       TAG_DONE,
58         ENDGROUP_KIND
59 };
60
61
62
63 XDEF LONG ClearWinTags[] =
64 {
65         XMWIN_LayoutArgs,       (LONG)ClearArgs,
66         XMWIN_GCount,           Clear_CNT,
67         XMWIN_Title,            MSG_CLEAR_TITLE,
68         XMWIN_WindowFlags,      WFLG_CLOSEGADGET,
69         XMWIN_IDCMPFlags,       CHECKBOXIDCMP | BUTTONIDCMP | IDCMP_CLOSEWINDOW | IDCMP_REFRESHWINDOW,
70         XMWIN_HelpNode,         (LONG)"Clear",
71         TAG_DONE
72 };
73
74
75
76 GLOBALCALL void UpdateClearSwitches (void)
77 {
78         struct WinUserData *wud = WDescr[WID_CLEAR].Wud;
79
80         if (wud && wud->Win)
81                 SetGadgets (wud,
82                         GD_ClearSequence,               ClearSwitches.ClearSeq,
83                         GD_ClearInstruments,    ClearSwitches.ClearInstr,
84                         GD_ClearPatterns,               ClearSwitches.ClearPatt,
85                         -1);
86 }
87
88
89 /*****************/
90 /* Clear Gadgets */
91 /*****************/
92
93 static void ClearPerformClicked (struct WinUserData *wud)
94 {
95         struct SongInfo *si;
96         LONG i;
97
98         if (si = xmLockActiveSong (SM_EXCLUSIVE))
99         {
100                 if (ClearSwitches.ClearPatt)
101                 {
102                         for (i = si->NumPatterns - 1 ; i >= 0 ; i--)
103                                 xmRemPattern (si, i, 0);
104
105                         xmAddPatternA (si, NULL);
106                 }
107
108                 if (ClearSwitches.ClearInstr)
109                 {
110                         for (i = 1 ; i <= si->LastInstrument ; i++)
111                                 xmRemInstrument (si, i);
112                 }
113
114                 if (ClearSwitches.ClearSeq)
115                 {
116                         xmSetSongLen (si, 1);
117                         si->Sequence[0] = 0;
118                 }
119
120                 ReleaseSemaphore (&si->Lock);
121         }
122
123         UpdateSongInfo();
124         MyCloseWindow (wud);
125 }