~ubuntu-branches/ubuntu/intrepid/aeolus/intrepid

« back to all changes in this revision

Viewing changes to instrwin.cc

  • Committer: Bazaar Package Importer
  • Author(s): Free Ekanayaka
  • Date: 2007-05-14 22:18:54 UTC
  • Revision ID: james.westby@ubuntu.com-20070514221854-274rj6fqs5tegu7q
Tags: upstream-0.6.6+2
ImportĀ upstreamĀ versionĀ 0.6.6+2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (C) 2003-2005 Fons Adriaensen <fons.adriaensen@skynet.be>
 
3
    
 
4
    This program is free software; you can redistribute it and/or modify
 
5
    it under the terms of the GNU General Public License as published by
 
6
    the Free Software Foundation; either version 2 of the License, or
 
7
    (at your option) any later version.
 
8
 
 
9
    This program is distributed in the hope that it will be useful,
 
10
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
    GNU General Public License for more details.
 
13
 
 
14
    You should have received a copy of the GNU General Public License
 
15
    along with this program; if not, write to the Free Software
 
16
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
17
*/
 
18
 
 
19
 
 
20
#include "instrwin.h"
 
21
#include "callbacks.h"
 
22
#include "styles.h"
 
23
 
 
24
 
 
25
Instrwin::Instrwin (X_window *parent, X_callback *callb, int xp, int yp, X_resman *xresm) :
 
26
    X_window (parent, xp, yp, XSIZE, YSIZE, Colors.main_bg),
 
27
    _callb (callb),
 
28
    _xresm (xresm),
 
29
    _xp (xp), _yp (yp)
 
30
{
 
31
    _atom = XInternAtom (dpy (), "WM_DELETE_WINDOW", True);
 
32
    XSetWMProtocols (dpy (), win (), &_atom, 1);
 
33
    _atom = XInternAtom (dpy (), "WM_PROTOCOLS", True);
 
34
}
 
35
 
 
36
 
 
37
Instrwin::~Instrwin (void)
 
38
{
 
39
}
 
40
 
 
41
 
 
42
void Instrwin::handle_event (XEvent *E)
 
43
{
 
44
    switch (E->type)
 
45
    {
 
46
    case ClientMessage:
 
47
        handle_xmesg ((XClientMessageEvent *) E);
 
48
        break;
 
49
    }
 
50
}
 
51
 
 
52
 
 
53
void Instrwin::handle_xmesg (XClientMessageEvent *E)
 
54
{
 
55
    if (E->message_type == _atom) x_unmap ();
 
56
}
 
57
 
 
58
 
 
59
void Instrwin::handle_callb (int k, X_window *W, XEvent *E)
 
60
{
 
61
    int c;
 
62
 
 
63
    switch (k)
 
64
    {
 
65
        case SLIDER | X_slider::MOVE: 
 
66
        case SLIDER | X_slider::STOP: 
 
67
        {
 
68
            X_slider *X = (X_slider *) W;
 
69
            c = X->cbid ();
 
70
            _divis = (c >> DIVIS_BIT0) - 1;
 
71
            _parid = c & DIVIS_MASK;
 
72
            _value = X->get_val (); 
 
73
            _final = k == (SLIDER | X_slider::STOP);
 
74
            _callb->handle_callb (CB_DIVIS_ACT, this, E);
 
75
            break; 
 
76
        }
 
77
 
 
78
        case BUTTON | X_button::PRESS:
 
79
        {
 
80
            X_button *B = (X_button *) W;
 
81
            k = B->cbid ();
 
82
            switch (k)
 
83
            {
 
84
            case TEMP_DEC:
 
85
            case TEMP_INC:
 
86
                incdec_temp (k == TEMP_DEC ? -1 : 1);
 
87
                break; 
 
88
 
 
89
            case FREQ_DEC:
 
90
            case FREQ_INC:
 
91
                incdec_freq (k == FREQ_DEC ? -1 : 1);
 
92
                break; 
 
93
 
 
94
            case TUNE_EXE:
 
95
                _callb->handle_callb (CB_RETUNE, this, E);
 
96
                break;
 
97
 
 
98
            case TUNE_CAN:
 
99
                _freq = _freq1;
 
100
                _temp = _temp1;
 
101
                show_tuning (0);
 
102
                break;
 
103
            }         
 
104
        }
 
105
    }
 
106
}
 
107
 
 
108
 
 
109
void Instrwin::setup (M_ifc_init *M)
 
110
{
 
111
    int      i, k, n1, n2, x1, x2, y;
 
112
    char     s [256];
 
113
    Divis    *D; 
 
114
    X_hints  H;
 
115
 
 
116
 
 
117
    add_text (100, 5, 60, 20, "Tuning", &text0, -1);
 
118
    but2.size.x = 17;
 
119
    but2.size.y = 17;
 
120
    _temp_txt = new X_textip  (this, 0,   &text0,  15, 41, 150, 20, 31);
 
121
    _temp_txt->set_align (1);     
 
122
    _temp_txt->x_map ();     
 
123
    _freq_txt = new X_textip  (this, 0,   &text0, 105, 65,  60, 20, 7);
 
124
    _freq_txt->set_align (1);     
 
125
    _freq_txt->x_map ();     
 
126
    (_dec_temp = new X_ibutton (this, this, &but2, 170, 41, disp ()->image1515 (X_display::IMG_LT), TEMP_DEC))->x_map ();
 
127
    (_inc_temp = new X_ibutton (this, this, &but2, 187, 41, disp ()->image1515 (X_display::IMG_RT), TEMP_INC))->x_map ();
 
128
    (_dec_freq = new X_ibutton (this, this, &but2, 170, 65, disp ()->image1515 (X_display::IMG_LT), FREQ_DEC))->x_map ();
 
129
    (_inc_freq = new X_ibutton (this, this, &but2, 187, 65, disp ()->image1515 (X_display::IMG_RT), FREQ_INC))->x_map ();
 
130
    but1.size.x = 60;
 
131
    but1.size.y = 20;
 
132
    (_tune_exe = new X_tbutton (this, this, &but1,  70, 100, "Retune", 0, TUNE_EXE))->x_map ();
 
133
    (_tune_can = new X_tbutton (this, this, &but1, 135, 100, "Cancel", 0, TUNE_CAN))->x_map ();
 
134
 
 
135
    for (i = n1 = n2 = 0; i < M->_ndivis; i++)
 
136
    {
 
137
        if (M->_divisd [i]._flags & 1) n1++;
 
138
        if (M->_divisd [i]._flags & 2) n2++;
 
139
    }
 
140
    x1 = 310;
 
141
    x2 = n1 ? 640 : x1;
 
142
    y = 40;
 
143
    D = _divisd;
 
144
    for (i = 0; i < M->_ndivis; i++)
 
145
    {
 
146
        k = DIVIS_STEP * (i + 1);
 
147
        if (M->_divisd [i]._flags & 1)
 
148
        {
 
149
            (D->_slid [0] = new X_hslider (this, this, &sli1, &sca_Swl, x2, y, 20, k))->x_map ();
 
150
            (new X_hscale (this, &sca_Swl, x2, y + 20, 10))->x_map ();
 
151
        }
 
152
        else D->_slid [0] = 0;
 
153
        if (M->_divisd [i]._flags & 2)
 
154
        {
 
155
            (D->_slid [1]  = new X_hslider (this, this, &sli1, &sca_Tfr, x1,       y, 20, k + 1))->x_map ();
 
156
            (D->_slid [2]  = new X_hslider (this, this, &sli1, &sca_Tmd, x1 + 160, y, 20, k + 2))->x_map ();
 
157
            (new X_hscale (this, &sca_Tfr, x1,       y + 20, 10))->x_map ();
 
158
            (new X_hscale (this, &sca_Tmd, x1 + 160, y + 20, 10))->x_map ();
 
159
        }
 
160
        else D->_slid [1] = D->_slid [2] = 0;
 
161
        if (D->_slid [0] || D->_slid [1])
 
162
        {
 
163
            add_text (x1 - 90, y, 80, 20,  M->_divisd [i]._label, &text0, 1);            
 
164
            D++;
 
165
            y += 40;
 
166
        }
 
167
    }
 
168
    if (n1)
 
169
    {
 
170
        add_text (x1,       5, 80, 20, "Trem freq", &text0, -1);
 
171
        add_text (x1 + 160, 5, 80, 20, "Trem amp",  &text0, -1);
 
172
    }
 
173
    if (n2) add_text (x2, 5, 80, 20, "Swell", &text0, -1);
 
174
 
 
175
    y += 5;
 
176
    if (y < YSIZE) y = YSIZE;
 
177
    sprintf (s, "%s   Aeolus-%s   Instrument settings", M->_appid, VERSION);
 
178
    x_set_title (s);
 
179
 
 
180
    _ntempe = M->_ntempe;
 
181
    if (_ntempe > NTEMPE) _ntempe = NTEMPE;
 
182
    for (i = 0; i < _ntempe; i++) _temped [i] = M->_temped [i]._label;
 
183
 
 
184
    H.position (_xp, _yp);
 
185
    H.minsize (200, 100);
 
186
    H.maxsize (XSIZE, y);
 
187
    H.rname (_xresm->rname ());
 
188
    H.rclas (_xresm->rclas ());
 
189
    x_apply (&H); 
 
190
    x_resize (XSIZE, y);
 
191
}
 
192
 
 
193
 
 
194
void Instrwin::set_dipar (M_ifc_dipar *M)
 
195
{
 
196
    X_slider *S;
 
197
 
 
198
    if ((M->_divis >= 0) && (M->_divis < NDIVIS))
 
199
    {
 
200
        if ((M->_parid >= 0) && (M->_parid < 3))
 
201
        {
 
202
            S = _divisd [M->_divis]._slid [M->_parid];
 
203
            if (S) S->set_val (M->_value);
 
204
        }
 
205
    }
 
206
}
 
207
 
 
208
 
 
209
void Instrwin::set_tuning (M_ifc_retune *M)
 
210
{
 
211
    _freq = _freq1 = M->_freq;
 
212
    _temp = _temp1 = M->_temp;
 
213
    show_tuning (0);
 
214
}
 
215
 
 
216
 
 
217
void Instrwin::show_tuning (int b)
 
218
{
 
219
    char s [16];
 
220
 
 
221
    sprintf (s, "%3.1lf", _freq);
 
222
    _freq_txt->set_text (s);
 
223
    _temp_txt->set_text (_temped [_temp] );
 
224
    _tune_exe->set_stat (b);
 
225
    _tune_can->set_stat (b);
 
226
}
 
227
 
 
228
void Instrwin::incdec_temp (int d)
 
229
{
 
230
    _temp += d + _ntempe;
 
231
    _temp %= _ntempe;    
 
232
    show_tuning (1);
 
233
}
 
234
 
 
235
 
 
236
void Instrwin::incdec_freq (int d)
 
237
{
 
238
    _freq += d;
 
239
    if (_freq < 400) _freq = 400;
 
240
    if (_freq > 480) _freq = 480;
 
241
    show_tuning (1);
 
242
}
 
243
 
 
244
 
 
245
void Instrwin::add_text (int xp, int yp, int xs, int ys, const char *text, X_textln_style *style, int align)
 
246
{
 
247
    (new X_textln (this, style, xp, yp, xs, ys, text, align))->x_map ();
 
248
}