the return of VST support
[ardour.git] / libs / ardour / state_manager.cc
1 #include <pbd/error.h>
2 #include <ardour/state_manager.h>
3
4 #include "i18n.h"
5
6 using namespace ARDOUR;
7 using namespace std;
8 using namespace PBD;
9
10 bool StateManager::_allow_save = true;
11 sigc::signal<void,const char*> StateManager::SaveAllowed;
12
13 StateManager::StateManager ()
14 {
15         _current_state_id = 0;
16 }
17
18 StateManager::~StateManager()
19 {
20 }
21
22 void
23 StateManager::prohibit_save ()
24 {
25         _allow_save = false;
26 }
27
28 void
29 StateManager::allow_save (const char* why, bool do_save)
30 {
31         _allow_save = true;
32         if (do_save) {
33                 SaveAllowed (why);
34                 SaveAllowed.slots().erase (SaveAllowed.slots().begin(), SaveAllowed.slots().end());
35         }
36 }
37
38 void
39 StateManager::drop_all_states ()
40 {
41         for (StateMap::iterator i = states.begin(); i != states.end(); ++i) {
42                 delete *i;
43         }
44
45         states.clear ();
46
47         save_state (_("cleared history"));
48 }
49
50 void
51 StateManager::use_state (state_id_t id)
52 {
53         Change what_changed;
54         state_id_t n;
55         StateMap::iterator i;
56
57         for (n = 0, i = states.begin(); n < id && i != states.end(); ++n, ++i);
58
59         if (n != id || i == states.end()) {
60                 fatal << string_compose (_("programming error: illegal state ID (%1) passed to "
61                                     "StateManager::set_state() (range = 0-%2)"), id, states.size()-1)
62                       << endmsg;
63                 /*NOTREACHED*/
64                 return;
65         }
66
67         what_changed = restore_state (**i);
68         _current_state_id = id;
69         send_state_changed (what_changed);
70 }
71
72 void
73 StateManager::save_state (std::string why)
74 {
75         if (!_allow_save) {
76                 SaveAllowed.connect (mem_fun (*this, &StateManager::save_state));
77                 return;
78         }
79
80         states.push_back (state_factory (why));
81         _current_state_id = states.size() - 1;
82 }
83
84 void
85 StateManager::send_state_changed (Change what_changed)
86 {
87         StateChanged (what_changed);
88 }