Class: Scruby::Buffer

Inherits:
Object show all
Defined in:
lib/scruby/buffer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server, frames = -1,, channels = 1) ⇒ Buffer

Returns a new instance of Buffer.



74
75
76
# File 'lib/scruby/buffer.rb', line 74

def initialize server, frames = -1, channels = 1
  @server, @frames, @channels = server, frames, channels
end

Instance Attribute Details

#channelsObject

Returns the value of attribute channels.



34
35
36
# File 'lib/scruby/buffer.rb', line 34

def channels
  @channels
end

#framesObject

Returns the value of attribute frames.



34
35
36
# File 'lib/scruby/buffer.rb', line 34

def frames
  @frames
end

#pathObject

Returns the value of attribute path.



34
35
36
# File 'lib/scruby/buffer.rb', line 34

def path
  @path
end

#rateObject

Returns the value of attribute rate.



34
35
36
# File 'lib/scruby/buffer.rb', line 34

def rate
  @rate
end

#serverObject (readonly)

readNoUpdate loadCollection sendCollection streamCollection loadToFloatArray getToFloatArray set setn get getn fill normalize gen sine1 … copy copyData query updateInfo queryDone printOn play duration asBufWithValues



33
34
35
# File 'lib/scruby/buffer.rb', line 33

def server
  @server
end

Class Method Details

.alloc_consecutive(buffers, server, frames = -1,, channels = 1, &message) ⇒ Object



135
136
137
138
139
140
141
142
# File 'lib/scruby/buffer.rb', line 135

def alloc_consecutive buffers, server, frames = -1, channels = 1, &message
  buffers = Array.new(buffers){ new server, frames, channels }
  server.allocate :buffers, buffers
  message ||= 0
  buffers.each do |buff|
    server.send '/b_alloc', buff.buffnum, frames, channels, message.value(buff)
  end
end

.allocate(server, frames = -1,, channels = 1, &message) ⇒ Object



114
115
116
# File 'lib/scruby/buffer.rb', line 114

def allocate server, frames = -1, channels = 1, &message
  new(server, frames, channels).allocate &message
end

.cue_sound_file(server, path, start, channels = 2, buff_size = 32768, &message) ⇒ Object



118
119
120
121
122
123
# File 'lib/scruby/buffer.rb', line 118

def cue_sound_file server, path, start, channels = 2, buff_size = 32768, &message
  allocate server, buff_size, channels do |buffer|
    message ||= 0
    ['/b_read', buffer.buffnum, expand_path(path), start, buff_size, 0, true, message.value(buffer)]
  end
end

.read(server, path, start = 0, frames = -1,, &message) ⇒ Object

Allocate a buffer and immediately read a soundfile into it.



126
127
128
129
# File 'lib/scruby/buffer.rb', line 126

def read server, path, start = 0, frames = -1, &message
  buffer = new server, &message
  buffer.allocate_and_read expand_path(path), start, frames
end

.read_channel(server, path, start = 0, frames = -1,, channels = [], &message) ⇒ Object



131
132
133
# File 'lib/scruby/buffer.rb', line 131

def read_channel server, path, start = 0, frames = -1, channels = [], &message
  new(server, frames, channels).allocate_read_channel expand_path(path), start, frames, channels, &message
end

Instance Method Details

#allocate(&message) ⇒ Object



78
79
80
81
82
83
# File 'lib/scruby/buffer.rb', line 78

def allocate &message
  message ||= 0
  @server.allocate :buffers, self
  @server.send '/b_alloc', buffnum, frames, channels, message.value(self)
  self
end

#allocate_and_read(path, start, frames, &message) ⇒ Object

:nodoc:



99
100
101
102
103
104
# File 'lib/scruby/buffer.rb', line 99

def allocate_and_read path, start, frames, &message
  @server.allocate :buffers, self
  message ||= ["/b_query", buffnum]
  @server.send "/b_allocRead", buffnum, @path = expand_path(path), start, frames, message.value(self)
  self
end

#allocate_read_channel(path, start, frames, channels, &message) ⇒ Object



106
107
108
109
110
111
# File 'lib/scruby/buffer.rb', line 106

def allocate_read_channel path, start, frames, channels, &message
  @server.allocate :buffers, self
  message ||= ["/b_query", buffnum]
  @server.send *(["/b_allocReadChannel", buffnum, expand_path(path), start, frames] + channels << message.value(self))
  self
end

#buffnumObject Also known as: as_ugen_input, index



85
86
87
# File 'lib/scruby/buffer.rb', line 85

def buffnum
   @server.buffers.index self
end

#close(&message) ⇒ Object



49
50
51
52
53
# File 'lib/scruby/buffer.rb', line 49

def close &message
  message ||= 0
  @server.send '/b_close', buffnum, message.value(self)
  self
end

#cue_sound_file(path, start = 0, &message) ⇒ Object



61
62
63
64
65
# File 'lib/scruby/buffer.rb', line 61

def cue_sound_file path, start = 0, &message
  message ||= 0
  @server.send "/b_read", buffnum, expand_path(path), start, @frames, 0, 1, message.value(self)
  self
end

#free(&message) ⇒ Object

alias :as_control_input :buffnum



92
93
94
95
96
# File 'lib/scruby/buffer.rb', line 92

def free &message
  message ||= 0
  @server.send "/b_free", buffnum, message.value(self)
  @server.buffers.delete self
end

#read(path, file_start = 0, frames = -1,, buff_start = 0, leave_open = false, &message) ⇒ Object



36
37
38
39
40
41
# File 'lib/scruby/buffer.rb', line 36

def read path, file_start = 0, frames = -1, buff_start = 0, leave_open = false, &message
  # @on_info  = message
  message ||= ["/b_query", buffnum]
  @server.send "/b_read", buffnum, expand_path(path), file_start, frames, buff_start, leave_open, message.value(self)
  self
end

#read_channel(path, file_start = 0, frames = -1,, buff_start = 0, leave_open = false, channels = [], &message) ⇒ Object



43
44
45
46
47
# File 'lib/scruby/buffer.rb', line 43

def read_channel path, file_start = 0, frames = -1, buff_start = 0, leave_open = false, channels = [], &message
  message ||= 0
  @server.send *(["/b_ReadChannel", buffnum, expand_path(path), start, frames, buff_start, leave_open] + channels << message.value(self))
  self
end

#write(path = nil, format = 'aiff', sample_format = 'int24', frames = -1,, start = 0, leave_open = false, &message) ⇒ Object



67
68
69
70
71
72
# File 'lib/scruby/buffer.rb', line 67

def write path = nil, format = 'aiff', sample_format = 'int24', frames = -1, start = 0, leave_open = false, &message
  message ||= 0
  path    ||= "#{ DateTime.now }.#{ format }"
  @server.send "/b_write", buffnum, expand_path(path), format, sample_format, frames, start, leave_open, message.value(self)
  self
end

#zero(&message) ⇒ Object



55
56
57
58
59
# File 'lib/scruby/buffer.rb', line 55

def zero &message
  message ||= 0
  @server.send '/b_zero', buffnum, message.value(self)
  self
end