-
Notifications
You must be signed in to change notification settings - Fork 0
/
SubstanceInstrumentManager.py
138 lines (108 loc) · 5.76 KB
/
SubstanceInstrumentManager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# -*- coding: utf-8 -*-
#
# IIKit -- the Instrumental Interaction Toolkit
# Copyright 2009-2011, Université Paris-Sud
# by James R. Eagan (code at my last name dot me)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 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
# and GNU Lesser General Public License along with this program.
# If not, see <http://www.gnu.org/licenses/>.
import InstrumentManager as InstrumentManagerModule
from InstrumentManager import IIKitInstrumentManager
import os
import sys
import jre.debug
from substance.core.bootstrap import *
from substance.std.tools.oobridge import OOAccessor
class SubstanceInstrumentManager(Facet, IIKitInstrumentManager):
"""The Substance Instrument Manager"""
# @Facet.DEPENDENCY("VICON", "The place where the VICON 2D Input representation is stored and updated")
# @Facet.DEPENDENCY("OSC", "The place where the OSC Input controller facet resides")
@Facet.DEPENDENCY("Scene Graph", "The Scene Graph of the WILD Universe")
def __init__(self):
# super(SubstanceInstrumentManager, self).__init__("InstrumentManager")
Facet.__init__(self, "InstrumentManager")
IIKitInstrumentManager.__init__(self)
self.__installedNode = None
self.__instrumentCounter = 0
def instantiate(self, with_state):
assert self.__installedNode is None, "SubstanceInstrumentManager has already been instantiated"
self.__installedNode = self.node
self._sg = local.get_dependency(self, "Scene Graph")
assert not self._sg.has_facet(self, "OOAccessor")
self._ooaccessor = OOAccessor()
self._sg.add_facet(self, self._ooaccessor, True, True)
print "Instrument Manager loaded and installed on", self.__installedNode
# if self._instruments:
# instrument = self._instruments.get('fr.lri.eaganj.instrument.Mover/MoveInstrument',
# self._instruments.values()[0])
# local.InstrumentManager.activateInstrument_(self, instrument)
# self.vicon = local.get_dependency(self, "VICON")
# self.osc = local.get_dependency(self, "OSC")
def _loadInstrumentPlugins(self):
from InstrumentLoader import InstrumentLoader
searchDirs = [ u'~/Library/Application Support/Substance Instruments',
u'~/.substance/instruments',
u'/Library/Application Support/Substance Instruments',
u'/usr/local/share/substance/instruments',
u'/usr/share/substance/instruments',
u'/Network/Library/Application Support/Substance Instruments',
]
searchDirs = [ os.path.expanduser(searchDir) for searchDir in searchDirs ]
InstrumentLoader.loadInstrumentsInSearchPaths(searchDirs)
@Facet.HANDLER("<void>::<void>")
def handleEvent(self, rawEvent, namespace):
return super(SubstanceInstrumentManager, self).handleEvent(rawEvent, namespace)
@Facet.HANDLER("<void::void>")
@jre.debug.trap_exceptions
def activateInstrument(self, instrumentOrInstrumentClass, context):
self.__instrumentCounter += 1
instrumentNodeName = "Instrument %s" % (self.__instrumentCounter)
self.instrumentNode = local.new_child(self, instrumentNodeName,
instrumentOrInstrumentClass.instrumentID)
self.instrumentNode.set_dependency(self, "Scene Graph", self._sg, "The Scene Graph")
instrument = super(SubstanceInstrumentManager, self).activateInstrument_(
instrumentOrInstrumentClass)
self._prepareInstrumentContext(instrument, context)
instrument.ooaccessor = self._ooaccessor
# print ">>> Activated instrument", instrument.instrumentID
return instrument
def _prepareInstrumentContext(self, instrument, context):
for logical_device in instrument.getDevices():
physical_device, label = context.bindLogicalDeviceToInstrument(logical_device, instrument)
# print "--- ", logical_device, "->", physical_device, "(%s)" % (label)
def _instantiateInstrument(self, instrumentClass):
instrument = instrumentClass()
self.instrumentNode.add_facet(self, instrument, True, True)
return instrument
def sortedInstruments(self):
# FIXME: Improve to properly use a priority queue/stack
result = []
for instrument in self._instruments.values():
if instrument.priority == 1:
result.insert(0, instrument)
else:
result.append(instrument)
return result
def _sortedActiveInstruments(self):
# FIXME: Improve to properly use a priority queue/stack
result = []
for instrument in self._activeInstruments:
if instrument.priority == 1:
result.insert(0, instrument)
else:
result.append(instrument)
return result
InstrumentManagerModule.InstrumentManager = SubstanceInstrumentManager
InstrumentManager = SubstanceInstrumentManager
__all__ = 'SubstanceInstrumentManager InstrumentManager'.split()