############################################################################### # # itunes_info.pl # # This script is a replica of the iTunes multiple track info dialog, but in # addition to the fields in the iTunes editor, it also lets you edit the # Comment and Description fields. Also, you can use it to set 1/2-star ratings # (e.g. 2.5 stars). However, you cannot use it to modify artwork (yet?). # # Copyright (C) 2007 Robert Jacobson # written by: Robert Jacobson (http://teridon.googlepages.com/itunesscripts) # Last Updated: 28 Jan 2007 # Version 1.0 # # This script is GPL v2. see http://www.gnu.org/copyleft/gpl.html # ############################################################################### use File::Basename; my $PROGNAME = basename($0); my $VERSION = "1.0"; my $AUTHOR = "Robert Jacobson"; my $HOMEPAGE = "http://teridon.googlepages.com/"; my $YEAR = 2007; my $GNU_URL = "http://www.gnu.org/copyleft/gpl.html"; { print "**************************************************************\n" . "$PROGNAME version $VERSION, Copyright (C) $YEAR $AUTHOR\n" . "Visit $HOMEPAGE for updates\n" . "$PROGNAME comes with ABSOLUTELY NO WARRANTY;\n". "This is free software, and you are welcome\n" . "to redistribute it under certain conditions\n" . "for details see $GNU_URL.\n" . "**************************************************************\n" . "\n" ; } ################## # # This file was generated with the asistance of ZooZ.pl v1.2 # on Sun Dec 10 19:52:21 2006. # ################## # # Headers # use strict; #use warnings; use Tk 804; use Win32::OLE; use Data::Dumper; # Create a signal handler to destroy the iTunes object # in case our program quits before the end use sigtrap 'handler', \&quit, 'normal-signals'; ## Create the OLE Object my $iTunes = Win32::OLE->new('iTunes.Application') or die Win32::OLE->LastError(); my $tracks = $iTunes->BrowserWindow->SelectedTracks; if (defined $tracks) { #print Dumper $tracks; } else { print "ERROR - You didn't select any tracks in iTunes!\n"; &quit; } # Iterate over the tracks and get the info that is the same my $num_tracks = $tracks->Count(); #print "\t$num_tracks tracks\n"; my %seen; my ($artist, $album, $grouping, $composer, $comments, $genre, $volume_adjustment, $category); my ($year, $track_number, $track_count, $disc_number, $disc_count, $bpm, $compilation, $rating, $equalizer, $description); my ($Artist, $Album, $Grouping, $Composer, $Comments, $Genre, $Volume_Adjustment, $Category); my ($Year, $Track_Number, $Track_Count, $Disc_Number, $Disc_Count, $BPM, $Compilation, $Rating, $Equalizer, $Description); my ($Old_Artist, $Old_Album, $Old_Grouping, $Old_Composer, $Old_Comments, $Old_Genre, $Old_Volume_Adjustment, $Old_Category); my ($Old_Year, $Old_Track_Number, $Old_Track_Count, $Old_Disc_Number, $Old_Disc_Count, $Old_BPM, $Old_Compilation, $Old_Rating, $Old_Equalizer, $Old_Description); my $Displayed_Rating; my @Presets; my $Checked_Artist; my $Checked_Album; my $Checked_Grouping; my $Checked_Composer; my $Checked_Comment; my $Checked_Genre; my $Checked_Volume; my $Checked_Category; my $Checked_Year; my $Checked_Track_Number; my $Checked_Disc_Number; my $Checked_BPM; my $Checked_Artwork; my $Checked_Compilation; my $Checked_Preset; my $Checked_Description; my $Checked_Track_Count; my $Checked_Disc_Count; my $Checked_Rating; Get_Presets(); # Get all the tracks in the playlist for (my $k = 1 ; $k <= $tracks->Count ; $k++ ) { #print "num: " , $num_tracks , " Count: ", $tracks->Count , " k: ", $k , "\n"; my $track = $tracks->Item($k); my $track_kind = $track->Kind(); if ($track_kind == 1) { # File $artist = $track->Artist(); $seen{artist}{$artist}++; $album = $track->Album(); $seen{album}{$album}++; $grouping = $track->Grouping(); $seen{grouping}{$grouping}++; $composer = $track->Composer(); $seen{composer}{$composer}++; $comments = $track->Comment(); $seen{comments}{$comments}++; $genre = $track->Genre(); $seen{genre}{$genre}++; $volume_adjustment = $track->VolumeAdjustment(); $seen{volume_adjustment}{$volume_adjustment}++; $category = $track->Category(); $seen{category}{$category}++; $year = $track->Year(); $seen{year}{$year}++; $track_number = $track->TrackNumber(); $seen{track_number}{$track_number}++; $track_count = $track->TrackCount(); $seen{track_count}{$track_count}++; $disc_number = $track->DiscNumber(); $seen{disc_number}{$disc_number}++; $disc_count = $track->DiscCount(); $seen{disc_count}{$disc_count}++; $bpm = $track->BPM(); $seen{bpm}{$bpm}++; $compilation = $track->Compilation(); if ($compilation) {$seen{compilation}{yes}++;} else {$seen{compilation}{no}++;} # print "compilation is $compilation, seen yes: $seen{compilation}{yes} no: $seen{compilation}{no}\n"; $rating = $track->Rating(); $seen{rating}{$rating}++; $equalizer = $track->EQ(); $seen{equalizer}{$equalizer}++; $description = $track->Description(); $seen{description}{$description}++; } } #print "artist: seen $seen{artist}{$artist} , num: $num_tracks\n"; if (($artist ne "" ) && ($seen{artist}{$artist} == $num_tracks)) { print "Same artist\n"; $Artist = $artist; $Old_Artist = $artist; } if (($album ne "") && ($seen{album}{$album} == $num_tracks)) { print "Same album\n"; $Album = $album; $Old_Album = $album; } if (($grouping ne "") && ($seen{grouping}{$grouping} == $num_tracks)) { print "Same grouping\n"; $Grouping = $grouping; $Old_Grouping = $grouping; } if (($composer ne "") && ($seen{composer}{$composer} == $num_tracks)) { print "Same composer\n"; $Composer = $composer; $Old_Composer = $composer; } if (($comments ne "") && ($seen{comments}{$comments} == $num_tracks)) { print "Same comments\n"; $Comments = $comments; $Old_Comments = $comments; } if (($genre ne "") && ($seen{genre}{$genre} == $num_tracks)) { print "Same genre\n"; $Genre = $genre; $Old_Genre = $genre; } if (($volume_adjustment != 0 ) && ($seen{volume_adjustment}{$volume_adjustment} == $num_tracks)) { print "Same volume_adjustment\n"; $Volume_Adjustment = $volume_adjustment; $Old_Volume_Adjustment = $volume_adjustment; } if (($category ne "") && ($seen{category}{$category} == $num_tracks)) { print "Same category\n"; $Category = $category; $Old_Category = $category; } if (($year != 0) && ($seen{year}{$year} == $num_tracks)) { print "Same year\n"; $Year = $year; $Old_Year = $year; } if (($track_number != 0 ) && ($seen{track_number}{$track_number} == $num_tracks)) { print "Same track_number\n"; $Track_Number = $track_number; $Old_Track_Number = $track_number; } if (($track_count != 0 ) && ($seen{track_count}{$track_count} == $num_tracks)) { print "Same track_count $track_count\n"; $Track_Count = $track_count; $Old_Track_Count = $track_count; } if (($disc_number != 0 ) && ( $seen{disc_number}{$disc_number}== $num_tracks)) { print "Same disc_number\n"; $Disc_Number = $disc_number; $Old_Disc_Number = $disc_number; } if (($disc_count != 0 ) && ($seen{disc_count}{$disc_count} == $num_tracks)) { print "Same disc_count\n"; $Disc_Count = $disc_count; $Old_Disc_Count = $disc_count; } if (($bpm != 0) && ( $seen{bpm}{$bpm}== $num_tracks)) { print "Same bpm\n"; $BPM = $bpm; $Old_BPM = $bpm; } if ( (defined($seen{compilation}{yes})) && ($seen{compilation}{yes} == $num_tracks) ) { $Compilation = "Yes"; $Old_Compilation = "Yes"; } else { $Compilation = "No"; $Old_Compilation = "No"; } if (($rating != 0 ) && ($seen{rating}{$rating} == $num_tracks)) { print "Same rating\n"; $Rating = $rating; $Old_Rating = $rating; } if (($equalizer ne "" ) && ($seen{equalizer}{$equalizer} == $num_tracks)) { print "Same equalizer\n"; $Equalizer = $equalizer; $Old_Equalizer = $equalizer; } else { $Equalizer = "None"; $Old_Equalizer = "None"; } if (($description ne "" ) && ($seen{description}{$description} == $num_tracks)) { print "Same description\n"; $Description = $description; $Old_Description = $description; } # # Global variables # my ( # MainWindow $MW, # Hash of all widgets %ZWIDGETS, ); # # User-defined variables (if any) # ###################### # # Create the MainWindow # ###################### $MW = MainWindow->new; ###################### # # Load any images and fonts # ###################### ZloadImages(); ZloadFonts (); # Widget Frame1 isa Frame $ZWIDGETS{'Frame1'} = $MW->Frame()->grid( -row => 0, -column => 0, -rowspan => 2, -columnspan => 2, ); # Widget Label_Artist isa Label $ZWIDGETS{'Label_Artist'} = $ZWIDGETS{Frame1}->Label( -text => 'Artist', )->grid( -row => 0, -column => 0, -columnspan => 5, -sticky => 'w', ); # Widget Checkbutton1 isa Checkbutton $ZWIDGETS{'Checkbutton_Artist'} = $ZWIDGETS{Frame1}->Checkbutton( -variable => \$Checked_Artist, -text => '', )->grid( -row => 1, -column => 0, ); # Widget Entry_Artist isa Entry $ZWIDGETS{'Entry_Artist'} = $ZWIDGETS{Frame1}->Entry( -textvariable => \$Artist, -validate => 'key', -validatecommand => [\&Entry_Artist], )->grid( -row => 1, -column => 1, -columnspan => 4, -sticky => 'ew', ); # Widget Label_Album isa Label $ZWIDGETS{'Label_Album'} = $ZWIDGETS{Frame1}->Label( -text => 'Album', )->grid( -row => 2, -column => 0, -columnspan => 5, -sticky => 'w', ); # Widget Checkbutton1 isa Checkbutton $ZWIDGETS{'Checkbutton_Album'} = $ZWIDGETS{Frame1}->Checkbutton( -variable => \$Checked_Album, -text => '', )->grid( -row => 3, -column => 0, ); # Widget Entry_Album isa Entry $ZWIDGETS{'Entry_Album'} = $ZWIDGETS{Frame1}->Entry( -textvariable => \$Album, -validate => 'key', -validatecommand => \&Entry_Album, )->grid( -row => 3, -column => 1, -columnspan => 4, -sticky => 'ew', ); # Widget Label_Grouping isa Label $ZWIDGETS{'Label_Grouping'} = $ZWIDGETS{Frame1}->Label( -text => 'Grouping', )->grid( -row => 4, -column => 0, -columnspan => 5, -sticky => 'w', ); # Widget Checkbutton1 isa Checkbutton $ZWIDGETS{'Checkbutton_Grouping'} = $ZWIDGETS{Frame1}->Checkbutton( -variable => \$Checked_Grouping, -text => '', )->grid( -row => 5, -column => 0, ); # Widget Entry_Grouping isa Entry $ZWIDGETS{'Entry_Grouping'} = $ZWIDGETS{Frame1}->Entry( -textvariable => \$Grouping, -validate => 'key', -validatecommand => \&Entry_Grouping, )->grid( -row => 5, -column => 1, -columnspan => 4, -sticky => 'ew', ); # Widget Label_Composer isa Label $ZWIDGETS{'Label_Composer'} = $ZWIDGETS{Frame1}->Label( -text => 'Composer', )->grid( -row => 6, -column => 0, -columnspan => 5, -sticky => 'w', ); # Widget Checkbutton1 isa Checkbutton $ZWIDGETS{'Checkbutton_Composer'} = $ZWIDGETS{Frame1}->Checkbutton( -variable => \$Checked_Composer, -text => '', )->grid( -row => 7, -column => 0, ); # Widget Entry_Composer isa Entry $ZWIDGETS{'Entry_Composer'} = $ZWIDGETS{Frame1}->Entry( -textvariable => \$Composer, -validate => 'key', -validatecommand => \&Entry_Composer, )->grid( -row => 7, -column => 1, -columnspan => 4, -sticky => 'ew', ); # Widget Label_Comments isa Label $ZWIDGETS{'Label_Comments'} = $ZWIDGETS{Frame1}->Label( -text => 'Comments', )->grid( -row => 8, -column => 0, -columnspan => 5, -sticky => 'w', ); # Widget Checkbutton2 isa Checkbutton $ZWIDGETS{'Checkbutton_Comment'} = $ZWIDGETS{Frame1}->Checkbutton( -variable => \$Checked_Comment, -text => '', )->grid( -row => 9, -column => 0, -rowspan => 2, ); # Widget Frame3 isa Frame $ZWIDGETS{'Frame3'} = $ZWIDGETS{Frame1}->Frame()->grid( -row => 9, -column => 1, -rowspan => 2, -columnspan => 4, -sticky => 'nsew', ); # Widget Text2 isa Text $ZWIDGETS{'Text_Comment'} = $ZWIDGETS{Frame3}->Text( -font => "Arial 8", -height => 3, -width => 30, )->grid( -row => 0, -column => 0, ); if (defined ($Comments)) { $ZWIDGETS{'Text_Comment'}->insert('end', $Comments); } # Widget Label_Genre isa Label $ZWIDGETS{'Label_Genre'} = $ZWIDGETS{Frame1}->Label( -text => "\nGenre", )->grid( -row => 11, -column => 0, -columnspan => 5, -sticky => 'w', ); # Widget Checkbutton1 isa Checkbutton $ZWIDGETS{'Checkbutton_Genre'} = $ZWIDGETS{Frame1}->Checkbutton( -variable => \$Checked_Genre, -text => '', )->grid( -row => 12, -column => 0, ); # Widget Entry_Genre isa Entry $ZWIDGETS{'Entry_Genre'} = $ZWIDGETS{Frame1}->Entry( -textvariable => \$Genre, -validate => 'key', -validatecommand => \&Entry_Genre, )->grid( -row => 12, -column => 1, -columnspan => 4, -sticky => 'ew', ); # Widget Label_Volume isa Label $ZWIDGETS{'Label_Volume'} = $ZWIDGETS{Frame1}->Label( -text => '-100% -- Volume Adjustment -- +100%', )->grid( -row => 13, -column => 0, -columnspan => 5, -sticky => 'w', ); # Widget Checkbutton1 isa Checkbutton $ZWIDGETS{'Checkbutton_Volume'} = $ZWIDGETS{Frame1}->Checkbutton( -variable => \$Checked_Volume, -text => '', )->grid( -row => 14, -column => 0, ); # Widget Scale_Volume isa Scale $ZWIDGETS{'Scale_Volume'} = $ZWIDGETS{Frame1}->Scale( -command => \&Volume_Slider, -variable => \$Volume_Adjustment, -orient => 'horizontal', -width => 10, -from => -100, -to => 100, -takefocus => 1, )->grid( -row => 14, -column => 1, -columnspan => 4, -sticky => 'ew', ); # Widget Label18_Category isa Label $ZWIDGETS{'Label_Category'} = $ZWIDGETS{Frame1}->Label( -text => 'Category', )->grid( -row => 15, -column => 0, -columnspan => 5, -sticky => 'w', ); # Widget Checkbutton1 isa Checkbutton $ZWIDGETS{'Checkbutton_Category'} = $ZWIDGETS{Frame1}->Checkbutton( -variable => \$Checked_Category, -text => '', )->grid( -row => 16, -column => 0, ); # Widget Entry_Category isa Entry $ZWIDGETS{'Entry_Category'} = $ZWIDGETS{Frame1}->Entry( -textvariable => \$Category, -validate => 'key', -validatecommand => \&Entry_Category, )->grid( -row => 16, -column => 1, -columnspan => 4, -sticky => 'ew', ); # Widget Frame2 isa Frame $ZWIDGETS{'Frame2'} = $MW->Frame()->grid( -row => 0, -column => 2, -rowspan => 2, -columnspan => 2, ); # Widget Label_Year isa Label $ZWIDGETS{'Label_Year'} = $ZWIDGETS{Frame2}->Label( -text => "\n\nYear", )->grid( -row => 0, -column => 0, -columnspan => 3, -sticky => 'w', ); # Widget Checkbutton1 isa Checkbutton $ZWIDGETS{'Checkbutton_Year'} = $ZWIDGETS{Frame2}->Checkbutton( -variable => \$Checked_Year, -text => '', )->grid( -row => 1, -column => 0, ); # Widget Entry_Year isa Entry $ZWIDGETS{'Entry_Year'} = $ZWIDGETS{Frame2}->Entry( -textvariable => \$Year, -validate => 'key', -validatecommand => \&Entry_Year, )->grid( -row => 1, -column => 1, -columnspan => 2, -sticky => 'w', ); # Widget Label_Track_Number isa Label $ZWIDGETS{'Label_Track_Number'} = $ZWIDGETS{Frame2}->Label( -text => 'Track Number', )->grid( -row => 2, -column => 0, -columnspan => 3, -sticky => 'w', ); # Widget Checkbutton1 isa Checkbutton $ZWIDGETS{'Checkbutton_Track_Number'} = $ZWIDGETS{Frame2}->Checkbutton( -variable => \$Checked_Track_Number, -text => '', )->grid( -row => 3, -column => 0, ); # Widget Entry_Track_Number_Left isa Entry $ZWIDGETS{'Entry_Track_Number_Left'} = $ZWIDGETS{Frame2}->Entry( -justify => 'right', -textvariable => \$Track_Number, -validate => 'key', -validatecommand => \&Entry_Track_Number, -width => 3, )->grid( -row => 3, -column => 1, -sticky => 'e', ); # Widget Label_Disc_Number isa Label $ZWIDGETS{'Label_Disc_Number'} = $ZWIDGETS{Frame2}->Label( -text => 'Disc Number', )->grid( -row => 4, -column => 0, -columnspan => 3, -sticky => 'w', ); # Widget Checkbutton1 isa Checkbutton $ZWIDGETS{'Checkbutton_Disc_Number'} = $ZWIDGETS{Frame2}->Checkbutton( -variable => \$Checked_Disc_Number, -text => '', )->grid( -row => 5, -column => 0, ); # Widget Entry_Disc_Number_Left isa Entry $ZWIDGETS{'Entry_Disc_Number_Left'} = $ZWIDGETS{Frame2}->Entry( -justify => 'right', -textvariable => \$Disc_Number, -validate => 'key', -validatecommand => \&Entry_Disc_Number, -width => 3, )->grid( -row => 5, -column => 1, -sticky => 'e', ); # Widget Label_BPM isa Label $ZWIDGETS{'Label_BPM'} = $ZWIDGETS{Frame2}->Label( -text => 'BPM', )->grid( -row => 6, -column => 0, -columnspan => 3, -sticky => 'w', ); # Widget Checkbutton1 isa Checkbutton $ZWIDGETS{'Checkbutton_BPM'} = $ZWIDGETS{Frame2}->Checkbutton( -variable => \$Checked_BPM, -text => '', )->grid( -row => 7, -column => 0, ); # Widget Entry_BPM isa Entry $ZWIDGETS{'Entry_BPM'} = $ZWIDGETS{Frame2}->Entry( -textvariable => \$BPM, -validate => 'key', -validatecommand => \&Entry_BPM, )->grid( -row => 7, -column => 1, -columnspan => 2, -sticky => 'w', ); # Widget Label_Artwork isa Label $ZWIDGETS{'Label_Artwork'} = $ZWIDGETS{Frame2}->Label( -text => 'Artwork', )->grid( -row => 8, -column => 0, -columnspan => 3, -sticky => 'w', ); # Widget Checkbutton1 isa Checkbutton $ZWIDGETS{'Checkbutton_Artwork'} = $ZWIDGETS{Frame2}->Checkbutton( -variable => \$Checked_Artwork, -text => '', )->grid( -row => 9, -column => 0, ); # Widget Image_Artwork isa Image $ZWIDGETS{'Image_Artwork'} = $ZWIDGETS{Frame2}->Label( -height => 4, )->grid( -row => 9, -column => 1, -rowspan => 2, -columnspan => 2, ); # Widget Label_Compilation isa Label $ZWIDGETS{'Label_Compilation'} = $ZWIDGETS{Frame2}->Label( -text => 'Part of a Compilation', )->grid( -row => 11, -column => 0, -columnspan => 2, -sticky => 'w', ); # Widget Checkbutton1 isa Checkbutton $ZWIDGETS{'Checkbutton_Compilation'} = $ZWIDGETS{Frame2}->Checkbutton( -variable => \$Checked_Compilation, -text => '', )->grid( -row => 12, -column => 0, ); my @Compilations = qw/ Yes No /; #my $Compilation = " "; # Widget Optionmenu_Compilation isa Optionmenu $ZWIDGETS{'Optionmenu_Compilation'} = $ZWIDGETS{Frame2}->Optionmenu( -width => 3, -variable => \$Compilation, -options => [@Compilations], -command => \&Optionmenu_Compilation, )->grid( -row => 12, -column => 1, -columnspan => 1, -sticky => 'w', ); # Widget Label17_Equalizer isa Label $ZWIDGETS{'Label17_Equalizer'} = $ZWIDGETS{Frame2}->Label( -text => 'Equalizer Preset', )->grid( -row => 13, -column => 0, -columnspan => 3, -sticky => 'w', ); #my $Equalizer = " "; # Widget Checkbutton1 isa Checkbutton $ZWIDGETS{'Checkbutton_Preset'} = $ZWIDGETS{Frame2}->Checkbutton( -variable => \$Checked_Preset, -text => '', )->grid( -row => 14, -column => 0, ); # Widget Optionmenu_Equalizer isa Optionmenu $ZWIDGETS{'Optionmenu_Equalizer'} = $ZWIDGETS{Frame2}->Optionmenu( -width => 15, -variable => \$Equalizer, -options => ["None", @Presets], -command => \&Optionmenu_Equalizer, )->grid( -row => 14, -column => 1, -columnspan => 2, -sticky => 'w', ); # Widget Label_Description isa Label $ZWIDGETS{'Label_Description'} = $ZWIDGETS{Frame2}->Label( -text => 'Description', )->grid( -row => 15, -column => 0, -columnspan => 3, -sticky => 'w', ); # Widget Checkbutton1 isa Checkbutton $ZWIDGETS{'Checkbutton_Description'} = $ZWIDGETS{Frame2}->Checkbutton( -variable => \$Checked_Description, -text => '', )->grid( -row => 16, -column => 0, ); # Widget Text3 isa Text $ZWIDGETS{'Text_Description'} = $ZWIDGETS{Frame2}->Text( -font => "Arial 8", -height => 3, -width => 30, )->grid( -row => 16, -column => 1, -columnspan => 2, -sticky => 'new', ); if (defined $Description) { $ZWIDGETS{'Text_Description'}->insert('end', $Description); } # Widget Label_of_1 isa Label $ZWIDGETS{'Label_of_1'} = $ZWIDGETS{Frame2}->Label( -padx => 0, -pady => 1, -text => 'of', -width => 0, )->grid( -row => 3, -column => 1, ); # Widget Label_of_2 isa Label $ZWIDGETS{'Label_of_2'} = $ZWIDGETS{Frame2}->Label( -padx => 0, -pady => 1, -text => 'of', )->grid( -row => 5, -column => 1, ); # Widget Checkbutton1 isa Checkbutton $ZWIDGETS{'Checkbutton_Track_Count'} = $ZWIDGETS{Frame2}->Checkbutton( -variable => \$Checked_Track_Count, -text => '', )->grid( -row => 3, -column => 2, ); # Widget Entry_Track_Number_Right isa Entry $ZWIDGETS{'Entry_Track_Number_Right'} = $ZWIDGETS{Frame2}->Entry( -width => 3, -textvariable => \$Track_Count, -validate => 'key', -validatecommand => \&Entry_Track_Count, )->grid( -row => 3, -column => 3, -sticky => 'w', ); # Widget Checkbutton1 isa Checkbutton $ZWIDGETS{'Checkbutton_Disc_Count'} = $ZWIDGETS{Frame2}->Checkbutton( -variable => \$Checked_Disc_Count, -text => '', )->grid( -row => 5, -column => 2, ); # Widget Entry_Disc_Number_Right isa Entry $ZWIDGETS{'Entry_Disc_Number_Right'} = $ZWIDGETS{Frame2}->Entry( -width => 3, -textvariable => \$Disc_Count, -validate => 'key', -validatecommand => \&Entry_Disc_Count, )->grid( -row => 5, -column => 3, -sticky => 'w', ); # Widget Label_Rating isa Label $ZWIDGETS{'Label_Rating'} = $ZWIDGETS{Frame2}->Label( -text => 'My Rating', )->grid( -row => 11, -column => 2, ); # my @Ratings = qw/ # 0.0 # 0.5 # 1.0 # 1.5 # 2.0 # 2.5 # 3.0 # 3.5 # 4.0 # 4.5 # 5.0 # 5.5 # 6.0 # 6.5 # 7.0 # 7.5 # 8.0 # 8.5 # 9.0 # 9.5 # 10.0 # /; # # my $Rating = " "; # # Widget Optionmenu_Rating isa Optionmenu # $ZWIDGETS{'Optionmenu_Rating'} = $ZWIDGETS{Frame2}->Optionmenu( # -width => 3, # -variable => \$Rating, # -options => ["", @Ratings], # )->grid( # -row => 12, # -column => 2, # ); # Widget Checkbutton1 isa Checkbutton $ZWIDGETS{'Checkbutton_Rating'} = $ZWIDGETS{Frame2}->Checkbutton( -variable => \$Checked_Rating, -text => '', )->grid( -row => 12, -column => 2, ); # Widget Scale_Volume isa Scale $ZWIDGETS{'Scale_Rating'} = $ZWIDGETS{Frame2}->Scale( -command => \&Calc_Rating, -orient => 'horizontal', -width => 10, -from => 0, -to => 5, -resolution => 0.5, -takefocus => 1, -variable => \$Displayed_Rating, )->grid( -row => 12, -column => 3, # -columnspan => 5, # -sticky => 'ew', ); # Widget Button1_OK isa Button $ZWIDGETS{'Button_OK'} = $MW->Button( -text => 'OK', -command => \&Set_Values, -width => 4, -height => 2, )->grid( -row => 2, -column => 2, ); # Widget Button_Cancel isa Button $ZWIDGETS{'Button_Cancel'} = $MW->Button( -text => 'Cancel', -width => 6, -height => 2, -command => \&quit, )->grid( -row => 2, -column => 3, ); ############### # # MainLoop # ############### Display_Rating(); MainLoop; ####################### # # Subroutines # ####################### sub ZloadImages { } sub ZloadFonts { } # Destroy the object. Otherwise zombie object will come back # to haunt you quit(); sub quit { # This destroys the object undef $iTunes; # print "Exec quit\n"; # sleep 2; exit; } sub Display_Rating { if ($Rating) { $Displayed_Rating = $Rating / 20; } else { $Displayed_Rating = 0; $Rating = 0; } #print "Display : $Displayed_Rating\tRating: $Rating\n"; } sub Calc_Rating { $Rating = $Displayed_Rating * 20; #print "Setting Rating: $Rating from $Displayed_Rating\n"; if (defined $Old_Rating && $Rating ne $Old_Rating) { $Checked_Rating = 1; } elsif (not defined $Old_Rating and $Rating) { $Checked_Rating = 1; } else { $Checked_Rating = 0; } } sub Get_Presets { my $presets = $iTunes->EQPresets(); my $num_presets = $presets->Count(); for (my $i = 1; $i <= $num_presets; $i++ ) { my $preset = $presets->Item($i); my $preset_name = $preset->Name(); # Add to the list push (@Presets , $preset_name); } } sub Set_Values { if ($Checked_Artist) {&Set_Value("Artist", $Artist)}; if ($Checked_Album) {&Set_Value("Album", $Album)}; if ($Checked_Grouping) {&Set_Value("Grouping", $Grouping)}; if ($Checked_Composer) {&Set_Value("Composer", $Composer)}; if ($Checked_Genre) {&Set_Value("Genre", $Genre)}; if ($Checked_Volume) {&Set_Value("VolumeAdjustment", $Volume_Adjustment)}; if ($Checked_Category) {&Set_Value("Category", $Category)}; if ($Checked_Year) {&Set_Value("Year", $Year)}; if ($Checked_Track_Number) {&Set_Value("TrackNumber", $Track_Number)}; if ($Checked_Track_Count) {&Set_Value("TrackCount", $Track_Count)}; if ($Checked_Disc_Number) {&Set_Value("DiscNumber", $Disc_Number)}; if ($Checked_Disc_Count) {&Set_Value("DiscCount", $Disc_Count)}; if ($Checked_BPM) {&Set_Value("BPM", $BPM)}; #if ($Checked_Artwork) {&Set_Value("Artwork", $Artwork)}; if ($Checked_Compilation) {&Set_Value("Compilation", $Compilation)}; if ($Checked_Preset) {&Set_Value("EQ", $Equalizer)}; if ($Checked_Rating) {&Set_Value("Rating", $Rating)}; if ($Checked_Comment) { $Comments = $ZWIDGETS{'Text_Comment'}->get('1.0','end'); $Comments =~ s/\s+$//; &Set_Value("Comment", $Comments); } if ($Checked_Description) { $Description = $ZWIDGETS{'Text_Description'}->get('1.0','end'); $Description =~ s/\s+$//; &Set_Value("Description", $Description); } &quit; } sub Set_Value { my $type = shift; my $value = shift; print "Setting $type to $value\n"; if ($type eq "Compilation") { if ($Compilation eq "Yes") { $value = 1; } else {$value = 0;} } for (my $k = 1 ; $k <= $tracks->Count ; $k++ ) { my $track = $tracks->Item($k); $track->{$type} = $value; } } sub Set_Artist { Set_Value("Artist", $Artist); } sub Volume_Slider { my $arg = shift; #print "Volume: $arg\n"; if (defined $Old_Volume_Adjustment && $Volume_Adjustment ne $Old_Volume_Adjustment) { $Checked_Volume = 1; } elsif (not defined $Old_Volume_Adjustment and $Volume_Adjustment) { $Checked_Volume = 1; } else { $Checked_Volume = 0; } } sub Optionmenu_Compilation { my $arg = shift; #print "compilation: $arg\n"; if ($arg ne $Old_Compilation) { $Checked_Compilation = 1; } else { $Checked_Compilation = 0; } } sub Optionmenu_Equalizer { my $arg = shift; #print "Equalizer: $arg\n"; if ($arg ne $Old_Equalizer) { $Checked_Preset = 1; } else { $Checked_Preset = 0; } } sub Entry_Artist { my $arg = shift; #print "Artist input: $arg\n"; if ($arg ne $Old_Artist) { $Checked_Artist = 1; } else { $Checked_Artist = 0; } return 1; } sub Entry_Album { my $arg = shift; #print "Album input: $arg\n"; if ($arg ne $Old_Album) { $Checked_Album = 1; } else { $Checked_Album = 0; } return 1; } sub Entry_Grouping { my $arg = shift; #print "Grouping input: $arg\n"; if ($arg ne $Old_Grouping) { $Checked_Grouping = 1; } else { $Checked_Grouping = 0; } return 1; } sub Entry_Composer { my $arg = shift; #print "Composer input: $arg\n"; if ($arg ne $Old_Composer) { $Checked_Composer = 1; } else { $Checked_Composer = 0; } return 1; } sub Entry_Genre { my $arg = shift; #print "Genre input: $arg\n"; if ($arg ne $Old_Genre) { $Checked_Genre = 1; } else { $Checked_Genre = 0; } return 1; } sub Entry_Category { my $arg = shift; #print "Category input: $arg\n"; if ($arg ne $Old_Category) { $Checked_Category = 1; } else { $Checked_Category = 0; } return 1; } sub Entry_Year { my $arg = shift; #print "Year input: $arg\n"; return 0 if ($arg !~ /^\d+$/ && ($arg ne "")); if ($arg ne $Old_Year) { $Checked_Year = 1; } else { $Checked_Year = 0; } return 1; } sub Entry_Track_Number { my $arg = shift; #print "Track_Number input: $arg\n"; return 0 if ($arg !~ /^\d+$/ && ($arg ne "")); if ($arg ne $Old_Track_Number) { $Checked_Track_Number = 1; } else { $Checked_Track_Number = 0; } return 1; } sub Entry_Disc_Number { my $arg = shift; #print "Disc_Number input: $arg\n"; return 0 if ($arg !~ /^\d+$/ && ($arg ne "")); if ($arg ne $Old_Disc_Number) { $Checked_Disc_Number = 1; } else { $Checked_Disc_Number = 0; } return 1; } sub Entry_BPM { my $arg = shift; return 0 if ($arg !~ /^\d+$/ && ($arg ne "")); #print "BPM input: $arg\n"; if ($arg ne $Old_BPM) { $Checked_BPM = 1; } else { $Checked_BPM = 0; } return 1; } sub Entry_Track_Count { my $arg = shift; #print "Track_Count input: $arg\n"; return 0 if ($arg !~ /^\d+$/ && ($arg ne "")); if ($arg ne $Old_Track_Count) { $Checked_Track_Count = 1; } else { $Checked_Track_Count = 0; } return 1; } sub Entry_Disc_Count { my $arg = shift; #print "Disc_Count input: $arg\n"; return 0 if ($arg !~ /^\d+$/ && ($arg ne "")); if ($arg ne $Old_Disc_Count) { $Checked_Disc_Count = 1; } else { $Checked_Disc_Count = 0; } return 1; } # sub Entry_Validate { # #no strict 'refs'; # my ($type, $arg) = (shift, shift); # print "Validate arg: $arg -- type: $type\n"; # my $old = "\$Old_" . $type; print "old is $old\n"; # $old =~ s{ # \$ # find a literal dollar sign # (\w+) # find a "word" and store it in $1 # }{ # no strict 'refs'; # for $$1 below # if (defined ${$1}) { # ${$1}; # expand global variables only # } else { # print "[NO VARIABLE: \$$1]\n" # error msg # } # }egx; # print "oldvalue is $old\n"; # my $checked = "\$Checked_" . $type; # $checked =~ s{ # \$ # find a literal dollar sign # (\w+) # find a "word" and store it in $1 # }{ # no strict 'refs'; # for $$1 below # if (defined ${$1}) { # ${$1}; # expand global variables only # } else { # print "[NO VARIABLE: \$$1]\n" # error msg # } # }egx; # # if ($arg ne $old) { # print "$type changed\n"; # $checked = 1; # } else { # print "$type back to ORIG\n"; # $checked = 0; # } # return 1; # }