Class: Wiretap::ClipFormat

Inherits:
Object
  • Object
show all
Defined in:
lib/wiretap.rb,
ext/format.cpp

Direct Known Subclasses

AudioFormat

Constant Summary collapse

BITS_PER_PIXEL_TO_BYTES =
{
  24 => 3.00003858024691,
  30 => 4,
  32 => 4,
  36 => 4.5,
  48 => 6,
}
@@audio_formats =
[:dlaudio_mixed, :dlaudio_float, :dlaudio_float_le, :dlaudio_int16, :dlaudio_int16_le,
:dlaudio_int24, :dlaudio_int24_le, :wav, :aiff, :aifc, :dlaudio ]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ClipFormat

Returns a new instance of ClipFormat.



279
280
281
282
283
# File 'lib/wiretap.rb', line 279

def initialize(options = {})
  options.each do |key, value| 
    self.send("#{key}=".to_sym, value) if self.respond_to?("#{key}=".to_sym) 
  end
end

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



293
294
295
# File 'lib/wiretap.rb', line 293

def node
  @node
end

Class Method Details

.buffer_size_for(*opts) ⇒ Object



304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
# File 'lib/wiretap.rb', line 304

def self.buffer_size_for(*opts)
  opts = opts.last || {}
  bpx = opts[:bpp]
  
  f_bpx = bpx.to_f
  f_width = opts[:width].to_f
  f_height = opts[:height].to_f
  
  puts f_bpx
  puts f_width
  puts f_height
  
  f_mult = BITS_PER_PIXEL_TO_BYTES[bpx]
  return (f_mult * f_width * f_height).to_i
end

Instance Method Details

#audio?Boolean

Returns:

  • (Boolean)


296
297
298
# File 'lib/wiretap.rb', line 296

def audio?
  @@audio_formats.include? self.tag
end

#bppObject

Get bits per pixel in clip



61
62
63
64
65
# File 'ext/format.cpp', line 61

static VALUE wiretap_format_get_bpp(VALUE self) {
	WireTapClipFormat* format;
	Data_Get_Struct(self, WireTapClipFormat, format);
	return INT2FIX(format->bitsPerPixel());
}

#bpp=(value_) ⇒ Object

Sets bits per pixel in clip



70
71
72
73
74
75
76
77
# File 'ext/format.cpp', line 70

static VALUE wiretap_format_set_bpp(VALUE self, VALUE value_){
	VALUE value = rb_funcall(value_, to_i, 0);

	WireTapClipFormat* format;
	Data_Get_Struct(self, WireTapClipFormat, format);
	format->setBitsPerPixel(NUM2INT(value));
	return self;
}

#buffer_sizeObject

Get buffer size in clip. It is size of one frame (really a bit more). Usually, it is not required from ruby



104
105
106
107
108
# File 'ext/format.cpp', line 104

static VALUE wiretap_format_get_buffer_size(VALUE self) {
	WireTapClipFormat* format;
	Data_Get_Struct(self, WireTapClipFormat, format);
	return INT2FIX(format->frameBufferSize());
}

#buffer_size=(value_) ⇒ Object

set buffer size for clip



113
114
115
116
117
118
119
120
# File 'ext/format.cpp', line 113

static VALUE wiretap_format_set_buffer_size(VALUE self, VALUE value_){
	VALUE value = rb_funcall(value_, to_i, 0);
	
	WireTapClipFormat* format;
	Data_Get_Struct(self, WireTapClipFormat, format);
	format->setFrameBufferSize(NUM2INT(value));
	return self;
}

#channelsObject

Get number of channels in clip



82
83
84
85
86
# File 'ext/format.cpp', line 82

static VALUE wiretap_format_get_channels(VALUE self) {
	WireTapClipFormat* format;
	Data_Get_Struct(self, WireTapClipFormat, format);
	return INT2FIX(format->numChannels());
}

#channels=(value_) ⇒ Object

Set number channels in clip



91
92
93
94
95
96
97
98
# File 'ext/format.cpp', line 91

static VALUE wiretap_format_set_channels(VALUE self, VALUE value_){
	VALUE value = rb_funcall(value_, to_i, 0);

	WireTapClipFormat* format;
	Data_Get_Struct(self, WireTapClipFormat, format);
	format->setNumChannels(NUM2INT(value));
	return self;
}

#heightObject

Get height of clip



40
41
42
43
44
# File 'ext/format.cpp', line 40

static VALUE wiretap_format_get_height(VALUE self) {
	WireTapClipFormat* format;
	Data_Get_Struct(self, WireTapClipFormat, format);
	return INT2FIX(format->height());
}

#height=(value_) ⇒ Object

Set height of clip



49
50
51
52
53
54
55
56
# File 'ext/format.cpp', line 49

static VALUE wiretap_format_set_height(VALUE self, VALUE value_){
	VALUE value = rb_funcall(value_, to_i, 0);

	WireTapClipFormat* format;
	Data_Get_Struct(self, WireTapClipFormat, format);
	format->setHeight(NUM2INT(value));
	return self;
}

#metaObject

Get metadata for format



206
207
208
209
210
# File 'ext/format.cpp', line 206

static VALUE wiretap_format_get_meta(VALUE self) {
	WireTapClipFormat* format;
	Data_Get_Struct(self, WireTapClipFormat, format);
	return rb_str_new2(format->metaData());
}

#meta=(value) ⇒ Object

Set metadata for format



215
216
217
218
219
220
221
# File 'ext/format.cpp', line 215

static VALUE wiretap_format_set_meta(VALUE self, VALUE value){
	WireTapClipFormat* format;
	Data_Get_Struct(self, WireTapClipFormat, format);
	VALUE meta = rb_funcall(value, rb_intern("to_s"), 0);
	format->setMetaData(CSTR(meta));
	return self;
}

#meta_tagObject

Get meta tag of format



226
227
228
229
230
# File 'ext/format.cpp', line 226

static VALUE wiretap_format_get_meta_tag(VALUE self) {
	WireTapClipFormat* format;
	Data_Get_Struct(self, WireTapClipFormat, format);
	return ID2SYM(rb_intern(format->metaDataTag()));
}

#meta_tag=(value) ⇒ Object

Set meta tag for format



235
236
237
238
239
240
241
# File 'ext/format.cpp', line 235

static VALUE wiretap_format_set_meta_tag(VALUE self, VALUE value){
	WireTapClipFormat* format;
	Data_Get_Struct(self, WireTapClipFormat, format);
	VALUE meta = rb_funcall(value, rb_intern("to_s"), 0);
	format->setMetaDataTag(CSTR(meta));
	return self;
}

#rateObject

Get frame rate per second of this clip



125
126
127
128
129
# File 'ext/format.cpp', line 125

static VALUE wiretap_format_get_rate(VALUE self) {
	WireTapClipFormat* format;
	Data_Get_Struct(self, WireTapClipFormat, format);
	return rb_float_new(double(format->frameRate()));
}

#rate=(value_) ⇒ Object

Set frame rate per second of this clip



134
135
136
137
138
139
140
# File 'ext/format.cpp', line 134

static VALUE wiretap_format_set_rate(VALUE self, VALUE value_){
	VALUE value = rb_funcall(value_, rb_intern("to_f"), 0);
	WireTapClipFormat* format;
	Data_Get_Struct(self, WireTapClipFormat, format);
	format->setFrameRate(float(RFLOAT(value)->value));
	return self;
}

#ratioObject

Get pixel ratio of clip. It is not frame ratio, but pixel ratio



145
146
147
148
149
# File 'ext/format.cpp', line 145

static VALUE wiretap_format_get_ratio(VALUE self) {
	WireTapClipFormat* format;
	Data_Get_Struct(self, WireTapClipFormat, format);
	return rb_float_new(double(format->pixelRatio()));
}

#ratio=(value_) ⇒ Object

Set pixel ratio of clip. It is not frame ratio, but pixel ratio



154
155
156
157
158
159
160
# File 'ext/format.cpp', line 154

static VALUE wiretap_format_set_ratio(VALUE self, VALUE value_){
	VALUE value = rb_funcall(value_, rb_intern("to_f"), 0);
	WireTapClipFormat* format;
	Data_Get_Struct(self, WireTapClipFormat, format);
	format->setPixelRatio(float(RFLOAT(value)->value));
	return self;
}

#scanObject

Get scan format of clip



165
166
167
168
169
# File 'ext/format.cpp', line 165

static VALUE wiretap_format_get_scan(VALUE self) {
	WireTapClipFormat* format;
	Data_Get_Struct(self, WireTapClipFormat, format);
	return ID2SYM(rb_intern(format->scanFormatStr(format->scanFormat())));
}

#scan=(value) ⇒ Object

Set scan format of clip



174
175
176
177
178
179
180
181
# File 'ext/format.cpp', line 174

static VALUE wiretap_format_set_scan(VALUE self, VALUE value){
	WireTapClipFormat* format;
	Data_Get_Struct(self, WireTapClipFormat, format);
	VALUE scan = rb_funcall(value, rb_intern("to_s"), 0);
	WireTapClipFormat::ScanFormat scan_format = format->strToScanFormat(CSTR(scan));
	format->setScanFormat(scan_format);
	return self;
}

#tagObject

Get format tag for clip



186
187
188
189
190
# File 'ext/format.cpp', line 186

static VALUE wiretap_format_get_tag(VALUE self) {
	WireTapClipFormat* format;
	Data_Get_Struct(self, WireTapClipFormat, format);
	return ID2SYM(rb_intern(format->formatTag()));
}

#tag=(value) ⇒ Object

Set format tag for clip



195
196
197
198
199
200
201
# File 'ext/format.cpp', line 195

static VALUE wiretap_format_set_tag(VALUE self, VALUE value){
	WireTapClipFormat* format;
	Data_Get_Struct(self, WireTapClipFormat, format);
	VALUE tag = rb_funcall(value, rb_intern("to_s"), 0);
	format->setFormatTag(CSTR(tag));
	return self;
}

#to_sObject



300
301
302
# File 'lib/wiretap.rb', line 300

def to_s
  "#<Wiretap::ClipFormat size: #{self.width}x#{self.height}, bpp: #{self.bpp}, channels: #{self.channels}, rate: #{self.rate}, tag: #{self.tag}>"
end

#widthObject

Get width of clip



19
20
21
22
23
# File 'ext/format.cpp', line 19

static VALUE wiretap_format_get_width(VALUE self) {
	WireTapClipFormat* format;
	Data_Get_Struct(self, WireTapClipFormat, format);
	return INT2FIX(format->width());
}

#width=(value_) ⇒ Object

Set width of clip



28
29
30
31
32
33
34
35
# File 'ext/format.cpp', line 28

static VALUE wiretap_format_set_width(VALUE self, VALUE value_) {
	VALUE value = rb_funcall(value_, to_i, 0);

	WireTapClipFormat* format;
	Data_Get_Struct(self, WireTapClipFormat, format);
	format->setWidth(NUM2INT(value));
	return self;
}