Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes for audio #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 76 additions & 68 deletions elm/Main.elm
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
port module Main exposing (..)

import WesternMusicData exposing (..)
import Fretboard exposing (..)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (onClick, onInput)
import Notes exposing (..)
import Tuning exposing (..)
import Fretboard exposing (..)
import WesternMusicData exposing (..)


main : Program (Maybe String) Model Msg
Expand Down Expand Up @@ -76,9 +76,9 @@ init s =
, rootNoteDouble = True
}
in
( initialModel
, notesChanged (notesForAudio initialModel)
)
( initialModel
, notesChanged (notesForAudio initialModel)
)


subscriptions : Model -> Sub Msg
Expand Down Expand Up @@ -123,27 +123,27 @@ update msg model =
newModel =
{ model | formulaName = v }
in
( newModel
, notesChanged (notesForAudio newModel)
)
( newModel
, notesChanged (notesForAudio newModel)
)

"Note" ->
let
newModel =
{ model | note = v }
in
( newModel
, notesChanged (notesForAudio newModel)
)
( newModel
, notesChanged (notesForAudio newModel)
)

"Octave" ->
let
newModel =
{ model | octave = Result.withDefault 0 (String.toInt v) }
in
( newModel
, notesChanged (notesForAudio newModel)
)
( newModel
, notesChanged (notesForAudio newModel)
)

"Mode" ->
case v of
Expand All @@ -152,18 +152,18 @@ update msg model =
newModel =
{ model | mode = v, formulaName = ionian }
in
( newModel
, notesChanged (notesForAudio newModel)
)
( newModel
, notesChanged (notesForAudio newModel)
)

"Chord" ->
let
newModel =
{ model | mode = v, formulaName = major }
in
( newModel
, notesChanged (notesForAudio newModel)
)
( newModel
, notesChanged (notesForAudio newModel)
)

_ ->
( model, notesChanged (notesForAudio model) )
Expand All @@ -179,9 +179,9 @@ update msg model =
newModel =
{ model | range = Result.withDefault 1 (String.toInt r) }
in
( newModel
, notesChanged (notesForAudio newModel)
)
( newModel
, notesChanged (notesForAudio newModel)
)

ToggleAudio ->
case model.audioPlaying of
Expand All @@ -200,23 +200,27 @@ update msg model =
newModel =
{ model | arpeggioPatterns = p }
in
( newModel
, notesChanged (notesForAudio newModel)
)
( newModel
, notesChanged (notesForAudio newModel)
)

BPMChanged newBpm ->
( { model | bpm = Result.withDefault 110 (String.toInt newBpm) }
, bpmChanged (model.bpm |> toString)
let
newModel =
{ model | bpm = Result.withDefault 110 (String.toInt newBpm) }
in
( newModel
, bpmChanged (newModel.bpm |> toString)
)

DoubleRootChanged dr ->
let
newModel =
{ model | rootNoteDouble = choiceToBool dr }
in
( newModel
, notesChanged (notesForAudio newModel)
)
( newModel
, notesChanged (notesForAudio newModel)
)



Expand Down Expand Up @@ -263,8 +267,8 @@ intToOption range i =
boolToOption : Bool -> String -> Html Msg
boolToOption dedup choice =
option
[ value (choice)
, selected (choice == (boolToChoice dedup))
[ value choice
, selected (choice == boolToChoice dedup)
]
[ text choice ]

Expand Down Expand Up @@ -313,7 +317,7 @@ selectionH1 model =
[ text <|
model.note
++ " "
++ (toString model.octave)
++ toString model.octave
++ " - "
++ model.formulaName
]
Expand Down Expand Up @@ -341,8 +345,8 @@ octaveMatrixDiv model =
]
]
(matrixOfStrings "Octave"
(List.map (\i -> toString (i)) (List.range -1 9))
(toString (model.octave))
(List.map (\i -> toString i) (List.range -1 9))
(toString model.octave)
)


Expand Down Expand Up @@ -374,19 +378,19 @@ notesForAudio model =
notes =
notesForModelState model
in
case model.arpeggioPatterns of
"Up" ->
notes
case model.arpeggioPatterns of
"Up" ->
notes

"Down" ->
List.reverse notes
"Down" ->
List.reverse notes

"Up And Down" ->
-- List.reverse notes |> List.append notes
notes ++ List.reverse notes
"Up And Down" ->
-- List.reverse notes |> List.append notes
notes ++ List.reverse notes

_ ->
notes
_ ->
notes



Expand All @@ -398,26 +402,22 @@ notesForAudio model =
notesForModelState : Model -> List String
notesForModelState model =
if model.mode == chordMode then
((chord model.note
chord model.note
model.octave
model.formulaName
model.range
(not (model.rootNoteDouble))
(not model.rootNoteDouble)
0
)
|> List.take 36
|> List.map (\i -> midiNoteNumberToString (i))
)
|> List.map (\i -> midiNoteNumberToString i)
else
((scale model.note
scale model.note
model.octave
model.formulaName
model.range
(not (model.rootNoteDouble))
)
(not model.rootNoteDouble)
|> List.take 36
|> List.map (\i -> midiNoteNumberToString (i))
)
|> List.map (\i -> midiNoteNumberToString i)


resultMatrixDiv : Model -> Html Msg
Expand All @@ -426,17 +426,17 @@ resultMatrixDiv model =
selectedCellNONE =
""
in
div
[ classList
[ ( "matrix", True )
, ( "result", True )
, ( "inline-block", True )
]
div
[ classList
[ ( "matrix", True )
, ( "result", True )
, ( "inline-block", True )
]
(matrixOfStrings "Result"
(notesForModelState model)
selectedCellNONE
)
]
(matrixOfStrings "Result"
(notesForModelState model)
selectedCellNONE
)


instrumentSelect : Model -> Html Msg
Expand All @@ -452,7 +452,7 @@ octaveRangeSelect model =
div [ class "select-cell" ]
[ select [ onInput OctaveRangeChanged, name "Range", class "soflow" ]
-- pass the model range as first argument so the menu can display '3' on start up
((List.range 1 6) |> List.map (intToOption model.range))
(List.range 1 6 |> List.map (intToOption model.range))
]


Expand Down Expand Up @@ -497,7 +497,15 @@ audioBannerDiv model =
button [ onClick ToggleAudio ] [ text "Play" ]
else
button [ onClick ToggleAudio ] [ text "Stop" ]
, input [ onInput BPMChanged, id "bpm", type_ "range", Html.Attributes.min "10", Html.Attributes.max "200" ] []
, input
[ onInput BPMChanged
, id "bpm"
, type_ "range"
, Html.Attributes.min "10"
, Html.Attributes.max "200"
, Html.Attributes.value (model.bpm |> toString)
]
[]
, span [] [ text (model.bpm |> toString) ]
]

Expand Down
13 changes: 4 additions & 9 deletions lib/fbaudio.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

function FBAudio() {
this.tempo = 120;
this.current_note = 0;
Expand Down Expand Up @@ -28,10 +27,10 @@ function FBAudio() {
Object.freeze(this.sampler);

var that = this;
this.part = new Tone.Part(function(time, event) {
that.sampler.triggerAttackRelease(event.note, event.dur);
this.part = new Tone.Sequence(function(time, pitch) {
that.sampler.triggerAttackRelease(pitch, "16n", time);
Logger.debug("sound loaded:" + that.sampler.loaded);
}, []);
}, [], "16n");
}


Expand All @@ -53,11 +52,7 @@ FBAudio.prototype = {
this.runLength = newNotes.length;
this.part.loopEnd = '16n * ' + (this.runLength);
for (var i = 0; i < this.runLength; i++) {
this.part.at('16n *' + i, {
time: '16n *' + i,
note: newNotes[i],
dur: '16n'
});
this.part.at(i, newNotes[i]);
}
}
};