trecs 0.1.7 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 11db22d959f646d759488d0e21e070a1dd131a86
4
- data.tar.gz: 14ea24c099109043abf9ee864350c21406a36d58
3
+ metadata.gz: e38f1fcbfcf313cbb527ee22c0c61b00b4364bfc
4
+ data.tar.gz: 081d03b77b6698d931cf1be2b9e2fe7807c935fd
5
5
  SHA512:
6
- metadata.gz: 5f5c7a11191cb0b495ea2fbb8759cf6f4af6da622d7c397deba90bc2382662ab344b6b5ed8021c6a2ea7c0cb22932fa4f636694a1b216658cc3b563dac3449ec
7
- data.tar.gz: b31502af511913ce740f5c8b05593223a5423b071b00344a443e3e0dc6fb34b9e3e61838b00cb6b84af2cf6401724900aff96cbdf01f2702eb5e77b4ec6c9172
6
+ metadata.gz: 655d12ca6d054f13fd1eebad2595ed3a9dc549166aabb20148a296ba293adcad9324cf19bee48729e48ca9d8c5cb53a865b7414d28471c45beffbb4d1ed6d0a7
7
+ data.tar.gz: 2685a98427201028eddcb024093aa5bfc7cfb61542297b93e2de770e62fd96cadda0700c39032c8ae182f9fadff5f46b3752b61b25beca61010f2712283371b3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- trecs (0.1.7)
4
+ trecs (0.1.8)
5
5
  trollop (~> 2.0)
6
6
 
7
7
  GEM
data/bin/trecs CHANGED
@@ -10,10 +10,12 @@ opts = Trollop::options do
10
10
  version TRecs::VERSION
11
11
 
12
12
  opt :step, "Time in ms between frames", short: 's', default: 100
13
- opt :format, "File format", type: String, default: "yaml_store"
13
+ opt :format, "File format", type: String, default: "json"
14
14
  opt :ticker, "Ticker", type: String, default: ""
15
15
 
16
16
  opt :ticker_file, "File to watch", type: String, default: "/tmp/ticker"
17
+
18
+ opt :audio, "Play with audio", type: String
17
19
  end
18
20
  opts[:trecs_file] = ARGV[0]
19
21
 
@@ -37,6 +39,24 @@ ticker_class = Kernel.const_get([
37
39
  ].join
38
40
  )
39
41
 
42
+ ########## AUDIO ##########
43
+ def start_sound_player(file_name='sound.ogg')
44
+ return unless File.exist?(file_name)
45
+ # at_exit { system('stty echo') }
46
+ STDOUT.puts "=> Starting sound player..."
47
+ @sox_pid = fork do
48
+ `play #{file_name} 2>&1`
49
+ end
50
+ end
51
+
52
+ def stop_sound_player
53
+ return unless File.exist?(file_name)
54
+ STDOUT.puts "=> Stopping sound player..."
55
+ Process.waitpid(@sox_pid)
56
+ end
57
+ ######## END AUDIO ########
58
+
59
+
40
60
  player_options = {
41
61
  reader: reader_class.new(opts),
42
62
  ticker: ticker_class.new(opts),
@@ -44,8 +64,10 @@ player_options = {
44
64
  }
45
65
 
46
66
  player = TRecs::Player.new(player_options)
67
+
68
+ opts[:audio] && start_sound_player(opts[:audio])
47
69
  player.play
48
70
 
49
71
  puts "Finished"
50
72
  puts "Replay with:"
51
- puts " bin/trecs #{opts[:trecs_file]}"
73
+ puts "trecs #{opts[:trecs_file]}"
data/bin/trecs_record CHANGED
@@ -10,7 +10,7 @@ opts = Trollop::options do
10
10
  version TRecs::VERSION
11
11
 
12
12
  opt :step, "Time in ms between frames", short: 's', default: 100
13
- opt :format, "File format", type: String, default: "yaml_store"
13
+ opt :format, "File format", type: String, default: "json"
14
14
  opt :strategy, "Strategy", type: String, default: "incremental"
15
15
 
16
16
  opt :message, "Message to record", type: String, default: "TRecs!"
@@ -19,6 +19,8 @@ opts = Trollop::options do
19
19
  opt :input_file, "File to record", type: String, default: ""
20
20
  opt :terminal, "Launch terminal", default: true
21
21
 
22
+ opt :audio, "Record audio", type: String
23
+
22
24
  end
23
25
  opts[:trecs_file] = ARGV[0]
24
26
 
@@ -41,28 +43,52 @@ strategy_class = Kernel.const_get([
41
43
  ].join
42
44
  )
43
45
 
46
+ ########## AUDIO ##########
47
+ def start_sound_recording(file_name='sound.ogg')
48
+ puts "Sound file stored in #{file_name}"
49
+ @sox_pid = fork do
50
+ Signal.trap("SIGINT") {
51
+ puts "=> Sound recording finished!"
52
+ exit
53
+ }
54
+ sleep 0.5
55
+ `rec -C 1 --channels 1 --rate 16k --comment 'TRecs' #{file_name} 2>&1`
56
+ end
57
+ end
58
+
59
+ def stop_sound_recording
60
+ puts "=> Stopping sound recorder"
61
+ sleep 2 # otherwise record will be cropped for some reason
62
+ Process.kill("SIGINT", @sox_pid)
63
+ Process.waitpid(@sox_pid)
64
+ end
65
+
66
+ ######## END AUDIO ########
44
67
 
45
68
 
46
69
  puts "Recording ..."
47
70
 
71
+
48
72
  if strategy_class.to_s == "TRecs::TtyrecStrategy"
49
73
  opts[:height], opts[:width] = `stty size`.split(" ").map(&:to_i)
74
+ opts[:audio] && start_sound_recording(opts[:audio])
50
75
  system "ttyrec #{opts[:input_file]}" if opts[:terminal]
51
76
  end
52
77
 
53
78
  recorder_options = {
54
- writer: writer_class.new(opts),
79
+ writer: writer_class.new(opts),
55
80
  strategy: strategy_class.new(opts),
56
- step: opts[:step],
81
+ step: opts[:step],
57
82
  }
58
83
 
59
-
84
+ opts[:audio] && stop_sound_recording
60
85
  RECORDER = TRecs::Recorder.new(recorder_options)
61
86
 
62
87
  trap "SIGINT" do
63
88
  RECORDER.stop
64
89
  end
65
90
 
91
+
66
92
  RECORDER.record
67
93
 
68
94
  puts "Recording finished"
@@ -0,0 +1,36 @@
1
+ require 'json'
2
+ require "pathname"
3
+
4
+ module TRecs
5
+ class JsonReader
6
+ attr_accessor :player
7
+ attr_reader :frames
8
+ attr_reader :file
9
+ attr_reader :timestamps
10
+
11
+ def initialize(options={})
12
+ @file = options.fetch(:trecs_file)
13
+ json_string = File.read(@file)
14
+ @frames = {}
15
+ parsed_json = JSON.parse(json_string)
16
+ parsed_json.each do |time, content|
17
+ @frames[Integer(time)] = content
18
+ end
19
+
20
+ @timestamps = @frames.keys
21
+ end
22
+
23
+ def setup
24
+ true
25
+ end
26
+
27
+ def frame_at(time)
28
+ @frames[time]
29
+ end
30
+
31
+ def to_s
32
+ "<#{self.class}>"
33
+ end
34
+ alias :inspect :to_s
35
+ end
36
+ end
@@ -4,9 +4,6 @@ module TRecs
4
4
 
5
5
  def current_content(str)
6
6
  if self.command
7
- #comm_array = command.split(" ")
8
- #str = IO.popen([*comm_array, "#{str}"]).read
9
-
10
7
  comm = command.gsub(/<frame>/, "\"#{str}\"")
11
8
  str = IO.popen(comm).read
12
9
  end
data/lib/trecs/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module TRecs
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
@@ -0,0 +1,33 @@
1
+ require 'json'
2
+ require "fileutils"
3
+
4
+ module TRecs
5
+ class JsonWriter
6
+ attr_accessor :recorder
7
+ attr_reader :frames
8
+ attr_reader :file
9
+
10
+ def initialize(options={})
11
+ @file = options.fetch(:trecs_file)
12
+ FileUtils.rm(@file, force: true)
13
+ end
14
+
15
+ def setup
16
+ @frames = {}
17
+ end
18
+
19
+ def create_frame(options={})
20
+ time = options.fetch(:time)
21
+ content = options.fetch(:content)
22
+ frames[time] = content
23
+ end
24
+
25
+ def render
26
+ json_string = frames.to_json
27
+
28
+ File.open(file, File::CREAT|File::TRUNC|File::RDWR, 0644) do |f|
29
+ f.write(json_string)
30
+ end
31
+ end
32
+ end
33
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trecs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Federico Iachetti
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-26 00:00:00.000000000 Z
11
+ date: 2014-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trollop
@@ -85,10 +85,7 @@ email:
85
85
  - iachetti.federico@gmail.com
86
86
  executables:
87
87
  - trecs
88
- - trecs_message
89
- - trecs_raw_file
90
88
  - trecs_record
91
- - trecs_terminal
92
89
  extensions: []
93
90
  extra_rdoc_files: []
94
91
  files:
@@ -103,10 +100,7 @@ files:
103
100
  - README.org
104
101
  - Rakefile
105
102
  - bin/trecs
106
- - bin/trecs_message
107
- - bin/trecs_raw_file
108
103
  - bin/trecs_record
109
- - bin/trecs_terminal
110
104
  - doc/steps.org
111
105
  - lib/players/zip_file_player.rb
112
106
  - lib/recorders/message_recorder.rb
@@ -116,6 +110,7 @@ files:
116
110
  - lib/timestamps.rb
117
111
  - lib/trecs.rb
118
112
  - lib/trecs/player.rb
113
+ - lib/trecs/readers/json_reader.rb
119
114
  - lib/trecs/readers/yaml_store_reader.rb
120
115
  - lib/trecs/recorder.rb
121
116
  - lib/trecs/recording_strategies/custom_strategy.rb
@@ -132,6 +127,7 @@ files:
132
127
  - lib/trecs/tickers/watch_file_ticker.rb
133
128
  - lib/trecs/version.rb
134
129
  - lib/trecs/writers/in_memory_writer.rb
130
+ - lib/trecs/writers/json_writer.rb
135
131
  - lib/trecs/writers/yaml_store_writer.rb
136
132
  - lib/trecs/writers/zip_file_writer.rb
137
133
  - old_specs/player_spec.rb
data/bin/trecs_message DELETED
@@ -1,24 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- $:.unshift(File.expand_path("../../lib", __FILE__))
4
-
5
- require "trollop"
6
-
7
- require "recorders/message_recorder"
8
-
9
- options = Trollop::options do
10
- opt :file_name, "File to process", short: 'f', type: String
11
- opt :message, "Message to record", short: 'm', type: String
12
- opt :step, "Time between frames in milliseconds", short: 's', default: 100
13
- end
14
-
15
- if options[:file_name]
16
-
17
- recorder = Recorder.new(
18
- persistence_strategy: ZipFileRecorder.new(file_name: file_name),
19
- recording_strategy: IncrementalRecordingStrategy.new(message: message)
20
- recorder = TRecs::MessageRecorder.new(options)
21
- recorder.record
22
- else
23
- puts "Please give a file name"
24
- end
data/bin/trecs_raw_file DELETED
@@ -1,28 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- $:.unshift(File.expand_path("../../lib", __FILE__))
4
-
5
- require "trollop"
6
-
7
- require "recorders/raw_file_recorder"
8
-
9
- options = Trollop::options do
10
- opt :input_file, "File to process", short: 'i', type: String
11
- opt :output_file, "Output file", short: 'o', type: String, default: "/tmp/output.txt"
12
- opt :step, "Step", short: 's', type: Integer, default: 100
13
- end
14
-
15
- unless options[:output_file]
16
- puts "Please give an input and an output file file name"
17
- exit(1)
18
- end
19
-
20
- RECORDER = TRecs::RawFileRecorder.new(options)
21
-
22
- trap "SIGINT" do
23
- RECORDER.stop
24
- end
25
-
26
- puts "Recording ..."
27
- RECORDER.record
28
- puts "Finish Recording ..."
data/bin/trecs_terminal DELETED
@@ -1,25 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- $:.unshift(File.expand_path("../../lib", __FILE__))
4
-
5
- require "trollop"
6
-
7
- require "recorders/ttyrec_recorder"
8
-
9
- options = Trollop::options do
10
- # opt :input_file, "File to process", short: 'i', type: String
11
- opt :output_file, "Output file", short: 'o', type: String
12
- end
13
-
14
- options[:input_file] ||= "/tmp/ttyrecord"
15
-
16
- if options[:output_file] # && options[:input_file]
17
- puts "Recording ..."
18
- options[:height], options[:width] = `stty size`.split(" ").map(&:to_i)
19
- system "ttyrec #{options[:input_file]}"
20
- recorder = TRecs::TtyrecRecorder.new(options)
21
- recorder.record
22
- puts "Finish Recording ..."
23
- else
24
- puts "Please give an input and an output file file name"
25
- end