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

« back to all changes in this revision

Viewing changes to midiwin.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 "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
 
 
97
 
    for (i = 0; i < 8; i++)
98
 
    {
99
 
        sprintf (s, "%d", i + 1);
100
 
        _bpres [i] = new X_tbutton (this, this, &but1, x, y, s, 0, i);        
101
 
        _bpres [i]->x_map ();
102
 
        x += 32;
103
 
    } 
104
 
 
105
 
    x += 10;
106
 
    add_text (x, y, 200, 20, "Shift-click to store preset", &text0, -1);
107
 
    _xs = _matrix->xsize () + 20;
108
 
    _ys = _matrix->ysize () + 60;
109
 
    H.position (_xp, _yp);
110
 
    H.minsize (_xs, _ys);
111
 
    H.maxsize (_xs, _ys);
112
 
    H.rname (_xresm->rname ());
113
 
    H.rclas (_xresm->rclas ());
114
 
    x_apply (&H); 
115
 
    x_resize (_xs, _ys);
116
 
 
117
 
    sprintf (s, "%s   Aeolus-%s   Midi settings", M->_appid, VERSION);
118
 
    x_set_title (s);
119
 
}
120
 
 
121
 
 
122
 
void Midiwin::setconf (M_ifc_chconf *M)
123
 
{
124
 
    int k;
125
 
 
126
 
    k = M->_index;
127
 
    if (k >= 0)
128
 
    {
129
 
        if (k >= 8) k = -1;
130
 
        set_butt (k);  
131
 
    }
132
 
    _matrix->set_chconf (M->_bits);
133
 
}
134
 
 
135
 
 
136
 
void Midiwin::set_butt (int i)
137
 
{
138
 
    if (i != _preset)
139
 
    {
140
 
        if (_preset >= 0) _bpres [_preset]->set_stat (0);
141
 
        _preset = i;
142
 
        if (_preset >= 0) _bpres [_preset]->set_stat (1);
143
 
    }
144
 
}
145
 
 
146
 
 
147
 
void Midiwin::add_text (int xp, int yp, int xs, int ys, const char *text, X_textln_style *style, int align)
148
 
{
149
 
    (new X_textln (this, style, xp, yp, xs, ys, text, align))->x_map ();
150
 
}