Sha256: a67002797eab1932e36e32d35f4fcc661f1463edc6611904ac2c65c92522833d
Contents?: true
Size: 1.89 KB
Versions: 27
Compression:
Stored size: 1.89 KB
Contents
# frozen_string_literal: true require 'glimmer-dsl-libui' class TinyMidiPlayer include Glimmer VERSION = '0.0.1' def initialize @pid = nil @music_directory = File.expand_path(ARGV[0] || '~/Music/') @midi_files = Dir.glob(File.join(@music_directory, '**/*.mid')) .sort_by { |path| File.basename(path) } at_exit { stop_midi } create_gui end def stop_midi if @pid if @th.alive? Process.kill(:SIGKILL, @pid) @pid = nil else @pid = nil end end end def play_midi stop_midi if @pid.nil? && @selected_file begin @pid = spawn "timidity #{@selected_file}" @th = Process.detach @pid rescue Errno::ENOENT warn 'Timidty++ not found. Please install Timidity++.' warn 'https://sourceforge.net/projects/timidity/' end end end def show_version(main_window) msg_box(main_window, 'Tiny Midi Player', "Written in Ruby\n" \ "https://github.com/kojix2/libui\n" \ "Version #{VERSION}") end def create_gui menu('Help') { |m| menu_item('Version') { on_clicked do show_version(@main_window) end } } @main_window = window('Tiny Midi Player', 200, 50) { horizontal_box { vertical_box { stretchy false button('▶') { on_clicked do play_midi end } button('■') { on_clicked do stop_midi end } } combobox { |c| items @midi_files.map { |path| File.basename(path) } on_selected do @selected_file = @midi_files[c.selected] play_midi if @th&.alive? end } } } @main_window.show end end TinyMidiPlayer.new
Version data entries
27 entries across 27 versions & 1 rubygems