2 Epichord - a midi sequencer
3 Copyright (C) 2008 Evan Rinehart
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to
18 The Free Software Foundation, Inc.
19 51 Franklin Street, Fifth Floor
20 Boston, MA 02110-1301, USA
26 #include <fltk/Group.h>
27 #include <fltk/Widget.h>
29 #include <fltk/draw.h>
38 extern std::vector
<track
*> tracks
;
41 extern char gm_names
[128][64];
43 extern struct conf config
;
45 void portcb(fltk::Widget
* w
, long i
){
46 //fltk::ValueInput* o = (fltk::ValueInput*)w;
49 int old_port
= t
->port
;
50 t
->port
= (int)o
->value
;
51 midi_channel_off(t
->chan
,old_port
);
54 void chancb(fltk::Widget
* w
, long i
){
55 //fltk::ValueInput* o = (fltk::ValueInput*)w;
58 int old_chan
= t
->chan
;
59 t
->chan
= (int)o
->value
;
60 midi_channel_off(old_chan
,t
->port
);
63 void progcb(fltk::Widget
* w
, long i
){
64 //fltk::ValueInput* o = (fltk::ValueInput*)w;
67 int prog
= (int)o
->value
;
69 program_change(i
, prog
);
70 if(config
.autotrackname
){
71 strncpy(t
->name
,gm_names
[prog
],64);
72 ui
->track_info
->update();
76 void bankcb(fltk::Widget
* w
, long i
){
77 //fltk::ValueInput* o = (fltk::ValueInput*)w;
80 int bank
= (int)o
->value
;
82 midi_bank_controller(i
, bank
);
85 void namecb(fltk::Widget
* w
, long i
){
86 fltk::Input
* o
= (fltk::Input
*)w
;
88 strcpy(t
->name
,o
->text());
90 t
->name
= (char*)malloc(strlen(o
->text())+1);
91 strcpy(t
->name
,o
->text());
94 void mutecb(fltk::Widget
* w
, long i
){
95 Toggle
* o
= (Toggle
*)w
;
110 void solocb(fltk::Widget
* w
, long i
){
111 Toggle
* o
= (Toggle
*)w
;
112 track
* t
= tracks
[i
];
114 ui
->track_info
->unset_solo();
128 void reccb(fltk::Widget
* w
, long i
){
129 Toggle
* o
= (Toggle
*)w
;
130 track
* t
= tracks
[i
];
132 ui
->track_info
->set_rec(i
);
133 ui
->keyboard
->cur_chan
= t
->chan
;
134 ui
->keyboard
->cur_port
= t
->port
;
140 void volcb(fltk::Widget
* w
, long i
){
141 Gauge
* o
= (Gauge
*)w
;
142 track
* t
= tracks
[i
];
145 midi_volume_controller(i
, t
->vol
);
146 //perhaps record this
149 void pancb(fltk::Widget
* w
, long i
){
150 Gauge
* o
= (Gauge
*)w
;
151 track
* t
= tracks
[i
];
154 midi_pan_controller(i
, t
->pan
);
157 TrackModule::TrackModule(int x
, int y
, int w
, int h
, int i
, const char* label
) :
158 fltk::Group(x
, y
, w
, h
, label
),
184 prog
.label_always
= 1;
186 prog
.tooltip("program");
196 bank
.label_always
= 1;
198 bank
.tooltip("bank");
207 chan
.label_always
= 1;
208 chan
.label_plusone
= 1;
211 chan
.tooltip("channel");
222 port
.label_always
= 1;
224 port
.tooltip("port");
227 port
.callback(portcb
, i
);
228 chan
.callback(chancb
, i
);
229 prog
.callback(progcb
, i
);
230 bank
.callback(bankcb
, i
);
231 rec
.callback(reccb
, i
);
232 name
.callback(namecb
, i
);
233 volume
.callback(volcb
, i
);
234 pan
.callback(pancb
, i
);
235 solo
.callback(solocb
, i
);
236 mute
.callback(mutecb
, i
);
238 rec
.tooltip("record on this track");
239 volume
.tooltip("volume");
241 solo
.tooltip("solo");
242 mute
.tooltip("mute");
265 add(rec
);//toggle recording
266 add(name
);//change track name
268 add(volume
);//set track volume
269 add(pan
);//set track pan
270 add(solo
);//set solo to this track
271 add(mute
);//mute or unmute track
273 add(port
);//change track port
274 add(chan
);//change track channel
275 add(prog
);//change track program
285 int TrackModule::handle(int e
){
286 return fltk::Group::handle(e
);
289 void TrackModule::toggle(){
315 void TrackModule::set_channel(int i
){
320 void TrackModule::unset_solo(){
321 if(tracks
[index
]->solo
){
322 tracks
[index
]->solo
= 0;
328 void TrackModule::unset_rec(){
333 void TrackModule::set_rec(){
339 void TrackModule::update(){
340 track
* t
= tracks
[index
];
342 port
.value
= t
->port
;
343 chan
.value
= t
->chan
;
344 prog
.value
= t
->prog
;
345 bank
.value
= t
->bank
;
367 void gauge_temp_cb(void* v
){
368 Gauge
* g
= (Gauge
*)v
;
370 if(g
->label_temp
==0){
374 if(g
->label_temp
==0){
378 //fltk::repeat_timeout(0.5, gauge_temp_cb, v);
382 Gauge::Gauge(int x
, int y
, int w
, int h
, const char* label
) :
383 fltk::Widget(x
, y
, w
, h
, label
){
396 VGauge::VGauge(int x
, int y
, int w
, int h
, const char* label
) :
397 Gauge(x
, y
, w
, h
, label
){
406 int VGauge::handle(int e
){
407 if(e
== fltk::MOUSEWHEEL
){
408 value
-=fltk::event_dy();
409 if(value
> max
){value
= max
;}
410 if(value
< 0){value
= 0;}
413 fltk::add_timeout(1,gauge_temp_cb
,this);
419 last
= fltk::event_y();
425 value
+= (last
- fltk::event_y());
426 if(value
> max
){value
= max
;}
427 if(value
< 0){value
= 0;}
428 if(value
!= last_value
){
432 last
= fltk::event_y();
436 if(e
== fltk::RELEASE
){
440 return fltk::Widget::handle(e
);
444 HGauge::HGauge(int x
, int y
, int w
, int h
, const char* label
) :
445 Gauge(x
, y
, w
, h
, label
){
454 int HGauge::handle(int e
){
455 if(e
== fltk::MOUSEWHEEL
){
456 value
-=fltk::event_dy();
457 if(value
> max
){value
= max
;}
458 if(value
< 0){value
= 0;}
461 fltk::add_timeout(1,gauge_temp_cb
,this);
467 last
= fltk::event_x();
473 value
+= fltk::event_x() - last
;
474 if(value
> max
){value
= max
;}
475 if(value
< 0){value
= 0;}
476 if(value
!= last_value
){
480 last
= fltk::event_x();
484 if(e
== fltk::RELEASE
){
488 return fltk::Widget::handle(e
);
493 fltk::setcolor(fltk::color(r
,g
,b
));
494 fltk::fillrect(2,2,w()-4,h()-4);
497 fltk::setcolor(fltk::color(R
,G
,B
));
499 int H
= value
* (h()-4) / max
;
500 fltk::fillrect(2,h()-2-H
,w()-4,H
);
502 if(label_flag
|| label_always
|| label_temp
){
504 int V
= label_plusone
? value
+ 1 : value
;
506 snprintf(buf
,3,"%x",V
);
509 snprintf(buf
,3,"%d",V
);
513 fltk::push_clip(2,2,w()-4,h()-4 - H
);
514 fltk::setcolor(fltk::color(R
,G
,B
));
515 fltk::setfont(fltk::HELVETICA
,12);
516 int W
= (int)fltk::getwidth(buf
);
517 fltk::drawtext(buf
,(w()-W
)/2,h()-fltk::getascent()/2);
521 fltk::push_clip(2,h()-2-H
,w()-4,H
);
523 fltk::setcolor(fltk::color(r
,g
,b
));
525 fltk::setfont(fltk::HELVETICA
,12);
526 fltk::drawtext(buf
,(w()-W
)/2,h()-fltk::getascent()/2);
533 fltk::setcolor(fltk::color(r
,g
,b
));
534 fltk::fillrect(2,2,w()-4,h()-4);
536 fltk::setcolor(fltk::color(R
,G
,B
));
537 int V
= value
* (h()-4) / max
;
538 fltk::fillrect(2,2,V
,h()-4);
540 if(label_flag
|| label_always
|| label_temp
){
542 snprintf(buf
,3,"%x",value
);
544 fltk::push_clip(V
+2,2,w()-4-V
,h()-4);
545 fltk::setcolor(fltk::color(R
,G
,B
));
546 fltk::setfont(fltk::HELVETICA
,12);
547 int W
= (int)fltk::getwidth(buf
);
548 fltk::drawtext(buf
,(w()-W
)/2,h()-fltk::getascent()/2);
551 fltk::push_clip(2,2,V
,h()-4);
552 fltk::setcolor(fltk::color(r
,g
,b
));
553 fltk::setfont(fltk::HELVETICA
,12);
554 fltk::drawtext(buf
,(w()-W
)/2,h()-fltk::getascent()/2);
559 Toggle::Toggle(int x
, int y
, int w
, int h
, const char* label
) :
560 fltk::Button(x
, y
, w
, h
, label
){
561 buttonbox(fltk::DOWN_BOX
);
562 when(fltk::WHEN_NEVER
);
575 int Toggle::handle(int e
){
580 return fltk::Button::handle(e
);
586 if(key_flag
){ //instead of drawing normally do something completely different
587 //redirect complaints to /dev/null
589 fltk::setcolor(fltk::BLACK
);
590 fltk::fillrect(2,h()-3,w()-4,1);
591 fltk::fillrect(w()-3,2,1,h()-4);
592 fltk::fillrect(1,1,w()-4,1);
593 fltk::fillrect(1,1,1,h()-4);
595 fltk::fillrect(6,2,1,h()-4);
596 fltk::fillrect(12,2,1,h()-4);
598 fltk::fillrect(5,2,3,9);
599 fltk::fillrect(11,2,3,9);
602 fltk::Button::draw(0);
608 fltk::setcolor(fltk::color(R
,G
,B
));
611 fltk::setcolor(fltk::color(r
,g
,b
));
613 fltk::fillrect(2,2,w()-4,h()-4);
615 fltk::setcolor(fltk::BLACK
);
616 fltk::setfont(fltk::HELVETICA
,12);
617 int W
= (int)fltk::getwidth(c
);
618 fltk::drawtext(c
,(w()-W
)/2,h()-fltk::getascent()/2);
622 void Toggle::set(int s
){