Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bramtayl committed Sep 4, 2021
1 parent 2b105b4 commit 74f04d1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
50 changes: 28 additions & 22 deletions src/Justly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function Interval(interval::Interval)
interval
end

function print_no_default(io, interval, prefix, property)
@inline function print_no_default(io, interval, prefix, property)
value = getproperty(interval, property)
if value != getproperty(INTERVAL_DEFAULTS, property)
print(io, prefix)
Expand Down Expand Up @@ -185,7 +185,7 @@ end

const CHORD_DEFAULTS = (words = "", beats = 1, notes = Note[], interval = Interval())

function getproperty(note::Note, property::Symbol)
@inline function getproperty(note::Note, property::Symbol)
if property === :interval
get_interval(note)
else
Expand Down Expand Up @@ -218,7 +218,7 @@ mutable struct Chord
end
export Chord

function getproperty(chord::Chord, property::Symbol)
@inline function getproperty(chord::Chord, property::Symbol)
if property === :interval
get_interval(chord)
else
Expand All @@ -235,7 +235,7 @@ function Chord(;
Chord(words, interval_pieces(Interval(interval))..., beats, notes, ListModel(notes))
end

function print_no_default(io, note_or_chord, property, level, ignore_level, empty)
@inline function print_no_default(io, note_or_chord, property, level, ignore_level, empty)
value = getproperty(note_or_chord, property)
if value != getproperty(CHORD_DEFAULTS, property)
_print(io, property => value, level, if empty
Expand Down Expand Up @@ -295,20 +295,25 @@ end

# TODO: add a special constructor to avoid Dict intermediates
function parse_chord(dictionary)
note_dictionaries = get(dictionary, :notes, Dict{Symbol, Any}[])
Chord(;
interval = get_default(dictionary, :interval),
words = get_default(dictionary, :words),
beats = get_default(dictionary, :beats),
# empty lists will come in as nothing
notes = if note_dictionaries === nothing
Note[]
else
map(parse_note, note_dictionaries)
end
notes = map(parse_note, get(dictionary, :notes, Dict{Symbol, Any}[]))
)
end

function add_chord!(chords_model, dictionary::Dict)
push!(chords_model, parse_chord(dictionary))
end

function add_chord!(chords_model, chords::Vector)
for chord in chords
add_chord!(chords_model, chord)
end
end

# we are working with the model, not the underlying data, so qt can know what we're doing
function from_yaml!(chords_model, text)
try
Expand All @@ -319,13 +324,12 @@ function from_yaml!(chords_model, text)
delete!(chords_model, 1)
end
for dictionary in result
push!(chords_model, parse_chord(dictionary))
add_chord!(chords_model, dictionary)
end
text
catch an_error
# TODO: more noisy error
@warn sprint(showerror, an_error)
string(an_error)
end
nothing
end

function press!(buffer, song, presses, releases;
Expand Down Expand Up @@ -441,19 +445,21 @@ function edit_song(song;
loadqml(joinpath(@__DIR__, "Justly.qml"), chords_model = chords_model, test = test)
stream = PortAudioStream(0, 1, writer = Weaver(); warn_xruns = false)
buffer = stream.sink_messanger.buffer
press_task = @spawn press!(buffer, song, presses, releases;
beat_duration = beat_duration,
initial_key = initial_key,
make_envelope = make_envelope,
ramp = ramp,
sample_rate = sample_rate,
volume = volume,
wave = wave
press_task = @spawn press!($buffer, $song, $presses, $releases;
beat_duration = $beat_duration,
initial_key = $initial_key,
make_envelope = $make_envelope,
ramp = $ramp,
sample_rate = $sample_rate,
volume = $volume,
wave = $wave
)
try
if test
simple_yaml = "- notes:\n - interval: \"3/2o1\"\n - {}\n- {}\n"
from_yaml!(chords_model, simple_yaml)
from_yaml!(chords_model, "nonsense")
from_yaml!(chords_model, simple_yaml)
# note: this is 1, 1 in julia
put!(presses, (0, 0))
put!(releases, nothing)
Expand Down
2 changes: 1 addition & 1 deletion src/Justly.qml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ApplicationWindow {
implicitHeight: button_side
implicitWidth: button_side
onClicked: {
Julia.from_yaml(yaml.text)
yaml.text = Julia.from_yaml(yaml.text)
}
}
ScrollView {
Expand Down

2 comments on commit 74f04d1

@bramtayl
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request updated: JuliaRegistries/General/44014

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.0.1 -m "<description of version>" 74f04d19a2e6d46b26decf7046be22025eb30d24
git push origin v0.0.1

Please sign in to comment.