~ubuntu-branches/ubuntu/trusty/aeolus/trusty

« back to all changes in this revision

Viewing changes to midiwin.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 "midiwin.h"
 
21
#include "callbacks.h"
 
22
#include "styles.h"
 
23
 
 
24
 
 
25
Midiwin::Midiwin (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),
 
30
    _yp (yp),
 
31
    _preset (-1)
 
32
{
 
33
    _atom = XInternAtom (dpy (), "WM_DELETE_WINDOW", True);
 
34
    XSetWMProtocols (dpy (), win (), &_atom, 1);
 
35
    _atom = XInternAtom (dpy (), "WM_PROTOCOLS", True);
 
36
}
 
37
 
 
38
 
 
39
Midiwin::~Midiwin (void)
 
40
{
 
41
}
 
42
 
 
43
 
 
44
void Midiwin::handle_event (XEvent *E)
 
45
{
 
46
    switch (E->type)
 
47
    {
 
48
    case ClientMessage:
 
49
        handle_xmesg ((XClientMessageEvent *) E);
 
50
        break;
 
51
    }
 
52
}
 
53
 
 
54
 
 
55
void Midiwin::handle_xmesg (XClientMessageEvent *E)
 
56
{
 
57
    if (E->message_type == _atom) x_unmap ();
 
58
}
 
59
 
 
60
 
 
61
void Midiwin::handle_callb (int k, X_window *W, XEvent *E)
 
62
{
 
63
    switch (k)
 
64
    {
 
65
    case BUTTON | X_button::PRESS:
 
66
    {
 
67
        X_button      *B = (X_button *) W;
 
68
        XButtonEvent  *X = (XButtonEvent *) E;
 
69
 
 
70
        set_butt (B->cbid ());
 
71
        if (X->state & ShiftMask) _callb->handle_callb (CB_MIDI_SETCONF, this, 0);
 
72
        else                      _callb->handle_callb (CB_MIDI_GETCONF, this, 0);
 
73
        break;
 
74
    }
 
75
    case CB_MIDI_MODCONF:
 
76
        set_butt (-1);
 
77
        _callb->handle_callb (CB_MIDI_SETCONF, this, 0);
 
78
        break;
 
79
    }
 
80
}
 
81
 
 
82
 
 
83
void Midiwin::setup (M_ifc_init *M)
 
84
{
 
85
    X_hints H;
 
86
    int     i, x, y;
 
87
    char    s [256];
 
88
 
 
89
    _matrix = new Midimatrix (this, this, 10, 10); 
 
90
    _matrix->init (M);
 
91
 
 
92
    x = 10;
 
93
    y = _matrix->ysize () + 20;
 
94
    but1.size.x = 30;
 
95
    but1.size.y = 20;
 
96
    for (i = 0; i < 8; i++)
 
97
    {
 
98
        sprintf (s, "%d", i + 1);
 
99
        _bpres [i] = new X_tbutton (this, this, &but1, x, y, s, 0, i);        
 
100
        _bpres [i]->x_map ();
 
101
        x += 32;
 
102
    } 
 
103
    x += 10;
 
104
    add_text (x, y, 200, 20, "Shift-click to store preset", &text0, -1);
 
105
    _xs = _matrix->xsize () + 20;
 
106
    _ys = _matrix->ysize () + 60;
 
107
    H.position (_xp, _yp);
 
108
    H.minsize (_xs, _ys);
 
109
    H.maxsize (_xs, _ys);
 
110
    H.rname (_xresm->rname ());
 
111
    H.rclas (_xresm->rclas ());
 
112
    x_apply (&H); 
 
113
    x_resize (_xs, _ys);
 
114
 
 
115
    sprintf (s, "%s   Aeolus-%s   Midi settings", M->_appid, VERSION);
 
116
    x_set_title (s);
 
117
}
 
118
 
 
119
 
 
120
void Midiwin::setconf (M_ifc_chconf *M)
 
121
{
 
122
    int k;
 
123
 
 
124
    k = M->_index;
 
125
    if (k >= 0)
 
126
    {
 
127
        if (k >= 8) k = -1;
 
128
        set_butt (k);  
 
129
    }
 
130
    _matrix->set_chconf (M->_bits);
 
131
}
 
132
 
 
133
 
 
134
void Midiwin::set_butt (int i)
 
135
{
 
136
    if (i != _preset)
 
137
    {
 
138
        if (_preset >= 0) _bpres [_preset]->set_stat (0);
 
139
        _preset = i;
 
140
        if (_preset >= 0) _bpres [_preset]->set_stat (1);
 
141
    }
 
142
}
 
143
 
 
144
 
 
145
void Midiwin::add_text (int xp, int yp, int xs, int ys, const char *text, X_textln_style *style, int align)
 
146
{
 
147
    (new X_textln (this, style, xp, yp, xs, ys, text, align))->x_map ();
 
148
}