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
){
72 t
->name
= (char*)malloc(64);
73 strncpy(t
->name
,gm_names
[prog
],64);
74 ui
->track_info
->update();
78 void bankcb(fltk::Widget
* w
, long i
){
79 //fltk::ValueInput* o = (fltk::ValueInput*)w;
82 int bank
= (int)o
->value
;
84 midi_bank_controller(i
, bank
);
87 void namecb(fltk::Widget
* w
, long i
){
88 fltk::Input
* o
= (fltk::Input
*)w
;
90 strcpy(t
->name
,o
->text());
92 t
->name
= (char*)malloc(strlen(o
->text())+1);
93 strcpy(t
->name
,o
->text());
96 void mutecb(fltk::Widget
* w
, long i
){
97 Toggle
* o
= (Toggle
*)w
;
112 void solocb(fltk::Widget
* w
, long i
){
113 Toggle
* o
= (Toggle
*)w
;
114 track
* t
= tracks
[i
];
116 ui
->track_info
->unset_solo();
130 void reccb(fltk::Widget
* w
, long i
){
131 Toggle
* o
= (Toggle
*)w
;
132 track
* t
= tracks
[i
];
134 ui
->track_info
->set_rec(i
);
135 ui
->keyboard
->cur_chan
= t
->chan
;
136 ui
->keyboard
->cur_port
= t
->port
;
142 void volcb(fltk::Widget
* w
, long i
){
143 Gauge
* o
= (Gauge
*)w
;
144 track
* t
= tracks
[i
];
147 midi_volume_controller(i
, t
->vol
);
148 //perhaps record this
151 void pancb(fltk::Widget
* w
, long i
){
152 Gauge
* o
= (Gauge
*)w
;
153 track
* t
= tracks
[i
];
156 midi_pan_controller(i
, t
->pan
);
159 TrackModule::TrackModule(int x
, int y
, int w
, int h
, int i
, const char* label
) :
160 fltk::Group(x
, y
, w
, h
, label
),
186 prog
.label_always
= 1;
188 prog
.tooltip("program");
198 bank
.label_always
= 1;
200 bank
.tooltip("bank");
209 chan
.label_always
= 1;
210 chan
.label_plusone
= 1;
213 chan
.tooltip("channel");
224 port
.label_always
= 1;
226 port
.tooltip("port");
229 port
.callback(portcb
, i
);
230 chan
.callback(chancb
, i
);
231 prog
.callback(progcb
, i
);
232 bank
.callback(bankcb
, i
);
233 rec
.callback(reccb
, i
);
234 name
.callback(namecb
, i
);
235 volume
.callback(volcb
, i
);
236 pan
.callback(pancb
, i
);
237 solo
.callback(solocb
, i
);
238 mute
.callback(mutecb
, i
);
240 rec
.tooltip("record on this track");
241 volume
.tooltip("volume");
243 solo
.tooltip("solo");
244 mute
.tooltip("mute");
267 add(rec
);//toggle recording
268 add(name
);//change track name
270 add(volume
);//set track volume
271 add(pan
);//set track pan
272 add(solo
);//set solo to this track
273 add(mute
);//mute or unmute track
275 add(port
);//change track port
276 add(chan
);//change track channel
277 add(prog
);//change track program
287 int TrackModule::handle(int e
){
288 return fltk::Group::handle(e
);
291 void TrackModule::toggle(){
317 void TrackModule::set_channel(int i
){
322 void TrackModule::unset_solo(){
323 if(tracks
[index
]->solo
){
324 tracks
[index
]->solo
= 0;
330 void TrackModule::unset_rec(){
335 void TrackModule::set_rec(){
341 void TrackModule::update(){
342 track
* t
= tracks
[index
];
344 port
.value
= t
->port
;
345 chan
.value
= t
->chan
;
346 prog
.value
= t
->prog
;
347 bank
.value
= t
->bank
;
369 void gauge_temp_cb(void* v
){
370 Gauge
* g
= (Gauge
*)v
;
372 if(g
->label_temp
==0){
376 if(g
->label_temp
==0){
380 //fltk::repeat_timeout(0.5, gauge_temp_cb, v);
384 Gauge::Gauge(int x
, int y
, int w
, int h
, const char* label
) :
385 fltk::Widget(x
, y
, w
, h
, label
){
398 VGauge::VGauge(int x
, int y
, int w
, int h
, const char* label
) :
399 Gauge(x
, y
, w
, h
, label
){
408 int VGauge::handle(int e
){
409 if(e
== fltk::MOUSEWHEEL
){
410 value
-=fltk::event_dy();
411 if(value
> max
){value
= max
;}
412 if(value
< 0){value
= 0;}
415 fltk::add_timeout(1,gauge_temp_cb
,this);
421 last
= fltk::event_y();
427 value
+= (last
- fltk::event_y());
428 if(value
> max
){value
= max
;}
429 if(value
< 0){value
= 0;}
430 if(value
!= last_value
){
434 last
= fltk::event_y();
438 if(e
== fltk::RELEASE
){
442 return fltk::Widget::handle(e
);
446 HGauge::HGauge(int x
, int y
, int w
, int h
, const char* label
) :
447 Gauge(x
, y
, w
, h
, label
){
456 int HGauge::handle(int e
){
457 if(e
== fltk::MOUSEWHEEL
){
458 value
-=fltk::event_dy();
459 if(value
> max
){value
= max
;}
460 if(value
< 0){value
= 0;}
463 fltk::add_timeout(1,gauge_temp_cb
,this);
469 last
= fltk::event_x();
475 value
+= fltk::event_x() - last
;
476 if(value
> max
){value
= max
;}
477 if(value
< 0){value
= 0;}
478 if(value
!= last_value
){
482 last
= fltk::event_x();
486 if(e
== fltk::RELEASE
){
490 return fltk::Widget::handle(e
);
495 fltk::setcolor(fltk::color(r
,g
,b
));
496 fltk::fillrect(2,2,w()-4,h()-4);
499 fltk::setcolor(fltk::color(R
,G
,B
));
501 int H
= value
* (h()-4) / max
;
502 fltk::fillrect(2,h()-2-H
,w()-4,H
);
504 if(label_flag
|| label_always
|| label_temp
){
506 int V
= label_plusone
? value
+ 1 : value
;
508 snprintf(buf
,3,"%x",V
);
511 snprintf(buf
,3,"%d",V
);
515 fltk::push_clip(2,2,w()-4,h()-4 - H
);
516 fltk::setcolor(fltk::color(R
,G
,B
));
517 fltk::setfont(fltk::HELVETICA
,12);
518 int W
= (int)fltk::getwidth(buf
);
519 fltk::drawtext(buf
,(w()-W
)/2,h()-fltk::getascent()/2);
523 fltk::push_clip(2,h()-2-H
,w()-4,H
);
525 fltk::setcolor(fltk::color(r
,g
,b
));
527 fltk::setfont(fltk::HELVETICA
,12);
528 fltk::drawtext(buf
,(w()-W
)/2,h()-fltk::getascent()/2);
535 fltk::setcolor(fltk::color(r
,g
,b
));
536 fltk::fillrect(2,2,w()-4,h()-4);
538 fltk::setcolor(fltk::color(R
,G
,B
));
539 int V
= value
* (h()-4) / max
;
540 fltk::fillrect(2,2,V
,h()-4);
542 if(label_flag
|| label_always
|| label_temp
){
544 snprintf(buf
,3,"%x",value
);
546 fltk::push_clip(V
+2,2,w()-4-V
,h()-4);
547 fltk::setcolor(fltk::color(R
,G
,B
));
548 fltk::setfont(fltk::HELVETICA
,12);
549 int W
= (int)fltk::getwidth(buf
);
550 fltk::drawtext(buf
,(w()-W
)/2,h()-fltk::getascent()/2);
553 fltk::push_clip(2,2,V
,h()-4);
554 fltk::setcolor(fltk::color(r
,g
,b
));
555 fltk::setfont(fltk::HELVETICA
,12);
556 fltk::drawtext(buf
,(w()-W
)/2,h()-fltk::getascent()/2);
561 Toggle::Toggle(int x
, int y
, int w
, int h
, const char* label
) :
562 fltk::Button(x
, y
, w
, h
, label
){
563 buttonbox(fltk::DOWN_BOX
);
564 when(fltk::WHEN_NEVER
);
577 int Toggle::handle(int e
){
582 return fltk::Button::handle(e
);
588 if(key_flag
){ //instead of drawing normally do something completely different
589 //redirect complaints to /dev/null
591 fltk::setcolor(fltk::BLACK
);
592 fltk::fillrect(2,h()-3,w()-4,1);
593 fltk::fillrect(w()-3,2,1,h()-4);
594 fltk::fillrect(1,1,w()-4,1);
595 fltk::fillrect(1,1,1,h()-4);
597 fltk::fillrect(6,2,1,h()-4);
598 fltk::fillrect(12,2,1,h()-4);
600 fltk::fillrect(5,2,3,9);
601 fltk::fillrect(11,2,3,9);
604 fltk::Button::draw(0);
610 fltk::setcolor(fltk::color(R
,G
,B
));
613 fltk::setcolor(fltk::color(r
,g
,b
));
615 fltk::fillrect(2,2,w()-4,h()-4);
617 fltk::setcolor(fltk::BLACK
);
618 fltk::setfont(fltk::HELVETICA
,12);
619 int W
= (int)fltk::getwidth(c
);
620 fltk::drawtext(c
,(w()-W
)/2,h()-fltk::getascent()/2);
624 void Toggle::set(int s
){