• Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r4wp

[Rebol School] REBOL School

james_nak
11-Sep-2012
[950]
Arnold, I've been using sound in a recent app with 2.7.8.3.1 with 
no issues (on XP too). I use a version of Nick's code http://musiclessonz.com/rebol_tutorial.html.
Look for "play-sound"
Endo
11-Sep-2012
[951]
this works for me on free version of View: (XP)

sound-port: open sound://
play: func [file] [
 wait sound-port
 clear sound-port
 insert sound-port file
 wait sound-port
]
Maxim
12-Sep-2012
[952]
yes enabled in View. not core (like all /pro features) .
Kaj
12-Sep-2012
[953]
Ah, is that the problem again. Sigh
Arnold
12-Sep-2012
[954]
An answer in a not web public group -> Chit chat
Arnold
13-Sep-2012
[955]
Somehow indeed I managed to mix up core and view console so sound 
did work afterall. Sorry for the noise :( 
But still a wish for sound in REBOL on other platforms.
Maxim
13-Sep-2012
[956]
in R3 we can add sound support via the host-kit, but its not as good 
as it could be because we cannot add devices and/or any new type 
of event to easily (asynchronously) signal audio-related events.
Kaj
13-Sep-2012
[957]
Devices cannot be added?
BrianH
13-Sep-2012
[958]
Not at the moment, as far as we know. At least if there's a workaround 
noone has figured it out yet. You can signal asynchronous events 
with callbacks though, afaik.
Kaj
13-Sep-2012
[959]
I never realised, because I only looked at them in the C code. I 
suppose devices can be added there, but not yet afterwards from REBOL
BrianH
13-Sep-2012
[960]
They can't necessarily be added in the C code either. IIRC the devices 
table is fixed-sixe and allocated in the core code. I welcome evidence 
to the contrary.
Maxim
13-Sep-2012
[961x4]
even the event list is a hard-coded list.  which is part of the problem.
there is no device code in the host-kit (which is the C api to rebol)
callbacks do have issues which make them unusable in the real-world 
IIRC (its been a while)
wasn't there a bug wrt errors and stuff like that?
BrianH
13-Sep-2012
[965x2]
There was a plan to make device extensions, but Carl didn't know 
what API to use. He did a callout for advice, but that didn't get 
much response.
There are bugs and design flaws in R2's callbacks, but I'm not sure 
there still are in R3's. Robert's group uses them IIRC, and might 
have fixed the bug. They'd have to chime in here.
Maxim
13-Sep-2012
[967]
people who where able to help did respond and he liked a few of the 
ideas, he just never acted on it or actualy start a real discussion.
Kaj
13-Sep-2012
[968]
I thought devices were always built on top of extensions. Anyway, 
the devices are in the host kit, about six of them
Maxim
13-Sep-2012
[969]
you can only implement the devices which are built-in, you cannot 
add your own.
Kaj
13-Sep-2012
[970]
OK, but the implementations are in the host kit
BrianH
13-Sep-2012
[971]
All of the implementations of the current devices are built into 
the host portion of the C code, but are not made with extensions.
Kaj
13-Sep-2012
[972]
As far as I know, Saphirion hasn't been able to solve the threading 
and callback problems
Maxim
13-Sep-2012
[973]
yes, cause they are platform dependent.    

The latest host-kits merged two projects... the command! interface 
(extensions) and the platform abstraction (host)
BrianH
13-Sep-2012
[974]
IIRC they had some success with the pattern of using a callback to 
signal R3 to grab data using a synchronous call.
Maxim
13-Sep-2012
[975]
to allow full (run-time) extensibility of R3 as it is, it needs two 
other apis:
-a decent event registration mechanism (add new types and specs)

-a device registration system (so we can link schemes and protocols 
to them).
Kaj
13-Sep-2012
[976]
Hm, my Atari 8-bit already had that. I guess that's progress these 
days
Maxim
13-Sep-2012
[977]
I must admit that if you can receive events in the host, you can 
just execute a code string within the root ( just like if one enters 
a command in the prompt).   It worked very well for interfacing with 
GLUT ... I had just built a little pseudo event system which I called 
from within the glut callback and it was fast enough to handle all 
events in real-time.
Marco
16-Sep-2012
[978]
How can I convert an integer! that is a pointer to a C struct returned 
by a library function to a binary! ?
BrianH
16-Sep-2012
[979x2]
With more C code that copies the binary to a REBOL-allocated buffer. 
You can't deallocate a pointer in REBOL.
I mean dereference.
Gregg
16-Sep-2012
[981]
Will this work?

    LPINT-def: [value [integer!]] none
    LPINT: make struct! LPINT-def none

    make-LPINT: does [make struct! LPINT-def none]

    get-dereferenced-data: func [

        {Given a pointer to memory, copy the target data into a REBOL struct.}
        pointer [struct!]   "LPINT structure"

        struct-def [block!] "Contains a sub-struct that is the real struct 
        you want."
        /local struct data orig-pointer result
    ] [

        struct: make struct! compose/deep/only [ ; make wrapper struct
            sub [struct! (struct-def)]
        ] none

        orig-pointer: third struct              ; store original inner pointer

        change third struct third pointer       ; change inner pointer to 
        ref'd data

        data: copy third struct/sub             ; copy data from the inner 
        struct
        ;print mold data

        change third struct orig-pointer        ; restore inner pointer

        result: make struct! struct-def none    ; make result struct

        change third result data                ; change data in result struct
        ;probe result
        struct: data: orig-pointer: none
        ;recycle
        result
    ]

It's from some old code, so no guarantees.
Marco
16-Sep-2012
[982]
@BrianH I am writing in Rebol, I am not able to write C code.

@Gregg I need to pass an integer! to a function that converts it 
to a binary, and your function expects a struct! how do I change 
it?
Gregg
16-Sep-2012
[983x2]
Put the integer value in an LPINT struct.
That is, use make-LPINT, set the /value, and pass that.
Marco
16-Sep-2012
[985]
Ok, thanks.
Gregg
16-Sep-2012
[986]
Also, get-dereferenced-data maps the buffer into another REBOL struct. 
If you just want the binary data, you can adapt it not to do that.
Marco
16-Sep-2012
[987]
ok it seems to work. it becomes:

 integer-address: get-address "hello" ; function courtesy of Anton 
 Rolls
	pointer: make-LPINT
	pointer/value: integer-address
	probe third get-dereferenced-data pointer [l1 [int] l2 [int]]
Kaj
16-Sep-2012
[988x2]
In my 0MQ binding, I import the memory copying function from the 
C library:
http://rebol.esperconsultancy.nl/REBOL-2-ZeroMQ-binding/dir?ci=tip
Ladislav
16-Sep-2012
[990]
You can't deallocate a pointer in REBOL.

 - that is false, use the http://www.fm.tul.cz/~ladislav/rebol/library-utils.r
BrianH
16-Sep-2012
[991]
I meant defererence, but I'm sure you're right.
MagnussonC
18-Sep-2012
[992]
I read a file, line by line and want parts of each line in certain 
variables. First is an integer then a space and then a 3-4 character 
word then a space and then the rest of the line in a string. I guess 
there is no way like in Perl to match those variabels at once and 
put the value in numbered variables. I suppose I need to parse that 
line with something like (thru "a" copy b to "c") once for each variable 
(or perhaps first char with line/1)!?
MaxV
18-Sep-2012
[993x2]
Please put some example, you are a bit vague
Read this http://rebol2.blogspot.it/2012/05/text-extraction-with-parse.html
   ;-)
Maxim
18-Sep-2012
[995x3]
does this help?
--------------------------

a: {123 abcd bla blca bla
534 hged bla blca bla
947 ahg psogie rpgioseg seo[rgieh rpgiu}

digits: charset "0123456789"
letters: charset [#"A" - #"Z" #"a" - #"z"]
space: charset " "
data: complement charset "^/"
ctx: copy [ ]
parse/all a [
	some [
		copy id some digits
		space 
		copy var 3 4 letters
		space
		copy line-data some data
		; we have a match for all data, add it in our container

  ( append ctx copy reduce [  to-set-word rejoin [var "-" id]   line-data] 
  )
		"^/"
	]	
]

ctx: context ctx

probe ctx
obviously, this depends on the input data being pristine... 

if there are chances that the input isn't, then a bit more code would 
allow you to safely skip invalid lines.
I added a bit of processing to show how to use parse in order to 
actually do things beyond just match patterns.


note that the paren is at the end, once we have all data we want 
to match.  An error people often do is to start processing too soon.
MagnussonC
18-Sep-2012
[998]
Thank you both! Now I have something to work with. Didn't realize 
you could do parse complex like that.
Maxim
18-Sep-2012
[999]
believe me... this is very simple parsin   ;-)