Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
cbossut committed Mar 7, 2020
2 parents 607d1f9 + 040bc1f commit 91e4976
Show file tree
Hide file tree
Showing 11 changed files with 981 additions and 414 deletions.
31 changes: 18 additions & 13 deletions playable.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// TODO clean changeVolume, use Tone.Draw

// pauseOffset = sound time after the start point = position of the animation in sound time
// startTime = date of the corresponding start = date of the last 0% of the animation
// startPercent = percent of the whole sound where to start

function prepare(model, rate = 1) {
model.paused = true
model.pauseOffset = 0
model.length = model.length
if (model.view && model.id) {
model.view = SVG.adopt(document.getElementById(model.id))
/* model.once
Expand All @@ -12,9 +15,9 @@ function prepare(model, rate = 1) {
}
if (model.soundName) {
model.player = new Tone.Player(buffers[model.soundName]).toMaster()
setVolume(model)
model.duration = model.player.buffer.duration
model.duration = model.loopPoints[1] - model.loopPoints[0]
model.player.playbackRate = model.rate = rate * model.duration / model.length
model.player.setLoopPoints.apply(model.player, model.loopPoints)
model.player.loop = true
}
if (model.mobile) {
Expand All @@ -27,11 +30,7 @@ function prepare(model, rate = 1) {
model.rate = (rate * model.duration / model.length) || 1 // TODO when preparing top collar, no model.length
model.durs = model.collar.beads.map(v => v.length / model.rate)
let totalDur = model.durs.reduce((a,b) => a+b, 0)
model.players = model.collar.beads.map((v,i) => {
v.id = model.baseId + i
// v.once = true
return prepare(v, model.rate)
})
model.players = model.collar.beads.map(v => prepare(v, model.rate))
model.clocks = model.players.map((subModel,i,a) => {
return new Tone.Clock(t => {
if (model.paused && (model.progPause <= t)) return;
Expand All @@ -46,6 +45,7 @@ function prepare(model, rate = 1) {
}, 1/totalDur)
})
}
setVolume(model)
return model
}

Expand All @@ -59,8 +59,7 @@ function play(model, t, newModel = {}, volume = 1, mute = false) { // TODO What
Tone.Draw.schedule(() => model.view.animate().play(), t)
}
if (model.soundName && model.player.output) {
setVolume(model, volume, mute)
model.player.start(t, model.pauseOffset + (model.startPercent * model.length))
model.player.start(t, model.pauseOffset + (model.startPercent * model.player.buffer.duration))
}
if (model.mobile) {
model.gears.map((v,i) => play(v, t, model.gears[i], model.volume * volume, model.mute || mute))
Expand All @@ -87,7 +86,7 @@ function play(model, t, newModel = {}, volume = 1, mute = false) { // TODO What
function pause(model, t, force = false, clocked = false) {
if (model.paused && !force) return;
model.paused = true
model.pauseOffset = ((t - model.startTime) * model.rate)
model.pauseOffset = ((t - model.startTime) * model.rate) % model.duration
if (model.view){//} && !clocked) {
Tone.Draw.schedule(() => model.view.animate().pause().at((model.pauseOffset/model.length/model.rate) % 1), t)
}
Expand Down Expand Up @@ -121,8 +120,14 @@ function stop(model) {

function setVolume(model, volume = 1, mute = false) {
if (model.soundName) {
if (mute || model.mute) model.player.volume.value = -100000
else model.player.volume.value = ((model.volume * volume) - 1) * 60
if (mute || model.mute) {
model.player.toMaster()
model.player.disconnect(Tone.Master)
}
else {
model.player.toMaster()
model.player.volume.value = ((model.volume * volume) - 1) * 60
}
}
if (model.mobile) model.gears.map(v => setVolume(v, model.volume * volume, model.mute || mute))
if (model.collar) model.players.map(v => setVolume(v, model.volume * volume, model.mute || mute))
Expand Down
30 changes: 24 additions & 6 deletions src/Data/Common.elm
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,37 @@ type alias Identifier =
getName : Identifier -> Mobile Wheel -> String
getName ( id, l ) mobile =
let
name =
(getWheel ( id, l ) mobile).name
w =
getWheel ( id, l ) mobile
in
if String.isEmpty name then
if String.isEmpty w.name then
case l of
[] ->
Gear.toUID id
case Wheel.getWheelContent w of
Content.S s ->
let
fileName =
Sound.fileName s
in
if String.isEmpty fileName then
Gear.toUID id

else
fileName

_ ->
Gear.toUID id

_ ->
"beadTODO"
toUid ( id, l )

else
name
w.name


toUid : Identifier -> String
toUid ( id, l ) =
List.foldl (\i uid -> Content.beadUIDExtension uid i) (Gear.toUID id) l


getWheel : Identifier -> Mobile Wheel -> Wheel
Expand Down
5 changes: 5 additions & 0 deletions src/Data/Content.elm
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ mobileDecoder wheelDecoder defaultWheel =
)


beadUIDExtension : String -> Int -> String
beadUIDExtension parentUid i =
parentUid ++ "-" ++ String.fromInt i


type alias Bead item =
{ length : Float, wheel : item }

Expand Down
Loading

0 comments on commit 91e4976

Please sign in to comment.