From 5e2a1bc9e56003349e533f7e5841041ba5c04e28 Mon Sep 17 00:00:00 2001 From: "N.N." Date: Tue, 4 Oct 2005 02:02:15 +0000 Subject: starting to commit gridflow 0.8.0 ... if you know how to use "cvs import" please mail me and i'll use it for 0.8.1 svn path=/trunk/; revision=3646 --- externals/gridflow/extra/jmax_format.rb | 167 ++++++++++++++++++++++++++++ externals/gridflow/extra/puredata_format.rb | 129 +++++++++++++++++++++ externals/gridflow/extra/server_1_grid.rb | 26 +++++ externals/gridflow/extra/server_1_ppm.rb | 20 ++++ externals/gridflow/extra/server_2.rb | 65 +++++++++++ externals/gridflow/extra/smpte.rb | 23 ++++ 6 files changed, 430 insertions(+) create mode 100644 externals/gridflow/extra/jmax_format.rb create mode 100644 externals/gridflow/extra/puredata_format.rb create mode 100644 externals/gridflow/extra/server_1_grid.rb create mode 100644 externals/gridflow/extra/server_1_ppm.rb create mode 100644 externals/gridflow/extra/server_2.rb create mode 100644 externals/gridflow/extra/smpte.rb (limited to 'externals/gridflow/extra') diff --git a/externals/gridflow/extra/jmax_format.rb b/externals/gridflow/extra/jmax_format.rb new file mode 100644 index 00000000..c1b93ce5 --- /dev/null +++ b/externals/gridflow/extra/jmax_format.rb @@ -0,0 +1,167 @@ +=begin + $Id: jmax_format.rb,v 1.1 2005-10-04 02:02:15 matju Exp $ + + GridFlow + Copyright (c) 2001,2002,2003 by Mathieu Bouchard + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + See file ../COPYING for further informations on licensing terms. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +=end + + +class JMaxFileHandler + Size = [4,1,2,4] + Packer = ["N","c","n","N"] + OpTable = [ + [0, :return], + [1, :push, :int], + [2, :push, :float], + [3, :push, :symbol], + [5, :set, :int], + [6, :set, :float], + [7, :set, :symbol], + [9, :pop_args, :int], + [10, :push_obj, :int], + [11, :mv_obj, :int], + [12, :pop_objs, :int], + [13, :make_obj, :int], + [14, :put_prop, :symbol], + [16, :obj_mess, :int, :symbol, :int], + [18, :push_obj_table, :int], + [19, :pop_obj_table], + [20, :connect], + [21, :make_top_obj, :int], + ] + OpTableById = {} + OpTableByName = {} + OpTable.each {|entry| + id,name,arg = entry + OpTableById[id] = entry + OpTableByName[name] = entry + } +end + +class JObject + attr_reader :properties + attr_accessor :parent_patcher + attr_reader :init_messages + attr_reader :connections + def self.[](*args) new(*args) end + def initialize(*args) + @args = args + @properties = {} + @init_messages = [] + end + def send_in(inlet,*args) + @init_messages << [inlet,*args] + end + def connect(inlet,target,outlet) + end + def subobjects + @subobjects={} if not defined? @subobjects + @subobjects + end +end + +class JMaxFileReader < JMaxFileHandler + def initialize(f,factory=JObject) + @f = f + @symbols = [] + @estack = [] + @ostack = [] + @tstack = [] + @factory = factory + end + def parse + magic, code_size, n_symbols = @f.read(12).unpack("a4NN") + case magic + when "bMax"; #ok + when "bMa2"; raise "bMa2 format (jMax 4) is not supported yet" + else raise "not a jMax file" + end + @code = @f.read code_size + @symbols = @f.read.split(/\0/).map {|x| x.intern } + @index = 0 + while @index < @code.size + read_opcode + end + raise "@estack.size!=0" if @estack.size!=0 + raise "@ostack.size!=1" if @ostack.size!=1 + raise "@tstack.size!=0" if @tstack.size!=0 + @ostack[0] + end + def read_opcode + #puts "#{@index} of #{@code.size}" + op = @code[@index]; @index+=1 + op1,op2 = op&0x3f,op>>6 + entry = OpTableById[op1] + if not entry + puts "skipping unknown opcode #{op1},#{op2}" + return + end + args = [] + (entry.length-2).times {|i| + args << (case entry[2+i] + when :int + n=Size[op2]; v=@code[@index,n].unpack(Packer[op2])[0] + x = if v[8*n-1]!=0 then ~(~v&((1<<(8*n-1))-1)) else v end + #STDERR.puts "WARNING: #{v} -> #{x}" if x<0 + x + when :float + n=4; @code[@index,4].unpack("g")[0] + when :symbol + n=Size[op2]; @symbols[@code[@index,n].unpack(Packer[op2])[0]] + when nil + end) + @index+=n + } + #text = sprintf "%05d: %2d,%1d: %s", @index, op1, op2, entry[1] + #text << "(" << args.map{|x|x.inspect}.join(",") << ")" + #puts text + send entry[1], *args + end + def push x; @estack << x end + def set x + if @estack.size>0 then @estack[-1]=x else @estack << x end + end + def put_prop x; @ostack[-1].properties[x] = @estack[-1] end + def make_obj x + patcher = @ostack[-1] if @ostack.size>0 + baby = @factory[*(@estack[-x,x].reverse)] + @ostack << baby + @ostack[-1].parent_patcher = patcher + patcher.subobjects[baby]=true if patcher + end + alias :make_top_obj :make_obj + def pop_args x; @estack[-x,x]=[] end + def push_obj_table x; @tstack<<[] end + def mv_obj x; @tstack[-1][x]=@ostack[-1] end + def pop_objs x; @ostack[-x,x]=[] end + def obj_mess i,s,n + o = @ostack[-1] + m = @estack[-n,n].reverse + if i<0 then o.send s,*m else o.send_in i,s,*m end + end + def push_obj x; @ostack<<@tstack[-1][x] end + def connect; @ostack[-1].connect @estack[-1],@ostack[-2],@estack[-2] end + def pop_obj_table; @tstack.pop end + def return; end +end + +if $0 == __FILE__ + jff = JMaxFileReader.new File.open("samples/fire.jmax") + jff.parse +end diff --git a/externals/gridflow/extra/puredata_format.rb b/externals/gridflow/extra/puredata_format.rb new file mode 100644 index 00000000..508f545e --- /dev/null +++ b/externals/gridflow/extra/puredata_format.rb @@ -0,0 +1,129 @@ +=begin + $Id: puredata_format.rb,v 1.1 2005-10-04 02:02:15 matju Exp $ + + GridFlow + Copyright (c) 2001,2002,2003 by Mathieu Bouchard + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + See file ../COPYING for further informations on licensing terms. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +=end + +class PureDataFileWriter + def initialize filename + @f = File.open filename, "w" + end + def close; @f.close end + def write_patcher o + pr = o.properties + @f.puts "#N canvas #{pr[:wx]} #{pr[:wy]} #{pr[:ww]} #{pr[:wh]} 10;" + ol = o.subobjects.keys + x=0 + ol.find_all {|a| a.classname=="inlet"}.sort {|a,b| a.argv[0] <=> b.argv[0] }.each {|a| + if x>a.properties[:x] + a.properties[:x]=x+16 + STDERR.puts "warning: moving inlet #{a.argv[0]} to the right" + end + x=a.properties[:x] + } + x=0 + ol.find_all {|a| a.classname=="outlet"}.sort {|a,b| a.argv[0] <=> b.argv[0] }.each {|a| + if x>a.properties[:x] + a.properties[:x]=x+16 + STDERR.puts "warning: moving outlet #{a.argv[0]} to the right" + end + x=a.properties[:x] + } + ol.each {|so| write_object so } + ol.each_with_index {|so,i| + next if not so.instance_eval{defined? @outlets} + so.outlets.each_with_index {|conns,outlet| + next if not conns + conns.each {|target,inlet| + @f.puts "#X connect #{i} #{outlet} #{ol.index target} #{inlet};" + } + } + } + end + + def list_to_s l + l.map {|x| + if Array===x then "( " + list_to_s(x) + " )" else escape(x.to_s) end + }.join " " + end + + # what am i supposed to do? + def escape x; x.gsub(/[;,]/) {|x| " \\#{x}" }.gsub(/\n/) {"\\\n"} end + def escape2 x; x.gsub(/[,]/) {|x| " \\#{x} " }.gsub(/[;\$\"]/) {|x| "\\#{x}" }.gsub(/\n/) {"\\\n"} end + + def write_object o + pr = o.properties + #classname = o.class.instance_eval{@foreign_name} + classname = o.classname + if classname=="jpatcher" + #@f.print "#N canvas 0 0 " + write_patcher o + end + + case classname + when "display"; classname="print" + when "list"; classname="listmake" + end + + t = case classname + when "jcomment"; "text" + when "messbox"; "msg" + when "jpatcher"; "restore" + when "intbox"; "floatatom" + else "obj" + end + @f.print "#X #{t} #{pr[:x]} #{pr[:y]} " + + case classname + when "button" + @f.print "bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1" + when "jcomment" + @f.print escape2(pr[:comment].to_s) + when "messbox" + av=o.argv[0] + i=0 + dollar="$".intern + while i0 + unless k+s.length>n + puts "trying #{k}" + (s << read(k)) rescue Errno::EWOULDBLOCK + end + k>>=1 + end + s + end + # this one works but is slow. + def bugfree_read_at_most n + s="" + (s << (read 1) while s.length> c)&1) })) + row_2 << yield (*([1,2,0].map{|c| 255 * ((n_barre_2 >> c)&1) })) + row_3 << yield (*(row_3_c[x/57] || [0,0,0])) + } + 160.times { picture << row_1 } + 20 .times { picture << row_2 } + 60 .times { picture << row_3 } + picture +end -- cgit v1.2.1