merged with 1697 revision of trunk (which is post-rc1 but pre-rc2
[ardour.git] / libs / surfaces / tranzport / state.cc
1 /*
2  *   Copyright (C) 2006 Paul Davis 
3  *   Copyright (C) 2007 Michael Taht
4  *
5  *   This program is free software; you can redistribute it and/or modify
6  *   it under the terms of the GNU General Public License as published by
7  *   the Free Software Foundation; either version 2 of the License, or
8  *   (at your option) any later version.
9  *
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.
14  *
15  *   You should have received a copy of the GNU General Public License
16  *   along with this program; if not, write to the Free Software
17  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  *  
19  */
20
21 #include <iostream>
22 #include <algorithm>
23 #include <cmath>
24
25 #define __STDC_FORMAT_MACROS
26 #include <inttypes.h>
27 #include <float.h>
28 #include <sys/time.h>
29 #include <errno.h>
30 #include <ardour/route.h>
31 #include <ardour/audio_track.h>
32 #include <ardour/session.h>
33 #include <ardour/location.h>
34 #include <ardour/dB.h>
35
36 using namespace ARDOUR;
37 using namespace std;
38 using namespace sigc;
39 using namespace PBD;
40
41 #include "i18n.h"
42
43 #include <pbd/abstract_ui.cc>
44
45 #include "tranzport_control_protocol.h"
46
47
48 // FIXME: How to handle multiple tranzports in a system?
49
50 XMLNode&
51 TranzportControlProtocol::get_state () 
52 {
53         XMLNode* node = new XMLNode (X_("Protocol"));
54         node->add_property (X_("name"), _name);
55         return *node;
56 }
57
58 int
59 TranzportControlProtocol::set_state (const XMLNode& node)
60 {
61         cout << "TranzportControlProtocol::set_state: active " << _active << endl;
62         int retval = 0;
63
64 // I think I want to make these strings rather than numbers
65 #if 0           
66         // fetch current display mode
67         if ( node.property( X_("display_mode") ) != 0 )
68         {
69                 string display = node.property( X_("display_mode") )->value();
70                 try
71                 {
72                         set_active( true );
73                         int32_t new_display = atoi( display.c_str() );
74                         if ( display_mode != new_display ) display_mode = (DisplayMode)new_display;
75                 }
76                 catch ( exception & e )
77                 {
78                         cout << "exception in TranzportControlProtocol::set_state: " << e.what() << endl;
79                         return -1;
80                 }
81         }
82
83         if ( node.property( X_("wheel_mode") ) != 0 )
84         {
85                 string wheel = node.property( X_("wheel_mode") )->value();
86                 try
87                 {
88                         int32_t new_wheel = atoi( wheel.c_str() );
89                         if ( wheel_mode != new_wheel ) wheel_mode = (WheelMode) new_wheel;
90                 }
91                 catch ( exception & e )
92                 {
93                         cout << "exception in TranzportControlProtocol::set_state: " << e.what() << endl;
94                         return -1;
95                 }
96         }
97
98         // fetch current bling mode
99         if ( node.property( X_("bling") ) != 0 )
100         {
101                 string bling = node.property( X_("bling_mode") )->value();
102                 try
103                 {
104                         int32_t new_bling = atoi( bling.c_str() );
105                         if ( bling_mode != new_bling ) bling_mode = (BlingMode) new_bling;
106                 }
107                 catch ( exception & e )
108                 {
109                         cout << "exception in TranzportControlProtocol::set_state: " << e.what() << endl;
110                         return -1;
111                 }
112         }
113 #endif 
114
115         return retval;
116
117 }
118
119 // These are intended for the day we have more options for tranzport modes
120 // And perhaps we could load up sessions this way, too
121
122 int
123 TranzportControlProtocol::save (char *name) 
124 {
125         // Presently unimplemented
126         return 0;
127 }
128
129 int
130 TranzportControlProtocol::load (char *name) 
131 {
132         // Presently unimplemented
133         return 0;
134 }
135
136 int
137 TranzportControlProtocol::save_config (char *name) 
138 {
139         // Presently unimplemented
140         return 0;
141 }
142
143 int
144 TranzportControlProtocol::load_config (char *name) 
145 {
146         // Presently unimplemented
147         return 0;
148 }