#include <algorithm>
#include <cmath>
+#define __STDC_FORMAT_MACROS
+#include <inttypes.h>
#include <float.h>
#include <sys/time.h>
#include <errno.h>
using namespace ARDOUR;
using namespace std;
using namespace sigc;
+using namespace PBD;
#include "i18n.h"
TranzportControlProtocol::TranzportControlProtocol (Session& s)
- : ControlProtocol (s, X_("Tranzport")),
- AbstractUI<TranzportRequest> (X_("Tranzport"), false)
-
+ : ControlProtocol (s, X_("Tranzport"))
{
+ /* tranzport controls one track at a time */
+
+ set_route_table_size (1);
+
timeout = 60000;
buttonmask = 0;
_datawheel = 0;
_device_status = STATUS_OFFLINE;
udev = 0;
- current_route = 0;
current_track_id = 0;
last_where = max_frames;
wheel_mode = WheelTimeline;
set_active (false);
}
+bool
+TranzportControlProtocol::probe ()
+{
+ struct usb_bus *bus;
+ struct usb_device *dev;
+
+ usb_init();
+ usb_find_busses();
+ usb_find_devices();
+
+ for (bus = usb_busses; bus; bus = bus->next) {
+
+ for(dev = bus->devices; dev; dev = dev->next) {
+ if (dev->descriptor.idVendor == VENDORID && dev->descriptor.idProduct == PRODUCTID) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
+
int
TranzportControlProtocol::set_active (bool yn)
{
void
TranzportControlProtocol::show_track_gain ()
{
- if (current_route) {
- gain_t g = current_route->gain();
+ if (route_table[0]) {
+ gain_t g = route_get_gain (0);
if (g != last_track_gain) {
char buf[16];
- snprintf (buf, sizeof (buf), "%6.1fdB", coefficient_to_dB (current_route->effective_gain()));
+ snprintf (buf, sizeof (buf), "%6.1fdB", coefficient_to_dB (route_get_effective_gain (0)));
print (0, 9, buf);
last_track_gain = g;
}
void
TranzportControlProtocol::show_meter ()
{
- if (current_route == 0) {
+ if (route_table[0] == 0) {
return;
}
- float level = current_route->peak_input_power (0);
+ float level = route_get_peak_input_power (0, 0);
float fraction = log_meter (level);
/* we draw using a choice of a sort of double colon-like character ("::") or a single, left-aligned ":".
void
TranzportControlProtocol::show_transport_time ()
{
- jack_nframes_t where = session.transport_frame();
+ jack_nframes_t where = session->transport_frame();
if (where != last_where) {
char buf[5];
- SMPTE_Time smpte;
+ SMPTE::Time smpte;
- session.smpte_time (where, smpte);
+ session->smpte_time (where, smpte);
if (smpte.negative) {
- sprintf (buf, "-%02ld:", smpte.hours);
+ sprintf (buf, "-%02" PRIu32 ":", smpte.hours);
} else {
- sprintf (buf, " %02ld:", smpte.hours);
+ sprintf (buf, " %02" PRIu32 ":", smpte.hours);
}
print (1, 8, buf);
- sprintf (buf, "%02ld:", smpte.minutes);
+ sprintf (buf, "%02" PRIu32 ":", smpte.minutes);
print (1, 12, buf);
- sprintf (buf, "%02ld:", smpte.seconds);
+ sprintf (buf, "%02" PRIu32 ":", smpte.seconds);
print (1, 15, buf);
- sprintf (buf, "%02ld", smpte.frames);
+ sprintf (buf, "%02" PRIu32, smpte.frames);
print (1, 18, buf);
last_where = where;
}
if (usb_set_configuration (udev, 1) < 0) {
- error << _("Tranzport: cannot configure USB interface") << endmsg;
- usb_close (udev);
- udev = 0;
- return -1;
+ cerr << _("Tranzport: cannot configure USB interface") << endmsg;
}
return 0;
if ((err = pthread_setschedparam (pthread_self(), SCHED_FIFO, &rtparam)) != 0) {
// do we care? not particularly.
- info << string_compose (_("%1: thread not running with realtime scheduling (%2)"), BaseUI::name(), strerror (errno)) << endmsg;
+ PBD::info << string_compose (_("%1: thread not running with realtime scheduling (%2)"), name(), strerror (errno)) << endmsg;
}
pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, 0);
val = usb_interrupt_read (udev, READ_ENDPOINT, (char*) buf, 8, 10);
pthread_testcancel();
- /* any requests to handle? */
-
- handle_ui_requests ();
-
if (val == 8) {
process (buf);
}
/* per track */
- if (current_route) {
- AudioTrack* at = dynamic_cast<AudioTrack*> (current_route);
+ if (route_table[0]) {
+ boost::shared_ptr<AudioTrack> at = boost::dynamic_pointer_cast<AudioTrack> (route_table[0]);
if (at && at->record_enabled()) {
pending_lights[LightTrackrec] = true;
} else {
pending_lights[LightTrackrec] = false;
}
- if (current_route->muted()) {
+ if (route_get_muted (0)) {
pending_lights[LightTrackmute] = true;
} else {
pending_lights[LightTrackmute] = false;
}
- if (current_route->soloed()) {
+ if (route_get_soloed (0)) {
pending_lights[LightTracksolo] = true;
} else {
pending_lights[LightTracksolo] = false;
/* global */
- if (session.get_auto_loop()) {
+ if (session->get_auto_loop()) {
pending_lights[LightLoop] = true;
} else {
pending_lights[LightLoop] = false;
}
- if (session.get_punch_in() || session.get_punch_out()) {
+ if (session->get_punch_in() || session->get_punch_out()) {
pending_lights[LightPunch] = true;
} else {
pending_lights[LightPunch] = false;
}
- if (session.get_record_enabled()) {
+ if (session->get_record_enabled()) {
pending_lights[LightRecord] = true;
} else {
pending_lights[LightRecord] = false;
}
- if (session.soloing ()) {
+ if (session->soloing ()) {
pending_lights[LightAnysolo] = true;
} else {
pending_lights[LightAnysolo] = false;
void
TranzportControlProtocol::show_current_track ()
{
- if (current_route == 0) {
+ if (route_table[0] == 0) {
print (0, 0, "--------");
} else {
- print (0, 0, current_route->name().substr (0, 8).c_str());
+ print (0, 0, route_get_name (0).substr (0, 8).c_str());
}
}
if (shifted) {
toggle_all_rec_enables ();
} else {
- if (current_route) {
- AudioTrack* at = dynamic_cast<AudioTrack*>(current_route);
- at->set_record_enable (!at->record_enabled(), this);
- }
+ route_set_rec_enable (0, !route_get_rec_enable (0));
}
}
void
TranzportControlProtocol::button_event_trackmute_press (bool shifted)
{
- if (current_route) {
- current_route->set_mute (!current_route->muted(), this);
- }
+ route_set_muted (0, !route_get_muted (0));
}
void
}
if (shifted) {
- session.set_all_solo (!session.soloing());
+ session->set_all_solo (!session->soloing());
} else {
- if (current_route) {
- current_route->set_solo (!current_route->soloed(), this);
- }
+ route_set_soloed (0, !route_get_soloed (0));
}
}
/* parameter control */
- if (current_route) {
+ if (route_table[0]) {
switch (wheel_shift_mode) {
case WheelShiftGain:
if (_datawheel < WheelDirectionThreshold) {
last_wheel_motion = now;
last_wheel_dir = dir;
- move_at (speed * dir);
+ set_transport_speed (speed * dir);
}
void
TranzportControlProtocol::shuttle ()
{
if (_datawheel < WheelDirectionThreshold) {
- if (session.transport_speed() < 0) {
- session.request_transport_speed (1.0);
+ if (session->transport_speed() < 0) {
+ session->request_transport_speed (1.0);
} else {
- session.request_transport_speed (session.transport_speed() + 0.1);
+ session->request_transport_speed (session->transport_speed() + 0.1);
}
} else {
- if (session.transport_speed() > 0) {
- session.request_transport_speed (-1.0);
+ if (session->transport_speed() > 0) {
+ session->request_transport_speed (-1.0);
} else {
- session.request_transport_speed (session.transport_speed() - 0.1);
+ session->request_transport_speed (session->transport_speed() - 0.1);
}
}
}
gain_fraction = 2.0;
}
- current_route->set_gain (slider_position_to_gain (gain_fraction), this);
+ route_set_gain (0, slider_position_to_gain (gain_fraction));
}
void
gain_fraction = 0.0;
}
- current_route->set_gain (slider_position_to_gain (gain_fraction), this);
+ route_set_gain (0, slider_position_to_gain (gain_fraction));
}
void
void
TranzportControlProtocol::next_track ()
{
- uint32_t limit = session.nroutes();
- uint32_t start = current_track_id;
- Route* cr = current_route;
-
- if (current_track_id == limit) {
- current_track_id = 0;
- } else {
- current_track_id++;
- }
-
- while (current_track_id < limit) {
- if ((cr = session.route_by_remote_id (current_track_id)) != 0) {
- break;
- }
- current_track_id++;
- }
-
- if (current_track_id == limit) {
- current_track_id = 0;
- while (current_track_id != start) {
- if ((cr = session.route_by_remote_id (current_track_id)) != 0) {
- break;
- }
- current_track_id++;
- }
- }
-
- current_route = cr;
- gain_fraction = gain_to_slider_position (current_route->effective_gain());
+ ControlProtocol::next_track (current_track_id);
+ gain_fraction = gain_to_slider_position (route_get_effective_gain (0));
}
void
TranzportControlProtocol::prev_track ()
{
- uint32_t limit = session.nroutes() - 1;
- uint32_t start = current_track_id;
- Route* cr = current_route;
-
- if (current_track_id == 0) {
- current_track_id = session.nroutes() - 1;
- } else {
- current_track_id--;
- }
-
- while (current_track_id >= 0) {
- if ((cr = session.route_by_remote_id (current_track_id)) != 0) {
- break;
- }
- current_track_id--;
- }
-
- if (current_track_id < 0) {
- current_track_id = limit;
- while (current_track_id > start) {
- if ((cr = session.route_by_remote_id (current_track_id)) != 0) {
- break;
- }
- current_track_id--;
- }
- }
-
- current_route = cr;
- gain_fraction = gain_to_slider_position (current_route->effective_gain());
-}
-
-void
-TranzportControlProtocol::set_current_track (Route* r)
-{
- TranzportRequest* req = get_request (SetCurrentTrack);
-
- if (req == 0) {
- return;
- }
-
- req->track = r;
-
- send_request (req);
+ ControlProtocol::prev_track (current_track_id);
+ gain_fraction = gain_to_slider_position (route_get_effective_gain (0));
}
void
}
}
-bool
-TranzportControlProtocol::caller_is_ui_thread ()
+XMLNode&
+TranzportControlProtocol::get_state ()
{
- return (pthread_self() == thread);
+ XMLNode* node = new XMLNode (_name); /* node name must match protocol name */
+ return *node;
}
-void
-TranzportControlProtocol::do_request (TranzportRequest* req)
+int
+TranzportControlProtocol::set_state (const XMLNode& node)
{
- if (req->type == SetCurrentTrack) {
- current_route = req->track;
- }
-
- return;
+ return 0;
}