Tk delay

Discussion in 'Ruby' started by Jesse Jurman, Apr 3, 2010.

  1. Jesse Jurman

    Jesse Jurman Guest

    I am somewhat new to Ruby and Tk, I have made a couple of simple
    programs, but now I'm working on a Music Automation Program... like for
    a Radio Station... something that will play song after song, infinitely.
    Right now I need a means to delay the next song for the number of
    seconds that the current song is playing. I've heard of a Tk::after
    method, but I am having trouble understanding how it works.

    Any help, links, or examples would be greatly appreciated...
    --
    Posted via http://www.ruby-forum.com/.
     
    Jesse Jurman, Apr 3, 2010
    #1
    1. Advertising

  2. Jesse Jurman

    Jesse Jurman Guest

    Jesse Jurman wrote:

    > Right now I need a means to delay the next song for the number of
    > seconds that the current song is playing.


    I'm using the Snack audio toolkit for ruby, so I already know how long
    the song is... I don't need to constantly check if the song is
    playing... I just need to have a block of code run after a set number of
    seconds.
    --
    Posted via http://www.ruby-forum.com/.
     
    Jesse Jurman, Apr 3, 2010
    #2
    1. Advertising

  3. On Sun, Apr 4, 2010 at 3:40 AM, Jesse Jurman <> wrote:
    > Jesse Jurman wrote:
    >
    >> Right now I need a means to delay the next song for the number of
    >> seconds that the current song is playing.

    >
    > I'm using the Snack audio toolkit for ruby, so I already know how long
    > the song is... I don't need to constantly check if the song is
    > playing... I just need to have a block of code run after a set number of
    > seconds.


    In stdlib Tk:
    ruby -rtk -e 'Tk.after(5000){ puts "hi" }; Tk.mainloop'

    In ffi-tk:
    ruby -rffi-tk -e 'Tk::After.ms(5000){ puts "hi" }; Tk.mainloop'

    --
    Michael Fellinger
    CTO, The Rubyists, LLC
     
    Michael Fellinger, Apr 4, 2010
    #3
  4. From: Jesse Jurman <>
    Subject: Re: Tk delay
    Date: Sun, 4 Apr 2010 03:40:47 +0900
    Message-ID: <>
    > I'm using the Snack audio toolkit for ruby, so I already know how long
    > the song is... I don't need to constantly check if the song is
    > playing... I just need to have a block of code run after a set number of
    > seconds.


    Snack toolkit can call a callback procedure at end of the sound.
    Isn't it enough for your purpose?

    I don't know Snack for Ruby (rbsnack) library.
    Even if rbsnack doesn't support such callback,
    you can call the feature of Tcl/Tk from Ruby/Tk
    (if your Tcl/Tk can load Snack, and your Ruby/Tk loads the Tcl/Tk's libs).

    For example,
    -----------------------------------------
    sndname = 'foobar'
    Tk.tk_call('snack::sound', sndname, '-file', sndfile, '-fileformat', fmt, ...)
    Tk.tk_call(sndname, 'play', '-callback', proc{puts "end of the sound"})
    -----------------------------------------
    --
    Hidetoshi NAGAI ()
     
    Hidetoshi NAGAI, Apr 4, 2010
    #4
  5. Jesse Jurman

    Jesse Jurman Guest

    Michael Fellinger wrote:
    > On Sun, Apr 4, 2010 at 3:40 AM, Jesse Jurman <>
    > wrote:
    >> Jesse Jurman wrote:
    >>
    >>> Right now I need a means to delay the next song for the number of
    >>> seconds that the current song is playing.

    >>
    >> I'm using the Snack audio toolkit for ruby, so I already know how long
    >> the song is... I don't need to constantly check if the song is
    >> playing... I just need to have a block of code run after a set number of
    >> seconds.

    >
    > In stdlib Tk:
    > ruby -rtk -e 'Tk.after(5000){ puts "hi" }; Tk.mainloop'
    >
    > In ffi-tk:
    > ruby -rffi-tk -e 'Tk::After.ms(5000){ puts "hi" }; Tk.mainloop'


    Thanks, this works... but I can't get it to loop! I'm going to try using
    this with a TkTimer widget... but is there perchance a loop option in
    this widget as well? Something like TkTimer's loop?
    i.e. 'TkTimer.start(5000, -1){puts "hi"}'
    --
    Posted via http://www.ruby-forum.com/.
     
    Jesse Jurman, Apr 5, 2010
    #5
  6. On Mon, Apr 5, 2010 at 9:52 AM, Jesse Jurman <> wrote:
    > Michael Fellinger wrote:
    >> On Sun, Apr 4, 2010 at 3:40 AM, Jesse Jurman <>
    >> wrote:
    >>> Jesse Jurman wrote:
    >>>
    >>>> Right now I need a means to delay the next song for the number of
    >>>> seconds that the current song is playing.
    >>>
    >>> I'm using the Snack audio toolkit for ruby, so I already know how long
    >>> the song is... I don't need to constantly check if the song is
    >>> playing... I just need to have a block of code run after a set number of
    >>> seconds.

    >>
    >> In stdlib Tk:
    >> ruby -rtk -e 'Tk.after(5000){ puts "hi" }; Tk.mainloop'
    >>
    >> In ffi-tk:
    >> ruby -rffi-tk -e 'Tk::After.ms(5000){ puts "hi" }; Tk.mainloop'

    >
    > Thanks, this works... but I can't get it to loop! I'm going to try using
    > this with a TkTimer widget... but is there perchance a loop option in
    > this widget as well? Something like TkTimer's loop?
    > i.e. 'TkTimer.start(5000, -1){puts "hi"}'


    tick = lambda{
    puts "hi"
    Tk.after(5000, &tick)
    }
    Tk.after(5000, &tick)

    > --
    > Posted via http://www.ruby-forum.com/.
    >
    >




    --
    Michael Fellinger
    CTO, The Rubyists, LLC
    972-996-5199
     
    Michael Fellinger, Apr 5, 2010
    #6
  7. From: Jesse Jurman <>
    Subject: Re: Tk delay
    Date: Mon, 5 Apr 2010 09:52:20 +0900
    Message-ID: <>
    > Thanks, this works... but I can't get it to loop! I'm going to try using
    > this with a TkTimer widget... but is there perchance a loop option in
    > this widget as well? Something like TkTimer's loop?
    > i.e. 'TkTimer.start(5000, -1){puts "hi"}'


    interval argument of TkTimer can accept a proc object.
    The proc is called when decide the interval time for the next call.
    So, the proc must return a milisecond value of integer.

    For example,
    ------------------------------------------------
    evloop = Thread.new{Tk.mainloop}
    ary = [500, 1000, 2000, 4000]
    TkTimer.new(proc{tm = ary.shift; ary.push(tm); tm}, -1){puts :hoge}.start
    evloop.join; exit
    ------------------------------------------------
    --
    Hidetoshi NAGAI ()
     
    Hidetoshi NAGAI, Apr 5, 2010
    #7
  8. Jesse Jurman

    Jesse Jurman Guest

    Michael Fellinger wrote:
    > On Mon, Apr 5, 2010 at 9:52 AM, Jesse Jurman <>
    > wrote:
    >>>> playing... I just need to have a block of code run after a set number of

    >> this widget as well? Something like TkTimer's loop?
    >> i.e. 'TkTimer.start(5000, -1){puts "hi"}'

    >
    > tick = lambda{
    > puts "hi"
    > Tk.after(5000, &tick)
    > }
    > Tk.after(5000, &tick)


    Thanks! Works perfectly!
    --
    Posted via http://www.ruby-forum.com/.
     
    Jesse Jurman, Apr 6, 2010
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ingmar Seifert

    Delay of control signals

    Ingmar Seifert, Aug 18, 2003, in forum: VHDL
    Replies:
    0
    Views:
    1,216
    Ingmar Seifert
    Aug 18, 2003
  2. john
    Replies:
    1
    Views:
    633
    Kai Harrekilde-Petersen
    Aug 28, 2003
  3. Kelvin
    Replies:
    0
    Views:
    962
    Kelvin
    Sep 14, 2003
  4. Ramakrishnan

    delta delay..

    Ramakrishnan, Sep 23, 2003, in forum: VHDL
    Replies:
    4
    Views:
    5,225
    Mike Treseler
    Sep 23, 2003
  5. moe
    Replies:
    1
    Views:
    2,344
    Tom Hawkins
    Oct 26, 2003
Loading...

Share This Page