Skip to content

Instantly share code, notes, and snippets.

@mikesmullin
Created May 12, 2013 22:48
Show Gist options
  • Save mikesmullin/5565242 to your computer and use it in GitHub Desktop.
Save mikesmullin/5565242 to your computer and use it in GitHub Desktop.
Pomodoro Timer
#!/usr/bin/env ruby
# vim: set ft=ruby :
class Sax
attr :b
attr :s1
attr :s2
def initialize
require 'bloops'
# the bloops o' phone
@b = Bloops.new
@b.tempo = 130
# melodious
@s1 = @b.sound Bloops::SINE
@s1.punch = 0.5
@s1.sustain = 0.4
@s1.decay = 0.2
@s1.arp = 0.4
@s1.aspeed = 0.0
@s1.repeat = 0.0
@s1.phase = 0.2
@s1.psweep = 0.2
# beats
@s2 = @b.sound Bloops::NOISE
@s2.punch = 0.5
@s2.sustain = 0.2
@s2.decay = 0.4
@s2.slide = -0.4
@s2.phase = 0.2
@s2.psweep = 0.2
end
def play(music, instrument = @s1)
@b.tune instrument, music
# and away we go
@b.play
sleep 1 while [email protected]?
end
end
# the tracks
#b.tune s1, "f#5 c6 e4 b6 g5 d6 4 f#5 e5 c5 b6 c6 d6 4 "
#b.tune s2, "4 c6 4 b5 4 4 e4 4 c6 4 b5 4 4 e4"
$sax = Sax.new
simpsons = "32 + C E F# 8:A G E C - 8:A 8:F# 8:F# 8:F# 2:G"
mario = %q{
16E 8E 16E 16 16C 8E 8G 8 - 8G 8 +
}
def random
notes = ['', 'C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B' ]
octaves = [1, 2, 3, 4, 5, 6]
intervals = ['', '2:', '8:'] # quarter, half, eighth
min = 8; max = 16;
song = ''
(rand(max)+min).times do
song += "#{intervals.sample}#{notes.sample}#{octaves.sample} "
end
song
end
class Work
@@screenshot_interval = 60*9; # 9min (lesser of TimeDoctor, oDesk)
def start(tasks = 3, tune = "C", start = 1)
i = (start - 1)
while true do
puts "focus on task #{(i % tasks)+1}."
#$sax.play "C C E F G A G F E C"
$sax.play tune
sleep @@screenshot_interval / tasks;
i += 1
end
end
end
tasks = ARGV[0] ? ARGV[0].to_i : 1
sound = ARGV[1] ? (ARGV[1].match(/ /) ? ARGV[1] : eval(ARGV[1])) : mario
start = ARGV[2] ? ARGV[2].to_i : 1
system 'clear'
puts "tasks: #{tasks}"
puts "sound: #{sound}"
puts 'start working.'
Work.new.start tasks, sound, start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment