[PD-cvs] externals/gridflow/devices4ruby ParallelPort.rb, NONE, 1.1 SoundMixer.rb, NONE, 1.1 SoundPCM.rb, NONE, 1.1 extconf.rb, NONE, 1.1 ioctl.rb, NONE, 1.1
Mathieu Bouchard
matju at users.sourceforge.net
Tue Oct 4 04:02:17 CEST 2005
Update of /cvsroot/pure-data/externals/gridflow/devices4ruby
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21117/devices4ruby
Added Files:
ParallelPort.rb SoundMixer.rb SoundPCM.rb extconf.rb ioctl.rb
Log Message:
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
--- NEW FILE: SoundPCM.rb ---
# $Id: SoundPCM.rb,v 1.1 2005/10/04 02:02:14 matju Exp $
require "linux/ioctl"
module Linux
module SoundPCM
extend IoctlClass
# SNDCTL Kernel Procedure Numbers
SEQ_RESET = 0x00005100
SEQ_SYNC = 0x00005101
SEQ_CTRLRATE = 0xc0045103
SEQ_GETOUTCOUNT = 0x80045104
SEQ_GETINCOUNT = 0x80045105
SEQ_PERCMODE = 0x40045106
SEQ_TESTMIDI = 0x40045108
SEQ_RESETSAMPLES = 0x40045109
SEQ_NRSYNTHS = 0x8004510a
SEQ_NRMIDIS = 0x8004510b
SEQ_THRESHOLD = 0x4004510d
SEQ_PANIC = 0x00005111
SEQ_OUTOFBAND = 0x40085112
SEQ_GETTIME = 0x80045113
SYNTH_INFO = 0xc08c5102
SYNTH_MEMAVL = 0xc004510e
SYNTH_ID = 0xc08c5114
SYNTH_CONTROL = 0xcfa45115
SYNTH_REMOVESAMPLE = 0xc00c5116
FM_LOAD_INSTR = 0x40285107
FM_4OP_ENABLE = 0x4004510f
TMR_TIMEBASE = 0xc0045401
TMR_START = 0x00005402
TMR_STOP = 0x00005403
TMR_CONTINUE = 0x00005404
TMR_TEMPO = 0xc0045405
TMR_SOURCE = 0xc0045406
TMR_METRONOME = 0x40045407
TMR_SELECT = 0x40045408
MIDI_INFO = 0xc074510c
MIDI_PRETIME = 0xc0046d00
MIDI_MPUMODE = 0xc0046d01
MIDI_MPUCMD = 0xc0216d02
# DSP_* names are obsolete ?
DSP_STEREO = 0xc0045003
DSP_GETBLKSIZE = 0xc0045004
DSP_SETDUPLEX = 0x00005016
DSP_GETODELAY = 0x80045017
DSP_PROFILE = 0x40045017
# what is this?
COPR_RESET = 0x00004300
COPR_LOAD = 0xcfb04301
COPR_RDATA = 0xc0144302
COPR_RCODE = 0xc0144303
COPR_WDATA = 0x40144304
COPR_WCODE = 0x40144305
COPR_RUN = 0xc0144306
COPR_HALT = 0xc0144307
COPR_SENDMSG = 0xcfa44308
COPR_RCVMSG = 0x8fa44309
# SOUND_PCM Kernel Procedure Numbers
PCM_READ_BITS , PCM_WRITE_BITS = 0x80045005, 0xc0045005
PCM_READ_CHANNELS , PCM_WRITE_CHANNELS = 0x80045006, 0xc0045006
PCM_READ_FILTER , PCM_WRITE_FILTER = 0x80045007, 0xc0045007
PCM_READ_RATE , PCM_WRITE_RATE = 0x80045002, 0xc0045002
PCM_RESET = 0x00005000
PCM_SYNC = 0x00005001
PCM_POST = 0x00005008
PCM_SUBDIVIDE = 0xc0045009
PCM_SETFRAGMENT = 0xc004500a
PCM_GETFMTS = 0x8004500b
PCM_SETFMT = 0xc0045005
PCM_GETOSPACE = 0x8010500c
PCM_GETISPACE = 0x8010500d
PCM_NONBLOCK = 0x0000500e
PCM_GETCAPS = 0x8004500f
PCM_GETTRIGGER , PCM_SETTRIGGER = 0x80045010, 0x40045010
PCM_SETSYNCRO = 0x00005015
PCM_GETIPTR = 0x800c5011
PCM_GETOPTR = 0x800c5012
PCM_MAPINBUF = 0x80085013
PCM_MAPOUTBUF = 0x80085014
ioctl_accessor :bits , :PCM_READ_BITS , :PCM_WRITE_BITS
ioctl_accessor :channels, :PCM_READ_CHANNELS, :PCM_WRITE_CHANNELS
ioctl_accessor :filter , :PCM_READ_FILTER , :PCM_WRITE_FILTER
ioctl_accessor :rate , :PCM_READ_RATE , :PCM_WRITE_RATE
end
# backward compatibility
SoundDSP = SoundPCM
end # Linux
--- NEW FILE: extconf.rb ---
#!/usr/bin/env ruby
# $Id: extconf.rb,v 1.1 2005/10/04 02:02:14 matju Exp $
# installer for RubyX11 / MetaRuby / etc
# by Mathieu Bouchard
require "rbconfig"
require "ftools"
include Config
$DESTDIR = "#{CONFIG["sitedir"]}/#{CONFIG["MAJOR"]}.#{CONFIG["MINOR"]}"
#$DESTDIR = "/home/matju/lib/ruby/#{RUBY_VERSION[0,3]}"
$RUBY = "ruby"
while ARGV.length>0
arg=ARGV.shift
case arg
when /=/
i=arg.index '='
ARGV.unshift arg[0..i-1], arg[i+1..-1]
when "--prefix"
$DESTDIR = ARGV.shift + "/lib/ruby/#{CONFIG["MAJOR"]}.#{CONFIG["MINOR"]}"
end
end
def install_files(f,base,entries)
entries.each {|type,name,*rest|
case type
when :ruby
f.puts "\tinstall -m644 #{base+name} $(DESTDIR)/#{base+name}"
when :directory
f.puts "\t at mkdir $(DESTDIR)/#{base+name} || true"
install_files(f,base+name,rest)
end
}
end
def uninstall_files(f,base,entries)
entries.each {|type,name,*rest|
case type
when :ruby
f.puts "\trm $(DESTDIR)/#{base+name}"
when :directory
uninstall_files(f,base+name,rest)
end
}
end
def make_makefile
File.open("Makefile","w") {|f|
f.puts "# Warning: this file is GENERATED by ./extconf.rb", ""
f.puts "DESTDIR = #{$DESTDIR}", ""
f.puts "RUBY = #{$RUBY}"
f.puts "all::", ""
f.puts "Makefile: extconf.rb"
f.puts "\t$(RUBY) extconf.rb", ""
f.puts "install::"
f.puts "\t at mkdir -p $(DESTDIR)"
install_files(f,"",FILES)
f.puts
f.puts "uninstall::"
uninstall_files(f,"",FILES)
f.puts
}
#FILES.each {|name|
# File.install "lib/#{name}", "#{DSTPATH}/#{name}", 0644, true
#end
end
#----------------------------------------------------------------#
$DESTDIR += "/linux/" #(HACK!)
FILES = [
# [:directory, "linux/",
[:ruby, "ioctl.rb"],
[:ruby, "SoundPCM.rb"],
[:ruby, "ParallelPort.rb"],
[:ruby, "SoundMixer.rb"],
# ]
]
make_makefile
__END__
### the following is discarded (just a test)
require "mkmf"
srcs = %w(
termios
)
#have_library("m")
#have_func("sincos")
#have_func("asinh")
#if have_header("fftw.h")
# if have_library("fftw", "fftwnd_create_plan")
# srcs.push "na_fftw"
# else
# $defs.delete "-DHAVE_FFTW_H"
# end
#end
$objs = srcs.map {|i| i+".o"}
#dir_config("linux")
create_makefile("linux")
--- NEW FILE: ioctl.rb ---
# general-purpose code for performing
# less-than-trivial IOCTL operations.
# note that this is quite hackish
# but is still better than writing actual C code.
module Linux; DEVICES_VERSION = "0.1.1"; end
module IoctlClass
def ioctl_reader(sym,cmd_in)
module_eval %{def #{sym}
ioctl_intp_in(#{cmd_in})
end}
end
def ioctl_writer(sym,cmd_out)
module_eval %{def #{sym}=(v)
ioctl_intp_out(#{cmd_out},v)
#{sym} if respond_to? :#{sym}
end}
end
def ioctl_accessor(sym,cmd_in,cmd_out)
ioctl_reader(sym,cmd_in)
ioctl_writer(sym,cmd_out)
end
end
module Ioctl
# this method is not used anymore
def int_from_4(foo)
# if it crashes, just insert foo=foo.reverse here.
(foo[0]+0x100*foo[1])+0x10000*(foo[2]+0x100*foo[3])
end
# this was a big hack (from hell) that i used until I actually
# learned the other feature of ioctl().
=begin
def ioctl_intp_out(arg1,arg2)
tmp = arg2 + 2**32
foo = [2*tmp.id + 16].pack("l").unpack("P4")[0]
tmp_ptr = int_from_4(foo)
# STDOUT.printf "tmp_ptr=%x\n", tmp_ptr
ioctl(arg1,tmp_ptr)
end
def ioctl_intp_in(arg1)
tmp = 0xdeadbeef + 2**32
foo = [2*tmp.id + 16].pack("l").unpack("P4")[0]
tmp_ptr = int_from_4(foo)
# tmp_ptr = foo.unpack("l")[0]
# STDOUT.printf "tmp_ptr=%x\n", tmp_ptr
ioctl(arg1,tmp_ptr)
tmp & (2**32-1)
end
=end
def ioctl_intp_out(arg1,arg2)
ioctl(arg1,[arg2].pack("l"))
end
def ioctl_intp_in(arg1)
ioctl(arg1,s="blah")
return s.unpack("l")[0]
end
end
class IO; include Ioctl; end
--- NEW FILE: ParallelPort.rb ---
require "linux/ioctl"
# Copyright (c) 2001, 2003 by Mathieu Bouchard
# this is published under the Ruby license
=begin
if using a DB-25 female connector as found on a PC,
then the pin numbering is like:
13 _____ 1
25 \___/ 14
1 = STROBE = the clock line is a square wave, often at 9600 Hz,
which determines the data rate in usual circumstances.
2..9 = D0..D7 = the eight ordinary data bits
10 = -ACK (status bit 6 ?)
11 = BUSY (status bit 7)
12 = PAPER_END (status bit 5)
13 = SELECT (status bit 4 ?)
14 = -AUTOFD
15 = -ERROR (status bit 3 ?)
16 = -INIT
17 = -SELECT_IN
18..25 = GROUND
=end
module Linux; module ParallelPort
extend IoctlClass
@port_flags = %w[
LP_EXIST
LP_SELEC
LP_BUSY
LP_OFFL
LP_NOPA
LP_ERR
LP_ABORT
LP_CAREFUL
LP_ABORTOPEN
LP_TRUST_IRQ
]
@port_status = %w[
nil,
nil,
nil,
LP_PERRORP # unchanged input, active low
LP_PSELECD # unchanged input, active high
LP_POUTPA # unchanged input, active high
LP_PACK # unchanged input, active low
LP_PBUSY # inverted input, active high
]
LPCHAR = 0x0601
LPTIME = 0x0602
LPABORT = 0x0604
LPSETIRQ = 0x0605
LPGETIRQ = 0x0606
LPWAIT = 0x0608
LPCAREFUL = 0x0609 # obsoleted??? wtf?
LPABORTOPEN = 0x060a
LPGETSTATUS = 0x060b # return LP_S(minor)
LPRESET = 0x060c # reset printer
LPGETSTATS = 0x060d # struct lp_stats (most likely turned off)
LPGETFLAGS = 0x060e # get status flags
LPTRUSTIRQ = 0x060f # set/unset the LP_TRUST_IRQ flag
ioctl_reader :port_flags , :LPGETFLAGS
ioctl_reader :port_status, :LPGETSTATUS
ioctl_writer :port_careful,:LPCAREFUL
ioctl_writer :port_char, :LPCHAR
end end
--- NEW FILE: SoundMixer.rb ---
require "linux/ioctl"
module Linux; module SoundMixer
extend IoctlClass
MIXER_NRDEVICES = 0x00000019
MIXER_VOLUME = 0x00000000
MIXER_BASS = 0x00000001
MIXER_TREBLE = 0x00000002
MIXER_SYNTH = 0x00000003
MIXER_PCM = 0x00000004
MIXER_SPEAKER = 0x00000005
MIXER_LINE = 0x00000006
MIXER_MIC = 0x00000007
MIXER_CD = 0x00000008
MIXER_IMIX = 0x00000009
MIXER_ALTPCM = 0x0000000a
MIXER_RECLEV = 0x0000000b
MIXER_IGAIN = 0x0000000c
MIXER_OGAIN = 0x0000000d
MIXER_LINE1 = 0x0000000e
MIXER_LINE2 = 0x0000000f
MIXER_LINE3 = 0x00000010
MIXER_DIGITAL1 = 0x00000011
MIXER_DIGITAL2 = 0x00000012
MIXER_DIGITAL3 = 0x00000013
MIXER_PHONEIN = 0x00000014
MIXER_PHONEOUT = 0x00000015
MIXER_VIDEO = 0x00000016
MIXER_RADIO = 0x00000017
MIXER_MONITOR = 0x00000018
ONOFF_MIN = 0x0000001c
ONOFF_MAX = 0x0000001e
MIXER_NONE = 0x0000001f
MIXER_ENHANCE = 0x0000001f
MIXER_MUTE = 0x0000001f
MIXER_LOUD = 0x0000001f
MIXER_RECSRC = 0x000000ff
MIXER_DEVMASK = 0x000000fe
MIXER_RECMASK = 0x000000fd
MIXER_CAPS = 0x000000fc
MIXER_STEREODEVS = 0x000000fb
MIXER_OUTSRC = 0x000000fa
MIXER_OUTMASK = 0x000000f9
MASK_VOLUME = 0x00000001
MASK_BASS = 0x00000002
MASK_TREBLE = 0x00000004
MASK_SYNTH = 0x00000008
MASK_PCM = 0x00000010
MASK_SPEAKER = 0x00000020
MASK_LINE = 0x00000040
MASK_MIC = 0x00000080
MASK_CD = 0x00000100
MASK_IMIX = 0x00000200
MASK_ALTPCM = 0x00000400
MASK_RECLEV = 0x00000800
MASK_IGAIN = 0x00001000
MASK_OGAIN = 0x00002000
MASK_LINE1 = 0x00004000
MASK_LINE2 = 0x00008000
MASK_LINE3 = 0x00010000
MASK_DIGITAL1 = 0x00020000
MASK_DIGITAL2 = 0x00040000
MASK_DIGITAL3 = 0x00080000
MASK_PHONEIN = 0x00100000
MASK_PHONEOUT = 0x00200000
MASK_RADIO = 0x00800000
MASK_VIDEO = 0x00400000
MASK_MONITOR = 0x01000000
MASK_MUTE = 0x80000000
MASK_ENHANCE = 0x80000000
MASK_LOUD = 0x80000000
MIXER_READ_VOLUME = 0x80044d00
MIXER_READ_BASS = 0x80044d01
MIXER_READ_TREBLE = 0x80044d02
MIXER_READ_SYNTH = 0x80044d03
MIXER_READ_PCM = 0x80044d04
MIXER_READ_SPEAKER = 0x80044d05
MIXER_READ_LINE = 0x80044d06
MIXER_READ_MIC = 0x80044d07
MIXER_READ_CD = 0x80044d08
MIXER_READ_IMIX = 0x80044d09
MIXER_READ_ALTPCM = 0x80044d0a
MIXER_READ_RECLEV = 0x80044d0b
MIXER_READ_IGAIN = 0x80044d0c
MIXER_READ_OGAIN = 0x80044d0d
MIXER_READ_LINE1 = 0x80044d0e
MIXER_READ_LINE2 = 0x80044d0f
MIXER_READ_LINE3 = 0x80044d10
MIXER_READ_MUTE = 0x80044d1f
MIXER_READ_ENHANCE = 0x80044d1f
MIXER_READ_LOUD = 0x80044d1f
MIXER_READ_RECSRC = 0x80044dff
MIXER_READ_DEVMASK = 0x80044dfe
MIXER_READ_RECMASK = 0x80044dfd
MIXER_READ_STEREODEVS = 0x80044dfb
MIXER_READ_CAPS = 0x80044dfc
MIXER_WRITE_VOLUME = 0xc0044d00
MIXER_WRITE_BASS = 0xc0044d01
MIXER_WRITE_TREBLE = 0xc0044d02
MIXER_WRITE_SYNTH = 0xc0044d03
MIXER_WRITE_PCM = 0xc0044d04
MIXER_WRITE_SPEAKER = 0xc0044d05
MIXER_WRITE_LINE = 0xc0044d06
MIXER_WRITE_MIC = 0xc0044d07
MIXER_WRITE_CD = 0xc0044d08
MIXER_WRITE_IMIX = 0xc0044d09
MIXER_WRITE_ALTPCM = 0xc0044d0a
MIXER_WRITE_RECLEV = 0xc0044d0b
MIXER_WRITE_IGAIN = 0xc0044d0c
MIXER_WRITE_OGAIN = 0xc0044d0d
MIXER_WRITE_LINE1 = 0xc0044d0e
MIXER_WRITE_LINE2 = 0xc0044d0f
MIXER_WRITE_LINE3 = 0xc0044d10
MIXER_WRITE_MUTE = 0xc0044d1f
MIXER_WRITE_ENHANCE = 0xc0044d1f
MIXER_WRITE_LOUD = 0xc0044d1f
MIXER_WRITE_RECSRC = 0xc0044dff
MIXER_INFO = 0x805c4d65
MIXER_ACCESS = 0xc0804d66
MIXER_AGC = 0xc0044d67
MIXER_3DSE = 0xc0044d68
MIXER_PRIVATE1 = 0xc0044d6f
MIXER_PRIVATE2 = 0xc0044d70
MIXER_PRIVATE3 = 0xc0044d71
MIXER_PRIVATE4 = 0xc0044d72
MIXER_PRIVATE5 = 0xc0044d73
MIXER_GETLEVELS = 0xc0a44d74
MIXER_SETLEVELS = 0xc0a44d75
DEVICE_LABELS = [
"Vol ", "Bass ", "Trebl", "Synth", "Pcm ",
"Spkr ","Line ", "Mic ", "CD ", "Mix ",
"Pcm2 ","Rec ", "IGain", "OGain",
"Line1", "Line2", "Line3", "Digital1", "Digital2", "Digital3",
"PhoneIn", "PhoneOut", "Video", "Radio", "Monitor"
]
DEVICE_NAMES = [
"vol", "bass", "treble", "synth", "pcm", "speaker", "line",
"mic", "cd", "mix", "pcm2", "rec", "igain", "ogain",
"line1", "line2", "line3", "dig1", "dig2", "dig3",
"phin", "phout", "video", "radio", "monitor"
]
DEVICE_NAMES.each_with_index {|name,i|
ioctl_accessor name,
MIXER_READ_VOLUME+i,
MIXER_WRITE_VOLUME+i
}
end end
More information about the Pd-cvs
mailing list