Metronome app built in under 10 minutes with Glimmer DSL for SWT [message #1838824] |
Fri, 05 March 2021 18:40 |
Andy Maleh Messages: 75 Registered: March 2020 Location: Montreal, Quebec, Canada |
Member |
|
|
While going through drum pad practice yesterday, I noticed that my iPhone metronome app was broken after the latest update as it was ticking up on the second beat, not the first anymore. It was a small thing, but quite annoying, so I deleted the app and wrote my own Metronome app in Glimmer DSL for SWT in under 10 minutes for the initial working 4/4 rhythm version (please don't mind the initial rough code).
# From: https://github.com/AndyObtiva/glimmer-dsl-swt/blob/master/docs/reference/GLIMMER_SAMPLES.md#metronome
require 'glimmer-dsl-swt'
class Metronome
class Beat
attr_accessor :on
def off!
self.on = false
end
def on!
self.on = true
end
end
class Rhythm
attr_accessor :beats, :signature_top, :signature_bottom
def initialize(signature_top, signature_bottom)
@signature_top = signature_top
@signature_bottom = signature_bottom
@beats = @signature_top.times.map {Beat.new}
end
end
include Glimmer::UI::CustomShell
attr_reader :beats
before_body {
@rhythm = Rhythm.new(4, 4)
@beats = @rhythm.beats
}
body {
shell {
grid_layout 4, true
text 'Glimmer Metronome'
minimum_size 200, 200
4.times { |n|
canvas {
layout_data {
width_hint 50
height_hint 50
}
oval(0, 0, 50, 50) {
background bind(self, "beats[#{n}].on") {|on| on ? :red : :yellow}
}
}
}
on_swt_show {
@thread ||= Thread.new {
4.times.cycle { |n|
sleep(0.25)
beats.each(&:off!)
beats[n].on!
}
}
}
on_widget_disposed {
@thread.kill # safe since no stored data is involved
}
}
}
end
Metronome.launch
Anyways, I later revised it, adding a beat count option in addition to the BPM (beats per minute), with auto-grow/shrink support for the window shell when adding/subtracting beats.
Learn more at this blog post:
https://andymaleh.blogspot.com/2021/03/glimmer-metronome-hello-canvas.htmlhttps://andymaleh.blogspot.com/2021/03/glimmer-metronome-hello-canvas.html
EclipseCon / EclipseWorld / Agile Conference Speaker
Open-Source Software Author of Glimmer DSL for SWT
[Updated on: Sat, 06 March 2021 02:00] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03472 seconds