Update of /cvsroot/pure-data/externals/gridflow/base In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18599
Modified Files: flow_objects.rb main.rb source_filter.rb test.rb Log Message: 0.8.1
Index: test.rb =================================================================== RCS file: /cvsroot/pure-data/externals/gridflow/base/test.rb,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** test.rb 4 Oct 2005 02:02:13 -0000 1.1 --- test.rb 15 Mar 2006 04:37:28 -0000 1.2 *************** *** 8,12 ****
$imdir = "./images" ! $animdir = "/opt/mex" srand Time.new.to_i $port = 4200+rand(100) --- 8,12 ----
$imdir = "./images" ! $animdir = "./images/movies" srand Time.new.to_i [...1488 lines suppressed...] end --- 1026,1030 ----
def test_error ! x = FO["@store"] x.send_in 0 end *************** *** 1085,1086 **** --- 1065,1074 ---- #test_metro #$mainloop.loop + + =begin + a = FO["@print"] + a.send_in 0, "3 3 #{nt} # 1 0 0 0" + a.send_in 0, "3 3 3 #{nt} # 1 2 3 4" + a.send_in 0, "base 16" + a.send_in 0, "3 3 3 #{nt} # 255 0 0 0" + =end
Index: source_filter.rb =================================================================== RCS file: /cvsroot/pure-data/externals/gridflow/base/source_filter.rb,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** source_filter.rb 4 Oct 2005 02:02:13 -0000 1.1 --- source_filter.rb 15 Mar 2006 04:37:28 -0000 1.2 *************** *** 1,2 **** --- 1,4 ---- + #!/usr/bin/env ruby + $keywords = %w(class decl def end grdecl) $stack = [] *************** *** 4,13 ****
ClassDecl = Struct.new(:name,:supername,:methods,:grins,:attrs,:info) ! MethodDecl = Struct.new(:rettype,:selector,:arglist,:minargs,:maxargs,:where) Arg = Struct.new(:type,:name,:default)
class MethodDecl def ==(o) ! return false unless rettype==o.rettype && maxargs==o.maxargs # && minargs==o.minargs arglist.each_index{|i| arglist[i] == o.arglist[i] or return false } --- 6,15 ----
ClassDecl = Struct.new(:name,:supername,:methods,:grins,:attrs,:info) ! MethodDecl = Struct.new(:rettype,:selector,:arglist,:minargs,:maxargs,:where,:static) Arg = Struct.new(:type,:name,:default)
class MethodDecl def ==(o) ! return false unless rettype==o.rettype && static==o.static && maxargs==o.maxargs # && minargs==o.minargs arglist.each_index{|i| arglist[i] == o.arglist[i] or return false } *************** *** 36,44 ****
def parse_methoddecl(line,term) ! /^(\w+)\s+(\w+)\s*(([^)]*))\s*#{term}/.match line or raise "syntax error #{where} #{line}" ! rettype,selector,arglist = $1,$2,$3 arglist,minargs,maxargs = parse_arglist arglist ! MethodDecl.new(rettype,selector,arglist,minargs,maxargs,where) end
--- 38,46 ----
def parse_methoddecl(line,term) ! /^(static\s)?\s*(\w+)\s+(\w+)\s*(([^)]*))\s*#{term}/.match line or raise "syntax error #{where} #{line}" ! static,rettype,selector,arglist = $1,$2,$3,$4 arglist,minargs,maxargs = parse_arglist arglist ! MethodDecl.new(rettype,selector,arglist,minargs,maxargs,where,static) end
*************** *** 76,83 **** not $stack[-1] or not ClassDecl===$stack[-1] $stack[-1].attrs[name]=Arg.new(type,name,nil) ! Out.print line ! Out.puts "//FCS" handle_decl "void _0_#{name}_m (#{type} #{name});" ! Out.puts "# #{$linenumber}" end
--- 78,84 ---- not $stack[-1] or not ClassDecl===$stack[-1] $stack[-1].attrs[name]=Arg.new(type,name,nil) ! Out.print line.gsub(///.*$/,"") # hack! handle_decl "void _0_#{name}_m (#{type} #{name});" ! # Out.puts "# #{$linenumber}" end
*************** *** 89,92 **** --- 90,94 ---- $stack[-1].methods[m.selector] = m
+ Out.print "static " if m.static Out.print "#{m.rettype} #{m.selector}(int argc, Ruby *argv" Out.print "," if m.arglist.length>0 *************** *** 94,102 **** Out.puts "static Ruby #{m.selector}_wrap"+ "(int argc, Ruby *argv, Ruby rself);//FCS" ! Out.puts "# #{$linenumber+1}" end
def handle_def(line) ! m = parse_methoddecl(line,"{?.*$") term = line[/{.*/] qlass = $stack[-1] --- 96,104 ---- Out.puts "static Ruby #{m.selector}_wrap"+ "(int argc, Ruby *argv, Ruby rself);//FCS" ! # Out.puts "# #{$linenumber}" end
def handle_def(line) ! m = parse_methoddecl(line,"\{?.*$") term = line[/{.*/] qlass = $stack[-1] *************** *** 177,181 **** "{ "#{s}",(RMethod)#{c}::#{s}_wrap }" }.join(",") ! Out.puts "}; FClass ci#{cl} = { #{cl}_allocator, #{cl}_startup," Out.puts "#{cl.inspect}, COUNT(#{cl}_methods), #{cl}_methods };" Out.puts "void #{frame.name}_startup (Ruby rself) "+line --- 179,183 ---- "{ "#{s}",(RMethod)#{c}::#{s}_wrap }" }.join(",") ! Out.puts "}; static FClass ci#{cl} = { #{cl}_allocator, #{cl}_startup," Out.puts "#{cl.inspect}, COUNT(#{cl}_methods), #{cl}_methods };" Out.puts "void #{frame.name}_startup (Ruby rself) "+line
Index: main.rb =================================================================== RCS file: /cvsroot/pure-data/externals/gridflow/base/main.rb,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** main.rb 4 Oct 2005 02:02:13 -0000 1.1 --- main.rb 15 Mar 2006 04:37:28 -0000 1.2 *************** *** 3,7 ****
GridFlow ! Copyright (c) 2001,2002 by Mathieu Bouchard
This program is free software; you can redistribute it and/or --- 3,7 ----
GridFlow ! Copyright (c) 2001,2002,2003,2004,2005 by Mathieu Bouchard
This program is free software; you can redistribute it and/or *************** *** 95,98 **** --- 95,99 ---- when :s, :i16, :int16; "s*" when :i, :i32, :int32; "l*" + when :l, :i64, :int64; raise "int64? lol" when :f, :f32, :float32; "f*" when :d, :f64, :float64; "d*" *************** *** 157,160 **** --- 158,173 ---- attr_accessor :comment def foreign_name; @foreign_name if defined? @foreign_name end + def doc(selector=nil,text=nil) + return @doc if not selector + if not defined? @doc; @doc={}; end + return @doc[selector] if not text + @doc[selector] = text + end + def doc_out(selector=nil,text=nil) + return @doc_out if not selector + if not defined? @doc_out; @doc_out={}; end + return @doc_out[selector] if not text + @doc_out[selector] = text + end end def post(*a) GridFlow.post(*a) end *************** *** 162,166 **** qlass = Class.new self qlass.install(*args) ! qlass.module_eval(&b) end alias :total_time :total_time_get --- 175,181 ---- qlass = Class.new self qlass.install(*args) ! #qlass.module_eval{qlass.instance_eval(&b)} ! qlass.instance_eval{qlass.module_eval(&b)} ! #qlass.module_eval(&b) end alias :total_time :total_time_get
Index: flow_objects.rb =================================================================== RCS file: /cvsroot/pure-data/externals/gridflow/base/flow_objects.rb,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** flow_objects.rb 4 Oct 2005 02:02:13 -0000 1.1 --- flow_objects.rb 15 Mar 2006 04:37:28 -0000 1.2 *************** *** 3,7 ****
GridFlow ! Copyright (c) 2001,2002,2003,2004 by Mathieu Bouchard
This program is free software; you can redistribute it and/or --- 3,7 ----
GridFlow ! Copyright (c) 2001,2002,2003,2004,2005 by Mathieu Bouchard
This program is free software; you can redistribute it and/or *************** *** 71,75 **** post "-"*32 GridFlow.fclasses.each {|k,v| ! next if not /#in:/ =~ k modes = case v.flags when 2; "#out" --- 71,75 ---- post "-"*32 GridFlow.fclasses.each {|k,v| ! next if not /#io:/ =~ k modes = case v.flags when 2; "#out" *************** *** 266,270 **** install_rgrid 0 class<<self;attr_reader :ninlets;end ! def initialize(n=nil,cast=:int32) n||=self.class.ninlets n>=16 and raise "too many inlets" --- 266,270 ---- install_rgrid 0 class<<self;attr_reader :ninlets;end ! def initialize(n=2,cast=:int32) n||=self.class.ninlets n>=16 and raise "too many inlets" *************** *** 299,309 **** # outlets can work. (install_rgrid is supposed to be for receiving) # maybe GF-0.8 doesn't need that. ! GridPack.subclass("@two", 2,1) { install_rgrid 0 } ! GridPack.subclass("@three",3,1) { install_rgrid 0 } ! GridPack.subclass("@four", 4,1) { install_rgrid 0 } ! GridPack.subclass("@eight",8,1) { install_rgrid 0 } GridObject.subclass("#unpack",1,0) { install_rgrid 0, true ! def initialize(n) @n=n n>=10 and raise "too many outlets" --- 299,309 ---- # outlets can work. (install_rgrid is supposed to be for receiving) # maybe GF-0.8 doesn't need that. ! GridPack.subclass("@two", 2,1) { install_rgrid 0; def initialize() super 2 end } ! GridPack.subclass("@three",3,1) { install_rgrid 0; def initialize() super 2 end } ! GridPack.subclass("@four", 4,1) { install_rgrid 0; def initialize() super 2 end } ! GridPack.subclass("@eight",8,1) { install_rgrid 0; def initialize() super 2 end } GridObject.subclass("#unpack",1,0) { install_rgrid 0, true ! def initialize(n=2) @n=n n>=10 and raise "too many outlets" *************** *** 339,344 **** send_out_grid_begin 0, [tt.length], :uint8 send_out_grid_flow 0, tt, :uint8 ! send_out 1, t.to_i ! send_out 2, t.to_f-t.to_f.floor end } --- 339,345 ---- send_out_grid_begin 0, [tt.length], :uint8 send_out_grid_flow 0, tt, :uint8 ! send_out 1, t.to_i/86400, t.to_i%86400, ! ((t.to_f-t.to_f.floor)*1000000).to_i ! send_out 2, t.year, t.month, t.day, t.hour, t.min, t.day end } *************** *** 353,356 **** --- 354,358 ---- FObject.subclass("ls",1,1) { def _0_symbol(s) send_out 0, :list, *Dir.new(s.to_s).map {|x| x.intern } end + def _0_glob (s) send_out 0, :list, *Dir[ s.to_s].map {|x| x.intern } end }
*************** *** 421,448 ****
#<vektor> told me to: ! # RGBtoYUV : @fobjects = ["#inner ( 3 3 # 66 -38 112 128 -74 -94 25 112 -18 )", # "@ >> 8","@ + {16 128 128}"] ! # YUVtoRGB : @fobjects = ["@ - ( 16 128 128 )", ! # "#inner ( 3 3 # 298 298 298 0 -100 516 409 -208 0 )","@ >> 8"]
FPatcher.subclass("#rotate",2,1) { ! @fobjects = ["@inner * + 0","@ >> 8"] @wires = [-1,0,0,0, 0,0,1,0, 1,0,-1,0] def update_rotator ! rotator = (0...@axis[2]).map {|i| ! (0...@axis[2]).map {|j| ! if i==j then 256 else 0 end ! } ! } th = @angle * Math::PI / 18000 scale = 1<<8 ! (0...2).each {|i| ! (0...2).each {|j| ! rotator[@axis[i]][@axis[j]] = ! (scale*Math.cos(th+(j-i)*Math::PI/2)).to_i ! } ! } ! @fobjects[0].send_in 2, ! @axis[2], @axis[2], "#".intern, *rotator.flatten end def _0_axis(from,to,total) --- 423,446 ----
#<vektor> told me to: ! # RGBtoYUV : @fobjects = ["#inner (3 3 # 66 -38 112 128 -74 -94 25 112 -18)", # "@ >> 8","@ + {16 128 128}"] ! # YUVtoRGB : @fobjects = ["@ - (16 128 128)", ! # "#inner (3 3 # 298 298 298 0 -100 516 409 -208 0)","@ >> 8"]
FPatcher.subclass("#rotate",2,1) { ! @fobjects = ["#inner","# >> 8"] @wires = [-1,0,0,0, 0,0,1,0, 1,0,-1,0] def update_rotator ! n = @axis[2] ! rotator = (0...n).map {|i| (0...n).map {|j| if i==j then 256 else 0 end }} th = @angle * Math::PI / 18000 scale = 1<<8 ! (0...2).each {|i| (0...2).each {|j| ! a = @axis[i].to_i ! b = @axis[j].to_i ! #GridFlow.post "(#{a},#{b}) #{rotator[a].inspect}" ! rotator[a][b] = (scale*Math.cos(th+(j-i)*Math::PI/2)).to_i ! }} ! @fobjects[0].send_in 1,n,n,"#".intern,*rotator.flatten end def _0_axis(from,to,total) *************** *** 450,454 **** from>=0 and from<total or raise "from-axis number incorrect" to >=0 and to <total or raise "to-axis number incorrect" ! @axis = [from,to,total] update_rotator end --- 448,452 ---- from>=0 and from<total or raise "from-axis number incorrect" to >=0 and to <total or raise "to-axis number incorrect" ! @axis = [from.to_i,to.to_i,total.to_i] update_rotator end *************** *** 645,649 **** end when :tcp ! if host=="-" then @server = TCPServer.new("localhost",port) else --- 643,647 ---- end when :tcp ! if host=="-" then @server = TCPServer.new("localhost",port) else *************** *** 723,727 **** # bogus class for representing objects that have no recognized class. FObject.subclass("broken",0,0) { ! def args; a=@args.dup; a[7,0] = " "+classname; a end }
--- 721,725 ---- # bogus class for representing objects that have no recognized class. FObject.subclass("broken",0,0) { ! def args; a=@args.dup; a[7,0] = " "+classname; a end }
*************** *** 893,896 **** --- 891,909 ---- end } + FObject.subclass("listfind",2,1) { + def initialize(*a) _1_list(*a) end + def _1_list(*a) @a = a end + def _0_float(x) + i=0 + while i<@a.length + (send_out 0,i; return) if @a[i]==x + i+=1 + end + send_out 0,-1 + end + doc:_1_list,"list to search into" + doc:_0_float,"float to find in that list" + doc_out:_0_float,"position of the incoming float in the stored list" + }
#-------- fClasses for: GUI *************** *** 1258,1347 **** #-------- fClasses for: Hardware
- if const_defined? :USB - - class<<USB - attr_reader :busses - end - - class DelcomUSB < GridFlow::FObject - Vendor,Product=0x0FC5,0x1222 - def self.find - r=[] - USB.busses.each {|dir,bus| - bus.each {|dev| - r<<dev if dev.idVendor==Vendor and dev.idProduct==Product - } - } - r - end - def initialize #(bus=nil,dev=nil) - r=DelcomUSB.find - raise "no such device" if r.length<1 - raise "#{r.length} such devices (which one???)" if r.length>1 - @usb=USB.new(r[0]) - if_num=nil - r[0].config.each {|config| - config.interface.each {|interface| - if_num = interface.bInterfaceNumber - } - } - # post "Interface # %i\n", if_num - @usb.set_configuration 1 - @usb.claim_interface if_num - @usb.set_altinterface 0 rescue ArgumentError - end - # libdelcom had this: - # uint8 recipient, deviceModel, major, minor, dataL, dataM; - # uint16 length; uint8[8] extension; - def _0_send_command(major,minor,dataL,dataM,extension="\0\0\0\0\0\0\0\0") - raise "closed" if not @usb - raise "extension.length!=8" if extension.length!=8 - @usb.control_msg( - 0x000000c8, 0x00000012, - minor*0x100+major, - dataM*0x100+dataL, - extension, 5000) - end - def delete; @usb.close; end - install "delcomusb", 1, 1 - end - - # Klippeltronics - FObject.subclass("multio",1,1) { - Vendor,Product=0xDEAD,0xBEEF - def self.find - r=[] - USB.busses.each {|dir,bus| - bus.each {|dev| - post "dir=%s, vendor=%x, product=%x", - dir, dev.idVendor, dev.idProduct - r<<dev if dev.idVendor==Vendor and dev.idProduct==Product - } - } - r - end - def initialize - r=self.class.find - raise "no such device" if r.length<1 - raise "#{r.length} such devices (which one???)" if r.length>1 - $iobox=@usb=USB.new(r[0]) - if_num=nil - r[0].config.each {|config| - config.interface.each {|interface| - #post "interface=%s", interface.to_s - if_num = interface.bInterfaceNumber - } - } - # post "Interface # %i\n", if_num - # @usb.set_configuration 0 - @usb.claim_interface if_num - @usb.set_altinterface 0 rescue ArgumentError - end - #@usb.control_msg(0b10100001,0x01,0,0,"",1000) - #@usb.control_msg(0b10100001,0x01,0,1," ",0) - def delete; @usb.close; end - } - end # if const_defined? :USB - # requires Ruby 1.8.0 because of bug in Ruby 1.6.x FObject.subclass("joystick_port",0,1) { --- 1271,1274 ---- *************** *** 1389,1392 **** --- 1316,1334 ---- }
+ # ASCII, useful for controlling pics + FObject.subclass("ascii",1,1) { + def puts(x) + x.each_byte {|b| send_out 0, b } + end + def _0_float x; puts "#{x.to_i}" end + } + + # System, similar to shell + FObject.subclass("system",1,1) { + def _0_system(*a) + system(a.join(" ")) + end + } + (begin require "linux/ParallelPort"; true; rescue LoadError; false end) and FObject.subclass("parallel_port",1,3) { *************** *** 1420,1424 ****
(begin require "linux/SoundMixer"; true; rescue LoadError; false end) and ! FObject.subclass("SoundMixer",1,1) { # BUG? i may have the channels (left,right) backwards def initialize(filename) --- 1362,1367 ----
(begin require "linux/SoundMixer"; true; rescue LoadError; false end) and ! #FObject.subclass("SoundMixer",1,1) { ! class GFSoundMixer < FObject; install "SoundMixer",1,1 # BUG? i may have the channels (left,right) backwards def initialize(filename) *************** *** 1450,1454 **** end end ! }
# experimental --- 1393,1397 ---- end end ! end#}
# experimental *************** *** 1474,1476 **** --- 1417,1457 ---- }
+ FObject.subclass("regsub",3,1) { + def initialize(from,to) _1_symbol(from); _2_symbol(to) end + def _0_symbol(s) send_out 0, :symbol, s.to_s.gsub(@from, @to).intern end + def _1_symbol(from) @from = Regexp.new(from.to_s.gsub(/`/,"\")) end + def _2_symbol(to) @to = to.to_s.gsub(/`/,"\") end + doc:_0_symbol,"a string to transform" + doc:_1_symbol,"a regexp pattern to be found inside of the string" + doc:_2_symbol,"a replacement for the found pattern" + doc_out:_0_symbol,"the transformed string" + } + + FObject.subclass("memstat",1,1) { + def _0_bang + f = File.open("/proc/#{$$}/stat") + send_out 0, Float(f.gets.split(" ")[22]) / 1024.0 + f.close + end + doc:_0_bang,"lookup process stats for the currently running pd+ruby "+ + "and figure out how much RAM it uses." + doc_out:_0_float,"virtual size of RAM in kilobytes (includes swapped out and shared memory)" + } + + FObject.subclass("sendgui",1,0) { + def _0_list(*x) + GridFlow.gui x.join(" ").gsub(/`/,";")+"\n" + end + install "sys_vgui", 1, 0 + doc:_0_list,"a Tcl/Tk command to send to the pd client." + } + end # module GridFlow + + begin + require "gridflow/rblti" + GridFlow.post "Ruby-LTI support loaded." + rescue Exception => e + #GridFlow.post "%s", e.inspect + #GridFlow.post "(rblti not found)" + end