Skip to content

Commit

Permalink
Removes Javascript display, Various small fixes (#53)
Browse files Browse the repository at this point in the history
* removes wavesurfer-based display, now just using audio tags

* Some Project.toml tweaks and fixes #52

* modernize travis and appveyor configs

* Adds IntervalSets to test deps

* Temporarily removes LibSndfile-based tests for wav display
  • Loading branch information
ssfrr authored Nov 19, 2019
1 parent 5005e1f commit 169d9f1
Show file tree
Hide file tree
Showing 14 changed files with 103 additions and 270 deletions.
32 changes: 32 additions & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Documentation: https://github.com/JuliaCI/Appveyor.jl
environment:
matrix:
- julia_version: 1.0
- julia_version: 1
- julia_version: nightly
platform:
- x86
- x64
matrix:
allow_failures:
- julia_version: nightly
branches:
only:
- master
- /release-.*/
notifications:
- provider: Email
on_build_success: false
on_build_failure: false
on_build_status_changed: true
install:
- ps: iex ((new-object net.webclient).DownloadString("https://raw.githubusercontent.com/JuliaCI/Appveyor.jl/version-1/bin/install.ps1"))
build_script:
- echo "%JL_BUILD_SCRIPT%"
- C:\julia\bin\julia -e "%JL_BUILD_SCRIPT%"
test_script:
- echo "%JL_TEST_SCRIPT%"
- C:\julia\bin\julia -e "%JL_TEST_SCRIPT%"
on_success:
- echo "%JL_CODECOV_SCRIPT%"
- C:\julia\bin\julia -e "%JL_CODECOV_SCRIPT%"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
*.jl.mem
coverage
*~
Manifest.toml
test/Manifest.toml
18 changes: 3 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,14 @@ os:
- linux
- osx
julia:
- 0.6
- 0.7
- 1.0
- 1
- nightly
matrix:
allow_failures:
- julia: nightly
fast_finish: true
branches:
only:
master
notifications:
email: false
script:
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
- julia --color=yes ci_setup.jl
- julia --color=yes --code-coverage test/runtests.jl
email: true
after_success:
- julia -e 'VERSION >= v"0.7.0-" && using Pkg;
VERSION < v"0.7.0-" && cd(Pkg.dir("SampledSignals"));
Pkg.add("Coverage");
using Coverage;
Codecov.submit(process_folder())'
- julia -e 'using Pkg; Pkg.add("Coverage"); using Coverage; Codecov.submit(process_folder())'
43 changes: 43 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name = "SampledSignals"
uuid = "bd7594eb-a658-542f-9e75-4c4d8908c167"

[deps]
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
DSP = "717857b8-e6f2-59f4-9121-6e50c889abd2"
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
FixedPointNumbers = "53c48c17-4a7d-5ca2-90c5-79b7896eea93"
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
TreeViews = "a2a6695c-b41b-5b7d-aed9-dbfdeacea5d7"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"

[compat]
Compat = "2"
DSP = "0.6.1"
FFTW = "1.1.0"
FixedPointNumbers = "0.6.1"
IntervalSets = "0.3.2"
Unitful = "0.17.0"
julia = "1"

[extras]
DSP = "717857b8-e6f2-59f4-9121-6e50c889abd2"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
FixedPointNumbers = "53c48c17-4a7d-5ca2-90c5-79b7896eea93"
# LibSndFile = "b13ce0c6-77b0-50c6-a2db-140568b8d1a5"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
SampledSignals = "bd7594eb-a658-542f-9e75-4c4d8908c167"
TreeViews = "a2a6695c-b41b-5b7d-aed9-dbfdeacea5d7"
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"

[targets]
test = ["DSP",
"FileIO",
"FixedPointNumbers",
# "LibSndFile",
"Unitful",
"Compat",
"SampledSignals",
"TreeViews",
"IntervalSets"]
7 changes: 0 additions & 7 deletions REQUIRE

This file was deleted.

43 changes: 0 additions & 43 deletions appveyor.yml

This file was deleted.

4 changes: 2 additions & 2 deletions src/SampleBuf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,11 @@ function toindex end
toindex(buf::SampleBuf, t::Number) = t
toindex(buf::SampleBuf, t::FrameQuant) = inframes(Int, t) + 1
toindex(buf::SampleBuf, t::Unitful.Time) = inframes(Int, t, samplerate(buf)) + 1
toindex(buf::SampleBuf, t::Quantity) = throw(Unitful.DimensionError(t, s))
toindex(buf::SampleBuf, t::Unitful.AbstractQuantity) = throw(Unitful.DimensionError(t, s))
toindex(buf::SpectrumBuf, f::Number) = f
toindex(buf::SpectrumBuf, f::FrameQuant) = inframes(Int, f) + 1
toindex(buf::SpectrumBuf, f::Unitful.Frequency) = inframes(Int, f, samplerate(buf)) + 1
toindex(buf::SpectrumBuf, f::Quantity) = throw(Unitful.DimensionError(f, Hz))
toindex(buf::SpectrumBuf, f::Unitful.AbstractQuantity) = throw(Unitful.DimensionError(f, Hz))

# indexing by vectors of Quantities not yet supported
toindex(buf::AbstractSampleBuf, I::ClosedInterval{Int}) =
Expand Down
2 changes: 1 addition & 1 deletion src/SampleStream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const DEFAULT_BLOCKSIZE=4096
function Base.write(sink::SampleSink, source::SampleSource, duration::Quantity;
blocksize=-1)
sr = samplerate(sink)
frames = trunc(Int, inseconds(duration) * sr)
frames = trunc(Int, inseconds(duration, sr) * sr)
n = write(sink, source, frames; blocksize=blocksize)

# if we completed the operation return back the original duration so the
Expand Down
8 changes: 2 additions & 6 deletions src/SampledSignals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ using Compat
using Compat: AbstractRange, undef, range
using Compat.Random: randstring
using Compat.Base64: base64encode
using TreeViews: TreeViews

if VERSION >= v"0.7.0-DEV"
using LinearAlgebra: mul!
import FFTW
Expand All @@ -53,12 +55,6 @@ include("SignalGen/SinSource.jl")
include("WAVDisplay.jl")
include("deprecated.jl")

function __init__()
if isdefined(Main, :IJulia) && Main.IJulia.inited
embed_javascript()
end
end

"""
metadata(x, key::Symbol)
metadata(x, key::Symbol, idx)
Expand Down
112 changes: 10 additions & 102 deletions src/WAVDisplay.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,117 +2,25 @@
# WAV.jl package. Rather than full WAV support here we just want to support
# enough for simple HTML display of SampleBufs

# notebook init code heavily inspired by PlotlyJS - thanks @sglyon!
function embed_javascript()
js_path = joinpath(dirname(dirname(@__FILE__)), "deps", "wavesurfer.min.js")
js_text = open(js_path) do io
read(io, String)
end
# the javascript file contains the code to add itself to the require module
# cache under the name 'wavesurfer'
display("text/html", """
<script charset="utf-8" type='text/javascript'>
$js_text
console.log("SampledSignals.jl: wavesurfer library loaded")
</script>
""")
end

# need to specify that T <: Number to avoid a method ambiguity with AbstractArray{Method} on 0.4
function show(io::IO, ::MIME"text/html", buf::SampleBuf{T, N}) where {T <: Number, N}
tempio = IOBuffer()
wavwrite(tempio, buf)
data = base64encode(take!(tempio))
# we want the divID to start with a letter
divid = string("a", randstring(10))
# include an error message that will get cleared if javascript loads correctly
# they won't be able to re-run this cell without importing SampledSignals,
# which will run the initialization code above. I can't think of a way to
# get in the state where the javascript isn't initialized but the module is
# loaded, but if it comes up we'll want to add an instruction to run
# `SampledSignals.embed_javascript()`.
println(io, """
<div id=$divid>
<h4>SampleBuf display requires javascript</h4>
<p>To enable for the whole notebook select "Trust Notebook" from the
"File" menu. You can also trust this cell by re-running it. You may
also need to re-run `using SampledSignals` if the module is not yet
loaded in the Julia kernel, or `SampledSignals.embed_javascript()`
if the Julia module is loaded but the javascript isn't initialized.</p>
</div>""")
# only show playback controls for real-valued SampleBufs. We also initialize
# them hidden and they get displayed if javascript is enabled.
if isa(buf, SampleBuf) && eltype(buf) <: Real
println(io, """
<button id=$divid-skipback class="btn" style="display:none">
<span class="fa fa-step-backward"></span>
</button>
<button id=$divid-playpause class="btn" style="display:none">
<span class="fa fa-play"></span>
</button>
<button id=$divid-stop class="btn" style="display:none">
<span class="fa fa-stop"></span>
</button>
<button id=$divid-skipahead class="btn" style="display:none">
<span class="fa fa-step-forward"></span>
</button>""")
<audio controls>
<source src="data:audio/wav;base64,$data" />
</audio>""")
else
show(io, MIME"text/plain"(), buf)
end
println(io, """
<script type="text/javascript">
require(["wavesurfer"], function(wavesurfer) {
\$("#$divid").empty();
var waveform = wavesurfer.create({
container: '#$divid',
splitChannels: true,
scrollParent: true,
height: 40
});
var base64 = "$data";
var binary_string = window.atob(base64);
var len = binary_string.length;
var bytes = new Uint8Array(len);
for (var i = 0; i < len; i++) {
bytes[i] = binary_string.charCodeAt(i);
}
waveform.loadArrayBuffer(bytes.buffer);
\$("#$divid-skipback").show();
\$("#$divid-skipahead").show();
\$("#$divid-playpause").show();
\$("#$divid-stop").show();
end

\$("#$divid-skipback").click(function(event) {
waveform.skip(-3);
});
\$("#$divid-skipahead").click(function(event) {
waveform.skip(3);
});
\$("#$divid-playpause").click(function(event) {
var el = \$("#$divid-playpause span")
if(waveform.isPlaying()) {
waveform.pause();
el.removeClass("fa-pause");
el.addClass("fa-play");
}
else {
waveform.play();
el.removeClass("fa-play");
el.addClass("fa-pause");
}
});
\$("#$divid-stop").click(function(event) {
waveform.stop();
var el = \$("#$divid-playpause span")
el.removeClass("fa-pause");
el.addClass("fa-play");
});
waveform.on('finish', function() {
var el = \$("#$divid-playpause span")
el.removeClass("fa-pause");
el.addClass("fa-play");
})
});
</script>
""")
TreeViews.hastreeview(::SampleBuf) = true
TreeViews.numberofnodes(::SampleBuf) = 0
function TreeViews.treelabel(io::IO, buf::SampleBuf, ::MIME"text/html")
show(io, MIME"text/html"(), buf)
end

# Required WAV Chunk; The format chunk describes how the waveform data is stored
Expand Down
4 changes: 2 additions & 2 deletions src/units.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ inframes(time::Unitful.Time, rate) = inseconds(time)*inHz(rate)
inframes(::Type{T}, freq::Unitful.Frequency, rate) where T <: Integer =
round(T, inHz(freq)*inseconds(rate))
inframes(freq::Unitful.Frequency, rate) = inHz(freq)*inseconds(rate)
inframes(::Type, frame::Quantity) = error("Unknown sample rate")
inframes(frame::Quantity) = error("Unknown sample rate")
inframes(::Type, frame::Unitful.AbstractQuantity) = error("Unknown sample rate")
inframes(frame::Unitful.AbstractQuantity) = error("Unknown sample rate")
inframes(::Type{T}, frame::Real) where T = T(frame)
inframes(frame::Real) = frame

Expand Down
7 changes: 0 additions & 7 deletions test/REQUIRE

This file was deleted.

Loading

0 comments on commit 169d9f1

Please sign in to comment.