~ubuntu-branches/ubuntu/utopic/ardour3/utopic

« back to all changes in this revision

Viewing changes to libs/pbd/controllable_descriptor.cc

  • Committer: Package Import Robot
  • Author(s): Felipe Sateler
  • Date: 2013-09-21 19:05:02 UTC
  • Revision ID: package-import@ubuntu.com-20130921190502-8gsftrku6jnzhd7v
Tags: upstream-3.4~dfsg
ImportĀ upstreamĀ versionĀ 3.4~dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (C) 2009 Paul Davis 
 
3
 
 
4
    This program is free software; you can redistribute it and/or modify
 
5
    it under the terms of the GNU General Public License as published by
 
6
    the Free Software Foundation; either version 2 of the License, or
 
7
    (at your option) any later version.
 
8
 
 
9
    This program is distributed in the hope that it will be useful,
 
10
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
    GNU General Public License for more details.
 
13
 
 
14
    You should have received a copy of the GNU General Public License
 
15
    along with this program; if not, write to the Free Software
 
16
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
17
*/
 
18
 
 
19
#include "pbd/controllable_descriptor.h"
 
20
#include "pbd/strsplit.h"
 
21
#include "pbd/convert.h"
 
22
 
 
23
using namespace std;
 
24
using namespace PBD;
 
25
 
 
26
int
 
27
ControllableDescriptor::set (const std::string& str)
 
28
{
 
29
        string::size_type first_space = str.find_first_of (" ");
 
30
 
 
31
        if (first_space == string::npos) {
 
32
                return -1;
 
33
        }
 
34
 
 
35
        string front = str.substr (0, first_space);
 
36
        string back = str.substr (first_space);
 
37
 
 
38
        vector<string> path;    
 
39
        split (front, path, '/');
 
40
 
 
41
        if (path.size() < 2) {
 
42
                return -1;
 
43
        }
 
44
 
 
45
        vector<string> rest;    
 
46
        split (back, rest, ' ');
 
47
 
 
48
        if (rest.size() < 1) {
 
49
                return -1;
 
50
        }
 
51
 
 
52
        if (path[0] == "route" || path[0] == "rid") {
 
53
 
 
54
                _top_level_type = RemoteControlID;
 
55
 
 
56
                if (rest[0][0] == 'B') {
 
57
                        _banked = true;
 
58
                        _rid = atoi (rest[0].substr (1));
 
59
                } else if (isdigit (rest[0][0])) {
 
60
                        _banked = false;
 
61
                        _rid = atoi (rest[0]);
 
62
                } else {
 
63
                        return -1;
 
64
                }
 
65
 
 
66
        } else if (path[0] == "bus" || path[0] == "track") {
 
67
 
 
68
                _top_level_type = NamedRoute;
 
69
                _top_level_name = rest[0];
 
70
        }
 
71
 
 
72
        if (path[1] == "gain") {
 
73
                _subtype = Gain;
 
74
 
 
75
        } else if (path[1] == "solo") {
 
76
                _subtype = Solo;
 
77
 
 
78
        } else if (path[1] == "mute") {
 
79
                _subtype = Mute;
 
80
 
 
81
        } else if (path[1] == "recenable") {
 
82
                _subtype = Recenable;
 
83
 
 
84
        } else if (path[1] == "balance") {
 
85
                _subtype = Balance;
 
86
 
 
87
        } else if (path[1] == "panwidth") {
 
88
                _subtype = PanWidth;
 
89
 
 
90
        } else if (path[1] == "pandirection") {
 
91
                _subtype = PanDirection;
 
92
 
 
93
        } else if (path[1] == "plugin") {
 
94
                if (path.size() == 3 && rest.size() == 3) {
 
95
                        if (path[2] == "parameter") {
 
96
                                _subtype = PluginParameter;
 
97
                                _target.push_back (atoi (rest[1]));
 
98
                                _target.push_back (atoi (rest[2]));
 
99
                        } else {
 
100
                                return -1;
 
101
                        }
 
102
                } else {
 
103
                        return -1;
 
104
                }
 
105
        } else if (path[1] == "send") {
 
106
                
 
107
                if (path.size() == 3 && rest.size() == 3) {
 
108
                        if (path[2] == "gain") {
 
109
                                _subtype = SendGain;
 
110
                                _target.push_back (atoi (rest[1]));
 
111
                                _target.push_back (atoi (rest[2]));
 
112
                        } else {
 
113
                                return -1;
 
114
                        }
 
115
                } else {
 
116
                        return -1;
 
117
                }
 
118
        }
 
119
        
 
120
        return 0;
 
121
}
 
122
 
 
123
uint32_t
 
124
ControllableDescriptor::rid() const
 
125
{
 
126
        if (banked()) {
 
127
                return _rid + _bank_offset;
 
128
        }               
 
129
 
 
130
        return _rid;
 
131
}
 
132
 
 
133
uint32_t
 
134
ControllableDescriptor::target (uint32_t n) const
 
135
{
 
136
        if (n < _target.size()) {
 
137
                return _target[n];
 
138
        } 
 
139
        
 
140
        return 0;
 
141
}