A
download nb.rb
Language: Ruby
LOC: 321
Project Info
Snd
Server: SourceForge
Type: cvs
SourceForge\s\snd\snd\cvs‑snd\
   _new_snd-test.rb
   _sndlib.h
   aclocal.m4
   analog-filter.scm
   audinfo.c
   audio.c
   autosave.scm
   bess.rb
   bess.scm
   bess1.rb
   bess1.scm
   bird.rb
   bird.scm
   clm-ins.rb
   clm-ins.scm
   clm-strings.h
   clm.c
   clm.h
   clm23.scm
   clm2xen.c
   clm2xen.h
   cmn-glyphs.lisp
   config.guess
   config.h.in
   config.rpath
   config.sub
   configure.ac
   debug.scm
   dlocsig.rb
   draw.rb
   draw.scm
   dsp.rb
   dsp.scm
   edit-menu.scm
   edit123.scm
   effects-utils.scm
   effects.rb
   env.rb
   env.scm
   enved.scm
   eval-c.scm
   event.scm
   examp.rb
   examp.scm
   extensions.rb
   extensions.scm
   fade.scm
   fft-menu.scm
   fix-optargs.scm
   fmv.scm
   freeverb.rb
   freeverb.scm
   gettext.h
   gl.c
   grani.scm
   gtk-effects.scm
   gtk-popup.scm
   gui.scm
   headers.c
   help-snd-fm.pd
   help-snd.pd
   HISTORY.Snd
   hooks.rb
   hooks.scm
   index.rb
   index.scm
   inf-snd.el
   io.c
   jcrev.scm
   ladspa-help.scm
   ladspa.scm
   makefile.in
   makefile.no-gettext
   maraca.rb
   maraca.scm
   marks-menu.scm
   marks.rb
   marks.scm
   maxf.rb
   maxf.scm
   midi.c
   misc.scm
   mix-menu.scm
   mix.rb
   mix.scm
   mixer.scm
   moog.scm
   musglyphs.rb
   musglyphs.scm
   nb.rb
   nb.scm
   new-backgrounds.scm
   new-buttons.scm
   new-effects.scm
   new-icons.scm
   noise.rb
   noise.scm
   old-mac-audio.c
   old-snd.spec
   oo.scm
   oscope.scm
   panic.scm
   pd-add.scm
   pd-any.scm
   pd-fm.scm
   pd-global.scm
   pd-inout.scm
   pd-local.scm
   pd-mozilla.scm
   pd-send_receive.scm
   peak-env.scm
   piano.rb
   piano.scm
   play.rb
   play.scm
   poly.rb
   poly.scm
   popup.rb
   popup.scm
   prc95.rb
   prc95.scm
   pvoc.rb
   pvoc.scm
   README.Snd
   rgb.rb
   rgb.scm
   rmsgain.scm
   rt-compiler.scm
   rt-engine.scm
   rt-examples.scm
   rt.tex
   rtio.rb
   rtio.scm
   rubber.rb
   rubber.scm
   saw.c
   singer.rb
   singer.scm
   snd-0.h
   snd-1.h
   snd-axis.c
   snd-chn.c
   snd-completion.c
   snd-dac.c
   snd-data.c
   snd-draw.c
   snd-edits.c
   snd-env.c
   snd-error.c
   snd-fft.c
   snd-file.c
   snd-file.h
   snd-find.c
   snd-g0.h
   snd-g1.h
   snd-gchn.c
   snd-gdraw.c
   snd-gdrop.c
   snd-genv.c
   snd-gfft.c
   snd-gfile.c
   snd-gfind.c
   snd-ghelp.c
   snd-gl.scm
   snd-glistener.c
   snd-gmain.c
   snd-gmenu.c
   snd-gmix.c
   snd-gprefs.c
   snd-gprint.c
   snd-grec.c
   snd-gregion.c
   snd-gsnd.c
   snd-gtk.scm
   snd-gutils.c
   snd-gxbitmaps.c
   snd-gxcolormaps.c
   snd-gxen.c
   snd-gxutils.c
   snd-help.c
   snd-hobbit.scm
   snd-io.c
   snd-kbd.c
   snd-ladspa.c
   snd-listener.c
   snd-main.c
   snd-marks.c
   snd-menu.c
   snd-menu.h
   snd-mix.c
   snd-motif.scm
   snd-nogui.c
   snd-nogui0.h
   snd-nogui1.h
   snd-prefs.c
   snd-print.c
   snd-rec.c
   snd-rec.h
   snd-region.c
   snd-run.c
   snd-select.c
   snd-sig.c
   snd-snd.c
   snd-strings.h
   snd-trans.c
   snd-utils.c
   snd-x0.h
   snd-x1.h
   snd-xchn.c
   snd-xdraw.c
   snd-xdrop.c
   snd-xen.c
   snd-xenv.c
   snd-xfft.c
   snd-xfile.c
   snd-xfind.c
   snd-xhelp.c
   snd-xlistener.c
   snd-xm.rb
   snd-xmain.c
   snd-xmenu.c
   snd-xmix.c
   snd-xprefs.c
   snd-xprint.c
   snd-xrec.c
   snd-xref.c
   snd-xregion.c
   snd-xsnd.c
   snd-xutils.c
   snd-xxen.c
   snd.1
   Snd.ad
   snd.c
   Snd.gtkrc
   snd.h
   snd.spec
   snd_conffile.scm
   snd_pd_external.c
   snd_pd_external.h
   snd4.scm
   snd5.scm
   snd6.scm
   snd7.scm
   sndctrl.c
   sndinfo.c
   sndlib-strings.h
   sndlib.h.in
   sndlib2xen.c
   sndlib2xen.h
   sndplay.c
   sndrecord.c
   sndwarp.scm
   sound.c
   special-menu.scm
   spectr.rb
   spectr.scm
   strad.rb
   strad.scm
   TODO.Snd
   track-colors.scm
   v.rb
   v.scm
   vct.c
   vct.h
   ws.rb
   ws.scm
   xen.c
   xen.h
   xg-x11.h
   xm-enved.rb
   xm-enved.scm
   zip.rb
   zip.scm

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
# nb.rb -- translation of nb.rb

# Translator/Author: Michael Scholz <scholz-micha@gmx.de>
# Created: Tue Dec 10 22:08:15 CET 2002
# Last: Sat Oct 30 15:24:19 CEST 2004

# Commentary:
#
# Tested with Snd 7.8, Motif 2.2.2, Ruby 1.6.6, 1.6.8 and 1.9.0.
#
# type nb = make_nb
#      nb.help
# or   xnb = make_nb_motif (installs a popup menu on info widget)
#
# global variable:
#   $nb_database
#
# make_nb(path)
#
# class NB
#   initialize(path)
#
# getter and setter:
#   name=(filename)
#   name
#   notes=(new_notes)
#   notes
#
# interactive methods:
#   unb
#   prune_db
#   open(path)
#   close
#   help           (alias info and description)
#
=begin
nb = make_nb
nb.name
nb.notes
nb.notes = "new text"
nb.prune_db                  # deletes empty entries
nb.unb                       # deletes entry of current file
nb.open                      # adds mouse hooks
nb.close                     # removes mouse hooks
nb.help                      # this help
=end

# Code:

require "examp"
require "hooks"
with_silence do
  unless defined? DBM.open
    require "dbm"
  end
end

$nb_database = "nb" unless defined? $nb_database

if provided?("snd-motif") and (not provided?("xm"))
  with_silence(LoadError) do
    require "libxm"
  end
end

module Kernel
  # XM_NB should only create one instance of the popup menu on the
  # info_widget.
  @@XM_NB = false
  
  def Kernel.xm_nb
    @@XM_NB
  end

  def Kernel.xm_nb=(val)
    @@XM_NB = val
  end
end

def make_nb(path = $nb_database)
  NB.new(path)
end

def make_nb_motif(path = $nb_database)
  if Kernel.xm_nb.kind_of?(XM_NB)
    Kernel.xm_nb.open(path)
  else
    Kernel.xm_nb = XM_NB.new(path)
  end
end if provided?("xm")

class NB
  include Info
  
  Region_viewer = 2
  View_files_dialog = 8
  Info_dialog = 20
  
  def initialize(path)
    @nb_database = path
    @type = nil
    @position = nil
    @name = nil
    @notes = ""
    @alert_color = make_color(1.0, 1.0, 0.94)
    @db_hook_name = format("%s-nb-hook", @nb_database)
    set_help
    create
  end
  attr_reader :name, :notes
  alias help description
  
  def inspect
    format("#<%s: nb_database: %s, open: %s, name: %s>",
           self.class,
           @nb_database.inspect,
           $mouse_enter_label_hook.member?(@db_hook_name).inspect,
           @name.inspect)
  end
  
  def name=(filename)
    if filename and File.exist?(File.expand_path(filename))
      @name = filename
      show_popup_info
    else
      snd_warning(format("no such file: %s", filename.inspect))
    end
  end
  
  def notes=(new_notes)
    @notes = new_notes
    nb
    @notes
  end

  def with_dbm(&body)
    ret = nil
    db = DBM.open(@nb_database)
    ret = body.call(db)
    db.close
    ret
  rescue
    warn("%s#%s", self.class, get_func_name)
  end

  def prune_db
    with_dbm do |db|
      db.delete_if do |k, v| k.empty? end
    end
    self
  end

  def open(path = @nb_database)
    @nb_database = path
    create
    self
  end
  
  def close
    $mouse_enter_label_hook.remove_hook!(@db_hook_name)
    $mouse_leave_label_hook.remove_hook!(@db_hook_name)
    self
  end
  
  def unb
    if @name and File.exist?(File.expand_path(@name))
      with_dbm do |db|
        db.delete(@name)
      end
      show_popup_info
    else
      snd_warning(format("no such file: %s", @name.inspect))
    end
  end
  
  private  
  def create
    close
    $mouse_enter_label_hook.add_hook!(@db_hook_name) do |t, p, n|
      files_popup_info(t, p, n) unless t == Region_viewer
    end
  end

  def nb
    if @name and File.exist?(File.expand_path(@name))
      with_dbm do |db|
        db[@name] = @notes
      end
      show_popup_info
    else
      snd_warning(format("no such file: %s", @name.inspect))
    end
  end

  def files_popup_info(type, position, name)
    @type = type
    @position = position
    @name = name
    show_popup_info
  end

  def show_popup_info
    let(dialog_widgets[Info_dialog]) do |info_exists_p|
      info_dialog(@name, file_info)
      if info_widget = dialog_widgets[Info_dialog]
        unless info_exists_p
          width, height = widget_size(dialog_widgets[View_files_dialog])
          set_widget_position(info_widget, [width + 10, 10])
        end
      end
    end
    @name
  end

  def file_info
    with_dbm do |db|
      @notes = (db[@name] or "")
    end
    cs = mus_sound_chans(@name)
    sr = mus_sound_srate(@name)
    len = format("%1.3f", mus_sound_samples(@name).to_f / (cs * sr.to_f))
    d_format = mus_data_format_name(mus_sound_data_format(@name))
    h_type = mus_header_type_name(mus_sound_header_type(@name))
    frms = mus_sound_frames(@name)
    max_amp = ""
    if mus_sound_maxamp_exists?(@name)
      str = ""
      mus_sound_maxamp(@name).each_pair do |s, v|
        str << format("%1.3f (%1.3fs), ", v, s / sr.to_f)
      end
      max_amp = format("\n maxamp: [%s]", str[0..-3])
    end
    date = Time.at(mus_sound_write_date(@name)).localtime.strftime("%a %d-%b-%y %H:%M %Z")
    info_string = format("\
  chans: %d, srate: %d
 length: %1.3f (%d frames)
 format: %s [%s]%s
written: %s\n", cs, sr, len, frms, d_format, h_type, max_amp, date)
    if defined?($info_comment_hook) and hook?($info_comment_hook)
      if $info_comment_hook.empty?
        if s = mus_sound_comment(@name)
          info_string += format("comment: %s\n", s)
        end
      else
        $info_comment_hook.run_hook do |prc| info_string = prc.call(@name, info_string) end
      end
    else
      if s = mus_sound_comment(@name)
        info_string += format("comment: %s\n", s)
      end
    end
    info_string += "\n" + @notes
  end
  
  def set_help
    self.description = "\
# global variable:
#   $nb_database (#{$nb_database})
#
# make_nb(path)
# make_nb_motif(path)
#
# class NB
#   initialize(path)
#
# getter and setter:
#   name=(filename)
#   name
#   notes=(new_notes)
#   notes
#
# interactive methods:
#   unb
#   prune_db
#   open(path)
#   close
#   help           (alias info and description)

nb = make_nb
nb.name
nb.notes
nb.notes = \"new text\"
nb.prune_db                  # deletes empty entries
nb.unb                       # deletes entry of current file
nb.open                      # adds mouse hooks
nb.close                     # removes mouse hooks
nb.help                      # this help
"
  end
end

class XM_NB < NB
  require "popup"

  def initialize(path)
    @dialog = nil
    @file_name = nil
    @text_widget = nil
    @message_widget = nil
    super
    @db_str = format("DB: %s", File.basename(@nb_database))
    @popup_nb_hook = Hook.new("@popup_nb_hook", 2, "\
lambda do |snd, info| ... \"new info\" end: called in popup.rb on
graph-popup-menu entry `Info'.  Its primary use is to communicate
between popup.rb and nb.rb.  To add your own information to the info
string, you may use $info_comment_hook.

The current selected SND is called with string INFO.  If more than one
hook procedures exists, each procedure's result is passed as input to
the next.  E.g. if an instance of NB or XM_NB is created (see nb.rb),
the $nb_database entries of SND will be returned.")
    @popup_nb_hook.add_hook!("initialize-nb-hook") do |snd, info|
      @name = file_name(snd)
      with_dbm do |db|
        @notes = (db[@name] or "")
      end
      unless @notes.empty?
        info += "\n" unless info.empty?
        info += @notes
      end
      info
    end
    install_menu
  end
  attr_reader :popup_nb_hook

  def close
    if @dialog.kind_of?(Dialog) and RWidget?(@dialog.dialog) and RXtIsManaged(@dialog.dialog)
      RXtUnmanageChild(@dialog.dialog)
    end
    super
  end

  protected
  def post_edit
    if !@name and RWidget?(@message_widget)
      @name = if File.exist?(file = current_label(@message_widget).split[0])
                file
              else
                format("no such file: %s", file.inspect)
              end
    end
    unless @dialog.kind_of?(Dialog) and RWidget?(@dialog.dialog)
      @dialog = make_dialog(@db_str,
                            :help_cb, lambda do |w, c, i|
                              help_cb
                            end, :clear_cb, lambda do |w, c, i|
                              RXmTextSetString(@text_widget, "")
                            end) do |w, c, i|
        self.notes = RXmTextGetString(@text_widget)
      end
      @file_name = @dialog.add_label(@name, [RXmNbackground, help_button_color])
      @text_widget = @dialog.add_text(:rows, 16, :columns, 60, :wordwrap, true, :value, @notes)
      @dialog.doit_string("Submit")
    end
    activate_dialog(@dialog.dialog)
    show_edit_info
  end

  def help_cb
    help_dialog(@db_str,
                  "Edit info DB of sound files (see nb.scm).

Provides pop-up help in the Files viewer.  \
If you have `dbm', any data associated with \
the file in the dbm database will also be posted.  \
The database name is defined by $nb_database \
(#{$nb_database.inspect}).

o Edit info: opens the edit widget

o Prune DB:  clears non-existent file references
             out of the database

o Clear:     removes info entry from current file

o Close:     removes mouse hooks and popup menu;
             type `make_nb_motif' to reinstall
             the hooks and popup menu

o Submit:    submits info from edit widget
             to file info database

#{self.description}",
                  ["{Libxm}: graphics module",
                   "{Ruby}: extension language",
                   "{Motif}: Motif extensions via Libxm"])
    end

  def post_popup?
    $mouse_enter_label_hook.member?(@db_hook_name) and
      File.exist?(current_label(@message_widget).split[0])
  end

  private
  def create
    @db_hook_name = format("%s-xm-nb-hook", @nb_database)
    super
  end
  
  def install_menu
    if RWidget?(wid = dialog_widgets[Info_dialog])
      setup_menu(wid)
    else
      $new_widget_hook.add_hook!("nb-edit-hook") do |w|
        if w == dialog_widgets[Info_dialog]
          setup_menu(w)
          $new_widget_hook.remove_hook!("nb-edit-hook")
        end
      end
    end
  end
  
  def setup_menu(wid)
    @message_widget = find_child(wid, "Message")
    make_snd_popup("NB Edit Info", :where, :event, :parent, find_child(wid, "post-it-text")) do
      entry("Edit Info") do |w, snd, chn| Kernel.xm_nb.post_edit end
      entry("Prune DB") do |w, snd, chn| Kernel.xm_nb.prune_db end
      entry("Clear current Info") do |w, snd, chn| Kernel.xm_nb.unb end
      entry("Close NB Edit") do |w, snd, chn| Kernel.xm_nb.close end
      separator
      entry("Help") do |w, snd, chn| Kernel.xm_nb.help_cb end
      before_popup_hook.add_hook!("NB Edit Info") do |d1, d2, d3| Kernel.xm_nb.post_popup? end
    end
  end

  def files_popup_info(type, position, name)
    super
    show_edit_info
  end

  def show_edit_info
    xfname = string2compound(@name)
    RWidget?(@file_name) and RXtVaSetValues(@file_name, [RXmNlabelString, xfname])
    RWidget?(@text_widget) and RXtVaSetValues(@text_widget, [RXmNvalue, @notes])
    RXmStringFree(xfname)
  end
end if provided?("xm")

# nb.rb ends here

About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us