summaryrefslogtreecommitdiff
path: root/libs/ardour/presentation_info.cc
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2016-05-16 07:30:28 -0400
committerPaul Davis <paul@linuxaudiosystems.com>2016-05-31 15:30:42 -0400
commite0ff70cf86c01c42f98faf8b0eaf1a8ccf867946 (patch)
treedcb5ac7037e3b41d850930ea0a1759d79f8ca82a /libs/ardour/presentation_info.cc
parentbae9474e9f04e324b1a2776b0fa9faefb5e6f0c2 (diff)
first vaguely working version using PresentationInfo
remote control ID and "order keys" have been removed.
Diffstat (limited to 'libs/ardour/presentation_info.cc')
-rw-r--r--libs/ardour/presentation_info.cc121
1 files changed, 121 insertions, 0 deletions
diff --git a/libs/ardour/presentation_info.cc b/libs/ardour/presentation_info.cc
new file mode 100644
index 0000000000..6ec45a7d04
--- /dev/null
+++ b/libs/ardour/presentation_info.cc
@@ -0,0 +1,121 @@
+/*
+ Copyright (C) 2016 Paul Davis
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include <sstream>
+#include <typeinfo>
+
+#include <cassert>
+
+#include "pbd/enumwriter.h"
+#include "pbd/error.h"
+#include "pbd/failed_constructor.h"
+#include "pbd/xml++.h"
+
+#include "ardour/presentation_info.h"
+
+#include "i18n.h"
+
+using namespace ARDOUR;
+using namespace PBD;
+using std::string;
+
+const PresentationInfo::order_t PresentationInfo::max_order = UINT32_MAX;
+const PresentationInfo::Flag PresentationInfo::Bus = PresentationInfo::Flag (PresentationInfo::AudioBus|PresentationInfo::MidiBus);
+const PresentationInfo::Flag PresentationInfo::Track = PresentationInfo::Flag (PresentationInfo::AudioTrack|PresentationInfo::MidiTrack);
+const PresentationInfo::Flag PresentationInfo::Route = PresentationInfo::Flag (PresentationInfo::Bus|PresentationInfo::Track);
+
+PresentationInfo::PresentationInfo (std::string const & str)
+{
+ if (parse (str)) {
+ throw failed_constructor ();
+ }
+}
+
+int
+PresentationInfo::parse (string const& str)
+{
+ std::stringstream s (str);
+
+ /* new school, segmented string "NNN:TYPE" */
+ string f;
+ char c;
+ s >> _order;
+ /* skip colon */
+ s >> c;
+ /* grab flags */
+ s >> f;
+ _flags = Flag (string_2_enum (f, _flags)|GroupOrderSet);
+ std::cerr << "Parsed [" << str << "] as " << _order << " + " << enum_2_string (_flags) << std::endl;
+ return 0;
+}
+
+int
+PresentationInfo::parse (uint32_t n, Flag f)
+{
+ if (n < UINT16_MAX) {
+ assert (f != Flag (0));
+ _order = n;
+ _flags = Flag (f|GroupOrderSet);
+ } else {
+ _order = (n & 0xffff);
+ _flags = Flag ((n >> 16)|GroupOrderSet);
+ }
+
+ return 0;
+}
+
+std::string
+PresentationInfo::to_string() const
+{
+ std::stringstream ss;
+
+ /* Do not save or selected hidden status, or group-order set bit */
+
+ Flag f = Flag (_flags & ~(Hidden|Selected|GroupOrderSet));
+
+ ss << _order << ':' << enum_2_string (f);
+
+ return ss.str();
+}
+
+PresentationInfo::Flag
+PresentationInfo::get_flags (XMLNode const& node)
+{
+ const XMLProperty *prop;
+ XMLNodeList nlist = node.children ();
+ XMLNodeConstIterator niter;
+ XMLNode *child;
+
+ for (niter = nlist.begin(); niter != nlist.end(); ++niter){
+ child = *niter;
+
+ if (child->name() == X_("PresentationInfo")) {
+ if ((prop = child->property (X_("value"))) != 0) {
+ PresentationInfo pi (prop->value());
+ return pi.flags ();
+ }
+ }
+ }
+ return Flag (0);
+}
+
+std::ostream&
+operator<<(std::ostream& o, ARDOUR::PresentationInfo const& rid)
+{
+ return o << rid.to_string ();
+}