class MultimediaParadise::GUI::Libui::TagMp3Files

Public Class Methods

new( commandline_arguments = ARGV, run_already = true ) click to toggle source
#

initialize

#
# File lib/multimedia_paradise/gui/libui/tag_mp3_files/tag_mp3_files.rb, line 27
def initialize(
    commandline_arguments = ARGV,
    run_already           = true
  )
  @commandline_arguments = commandline_arguments
  run if run_already
end

Public Instance Methods

create_skeleton() click to toggle source
#

create_skeleton (skeleton tag, create tag)

#
# File lib/multimedia_paradise/gui/libui/tag_mp3_files/tag_mp3_files.rb, line 99
def create_skeleton
  create_the_entries
  create_the_buttons
end
create_the_buttons() click to toggle source
#

create_the_buttons

#
# File lib/multimedia_paradise/gui/libui/tag_mp3_files/tag_mp3_files.rb, line 107
def create_the_buttons
  # ======================================================================= #
  # === @button_play
  # ======================================================================= #
  @button_play = button('Play 🔉️')
  @button_play.on_clicked {
    do_play_the_selected_song
  }
  # ======================================================================= #
  # === @button_save
  # ======================================================================= #
  @button_save = button('Save')
  @button_save.on_clicked {
    do_save_the_dataset
  }
  # ======================================================================= #
  # === @button_open_file
  # ======================================================================= #
  @button_open_file = button('Open a local file')
  @button_open_file.on_clicked {
    cd song_directory? if File.directory?(song_directory?)
    @filename = ui_open_file(window).to_s # This is the part that will open a local file.
    if @filename and File.exist?(@filename)
      @entry_file_path.set_text(@filename)
      do_infer_information_about_this_file_and_set_related_entries(@filename)
    end
  }
end
create_the_entries() click to toggle source
#

create_the_entries

#
# File lib/multimedia_paradise/gui/libui/tag_mp3_files/tag_mp3_files.rb, line 50
def create_the_entries
  # ======================================================================= #
  # === @entry_file_path
  # ======================================================================= #
  @entry_file_path = ui_entry
end
do_save_the_dataset() click to toggle source
#

do_save_the_dataset

#
# File lib/multimedia_paradise/gui/libui/tag_mp3_files/tag_mp3_files.rb, line 233
def do_save_the_dataset
  @metadata_for_the_song = MultimediaParadise.analyse_tags_of_this_mp3_file(@filename)
  title   = @entry_containing_the_title_of_the_song.text?
  artist  = @entry_containing_the_artist.text?
  comment = @entry_containing_the_comment.text?
  @metadata_for_the_song.title = title
  @metadata_for_the_song.artist = artist
  @metadata_for_the_song.comment = comment
  @metadata_for_the_song.update! # Save it here.
end
menu( i = @commandline_arguments ) click to toggle source
#

menu (menu tag)

#
reset() click to toggle source
#

reset (reset tag)

#
# File lib/multimedia_paradise/gui/libui/tag_mp3_files/tag_mp3_files.rb, line 38
def reset
  title_width_height(TITLE, WIDTH, HEIGHT)
  # ======================================================================= #
  # === @filename
  # ======================================================================= #
  @filename = nil
  try_to_load_the_appropriate_id_tagger
end
run() click to toggle source
#

run

#
# File lib/multimedia_paradise/gui/libui/tag_mp3_files/tag_mp3_files.rb, line 146
def run
  reset
  create_skeleton
  @main_window = ui_main_window(
    title?, width?, height?, 0
  )
  outer_vbox = ui_vbox
  outer_vbox.is_padded
  outer_vbox.text(
    'This widget can be used to modify the ID3 tags '\
    'of .mp3 files. The taglib-ruby gem is required for this functionality.'
  )
  hbox = padded_hbox
  hbox.text(' 🎵️ Input the path to a local .mp3 file ')
  hbox.add(@entry_file_path, 1)

  hbox.add(@button_open_file, 0)
  outer_vbox.add(hbox, 0)

  middle_hbox = padded_hbox
  # ======================================================================= #
  # And the quit button next:
  # ======================================================================= #
  a_quit_button = ui_quit_button(
    text: 'Quit' # Use a quit button.
  ) { :with_emoji }
  left_vbox = padded_vbox

  left_vbox.add(button('Open a local file'),   1)
  left_vbox.add(button('Debug'),               1)
  left_vbox.add(button('Delete the tags'),     1)
  left_vbox.add(button('Update'),              1)
  left_vbox.add(@button_play,                  1)
  left_vbox.add(@button_save,                  1)
  left_vbox.add(a_quit_button,                 1)
  middle_hbox.add(left_vbox, 0)
  right_vbox = ui_vbox
  vbox = ui_vbox
  # ======================================================================= #
  # === Title of the song:
  # ======================================================================= #
  vbox.text('Title of the song:')
  @entry_containing_the_title_of_the_song = ui_entry
  vbox.add(@entry_containing_the_title_of_the_song, 0)
  # ======================================================================= #
  # === Artist:
  # ======================================================================= #
  vbox.text('Artist:')
  @entry_containing_the_artist = ui_entry
  vbox.add(@entry_containing_the_artist, 0)
  # ======================================================================= #
  # === Comment:
  # ======================================================================= #
  vbox.text('Comment:')
  @entry_containing_the_comment = ui_entry
  vbox.add(@entry_containing_the_comment, 0)
  
  right_vbox.add(vbox)
  middle_hbox << right_vbox

  outer_vbox.add(middle_hbox, 0)
  menu
  @main_window.child = outer_vbox
  @main_window.intelligent_exit
end
set_filename(i) click to toggle source
#

set_filename

#
# File lib/multimedia_paradise/gui/libui/tag_mp3_files/tag_mp3_files.rb, line 139
def set_filename(i)
  @filename = i
end
try_to_load_the_appropriate_id_tagger( i = :taglib ) click to toggle source
#

try_to_load_the_appropriate_id_tagger

#
# File lib/multimedia_paradise/gui/libui/tag_mp3_files/tag_mp3_files.rb, line 60
def try_to_load_the_appropriate_id_tagger(
    i = :taglib
  )
  case i # case tag
  # ======================================================================= #
  # === :taglib
  #
  # Note that since as of 2021, taglib is the default, thus replacing
  # the older id3lib code. The latter is still retained, though, in
  # the event we may have to switch again one day.
  # ======================================================================= #
  when :taglib
    begin
      require 'taglib'
    rescue LoadError
      e "taglib is not available. Please install it."
      e
      e '  gem install taglib-ruby # Github-page at: '\
        'https://github.com/robinst/taglib-ruby'
      e
    end
  # ======================================================================= #
  # === :id3lib
  # ======================================================================= #
  when :id3lib
    begin
      require 'id3lib'
    rescue LoadError
      e "ruby-id3lib not available. Please install it."
      e
      e '  gem install id3lib-ruby'
      e
    end
  end
end