More dropped patches.
[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
8 StateManager::StateManager ()
9 {
10         _current_state_id = 0;
11 }
12
13 StateManager::~StateManager()
14 {
15 }
16
17 void
18 StateManager::drop_all_states ()
19 {
20         for (StateMap::iterator i = states.begin(); i != states.end(); ++i) {
21                 delete *i;
22         }
23
24         states.clear ();
25
26         save_state (_("cleared history"));
27 }
28
29 void
30 StateManager::use_state (state_id_t id)
31 {
32         Change what_changed;
33         state_id_t n;
34         StateMap::iterator i;
35         
36         for (n = 0, i = states.begin(); n < id && i != states.end(); ++n, ++i);
37
38         if (n != id || i == states.end()) {
39                 fatal << compose (_("programming error: illegal state ID (%1) passed to "
40                                     "StateManager::set_state() (range = 0-%3)"), id,
41                                   states.size()-1)
42                       << endmsg;
43                 /*NOTREACHED*/
44                 return;
45         }
46
47         what_changed = restore_state (**i);
48         _current_state_id = id;
49         send_state_changed (what_changed);
50 }
51
52 void
53 StateManager::save_state (std::string why)
54 {
55         states.push_back (state_factory (why));
56         _current_state_id = states.size() - 1;
57 }
58
59 void
60 StateManager::send_state_changed (Change what_changed)
61 {
62         StateChanged (what_changed);
63 }