-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautomationtrack.cpp
More file actions
executable file
·154 lines (124 loc) · 3.74 KB
/
automationtrack.cpp
File metadata and controls
executable file
·154 lines (124 loc) · 3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#include "automationtrack.hpp"
#include <sstream>
// To Convert Floats to STR. Used to display the Value of the Widget on the widget.
std::string floatToStr (float number)
{
std::ostringstream buff;
buff<<number;
return buff.str();
}
int strToInt(std::string string)
{
std::istringstream buffer(string);
int output;
buffer >> output;
return output;
}
AutomationTrack::AutomationTrack()
{
midiCC = 10;
midiChannel = 0;
//Load the widget from Glade file and instiate its widgets
Glib::RefPtr<Gtk::Builder> refBuilder = Gtk::Builder::create();
std::string gladeFile = "automate.glade";
try
{
refBuilder->add_from_file(gladeFile);
}
catch(const Glib::FileError& ex)
{
std::cerr << "FileError: " << ex.what() << std::endl;
std::cout << "\nAutoMate has encountered an error. It seems that" << std::endl;
std::cout << "automate.glade, cannot be found in its usual place." << std::endl;
std::cout << "AutoMate cannot continue without this file. Sorry..." << std::endl;
exit(1);
}
catch(const Gtk::BuilderError& ex)
{
std::cerr << "BuilderError: " << ex.what() << std::endl;
std::cout << "\nLuppp has encountered an error. It seems that" << std::endl;
std::cout << "mainwindow.glade, cannot be found in its usual place." << std::endl;
std::cout << "Luppp cannot continue without this file. Sorry..." << std::endl;
exit(1);
}
refBuilder->get_widget("widgetBox", box);
refBuilder->get_widget("leftBox" , leftBox);
refBuilder->get_widget("activate" , toggleButton);
leftBox->add(channel);
leftBox->add(cc);
for (int i = 0; i < 16; i++)
channel.append_text( floatToStr(i) );
cc.append_text( "1"); // mod wheel
cc.append_text( "2"); // breath
cc.append_text( "7"); // vol
cc.append_text( "10"); // pan
cc.append_text( "64"); // sustain pedal
cc.append_text( "71"); // resonance (timbre)
cc.append_text( "74"); // Cutoff freq
cc.append_text( "91"); // reverb
cc.append_text( "93"); // Chorus
box->add( widget );
box->show_all();
entry = cc.get_entry(); // gets the entry buffer, we connect to it below
channel.signal_changed().connect( sigc::mem_fun(*this, &AutomationTrack::on_channel_changed ));
entry->signal_changed().connect( sigc::mem_fun(*this, &AutomationTrack::on_cc_changed ));
}
void AutomationTrack::on_channel_changed()
{
std::cout << "Channel changed: " << midiChannel << std::endl;
midiChannel = channel.get_active_row_number();
}
void AutomationTrack::on_cc_changed()
{
std::string string = cc.get_entry()->get_text(); //cc.get_active_row_number();
if (string != "")
{
midiCC = strToInt(string);
std::cout << "CC changed: " << midiCC << std::endl;
}
}
AutomationTrack::~AutomationTrack()
{
}
bool AutomationTrack::setTime(jack_transport_state_t inTransport , jack_position_t inPos)
{
pos = inPos;
transport = inTransport;
// gotta sort out the length of the automation loop, beats bars,
// current frame & beat bar tick. Finally send a float to update_time
if (transport & JackTransportRolling)
{
time = ((pos.beat-1) + (pos.tick / pos.ticks_per_beat)) / 4.0;
// here we pass a float value 0 = begin, 1 = end
widget.update_time( time );
}
return true;
}
float AutomationTrack::getValue()
{
//std::cout << "AutomationTrack::getValue();" << std::endl;
if (transport & JackTransportRolling)
return widget.getValue();
}
int AutomationTrack::getCC()
{
return midiCC;
}
int AutomationTrack::getChannel()
{
return midiChannel;
}
int AutomationTrack::getActive()
{
return toggleButton->get_active();
}
void AutomationTrack::setChannel(int inChannel)
{
std::cout << "AutomationTrack::setChannel("<<inChannel<<");" << std::endl;
midiChannel = inChannel;
}
void AutomationTrack::setCC(int inCC)
{
std::cout << "AutomationTrack::setCC("<<inCC<<");" << std::endl;
midiCC = inCC;
}