7 from calfgtkutils
import *
8 Colors
= conndiagram
.Colors
10 class JACKGraphParser():
12 self
.client
= calfpytools
.JackClient()
13 self
.client
.open("jackvis")
14 def get_port_color(self
, portData
):
15 if portData
.get_type() == calfpytools
.JACK_DEFAULT_AUDIO_TYPE
:
16 color
= Colors
.audioPort
17 if portData
.get_type() == calfpytools
.JACK_DEFAULT_MIDI_TYPE
:
18 color
= Colors
.eventPort
20 def is_port_input(self
, portData
):
21 return (portData
.get_flags() & calfpytools
.JackPortIsInput
) != 0
22 def get_port_name(self
, portData
):
23 return portData
.get_name()
24 def get_port_id(self
, portData
):
25 return portData
.get_full_name()
26 def get_module_name(self
, moduleData
):
27 return moduleData
.name
28 def get_module_port_list(self
, moduleData
):
29 return [(port
, self
.client
.get_port(port
)) for port
in self
.client
.get_ports(moduleData
.name
+":.*", moduleData
.type, moduleData
.flags
)]
30 def can_connect(self
, first
, second
):
31 if self
.is_port_input(first
) == self
.is_port_input(second
):
33 if first
.get_type() != second
.get_type():
36 def connect(self
, first
, second
):
37 if self
.client
.connect(first
.get_full_name(), second
.get_full_name()) != True:
38 raise RuntimeError, "Connection error"
39 def disconnect(self
, name_first
, name_second
):
40 self
.client
.disconnect(name_first
, name_second
)
42 class JACKClientData():
43 def __init__(self
, name
, type, flags
):
44 (self
.name
, self
.type, self
.flags
) = (name
, type, flags
)
48 self
.parser
= JACKGraphParser()
49 self
.cgraph
= conndiagram
.ConnectionGraphEditor(self
, self
.parser
)
51 def canvas_popup_menu_handler(self
, widget
):
52 self
.canvas_popup_menu(0, 0, 0)
55 def canvas_button_press_handler(self
, widget
, event
):
57 self
.canvas_popup_menu(event
.x
, event
.y
, event
.time
)
60 def canvas_popup_menu(self
, x
, y
, time
):
62 items
= self
.cgraph
.get_data_items_at(x
, y
)
63 types
= set([di
[0] for di
in items
])
68 add_option(menu
, "Disconnect", self
.disconnect
, wire
)
72 menu
.popup(None, None, None, 3, time
)
74 def disconnect(self
, wire
):
75 self
.parser
.disconnect(wire
.src
.get_id(), wire
.dest
.get_id())
79 self
.window
= gtk
.Window(gtk
.WINDOW_TOPLEVEL
)
80 self
.window
.connect("delete_event", self
.delete_event
)
81 self
.window
.connect("destroy", self
.destroy
)
82 self
.main_vbox
= gtk
.VBox()
83 self
.create_main_menu()
84 self
.scroll
= gtk
.ScrolledWindow()
85 self
.scroll
.add(self
.cgraph
.create())
86 self
.main_vbox
.pack_start(self
.menu_bar
, expand
= False, fill
= False)
87 self
.main_vbox
.add(self
.scroll
)
88 self
.window
.add(self
.main_vbox
)
89 self
.window
.show_all()
90 self
.main_vbox
.connect("popup-menu", self
.canvas_popup_menu_handler
)
91 self
.cgraph
.canvas
.connect("button-press-event", self
.canvas_button_press_handler
)
92 self
.cgraph
.canvas
.update()
93 self
.add_clients(0.0, 0.0, calfpytools
.JackPortIsOutput
)
94 self
.add_clients(200, 0.0, calfpytools
.JackPortIsInput
)
95 self
.cgraph
.canvas
.update()
99 def add_clients(self
, x
, y
, flags
):
100 ports
= self
.parser
.client
.get_ports("", "", flags
)
101 clients
= set([p
.split(":")[0] for p
in ports
])
103 y
+= self
.cgraph
.add_module(JACKClientData(cl
, "", flags
), x
, y
).rect
.props
.height
106 ports
= self
.parser
.client
.get_ports("", "", calfpytools
.JackPortIsInput
)
107 pmap
= self
.cgraph
.get_port_map()
109 conns
= self
.parser
.client
.get_port(p
).get_connections()
111 if p
in pmap
and c
in pmap
:
112 print "Connect %s to %s" % (c
, p
)
113 self
.cgraph
.connect(pmap
[c
], pmap
[p
])
115 print "Connect %s to %s - not found" % (c
, p
)
117 def create_main_menu(self
):
118 self
.menu_bar
= gtk
.MenuBar()
119 self
.file_menu
= add_submenu(self
.menu_bar
, "_File")
120 add_option(self
.file_menu
, "_Blow-up", self
.blow_up
)
121 add_option(self
.file_menu
, "_Exit", self
.exit
)
123 def blow_up(self
, data
):
124 self
.cgraph
.blow_up()
126 def exit(self
, data
):
127 self
.window
.destroy()
129 def delete_event(self
, widget
, data
= None):
131 def destroy(self
, widget
, data
= None):