~ubuntu-branches/ubuntu/vivid/aeolus/vivid

« back to all changes in this revision

Viewing changes to instrwin.cc

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2010-04-19 19:12:51 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20100419191251-hgarjfcdfl7c0ryl
Tags: 0.8.4-3
debian/patches/01-makefile.patch: Drop -march=native flag, it isn't valid
for Debian packages as the results are unpredictable, thanks to
Bastian Blank for reporting this (Closes: #578278).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
    Copyright (C) 2003-2008 Fons Adriaensen <fons@kokkinizita.net>
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
 
            y += 40;
165
 
        }
166
 
        D++;
167
 
    }
168
 
 
169
 
    if (n1)
170
 
    {
171
 
        add_text (x1,       5, 80, 20, "Trem freq", &text0, -1);
172
 
        add_text (x1 + 160, 5, 80, 20, "Trem amp",  &text0, -1);
173
 
    }
174
 
    if (n2) add_text (x2, 5, 80, 20, "Swell", &text0, -1);
175
 
 
176
 
    y += 5;
177
 
    if (y < YSIZE) y = YSIZE;
178
 
    sprintf (s, "%s   Aeolus-%s   Instrument settings", M->_appid, VERSION);
179
 
    x_set_title (s);
180
 
 
181
 
    _ntempe = M->_ntempe;
182
 
    if (_ntempe > NTEMPE) _ntempe = NTEMPE;
183
 
    for (i = 0; i < _ntempe; i++) _temped [i] = M->_temped [i]._label;
184
 
 
185
 
    H.position (_xp, _yp);
186
 
    H.minsize (200, 100);
187
 
    H.maxsize (XSIZE, y);
188
 
    H.rname (_xresm->rname ());
189
 
    H.rclas (_xresm->rclas ());
190
 
    x_apply (&H); 
191
 
    x_resize (XSIZE, y);
192
 
}
193
 
 
194
 
 
195
 
void Instrwin::set_dipar (M_ifc_dipar *M)
196
 
{
197
 
    X_slider *S;
198
 
 
199
 
    if ((M->_divis >= 0) && (M->_divis < NDIVIS))
200
 
    {
201
 
        if ((M->_parid >= 0) && (M->_parid < 3))
202
 
        {
203
 
            S = _divisd [M->_divis]._slid [M->_parid];
204
 
            if (S) S->set_val (M->_value);
205
 
        }
206
 
    }
207
 
}
208
 
 
209
 
 
210
 
void Instrwin::set_tuning (M_ifc_retune *M)
211
 
{
212
 
    _freq = _freq1 = M->_freq;
213
 
    _temp = _temp1 = M->_temp;
214
 
    show_tuning (0);
215
 
}
216
 
 
217
 
 
218
 
void Instrwin::show_tuning (int b)
219
 
{
220
 
    char s [16];
221
 
 
222
 
    sprintf (s, "%3.1lf", _freq);
223
 
    _freq_txt->set_text (s);
224
 
    _temp_txt->set_text (_temped [_temp] );
225
 
    _tune_exe->set_stat (b);
226
 
    _tune_can->set_stat (b);
227
 
}
228
 
 
229
 
void Instrwin::incdec_temp (int d)
230
 
{
231
 
    _temp += d + _ntempe;
232
 
    _temp %= _ntempe;    
233
 
    show_tuning (1);
234
 
}
235
 
 
236
 
 
237
 
void Instrwin::incdec_freq (int d)
238
 
{
239
 
    _freq += d;
240
 
    if (_freq < 400) _freq = 400;
241
 
    if (_freq > 480) _freq = 480;
242
 
    show_tuning (1);
243
 
}
244
 
 
245
 
 
246
 
void Instrwin::add_text (int xp, int yp, int xs, int ys, const char *text, X_textln_style *style, int align)
247
 
{
248
 
    (new X_textln (this, style, xp, yp, xs, ys, text, align))->x_map ();
249
 
}