From b5bc0240f47dba01ff0a09263c210e5d391f88dc Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 17 Jan 2015 11:30:51 +0000 Subject: dtas-sourceedit: update player as user saves in the editor This allows changes in the source YAML file to be reflected immediately in player after the user saves the file in their favorite $EDITOR. Previously, a user would need to: 1) start dtas-sourceedit, spawning $EDITOR 2) edit the file 3) save changes 4) exit $EDITOR 5) repeat starting from 1) until happy with the results Now, the workflow allows avoiding the context switch between their $EDITOR and terminal to restart dtas-sourcedit: 1) start dtas-sourceedit, spawning $EDITOR 2) edit the file 3) save changes 4) repeat starting from 1) until happy with the results 5) exit $EDITOR In my experience, this greatly speeds up tuning of the playback change, giving all the repeatability and flexibility of editing text files while having the immediacy of an interactive UI. Keep in mind this can cause problems for those with auto-save enabled in their $EDITOR buffer at inopportune times, so a -N/--no-watch option is added. --- lib/dtas/source/splitfx.rb | 4 ++-- lib/dtas/source/watchable.rb | 54 -------------------------------------------- 2 files changed, 2 insertions(+), 56 deletions(-) delete mode 100644 lib/dtas/source/watchable.rb (limited to 'lib/dtas/source') diff --git a/lib/dtas/source/splitfx.rb b/lib/dtas/source/splitfx.rb index 19b2c16..80d8473 100644 --- a/lib/dtas/source/splitfx.rb +++ b/lib/dtas/source/splitfx.rb @@ -3,12 +3,12 @@ require 'yaml' require_relative 'sox' require_relative '../splitfx' -require_relative 'watchable' +require_relative '../watchable' class DTAS::Source::SplitFX < DTAS::Source::Sox # :nodoc: MAX_YAML_SIZE = 512 * 1024 attr_writer :sox, :sfx - include DTAS::Source::Watchable if defined?(DTAS::Source::Watchable) + include DTAS::Watchable if defined?(DTAS::Watchable) SPLITFX_DEFAULTS = SOX_DEFAULTS.merge( "command" => "#{SOX_DEFAULTS["command"]} $FX", diff --git a/lib/dtas/source/watchable.rb b/lib/dtas/source/watchable.rb deleted file mode 100644 index 3ff9ef8..0000000 --- a/lib/dtas/source/watchable.rb +++ /dev/null @@ -1,54 +0,0 @@ -# Copyright (C) 2014, all contributors -# License: GPLv3 or later -begin - require 'sleepy_penguin' -rescue LoadError -end - -# used to restart DTAS::Source::SplitFX processing in dtas-player -# if the YAML file is edited -module DTAS::Source::Watchable - class InotifyReadableIter < SleepyPenguin::Inotify - def self.new - super(:CLOEXEC) - end - - FLAGS = CLOSE_WRITE | MOVED_TO - - def readable_iter - or_call = false - while event = take(true) # drain the buffer - if (event.mask & FLAGS) != 0 && @watching[1] == event.name - or_call = true - end - end - if or_call && @on_readable - @on_readable.call - :delete - else - :wait_readable - end - end - - # we must watch the directory, since - def watch_file(path, blk) - @on_readable = blk - @watching = File.split(File.expand_path(path)) - add_watch(@watching[0], FLAGS) - end - end - - def watch_begin(blk) - @ino = InotifyReadableIter.new - @ino.watch_file(@infile, blk) - @ino - end - - # Closing the inotify descriptor (instead of using inotify_rm_watch) - # is cleaner because it avoids EINVAL on race conditions in case - # a directory is deleted: https://lkml.org/lkml/2007/7/9/3 - def watch_end(srv) - srv.wait_ctl(@ino, :delete) - @ino = @ino.close - end -end if defined?(SleepyPenguin::Inotify) -- cgit v1.2.3-24-ge0c7