-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDRANDOM.CPP
executable file
·222 lines (184 loc) · 5.74 KB
/
DRANDOM.CPP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
_CLASSDEF(TDlgRandom)
// inherit from TDlgTrackEdit, which has the track settings
class TDlgRandom :public TDialog, TDlgTrackEdit, TNoteEdit
{
public:
BOOL bToggleOn;
TDlgRandom(PTWindowsObject pwParent, int nResourceID)
: TDialog(pwParent, nResourceID),
TNoteEdit(this),
TDlgTrackEdit(this) {}
~TDlgRandom()
{
WinHelp(this->HWindow, "alcomp.hlp", HELP_QUIT, 0L);
}
virtual void SetupWindow();
virtual BOOL CanClose();
virtual void Toggle(RTMessage Msg) = [ID_FIRST + ID_TOGGLENOTES];
virtual void Ok(RTMessage Msg) = [ID_FIRST + IDOK];
virtual void Rhythm(RTMessage Msg) = [ID_FIRST + ID_RHYTHM];
virtual void Help(RTMessage Msg) = [ID_FIRST + IDHELP];
// functions to update tempo text when scroll bar moved
virtual void ShowTempo(/*RTMessage Msg*/) = [ID_FIRST + SB_TEMPO];
// functions to update volume text when scroll bar moved
virtual void ShowVolume(/*RTMessage Msg*/) = [ID_FIRST + SB_VOLUME];
// functions to update tempo text when scroll bar moved
virtual void ShowChannel(RTMessage Msg) = [ID_FIRST + CB_MIDICHANNEL];
// functions to update volume text when scroll bar moved
virtual void ShowPatch(RTMessage Msg) = [ID_FIRST + CB_PATCH];
// boxes for probabilities
virtual void Cauchy (RTMessage Msg) = [ID_FIRST + ID_CAUCHY];
virtual void Linear (RTMessage Msg) = [ID_FIRST + ID_LINEAR];
virtual void Uniform (RTMessage Msg) = [ID_FIRST + ID_UNIFORM];
virtual void Gaussian(RTMessage Msg) = [ID_FIRST + ID_GAUSSIAN];
virtual void Exponent(RTMessage Msg) = [ID_FIRST + ID_EXPONENT];
virtual void Poisson (RTMessage Msg) = [ID_FIRST + ID_POISSON];
};
void TDlgRandom::SetupWindow()
{
TDialog::SetupWindow();
// now show the rest of the screen
TDlgTrackEdit::SetupWindow();
InitNotes(); // now we're ready to show the notes
bToggleOn = TRUE; // at first, toggle all to on
}
void TDlgRandom::Toggle(RTMessage Msg)
{
if (Msg.LP.Hi == BN_CLICKED) {
for (int i = 0; i < MAX_NOTENUM; i++)
pTENote[i]->SetText( bToggleOn ? "50" : " 0" );
bToggleOn = ! bToggleOn;
}
}
// throw these dummy fns here, can't have dispatch msgs in base class
void TDlgRandom::ShowTempo(/*RTMessage Msg*/)
{
TDlgTrackEdit::Tempo(/*Msg*/);
}
void TDlgRandom::ShowVolume(/*RTMessage Msg*/)
{
TDlgTrackEdit::Volume(/*Msg*/);
}
void TDlgRandom::ShowPatch(RTMessage Msg)
{
TDlgTrackEdit::Patch(Msg);
}
void TDlgRandom::ShowChannel(RTMessage Msg)
{
TDlgTrackEdit::Channel(Msg);
}
void TDlgRandom::Cauchy(RTMessage Msg)
{
if (Msg.LP.Hi == BN_CLICKED) {
SetTempNotes();
// allow the probability functions here
Probability prob(note, MAX_NOTENUM); // allow the probability functions her
prob.Cauchy();
ShowNotes();
}
}
void TDlgRandom::Linear (RTMessage Msg)
{
if (Msg.LP.Hi == BN_CLICKED) {
SetTempNotes();
// allow the probability functions here
Probability prob(note, MAX_NOTENUM); // allow the probability functions her
prob.Linear();
ShowNotes();
}
}
void TDlgRandom::Uniform (RTMessage Msg)
{
if (Msg.LP.Hi == BN_CLICKED) {
SetTempNotes();
// allow the probability functions here
Probability prob(note, MAX_NOTENUM); // allow the probability functions her
prob.Uniform();
ShowNotes();
}
}
void TDlgRandom::Gaussian(RTMessage Msg)
{
if (Msg.LP.Hi == BN_CLICKED) {
SetTempNotes();
// allow the probability functions here
Probability prob(note, MAX_NOTENUM); // allow the probability functions her
prob.Gaussian();
ShowNotes();
}
}
void TDlgRandom::Exponent(RTMessage Msg)
{
if (Msg.LP.Hi == BN_CLICKED) {
SetTempNotes();
// allow the probability functions here
Probability prob(note, MAX_NOTENUM); // allow the probability functions her
prob.Exponent();
ShowNotes();
}
}
void TDlgRandom::Poisson (RTMessage Msg)
{
if (Msg.LP.Hi == BN_CLICKED) {
SetTempNotes();
// allow the probability functions here
Probability prob(note, MAX_NOTENUM); // allow the probability functions her
prob.Poisson();
ShowNotes();
}
}
BOOL TDlgRandom::CanClose()
{
// check for invalid notes (non numeric and not between 0 and 99)
// setup the notes now
char errstr[100], tempstr[100];
memset(errstr, 0, 100);
memset(tempstr, 0, 100);
UINT sumnotes = 0;
BOOL check = TRUE;
SetTempNotes();
// check rhythm probabilities
for (int i=0; i < MAX_RHYTHM; i++)
sumnotes += tempTrack.Rhythm[i].Prob;
if (! sumnotes) {
check = FALSE;
sprintf(errstr, "* No Rhythms Assigned.\n");
}
if (! check) {
BWCCMessageBox(HWindow, errstr, "Error!", MB_OK | MB_ICONEXCLAMATION);
return FALSE; // don't bother with other checks
}
// made it past local check, try base classes
return TDlgTrackEdit::CanClose() && TNoteEdit::CanClose(); // TNoteEdit::CanClose();
}
void TDlgRandom::Help(RTMessage Msg)
{
if ( Msg.LP.Hi == BN_CLICKED )
if (! WinHelp(this->HWindow, "alcomp.hlp", HELP_CONTEXT, EDIT_RANDOM_PROB ))
BWCCMessageBox(this->HWindow, "Help File Not Found", "Error!", MB_OK|MB_ICONEXCLAMATION);
}
void TDlgRandom::Ok(RTMessage Msg)
{
if( Msg.LP.Hi == BN_CLICKED && CanClose() )
{
// detach all objects
tempTrack.Note.flush(TRUE);
StrNote tn;
tn.From = UCHAR_MAX;
for (int j = 0; j < MAX_NOTENUM; j++)
// detached all tempNote, now add non-zero note[]
if ( note[j] ) {// non-zero value, add to array
tn.To = j;
tn.Prob = note[j];
tempTrack.Note.add( tn );
}
SaveIt(); // call this from TDlgTrackEdit
bModified = TRUE;
TDialog::Ok(Msg);
}
}
void TDlgRandom::Rhythm(RTMessage Msg)
{
if( Msg.LP.Hi == BN_CLICKED )
GetModule()->ExecDialog( new TDlgRhythm(this, DG_RHYTHM) );
}