13
0

finish use of EnumWriter for saving flags etc. throughout the session file

git-svn-id: svn://localhost/ardour2/trunk@1259 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Paul Davis 2007-01-02 17:36:38 +00:00
parent b529cbc5dc
commit 8fabcf4f76
21 changed files with 160 additions and 115 deletions

View File

@ -121,6 +121,7 @@
; (gtk_accel_path "<Actions>/Editor/EditSelectRegionOptions" "")
(gtk_accel_path "<Actions>/Editor/crop" "c")
; (gtk_accel_path "<Actions>/redirectmenu/newsend" "")
; (gtk_accel_path "<Actions>/Editor/ToggleGeneric MIDISurfaceSubMenu" "")
; (gtk_accel_path "<Actions>/Editor/MeterFalloff" "")
; (gtk_accel_path "<Actions>/RegionList/rlRemove" "")
(gtk_accel_path "<Actions>/Transport/GotoStart" "Home")
@ -276,6 +277,7 @@
; (gtk_accel_path "<Actions>/Editor/Subframes80" "")
; (gtk_accel_path "<Actions>/options/FileHeaderFormatCAF" "")
(gtk_accel_path "<Actions>/Common/ToggleLocations" "<Alt>l")
; (gtk_accel_path "<Actions>/Editor/ToggleGeneric MIDISurface" "")
(gtk_accel_path "<Actions>/Editor/editor-delete" "Delete")
; (gtk_accel_path "<Actions>/JACK/JACKLatency256" "")
(gtk_accel_path "<Actions>/Editor/select-all-between-cursors" "u")
@ -298,6 +300,7 @@
; (gtk_accel_path "<Actions>/Snap/snap-to-region-sync" "")
(gtk_accel_path "<Actions>/Editor/edit-cursor-to-previous-region-sync" "apostrophe")
; (gtk_accel_path "<Actions>/redirectmenu/clear" "")
; (gtk_accel_path "<Actions>/Editor/ToggleGeneric MIDISurfaceFeedback" "")
; (gtk_accel_path "<Actions>/Editor/PullupPlus4Minus1" "")
; (gtk_accel_path "<Actions>/JACK/JACKLatency512" "")
(gtk_accel_path "<Actions>/Editor/edit-cursor-to-next-region-end" "<Control>bracketright")

View File

@ -76,8 +76,8 @@ class IO;
virtual float playback_buffer_load() const = 0;
virtual float capture_buffer_load() const = 0;
void set_flag (Flag f) { _flags |= f; }
void unset_flag (Flag f) { _flags &= ~f; }
void set_flag (Flag f) { _flags = Flag (_flags | f); }
void unset_flag (Flag f) { _flags = Flag (_flags & ~f); }
AlignStyle alignment_style() const { return _alignment_style; }
void set_align_style (AlignStyle);
@ -303,7 +303,7 @@ class IO;
sigc::connection plmod_connection;
sigc::connection plgone_connection;
unsigned char _flags;
Flag _flags;
};
}; /* namespace ARDOUR */

View File

@ -68,7 +68,7 @@ class Location : public PBD::StatefulDestructible
Location () {
_start = 0;
_end = 0;
_flags = 0;
_flags = Flags (0);
}
Location (const Location& other);
@ -124,7 +124,7 @@ class Location : public PBD::StatefulDestructible
string _name;
nframes_t _start;
nframes_t _end;
uint32_t _flags;
Flags _flags;
void set_mark (bool yn);
bool set_flag_internal (bool yn, Flags flag);

View File

@ -111,8 +111,6 @@ class Redirect : public IO
virtual void transport_stopped (nframes_t frame) {};
protected:
void set_placement (const string&, void *src);
/* children may use this stuff as they see fit */
map<uint32_t,AutomationList*> parameter_automation;

View File

@ -250,7 +250,7 @@ class Route : public IO
void curve_reallocate ();
protected:
unsigned char _flags;
Flag _flags;
/* tight cache-line access here is more important than sheer speed of
access.

View File

@ -115,7 +115,7 @@ class RouteGroup : public Stateful, public sigc::trackable {
Session& _session;
list<Route *> routes;
string _name;
uint32_t _flags;
Flag _flags;
void remove_when_going_away (Route*);
};

View File

@ -37,7 +37,6 @@ void elapsed_time_to_str (char *buf, uint32_t seconds);
Glib::ustring legalize_for_path (Glib::ustring str);
std::ostream& operator<< (std::ostream& o, const ARDOUR::BBT_Time& bbt);
XMLNode* find_named_node (const XMLNode& node, std::string name);
std::string placement_as_string (ARDOUR::Placement);
static inline float f_max(float x, float a) {
x -= a;

View File

@ -35,6 +35,7 @@
#include <glibmm/thread.h>
#include <pbd/xml++.h>
#include <pbd/memento_command.h>
#include <pbd/enumwriter.h>
#include <ardour/ardour.h>
#include <ardour/audioengine.h>
@ -1760,8 +1761,7 @@ AudioDiskstream::get_state ()
char buf[64] = "";
LocaleGuard lg (X_("POSIX"));
snprintf (buf, sizeof(buf), "0x%x", _flags);
node->add_property ("flags", buf);
node->add_property ("flags", enum_2_string (_flags));
snprintf (buf, sizeof(buf), "%zd", channels.size());
node->add_property ("channels", buf);
@ -1848,7 +1848,7 @@ AudioDiskstream::set_state (const XMLNode& node)
}
if ((prop = node.property ("flags")) != 0) {
_flags = strtol (prop->value().c_str(), 0, 0);
_flags = Flag (string_2_enum (prop->value(), _flags));
}
if ((prop = node.property ("channels")) != 0) {
@ -2258,10 +2258,10 @@ AudioDiskstream::set_destructive (bool yn)
if (!can_become_destructive (bounce_ignored)) {
return -1;
}
_flags |= Destructive;
_flags = Flag (_flags | Destructive);
use_destructive_playlist ();
} else {
_flags &= ~Destructive;
_flags = Flag (_flags & ~Destructive);
reset_write_sources (true, true);
}
}

View File

@ -17,11 +17,14 @@
$Id$
*/
#include <pbd/error.h>
#include <sigc++/retype.h>
#include <sigc++/retype_return.h>
#include <sigc++/bind.h>
#include <pbd/error.h>
#include <pbd/enumwriter.h>
#include <ardour/audio_track.h>
#include <ardour/audio_diskstream.h>
#include <ardour/session.h>
@ -236,14 +239,7 @@ AudioTrack::_set_state (const XMLNode& node, bool call_base)
}
if ((prop = node.property (X_("mode"))) != 0) {
if (prop->value() == X_("normal")) {
_mode = Normal;
} else if (prop->value() == X_("destructive")) {
_mode = Destructive;
} else {
warning << string_compose ("unknown audio track mode \"%1\" seen and ignored", prop->value()) << endmsg;
_mode = Normal;
}
_mode = TrackMode (string_2_enum (prop->value(), _mode));
} else {
_mode = Normal;
}
@ -312,8 +308,7 @@ AudioTrack::state(bool full_state)
freeze_node = new XMLNode (X_("freeze-info"));
freeze_node->add_property ("playlist", _freeze_record.playlist->name());
snprintf (buf, sizeof (buf), "%d", (int) _freeze_record.state);
freeze_node->add_property ("state", buf);
freeze_node->add_property ("state", enum_2_string (_freeze_record.state));
for (vector<FreezeRecordInsertInfo*>::iterator i = _freeze_record.insert_info.begin(); i != _freeze_record.insert_info.end(); ++i) {
inode = new XMLNode (X_("insert"));
@ -330,15 +325,8 @@ AudioTrack::state(bool full_state)
/* Alignment: act as a proxy for the diskstream */
XMLNode* align_node = new XMLNode (X_("alignment"));
switch (_diskstream->alignment_style()) {
case ExistingMaterial:
snprintf (buf, sizeof (buf), X_("existing"));
break;
case CaptureTime:
snprintf (buf, sizeof (buf), X_("capture"));
break;
}
align_node->add_property (X_("style"), buf);
AlignStyle as = _diskstream->alignment_style ();
align_node->add_property (X_("style"), enum_2_string (as));
root.add_child_nocopy (*align_node);
XMLNode* remote_control_node = new XMLNode (X_("remote_control"));
@ -346,14 +334,7 @@ AudioTrack::state(bool full_state)
remote_control_node->add_property (X_("id"), buf);
root.add_child_nocopy (*remote_control_node);
switch (_mode) {
case Normal:
root.add_property (X_("mode"), X_("normal"));
break;
case Destructive:
root.add_property (X_("mode"), X_("destructive"));
break;
}
root.add_property (X_("mode"), enum_2_string (_mode));
/* we don't return diskstream state because we don't
own the diskstream exclusively. control of the diskstream
@ -407,7 +388,7 @@ AudioTrack::set_state_part_two ()
}
if ((prop = fnode->property (X_("state"))) != 0) {
_freeze_record.state = (FreezeState) atoi (prop->value().c_str());
_freeze_record.state = FreezeState (string_2_enum (prop->value(), _freeze_record.state));
}
XMLNodeConstIterator citer;
@ -434,11 +415,21 @@ AudioTrack::set_state_part_two ()
if ((fnode = find_named_node (*pending_state, X_("alignment"))) != 0) {
if ((prop = fnode->property (X_("style"))) != 0) {
if (prop->value() == "existing") {
_diskstream->set_persistent_align_style (ExistingMaterial);
} else if (prop->value() == "capture") {
_diskstream->set_persistent_align_style (CaptureTime);
/* fix for older sessions from before EnumWriter */
string pstr;
if (prop->value() == "capture") {
pstr = "CaptureTime";
} else if (prop->value() == "existing") {
pstr = "ExistingMaterial";
} else {
pstr = prop->value();
}
AlignStyle as = AlignStyle (string_2_enum (pstr, as));
_diskstream->set_persistent_align_style (as);
}
}
return;

View File

@ -29,6 +29,7 @@
#include <pbd/pathscanner.h>
#include <pbd/stl_delete.h>
#include <pbd/strsplit.h>
#include <pbd/enumwriter.h>
#include <sndfile.h>
@ -194,9 +195,7 @@ XMLNode&
AudioFileSource::get_state ()
{
XMLNode& root (AudioSource::get_state());
char buf[16];
snprintf (buf, sizeof (buf), "0x%x", (int)_flags);
root.add_property ("flags", buf);
root.add_property ("flags", enum_2_string (_flags));
return root;
}
@ -211,9 +210,7 @@ AudioFileSource::set_state (const XMLNode& node)
if ((prop = node.property (X_("flags"))) != 0) {
int ival;
sscanf (prop->value().c_str(), "0x%x", &ival);
_flags = Flag (ival);
_flags = Flag (string_2_enum (prop->value(), _flags));
} else {

View File

@ -602,8 +602,6 @@ AudioRegion::state (bool full)
char buf2[64];
LocaleGuard lg (X_("POSIX"));
// snprintf (buf, sizeof (buf), "0x%x", (int) _flags);
// node.add_property ("flags", buf);
node.add_property ("flags", enum_2_string (_flags));
snprintf (buf, sizeof(buf), "%.12g", _scale_amplitude);

View File

@ -8,6 +8,7 @@
#include <ardour/audioregion.h>
#include <ardour/route_group.h>
#include <ardour/panner.h>
#include <ardour/track.h>
using namespace std;
using namespace PBD;
@ -20,7 +21,6 @@ setup_enum_writer ()
vector<int> i;
vector<string> s;
OverlapType _OverlapType;
AlignStyle _AlignStyle;
MeterPoint _MeterPoint;
@ -59,6 +59,7 @@ setup_enum_writer ()
Location::Flags _Location_Flags;
RouteGroup::Flag _RouteGroup_Flag;
Region::Flag _Region_Flag;
Track::FreezeState _Track_FreezeState;
#define REGISTER(e) enum_writer->register_distinct (typeid(e).name(), i, s); i.clear(); s.clear()
#define REGISTER_BITS(e) enum_writer->register_bits (typeid(e).name(), i, s); i.clear(); s.clear()
@ -317,5 +318,10 @@ setup_enum_writer ()
REGISTER_CLASS_ENUM (Region, Hidden);
REGISTER_CLASS_ENUM (Region, DoNotSaveState);
REGISTER_BITS (_Region_Flag);
REGISTER_CLASS_ENUM (Track, NoFreeze);
REGISTER_CLASS_ENUM (Track, Frozen);
REGISTER_CLASS_ENUM (Track, UnFrozen);
REGISTER (_Track_FreezeState);
}

View File

@ -28,6 +28,7 @@
#include <pbd/stl_delete.h>
#include <pbd/xml++.h>
#include <pbd/enumwriter.h>
#include <ardour/location.h>
#include <ardour/session.h>
@ -217,12 +218,12 @@ Location::set_flag_internal (bool yn, Flags flag)
{
if (yn) {
if (!(_flags & flag)) {
_flags |= flag;
_flags = Flags (_flags | flag);
return true;
}
} else {
if (_flags & flag) {
_flags &= ~flag;
_flags = Flags (_flags & ~flag);
return true;
}
}
@ -273,8 +274,7 @@ Location::get_state (void)
node->add_property ("start", buf);
snprintf (buf, sizeof (buf), "%u", end());
node->add_property ("end", buf);
snprintf (buf, sizeof (buf), "%" PRIu32, (uint32_t) _flags);
node->add_property ("flags", buf);
node->add_property ("flags", enum_2_string (_flags));
return *node;
}
@ -327,14 +327,12 @@ Location::set_state (const XMLNode& node)
_end = atoi (prop->value().c_str());
_flags = 0;
if ((prop = node.property ("flags")) == 0) {
error << _("XML node for Location has no flags information") << endmsg;
return -1;
}
_flags = Flags (atoi (prop->value().c_str()));
_flags = Flags (string_2_enum (prop->value(), _flags));
for (cd_iter = cd_list.begin(); cd_iter != cd_list.end(); ++cd_iter) {

View File

@ -33,6 +33,7 @@
#include <pbd/error.h>
#include <pbd/failed_constructor.h>
#include <pbd/xml++.h>
#include <pbd/enumwriter.h>
#include <ardour/session.h>
#include <ardour/panner.h>
@ -1055,8 +1056,7 @@ Panner::state (bool full)
char buf[32];
root->add_property (X_("linked"), (_linked ? "yes" : "no"));
snprintf (buf, sizeof (buf), "%d", _link_direction);
root->add_property (X_("link_direction"), buf);
root->add_property (X_("link_direction"), enum_2_string (_link_direction));
root->add_property (X_("bypassed"), (bypassed() ? "yes" : "no"));
/* add each output */
@ -1100,8 +1100,8 @@ Panner::set_state (const XMLNode& node)
}
if ((prop = node.property (X_("link_direction"))) != 0) {
sscanf (prop->value().c_str(), "%d", &i);
set_link_direction ((LinkDirection) (i));
LinkDirection ld; /* here to provide type information */
set_link_direction (LinkDirection (string_2_enum (prop->value(), ld)));
}
nlist = node.children();

View File

@ -28,6 +28,7 @@
#include <sigc++/bind.h>
#include <pbd/xml++.h>
#include <pbd/enumwriter.h>
#include <ardour/redirect.h>
#include <ardour/session.h>
@ -97,18 +98,6 @@ Redirect::set_placement (Placement p, void *src)
}
}
void
Redirect::set_placement (const string& str, void *src)
{
if (str == _("pre")) {
set_placement (PreFader, this);
} else if (str == _("post")) {
set_placement (PostFader, this);
} else {
error << string_compose(_("Redirect: unknown placement string \"%1\" (ignored)"), str) << endmsg;
}
}
/* NODE STRUCTURE
<Automation [optionally with visible="...." ]>
@ -195,7 +184,7 @@ Redirect::state (bool full_state)
stringstream sstr;
node->add_property("active", active() ? "yes" : "no");
node->add_property("placement", placement_as_string (placement()));
node->add_property("placement", enum_2_string (_placement));
node->add_child_nocopy (IO::state (full_state));
if (_extra_xml){
@ -295,7 +284,20 @@ Redirect::set_state (const XMLNode& node)
return -1;
}
set_placement (prop->value(), this);
/* hack to handle older sessions before we only used EnumWriter */
string pstr;
if (prop->value() == "pre") {
pstr = "PreFader";
} else if (prop->value() == "post") {
pstr = "PostFader";
} else {
pstr = prop->value();
}
Placement p = Placement (string_2_enum (pstr, p));
set_placement (p, this);
return 0;
}

View File

@ -768,7 +768,7 @@ Region::state (bool full_state)
snprintf (buf, sizeof (buf), "%d", (int) _layer);
node->add_property ("layer", buf);
snprintf (buf, sizeof (buf), "%u", _sync_position);
snprintf (buf, sizeof (buf), "%" PRIu32, _sync_position);
node->add_property ("sync-position", buf);
return *node;

View File

@ -24,6 +24,7 @@
#include <sigc++/bind.h>
#include <pbd/xml++.h>
#include <pbd/enumwriter.h>
#include <ardour/timestamps.h>
#include <ardour/buffer.h>
@ -1372,8 +1373,7 @@ Route::state(bool full_state)
char buf[32];
if (_flags) {
snprintf (buf, sizeof (buf), "0x%x", _flags);
node->add_property("flags", buf);
node->add_property("flags", enum_2_string (_flags));
}
node->add_property("default-type", _default_type.to_string());
@ -1533,9 +1533,7 @@ Route::_set_state (const XMLNode& node, bool call_base)
}
if ((prop = node.property (X_("flags"))) != 0) {
int x;
sscanf (prop->value().c_str(), "0x%x", &x);
_flags = Flag (x);
_flags = Flag (string_2_enum (prop->value(), _flags));
} else {
_flags = Flag (0);
}

View File

@ -26,6 +26,7 @@
#include <sigc++/bind.h>
#include <pbd/error.h>
#include <pbd/enumwriter.h>
#include <ardour/route_group.h>
#include <ardour/audio_track.h>
@ -125,11 +126,9 @@ RouteGroup::get_max_factor(gain_t factor)
XMLNode&
RouteGroup::get_state (void)
{
char buf[32];
XMLNode *node = new XMLNode ("RouteGroup");
node->add_property ("name", _name);
snprintf (buf, sizeof (buf), "%" PRIu32, (uint32_t) _flags);
node->add_property ("flags", buf);
node->add_property ("flags", enum_2_string (_flags));
return *node;
}
@ -143,7 +142,7 @@ RouteGroup::set_state (const XMLNode& node)
}
if ((prop = node.property ("flags")) != 0) {
_flags = atoi (prop->value().c_str());
_flags = Flag (string_2_enum (prop->value(), _flags));
}
return 0;
@ -157,9 +156,9 @@ RouteGroup::set_active (bool yn, void *src)
return;
}
if (yn) {
_flags |= Active;
_flags = Flag (_flags | Active);
} else {
_flags &= ~Active;
_flags = Flag (_flags & ~Active);
}
_session.set_dirty ();
FlagsChanged (src); /* EMIT SIGNAL */
@ -173,9 +172,9 @@ RouteGroup::set_relative (bool yn, void *src)
return;
}
if (yn) {
_flags |= Relative;
_flags = Flag (_flags | Relative);
} else {
_flags &= ~Relative;
_flags = Flag (_flags & ~Relative);
}
_session.set_dirty ();
FlagsChanged (src); /* EMIT SIGNAL */
@ -189,14 +188,14 @@ RouteGroup::set_hidden (bool yn, void *src)
return;
}
if (yn) {
_flags |= Hidden;
_flags = Flag (_flags | Hidden);
if (Config->get_hiding_groups_deactivates_groups()) {
_flags &= ~Active;
_flags = Flag (_flags & ~Active);
}
} else {
_flags &= ~Hidden;
_flags = Flag (_flags & ~Hidden);
if (Config->get_hiding_groups_deactivates_groups()) {
_flags |= Active;
_flags = Flag (_flags | Active);
}
}
_session.set_dirty ();

View File

@ -208,18 +208,6 @@ touch_file (ustring path)
return 1;
}
string
placement_as_string (Placement p)
{
switch (p) {
case PreFader:
return _("pre");
default: /* to get g++ to realize we have all the cases covered */
case PostFader:
return _("post");
}
}
ustring
region_name_from_path (ustring path, bool strip_channels)
{

View File

@ -18,6 +18,9 @@
$Id$
*/
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <pbd/enumwriter.h>
@ -30,6 +33,35 @@ using namespace PBD;
#include "i18n.h"
EnumWriter* EnumWriter::_instance = 0;
map<string,string> EnumWriter::hack_table;
static int
nocase_cmp(const string & s1, const string& s2)
{
string::const_iterator it1 = s1.begin();
string::const_iterator it2 = s2.begin();
while ((it1 != s1.end()) && (it2 != s2.end())) {
if(::toupper(*it1) != ::toupper(*it2)) {//letters differ?
// return -1 to indicate 'smaller than', 1 otherwise
return (::toupper(*it1) < ::toupper(*it2)) ? -1 : 1;
}
++it1;
++it2;
}
string::size_type size1 = s1.size();
string::size_type size2 = s2.size();
//return -1,0 or 1 according to strings' lengths
if (size1 == size2) {
return 0;
}
return (size1 < size2) ? -1 : 1;
}
EnumWriter::EnumWriter ()
{
@ -157,13 +189,19 @@ EnumWriter::read_bits (EnumRegistration& er, string str)
return strtol (str.c_str(), (char **) 0, 16);
}
/* catch old style dec numerics */
if (strspn (str.c_str(), "0123456789") == str.length()) {
return strtol (str.c_str(), (char **) 0, 10);
}
do {
comma = str.find_first_of (',');
string segment = str.substr (0, comma);
for (i = er.values.begin(), s = er.names.begin(); i != er.values.end(); ++i, ++s) {
if (segment == (*s)) {
if (segment == *s || nocase_cmp (segment, *s) == 0) {
result |= (*i);
found = true;
}
@ -196,13 +234,40 @@ EnumWriter::read_distinct (EnumRegistration& er, string str)
return strtol (str.c_str(), (char **) 0, 16);
}
/* catch old style dec numerics */
if (strspn (str.c_str(), "0123456789") == str.length()) {
return strtol (str.c_str(), (char **) 0, 10);
}
for (i = er.values.begin(), s = er.names.begin(); i != er.values.end(); ++i, ++s) {
if (str == (*s)) {
if (str == (*s) || nocase_cmp (str, *s) == 0) {
return (*i);
}
}
/* failed to find it as-is. check to see if there a hack for the name we're looking up */
map<string,string>::iterator x;
if ((x = hack_table.find (str)) != hack_table.end()) {
cerr << "found hack for " << str << " = " << x->second << endl;
str = x->second;
for (i = er.values.begin(), s = er.names.begin(); i != er.values.end(); ++i, ++s) {
if (str == (*s) || nocase_cmp (str, *s) == 0) {
return (*i);
}
}
}
throw unknown_enumeration();
}
void
EnumWriter::add_to_hack_table (string str, string hacked)
{
hack_table[str] = hacked;
}

View File

@ -44,6 +44,8 @@ class EnumWriter {
std::string write (std::string type, int value);
int read (std::string type, std::string value);
void add_to_hack_table (std::string str, std::string hacked_str);
private:
struct EnumRegistration {
std::vector<int> values;
@ -65,6 +67,7 @@ class EnumWriter {
int read_distinct (EnumRegistration&, std::string value);
static EnumWriter* _instance;
static std::map<std::string,std::string> hack_table;
};
}