1 |
/* |
/* |
2 |
* Copyright (C) 2006-2010 Andreas Persson |
* Copyright (C) 2006-2014 Andreas Persson |
3 |
* |
* |
4 |
* This program is free software; you can redistribute it and/or |
* This program is free software; you can redistribute it and/or |
5 |
* modify it under the terms of the GNU General Public License as |
* modify it under the terms of the GNU General Public License as |
20 |
#include "dimregionedit.h" |
#include "dimregionedit.h" |
21 |
|
|
22 |
#include "global.h" |
#include "global.h" |
23 |
|
#include "compat.h" |
24 |
|
|
25 |
|
VelocityCurve::VelocityCurve(double (gig::DimensionRegion::*getter)(uint8_t)) : |
26 |
|
getter(getter), dimreg(0) { |
27 |
|
set_size_request(80, 80); |
28 |
|
} |
29 |
|
|
30 |
|
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
31 |
|
bool VelocityCurve::on_expose_event(GdkEventExpose* e) { |
32 |
|
const Cairo::RefPtr<Cairo::Context>& cr = |
33 |
|
get_window()->create_cairo_context(); |
34 |
|
#if 0 |
35 |
|
} |
36 |
|
#endif |
37 |
|
#else |
38 |
|
bool VelocityCurve::on_draw(const Cairo::RefPtr<Cairo::Context>& cr) { |
39 |
|
#endif |
40 |
|
if (dimreg) { |
41 |
|
int w = get_width(); |
42 |
|
int h = get_height(); |
43 |
|
|
44 |
|
for (int pass = 0 ; pass < 2 ; pass++) { |
45 |
|
for (double x = 0 ; x <= w ; x++) { |
46 |
|
int vel = int(x * (127 - 1e-10) / w + 1); |
47 |
|
double y = (1 - (dimreg->*getter)(vel)) * (h - 3) + 1.5; |
48 |
|
|
49 |
|
if (x < 1e-10) { |
50 |
|
cr->move_to(x, y); |
51 |
|
} else { |
52 |
|
cr->line_to(x, y); |
53 |
|
} |
54 |
|
} |
55 |
|
if (pass == 0) { |
56 |
|
cr->line_to(w, h); |
57 |
|
cr->line_to(0, h); |
58 |
|
cr->set_source_rgba(0.5, 0.44, 1.0, is_sensitive() ? 0.2 : 0.1); |
59 |
|
cr->fill(); |
60 |
|
} else { |
61 |
|
cr->set_line_width(3); |
62 |
|
cr->set_source_rgba(0.5, 0.44, 1.0, is_sensitive() ? 1.0 : 0.3); |
63 |
|
cr->stroke(); |
64 |
|
} |
65 |
|
} |
66 |
|
} |
67 |
|
return true; |
68 |
|
} |
69 |
|
|
70 |
|
|
71 |
|
CrossfadeCurve::CrossfadeCurve() : dimreg(0) { |
72 |
|
set_size_request(280, 80); |
73 |
|
} |
74 |
|
|
75 |
|
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
76 |
|
bool CrossfadeCurve::on_expose_event(GdkEventExpose* e) { |
77 |
|
const Cairo::RefPtr<Cairo::Context>& cr = |
78 |
|
get_window()->create_cairo_context(); |
79 |
|
#if 0 |
80 |
|
} |
81 |
|
#endif |
82 |
|
#else |
83 |
|
bool CrossfadeCurve::on_draw(const Cairo::RefPtr<Cairo::Context>& cr) { |
84 |
|
#endif |
85 |
|
if (dimreg) { |
86 |
|
cr->translate(1.5, 0); |
87 |
|
|
88 |
|
// first, draw curves for the other layers |
89 |
|
gig::Region* region = dimreg->GetParent(); |
90 |
|
int dimregno; |
91 |
|
for (dimregno = 0 ; dimregno < region->DimensionRegions ; dimregno++) { |
92 |
|
if (region->pDimensionRegions[dimregno] == dimreg) { |
93 |
|
break; |
94 |
|
} |
95 |
|
} |
96 |
|
int bitcount = 0; |
97 |
|
for (int dim = 0 ; dim < region->Dimensions ; dim++) { |
98 |
|
if (region->pDimensionDefinitions[dim].dimension == |
99 |
|
gig::dimension_layer) { |
100 |
|
int mask = |
101 |
|
~(((1 << region->pDimensionDefinitions[dim].bits) - 1) << |
102 |
|
bitcount); |
103 |
|
int c = dimregno & mask; // mask away the layer dimension |
104 |
|
|
105 |
|
for (int i = 0 ; i < region->pDimensionDefinitions[dim].zones ; |
106 |
|
i++) { |
107 |
|
gig::DimensionRegion* d = |
108 |
|
region->pDimensionRegions[c + (i << bitcount)]; |
109 |
|
if (d != dimreg) { |
110 |
|
draw_one_curve(cr, d, false); |
111 |
|
} |
112 |
|
} |
113 |
|
break; |
114 |
|
} |
115 |
|
bitcount += region->pDimensionDefinitions[dim].bits; |
116 |
|
} |
117 |
|
|
118 |
|
// then, draw the currently selected layer |
119 |
|
draw_one_curve(cr, dimreg, is_sensitive()); |
120 |
|
} |
121 |
|
return true; |
122 |
|
} |
123 |
|
|
124 |
|
void CrossfadeCurve::draw_one_curve(const Cairo::RefPtr<Cairo::Context>& cr, |
125 |
|
const gig::DimensionRegion* d, |
126 |
|
bool sensitive) { |
127 |
|
int w = get_width(); |
128 |
|
int h = get_height(); |
129 |
|
|
130 |
|
if (d->Crossfade.out_end) { |
131 |
|
for (int pass = 0 ; pass < 2 ; pass++) { |
132 |
|
cr->move_to(d->Crossfade.in_start / 127.0 * (w - 3), h); |
133 |
|
cr->line_to(d->Crossfade.in_end / 127.0 * (w - 3), 1.5); |
134 |
|
cr->line_to(d->Crossfade.out_start / 127.0 * (w - 3), 1.5); |
135 |
|
cr->line_to(d->Crossfade.out_end / 127.0 * (w - 3), h); |
136 |
|
|
137 |
|
if (pass == 0) { |
138 |
|
cr->set_source_rgba(0.5, 0.44, 1.0, sensitive ? 0.2 : 0.1); |
139 |
|
cr->fill(); |
140 |
|
} else { |
141 |
|
cr->set_line_width(3); |
142 |
|
cr->set_source_rgba(0.5, 0.44, 1.0, sensitive ? 1.0 : 0.3); |
143 |
|
cr->stroke(); |
144 |
|
} |
145 |
|
} |
146 |
|
} |
147 |
|
} |
148 |
|
|
149 |
|
|
150 |
DimRegionEdit::DimRegionEdit() : |
DimRegionEdit::DimRegionEdit() : |
151 |
|
velocity_curve(&gig::DimensionRegion::GetVelocityAttenuation), |
152 |
|
release_curve(&gig::DimensionRegion::GetVelocityRelease), |
153 |
|
cutoff_curve(&gig::DimensionRegion::GetVelocityCutoff), |
154 |
eEG1PreAttack(_("Pre-attack"), 0, 100, 2), |
eEG1PreAttack(_("Pre-attack"), 0, 100, 2), |
155 |
eEG1Attack(_("Attack"), 0, 60, 3), |
eEG1Attack(_("Attack"), 0, 60, 3), |
156 |
eEG1Decay1(_("Decay 1"), 0.005, 60, 3), |
eEG1Decay1(_("Decay 1"), 0.005, 60, 3), |
473 |
addProp(eCrossfade_out_start); |
addProp(eCrossfade_out_start); |
474 |
addProp(eCrossfade_out_end); |
addProp(eCrossfade_out_end); |
475 |
|
|
476 |
|
Gtk::Frame* frame = new Gtk::Frame; |
477 |
|
frame->add(crossfade_curve); |
478 |
|
table[pageno]->attach(*frame, 1, 3, rowno, rowno + 1, |
479 |
|
Gtk::SHRINK, Gtk::SHRINK); |
480 |
|
rowno++; |
481 |
|
|
482 |
|
eCrossfade_in_start.signal_value_changed().connect( |
483 |
|
sigc::mem_fun(crossfade_curve, &CrossfadeCurve::queue_draw)); |
484 |
|
eCrossfade_in_end.signal_value_changed().connect( |
485 |
|
sigc::mem_fun(crossfade_curve, &CrossfadeCurve::queue_draw)); |
486 |
|
eCrossfade_out_start.signal_value_changed().connect( |
487 |
|
sigc::mem_fun(crossfade_curve, &CrossfadeCurve::queue_draw)); |
488 |
|
eCrossfade_out_end.signal_value_changed().connect( |
489 |
|
sigc::mem_fun(crossfade_curve, &CrossfadeCurve::queue_draw)); |
490 |
|
|
491 |
nextPage(); |
nextPage(); |
492 |
|
|
493 |
addHeader(_("General Filter Settings")); |
addHeader(_("General Filter Settings")); |
538 |
addProp(eVCFVelocityCurve); |
addProp(eVCFVelocityCurve); |
539 |
addProp(eVCFVelocityScale); |
addProp(eVCFVelocityScale); |
540 |
addProp(eVCFVelocityDynamicRange); |
addProp(eVCFVelocityDynamicRange); |
541 |
|
|
542 |
|
eVCFCutoffController.signal_value_changed().connect( |
543 |
|
sigc::mem_fun(cutoff_curve, &VelocityCurve::queue_draw)); |
544 |
|
eVCFVelocityCurve.signal_value_changed().connect( |
545 |
|
sigc::mem_fun(cutoff_curve, &VelocityCurve::queue_draw)); |
546 |
|
eVCFVelocityScale.signal_value_changed().connect( |
547 |
|
sigc::mem_fun(cutoff_curve, &VelocityCurve::queue_draw)); |
548 |
|
eVCFVelocityDynamicRange.signal_value_changed().connect( |
549 |
|
sigc::mem_fun(cutoff_curve, &VelocityCurve::queue_draw)); |
550 |
|
|
551 |
|
frame = new Gtk::Frame; |
552 |
|
frame->add(cutoff_curve); |
553 |
|
table[pageno]->attach(*frame, 1, 3, rowno, rowno + 1, |
554 |
|
Gtk::SHRINK, Gtk::SHRINK); |
555 |
|
rowno++; |
556 |
|
|
557 |
addProp(eVCFResonance); |
addProp(eVCFResonance); |
558 |
addProp(eVCFResonanceDynamic); |
addProp(eVCFResonanceDynamic); |
559 |
{ |
{ |
636 |
|
|
637 |
nextPage(); |
nextPage(); |
638 |
|
|
639 |
|
addHeader(_("Velocity Reponse")); |
640 |
eVelocityResponseCurve.set_choices(curve_type_texts, curve_type_values); |
eVelocityResponseCurve.set_choices(curve_type_texts, curve_type_values); |
641 |
addProp(eVelocityResponseCurve); |
addProp(eVelocityResponseCurve); |
642 |
addProp(eVelocityResponseDepth); |
addProp(eVelocityResponseDepth); |
643 |
addProp(eVelocityResponseCurveScaling); |
addProp(eVelocityResponseCurveScaling); |
644 |
|
|
645 |
|
eVelocityResponseCurve.signal_value_changed().connect( |
646 |
|
sigc::mem_fun(velocity_curve, &VelocityCurve::queue_draw)); |
647 |
|
eVelocityResponseDepth.signal_value_changed().connect( |
648 |
|
sigc::mem_fun(velocity_curve, &VelocityCurve::queue_draw)); |
649 |
|
eVelocityResponseCurveScaling.signal_value_changed().connect( |
650 |
|
sigc::mem_fun(velocity_curve, &VelocityCurve::queue_draw)); |
651 |
|
|
652 |
|
frame = new Gtk::Frame; |
653 |
|
frame->add(velocity_curve); |
654 |
|
table[pageno]->attach(*frame, 1, 3, rowno, rowno + 1, |
655 |
|
Gtk::SHRINK, Gtk::SHRINK); |
656 |
|
rowno++; |
657 |
|
|
658 |
|
addHeader(_("Release Velocity Reponse")); |
659 |
eReleaseVelocityResponseCurve.set_choices(curve_type_texts, |
eReleaseVelocityResponseCurve.set_choices(curve_type_texts, |
660 |
curve_type_values); |
curve_type_values); |
661 |
addProp(eReleaseVelocityResponseCurve); |
addProp(eReleaseVelocityResponseCurve); |
662 |
addProp(eReleaseVelocityResponseDepth); |
addProp(eReleaseVelocityResponseDepth); |
663 |
|
|
664 |
|
eReleaseVelocityResponseCurve.signal_value_changed().connect( |
665 |
|
sigc::mem_fun(release_curve, &VelocityCurve::queue_draw)); |
666 |
|
eReleaseVelocityResponseDepth.signal_value_changed().connect( |
667 |
|
sigc::mem_fun(release_curve, &VelocityCurve::queue_draw)); |
668 |
|
frame = new Gtk::Frame; |
669 |
|
frame->add(release_curve); |
670 |
|
table[pageno]->attach(*frame, 1, 3, rowno, rowno + 1, |
671 |
|
Gtk::SHRINK, Gtk::SHRINK); |
672 |
|
rowno++; |
673 |
|
|
674 |
addProp(eReleaseTriggerDecay); |
addProp(eReleaseTriggerDecay); |
675 |
{ |
{ |
676 |
const char* choices[] = { _("none"), _("effect4depth"), _("effect5depth"), 0 }; |
const char* choices[] = { _("none"), _("effect4depth"), _("effect5depth"), 0 }; |
747 |
Gtk::Entry*& widget) |
Gtk::Entry*& widget) |
748 |
{ |
{ |
749 |
label = new Gtk::Label(Glib::ustring(labelText) + ":"); |
label = new Gtk::Label(Glib::ustring(labelText) + ":"); |
750 |
label->set_alignment(Gtk::ALIGN_LEFT); |
label->set_alignment(Gtk::ALIGN_START); |
751 |
|
|
752 |
table[pageno]->attach(*label, 1, 2, rowno, rowno + 1, |
table[pageno]->attach(*label, 1, 2, rowno, rowno + 1, |
753 |
Gtk::FILL, Gtk::SHRINK); |
Gtk::FILL, Gtk::SHRINK); |
773 |
str += "</b>"; |
str += "</b>"; |
774 |
Gtk::Label* label = new Gtk::Label(str); |
Gtk::Label* label = new Gtk::Label(str); |
775 |
label->set_use_markup(); |
label->set_use_markup(); |
776 |
label->set_alignment(Gtk::ALIGN_LEFT); |
label->set_alignment(Gtk::ALIGN_START); |
777 |
table[pageno]->attach(*label, 0, 3, rowno, rowno + 1, |
table[pageno]->attach(*label, 0, 3, rowno, rowno + 1, |
778 |
Gtk::FILL, Gtk::SHRINK); |
Gtk::FILL, Gtk::SHRINK); |
779 |
rowno++; |
rowno++; |
821 |
void DimRegionEdit::set_dim_region(gig::DimensionRegion* d) |
void DimRegionEdit::set_dim_region(gig::DimensionRegion* d) |
822 |
{ |
{ |
823 |
dimregion = d; |
dimregion = d; |
824 |
|
velocity_curve.set_dim_region(d); |
825 |
|
release_curve.set_dim_region(d); |
826 |
|
cutoff_curve.set_dim_region(d); |
827 |
|
crossfade_curve.set_dim_region(d); |
828 |
|
|
829 |
set_sensitive(d); |
set_sensitive(d); |
830 |
if (!d) return; |
if (!d) return; |
925 |
d->pSample ? d->pSample->LoopPlayCount : 0); |
d->pSample ? d->pSample->LoopPlayCount : 0); |
926 |
update_model--; |
update_model--; |
927 |
|
|
928 |
wSample->set_text(d->pSample ? d->pSample->pInfo->Name.c_str() : _("NULL")); |
wSample->set_text(d->pSample ? gig_to_utf8(d->pSample->pInfo->Name) : |
929 |
|
_("NULL")); |
930 |
|
|
931 |
update_loop_elements(); |
update_loop_elements(); |
932 |
VCFEnabled_toggled(); |
VCFEnabled_toggled(); |
941 |
eVCFVelocityCurve.set_sensitive(sensitive); |
eVCFVelocityCurve.set_sensitive(sensitive); |
942 |
eVCFVelocityScale.set_sensitive(sensitive); |
eVCFVelocityScale.set_sensitive(sensitive); |
943 |
eVCFVelocityDynamicRange.set_sensitive(sensitive); |
eVCFVelocityDynamicRange.set_sensitive(sensitive); |
944 |
|
cutoff_curve.set_sensitive(sensitive); |
945 |
eVCFResonance.set_sensitive(sensitive); |
eVCFResonance.set_sensitive(sensitive); |
946 |
eVCFResonanceController.set_sensitive(sensitive); |
eVCFResonanceController.set_sensitive(sensitive); |
947 |
eVCFKeyboardTracking.set_sensitive(sensitive); |
eVCFKeyboardTracking.set_sensitive(sensitive); |
1034 |
eCrossfade_in_end.set_sensitive(hasController); |
eCrossfade_in_end.set_sensitive(hasController); |
1035 |
eCrossfade_out_start.set_sensitive(hasController); |
eCrossfade_out_start.set_sensitive(hasController); |
1036 |
eCrossfade_out_end.set_sensitive(hasController); |
eCrossfade_out_end.set_sensitive(hasController); |
1037 |
|
crossfade_curve.set_sensitive(hasController); |
1038 |
} |
} |
1039 |
|
|
1040 |
void DimRegionEdit::LFO1Controller_changed() |
void DimRegionEdit::LFO1Controller_changed() |
1148 |
update_model--; |
update_model--; |
1149 |
} |
} |
1150 |
|
|
1151 |
bool DimRegionEdit::set_sample(gig::Sample* sample) |
bool DimRegionEdit::set_sample(gig::Sample* sample, bool copy_sample_unity, bool copy_sample_tune, bool copy_sample_loop) |
1152 |
{ |
{ |
1153 |
if (dimregion) { |
if (dimregion) { |
1154 |
//TODO: we should better move the code from MainWindow::on_sample_label_drop_drag_data_received() here |
//TODO: we should better move the code from MainWindow::on_sample_label_drop_drag_data_received() here |
1192 |
d[i]->pSample = sample; |
d[i]->pSample = sample; |
1193 |
|
|
1194 |
// copy sample information from Sample to DimensionRegion |
// copy sample information from Sample to DimensionRegion |
1195 |
|
if (copy_sample_unity) |
1196 |
d[i]->UnityNote = sample->MIDIUnityNote; |
d[i]->UnityNote = sample->MIDIUnityNote; |
1197 |
d[i]->FineTune = sample->FineTune; |
if (copy_sample_tune) |
1198 |
|
d[i]->FineTune = sample->FineTune; |
1199 |
int loops = sample->Loops ? 1 : 0; |
if (copy_sample_loop) { |
1200 |
while (d[i]->SampleLoops > loops) { |
int loops = sample->Loops ? 1 : 0; |
1201 |
d[i]->DeleteSampleLoop(&d[i]->pSampleLoops[0]); |
while (d[i]->SampleLoops > loops) { |
1202 |
} |
d[i]->DeleteSampleLoop(&d[i]->pSampleLoops[0]); |
1203 |
while (d[i]->SampleLoops < sample->Loops) { |
} |
1204 |
DLS::sample_loop_t loop; |
while (d[i]->SampleLoops < sample->Loops) { |
1205 |
d[i]->AddSampleLoop(&loop); |
DLS::sample_loop_t loop; |
1206 |
} |
d[i]->AddSampleLoop(&loop); |
1207 |
if (loops) { |
} |
1208 |
d[i]->pSampleLoops[0].Size = sizeof(DLS::sample_loop_t); |
if (loops) { |
1209 |
d[i]->pSampleLoops[0].LoopType = sample->LoopType; |
d[i]->pSampleLoops[0].Size = sizeof(DLS::sample_loop_t); |
1210 |
d[i]->pSampleLoops[0].LoopStart = sample->LoopStart; |
d[i]->pSampleLoops[0].LoopType = sample->LoopType; |
1211 |
d[i]->pSampleLoops[0].LoopLength = sample->LoopEnd - sample->LoopStart + 1; |
d[i]->pSampleLoops[0].LoopStart = sample->LoopStart; |
1212 |
|
d[i]->pSampleLoops[0].LoopLength = sample->LoopEnd - sample->LoopStart + 1; |
1213 |
|
} |
1214 |
} |
} |
1215 |
} |
} |
1216 |
|
|
1217 |
// update ui |
// update ui |
1218 |
update_model++; |
update_model++; |
1219 |
wSample->set_text(dimregion->pSample->pInfo->Name); |
wSample->set_text(gig_to_utf8(dimregion->pSample->pInfo->Name)); |
1220 |
eUnityNote.set_value(dimregion->UnityNote); |
eUnityNote.set_value(dimregion->UnityNote); |
1221 |
eFineTune.set_value(dimregion->FineTune); |
eFineTune.set_value(dimregion->FineTune); |
1222 |
eSampleLoopEnabled.set_value(dimregion->SampleLoops); |
eSampleLoopEnabled.set_value(dimregion->SampleLoops); |