@@ -13,6 +13,51 @@ using namespace juce;
1313
1414namespace element {
1515
16+ namespace detail {
17+
18+ void migrateControllerMaps (ValueTree session)
19+ {
20+ if (! session.isValid ())
21+ return ;
22+
23+ auto controllers = session.getChildWithName (tags::controllers);
24+ auto maps = session.getChildWithName (tags::maps);
25+ auto mappings = session.getOrCreateChildWithName (tags::midiMappings, nullptr );
26+
27+ for (int i = 0 ; i < maps.getNumChildren (); ++i)
28+ {
29+ const auto map = maps.getChild (i);
30+ if (! map.hasType (types::ControllerMap))
31+ continue ;
32+
33+ const auto controllerId = map.getProperty (tags::controller).toString ();
34+ const auto controlId = map.getProperty (tags::control).toString ();
35+
36+ auto controller = controllers.getChildWithProperty (tags::uuid, controllerId);
37+ if (! controller.isValid ())
38+ continue ;
39+ auto control = controller.getChildWithProperty (tags::uuid, controlId);
40+ if (! control.isValid ())
41+ continue ;
42+
43+ MidiMapping mapping (String {});
44+ mapping.setProperty (tags::device, controller.getProperty (tags::inputDevice).toString ());
45+ mapping.setProperty (tags::name, control.getProperty (tags::name).toString ());
46+ mapping.setProperty (tags::eventType, control.getProperty (" eventType" ).toString ());
47+ mapping.setProperty (tags::eventId, (int ) control.getProperty (" eventId" , 0 ));
48+ mapping.setProperty (tags::midiChannel, (int ) control.getProperty (tags::midiChannel, 0 ));
49+ mapping.setProperty (tags::toggle, ! (bool ) control.getProperty (" momentary" , false ));
50+ mapping.setProperty (tags::targetType, " parameter" );
51+ mapping.setProperty (tags::node, map.getProperty (tags::node).toString ());
52+ mapping.setProperty (tags::parameter, (int ) map.getProperty (tags::parameter, -1 ));
53+
54+ mappings.addChild (mapping.data (), -1 , nullptr );
55+ }
56+
57+ session.removeChild (controllers, nullptr );
58+ session.removeChild (maps, nullptr );
59+ }
60+
1661static Node findNodeRecursive (const Node& start, const Uuid& uuid)
1762{
1863 if (! uuid.isNull () && uuid == start.getUuid ())
@@ -28,6 +73,8 @@ static Node findNodeRecursive (const Node& start, const Uuid& uuid)
2873 return Node ();
2974}
3075
76+ } // namespace detail
77+
3178class Session ::Impl
3279{
3380public:
@@ -98,7 +145,7 @@ bool Session::loadData (const ValueTree& data)
98145 objectData.removeListener (this );
99146 objectData = data;
100147 setMissingProperties ();
101- migrateControllerMaps (objectData);
148+ detail:: migrateControllerMaps (objectData);
102149 cleanOrphanMidiMappings ();
103150 objectData.addListener (this );
104151 return true ;
@@ -183,7 +230,7 @@ Node Session::findNodeById (const Uuid& uuid)
183230
184231 for (int i = getNumGraphs (); --i >= 0 ;)
185232 {
186- node = findNodeRecursive (getGraph (i), uuid);
233+ node = detail:: findNodeRecursive (getGraph (i), uuid);
187234 if (node.isValid ())
188235 break ;
189236 }
@@ -260,46 +307,6 @@ void Session::forEach (const ValueTree tree, ValueTreeFunction handler) const
260307 forEach (tree.getChild (i), handler);
261308}
262309
263- void migrateControllerMaps (ValueTree session)
264- {
265- if (! session.isValid ())
266- return ;
267-
268- auto controllers = session.getChildWithName (tags::controllers);
269- auto maps = session.getChildWithName (tags::maps);
270- auto mappings = session.getOrCreateChildWithName (tags::midiMappings, nullptr );
271-
272- for (int i = 0 ; i < maps.getNumChildren (); ++i)
273- {
274- const auto map = maps.getChild (i);
275- if (! map.hasType (types::ControllerMap))
276- continue ;
277-
278- const auto controllerId = map.getProperty (tags::controller).toString ();
279- const auto controlId = map.getProperty (tags::control).toString ();
280-
281- auto controller = controllers.getChildWithProperty (tags::uuid, controllerId);
282- if (! controller.isValid ())
283- continue ;
284- auto control = controller.getChildWithProperty (tags::uuid, controlId);
285- if (! control.isValid ())
286- continue ;
287-
288- MidiMapping mapping (String {});
289- mapping.setProperty (tags::device, controller.getProperty (tags::inputDevice).toString ());
290- mapping.setProperty (tags::name, control.getProperty (tags::name).toString ());
291- mapping.setProperty (tags::eventType, control.getProperty (" eventType" ).toString ());
292- mapping.setProperty (tags::eventId, (int ) control.getProperty (" eventId" , 0 ));
293- mapping.setProperty (tags::midiChannel, (int ) control.getProperty (tags::midiChannel, 0 ));
294- mapping.setProperty (tags::toggle, ! (bool ) control.getProperty (" momentary" , false ));
295- mapping.setProperty (tags::targetType, " parameter" );
296- mapping.setProperty (tags::node, map.getProperty (tags::node).toString ());
297- mapping.setProperty (tags::parameter, (int ) map.getProperty (tags::parameter, -1 ));
298-
299- mappings.addChild (mapping.data (), -1 , nullptr );
300- }
301- }
302-
303310void Session::setActiveGraph (int index)
304311{
305312 if (! isPositiveAndBelow (index, getNumGraphs ()))
0 commit comments