carrierwave-audio-waveform 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6497146ba653815208e4665a1ed1bfad567a9f1b
4
- data.tar.gz: c727ed3c1b3b5575a026fc42fa6d3635640e2ceb
3
+ metadata.gz: 2cf043df5b38e07639eb6a531706b07163868e36
4
+ data.tar.gz: 67140c30355b8c621c5d2b2fbe69775cd6c79aa4
5
5
  SHA512:
6
- metadata.gz: f475378005b85801917e5083709056a665e59441b36712b812956287947301bd70f81d671cd7e35adc68fe3ea978cefe02a6cf54b7abb2cdac02800d5bffa976
7
- data.tar.gz: a26fd903358e1978545d4754524ed3f29f495e3eceac6c5d49d61556024963c035b7a13ca227609c9107c50bee4736fd7069bf8418191b49b9b8b254e77c6f75
6
+ metadata.gz: 69db0a620320c1ecf4b36c5530c45abbe232ec10489410c8c1c0b0452b8dca38e88ffb890877dafe8f0afee5c4bad572761b0eaae48c6059ed1d36e8c80ca41c
7
+ data.tar.gz: 3787b962fa47074f2cc3c6ccdffd241529c947869a1772717a621a32fd32ee9206af20f6422148b8a46f5fe635842457157cd8c0b2b1fddcfce9e79a24cce3c5
@@ -1,5 +1,5 @@
1
1
  module CarrierWave
2
2
  module AudioWaveform
3
- VERSION = '1.0.4'
3
+ VERSION = '1.0.5'
4
4
  end
5
5
  end
@@ -106,7 +106,7 @@ module CarrierWave
106
106
  # the larger the frames are, the more "peaky" the waveform should get,
107
107
  # perhaps to the point of inaccurately reflecting the actual sound.
108
108
  samples = frames(source, options[:width], options[:method]).collect do |frame|
109
- frame.inject(0.0) { |sum, peak| sum + peak } / frame.size
109
+ frame.inject(0.0) { |sum, peak| sum + peak } / frame.size
110
110
  end
111
111
 
112
112
  @log.timed("\nDrawing...") do
@@ -211,15 +211,34 @@ module CarrierWave
211
211
  end
212
212
 
213
213
  def draw_svg(samples, options)
214
- image = "<svg viewbox=\"0 0 #{options[:width]} #{options[:height]}\" preserveAspectRatio=\"none\" width=\"100%\" height=\"100%\">"
215
- if options[:hide_style].nil?
214
+ wave_image = ""
215
+ samples = spaced_samples(samples, options[:sample_width], options[:gap_width]) if options[:sample_width]
216
+ height_factor = (options[:height] * 0.85 / 2.0)
217
+
218
+ bar_pos = 0
219
+ samples.each_with_index do |sample, pos|
220
+ next if sample.nil?
221
+
222
+ if (pos%3 == 0)
223
+ amplitude = sample * height_factor
224
+ top = (0 - amplitude).round
225
+ bottom = (0 + amplitude).round
226
+
227
+ wave_image+= "M#{bar_pos},#{top}V#{bottom}"
228
+
229
+ bar_pos += 1
230
+ end
231
+ end
232
+
233
+ image = "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3/org/1999/xlink\" viewbox=\"0 0 #{iPos+1} #{options[:height]}\" preserveAspectRatio=\"none\" width=\"100%\" height=\"100%\">"
234
+ if (options[:hide_style].nil? || options[:hide_style] == false)
216
235
  image+= "<style>"
217
236
  image+= "svg {"
218
237
  image+= "stroke: #000;"
219
- image+= "stroke-width: 1;"
238
+ image+= "stroke-width: 0.25;"
220
239
  image+= "}"
221
240
  image+= "use.waveform-progress {"
222
- image+= "stroke-width: 2;"
241
+ image+= "stroke-width: 0.25;"
223
242
  image+= "clip-path: polygon(0% 0%, 0% 0%, 0% 100%, 0% 100%);"
224
243
  image+= "}"
225
244
  image+= "svg path {"
@@ -239,22 +258,10 @@ module CarrierWave
239
258
  end
240
259
  uniqueWaveformID = "waveform-#{SecureRandom.uuid}"
241
260
  image+= "<g id=\"#{uniqueWaveformID}\">"
242
- image+= '<g transform="translate(0, 125.0)">'
261
+ image+= "<g transform=\"translate(0, #{options[:height] / 2.0})\">"
243
262
  image+= '<path stroke="currrentColor" d="'
244
263
 
245
- samples = spaced_samples(samples, options[:sample_width], options[:gap_width]) if options[:sample_width]
246
- max = samples.reject {|v| v.nil? }.max
247
- height_factor = (options[:height] / 2.0) / max
248
-
249
- samples.each_with_index do |sample, pos|
250
- next if sample.nil?
251
-
252
- amplitude = sample * height_factor
253
- top = (0 - amplitude).round
254
- bottom = (0 + amplitude).round
255
-
256
- image+= " M#{pos},#{top} V#{bottom}"
257
- end
264
+ image+= wave_image
258
265
 
259
266
  image+= '"/>'
260
267
  image+= "</g>"
@@ -315,7 +322,7 @@ module CarrierWave
315
322
 
316
323
  def spaced_samples samples, sample_width = 1, gap_width = 1
317
324
  sample_width = sample_width.to_i >= 1 ? sample_width.to_i : 1
318
- gap_width = gap_width.to_i >= 1 ? gap_width.to_i : 1
325
+ gap_width = gap_width.to_i >= 0 ? gap_width.to_i : 1
319
326
  width_counter = sample_width
320
327
  current_sample_index = 0
321
328
  spaced_samples = []
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrierwave-audio-waveform
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Trevor Hinesley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-28 00:00:00.000000000 Z
11
+ date: 2018-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: carrierwave