Class: JACK::Client

Inherits:
Object
  • Object
show all
Extended by:
FFI::Library
Defined in:
lib/jack/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = 0x00, &b) ⇒ Client

Returns a new instance of Client.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/jack/client.rb', line 25

def initialize(name, options = 0x00, &b)
  @name = name
  @options = options
  
  status = FFI::MemoryPointer.new :pointer
  
  @server = jack_client_open name, options, status
  # TODO return status handling
  
  if block_given?
    yield self
    close
  end
  
end

Instance Attribute Details

#pointerObject (readonly)

Returns the value of attribute pointer.



23
24
25
# File 'lib/jack/client.rb', line 23

def pointer
  @pointer
end

Instance Method Details

#change_graph(method, source, destination) ⇒ Object

Raises:

  • (ArgumentError)


67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/jack/client.rb', line 67

def change_graph(method, source, destination)
  raise ArgumentError, "You must pass JACK::Port or String to JACK::Client.port_connect" if not source.is_a? Port and not source.is_a? String and not destination.is_a? Port and not destination.is_a? String
  
  source = port_by_name(source) if source.is_a? String
  destination = port_by_name(destination) if destination.is_a? String

  if source.is_input? and destination.is_output?
    source = destination
    destination = source
  elsif source.is_output? and destination.is_input?
    # Direction ok
  else
    raise Errors::InvalidPortsChosenToConnect, "Cannot connect ports #{source} and #{destination} - both are input or output ports"
  end

  # TODO checking result
  send("jack_#{method}", @server, source.name, destination.name)    
end

#closeObject



41
42
43
# File 'lib/jack/client.rb', line 41

def close
  jack_client_close @server
end

#connect(source, destination) ⇒ Object



59
60
61
# File 'lib/jack/client.rb', line 59

def connect(source, destination)
  change_graph(:connect, source, destination) == 0
end

#disconnect(source, destination) ⇒ Object



63
64
65
# File 'lib/jack/client.rb', line 63

def disconnect(source, destination)
  change_graph(:disconnect, source, destination) == 0
end

#get_portsObject



45
46
47
48
49
# File 'lib/jack/client.rb', line 45

def get_ports
  # TODO checking if i am connected
  # TODO parameters
  jack_get_ports(@server, nil, nil, 0).read_array_of_string_until_end.collect{ |port| Port.new(port, self) }
end

#port_by_name(name) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/jack/client.rb', line 51

def port_by_name(name)
  port = jack_port_by_name(@server, name)
  
  raise Errors::NoSuchPortError, "There no such port as #{name}" if port.null?
  
  Port.new(port, self)
end