Jump to content

cbox


Recommended Posts

Posted (edited)

I have one section of my program for renaming music files I got one part with text boxs for renaming artist, song, track #, album and it works but I want to do a auto rename where when the person opens the file and if they click a button called auto rename it will look in the music file\'s properties and find artist etc.

 

Ordering them too like Artist - Album - Track # - Song.format

 

Here's a photo of the renaming section there\'s a lot of bugs I guess I found but since I\'m not pro I will find someone who is willing to fix them for me.

http://img23.imageshack.us/img23/9711/deviantmanager.th.jpg

Edited by ColinMc
Posted
So you want to auto-populate the tags from online? I have no clue.

 

 

Or you want to sort them based on those tags? I can do that.

 

I sorta don't know what you mean but like the tags for like artist,album,track number, and song I want to press a button to open the music file which I got and another file that will take those tags from the music file itself not online just from the music file and rename the file with those tags and in the order in my earlier post. Thank you for replying I've been waiting for a response.

Posted

So you want to be-able to rename the (artist name, song name) of a song you opened in some language I've yet to find out lol.

 

I think those are called the ID3 tags of the song (or if older the ID2 titles)

 

fileNamepath to the MP3 filearrayVarNamename of the array variable to be used as container for the MP3 information, will be erased before filleddebugFlagboolean - true if information about the first 2 frame headers shouldn't be deleted and be returned

 namespace eval ::mp3InfoReader {
variable bitRateTable;
variable sampleRateTable;
variable channelModeTable;

array set bitRateTable {
   0.1.0	  0   0.1.1	  8   0.1.2	 16   0.1.3	 24
   0.1.4	 32   0.1.5	 40   0.1.6	 48   0.1.7	 56
   0.1.8	 64   0.1.9	 80   0.1.10	96   0.1.11   112
   0.1.12   128   0.1.13   144   0.1.14   160   0.1.15	-1
   0.3.0	  0   0.3.1	 32   0.3.2	 48   0.3.3	 56
   0.3.4	 64   0.3.5	 80   0.3.6	 96   0.3.7	112
   0.3.8	128   0.3.9	144   0.3.10   160   0.3.11   176
   0.3.12   192   0.3.13   224   0.3.14   256   0.3.15	-1
   3.1.0	  0   3.1.1	 32   3.1.2	 40   3.1.3	 48
   3.1.4	 56   3.1.5	 64   3.1.6	 80   3.1.7	 96
   3.1.8	112   3.1.9	128   3.1.10   160   3.1.11   192
   3.1.12   224   3.1.13   256   3.1.14   320   3.1.15	-1
   3.2.0	  0   3.2.1	 32   3.2.2	 48   3.2.3	 56
   3.2.4	 64   3.2.5	 80   3.2.6	 96   3.2.7	112
   3.2.8	128   3.2.9	160   3.2.10   192   3.2.11   224
   3.2.12   256   3.2.13   320   3.2.14   384   3.2.15	-1
   3.3.0	  0   3.3.1	 32   3.3.2	 64   3.3.3	 96
   3.3.4	128   3.3.5	160   3.3.6	192   3.3.7	224
   3.3.8	256   3.3.9	288   3.3.10   320   3.3.11   352
   3.3.12   384   3.3.13   416   3.3.14   448   3.3.15	-1
   0.2.10	-1   0.2.12	-1   0.2.7	 -1   0.2.0	 -1
   0.2.4	 -1   0.2.8	 -1   0.2.6	 -1   0.2.3	 -1
   0.2.14	-1   0.2.5	 -1   0.2.2	 -1
}

array set sampleRateTable {
   0.0   11025   0.1   12000   0.2	8000
   2.0   22050   2.1   24000   2.2   16000
   3.0   44100   3.1   48000   3.2   32000
}

array set channelModeTable {
   3.0   {4 31}   3.1   {8 31}				 3.2   {12 31}		 3.3   {16 31}
   1.0   {}	   1.1   {"intensity stereo"}   1.2   {"ms stereo"}   1.3   {"intensity stereo" "ms stereo"}
};

proc readI4 {fileId} {
   if {[binary scan [read $fileId 4] I I4] != 1} {
	  error "couldn't read a 4byte bit-endian integer value from \"$fileId\"";
   }

   return $I4
}

variable genres {
	Blues				   {Classic Rock}		  Country				 Dance
	Disco				   Funk					Grunge				  Hip-Hop
	Jazz					Metal				   {New Age}			   Oldies
	Other				   Pop					 R&B					 Rap
	Reggae				  Rock					Techno				  Industrial
	Alternative			 Ska					 {Death Metal}		   Pranks
	Soundtrack			  Euro-Techno			 Ambient				 Trip-Hop
	Vocal				   Jazz+Funk			   Fusion				  Trance
	Classical			   Instrumental			Acid					House
	Game					{Sound Clip}			Gospel				  Noise
	AlternRock			  Bass					Soul					Punk
	Space				   Meditative			  {Instrumental Pop}	  {Instrumental Rock}
	Ethnic				  Gothic				  Darkwave				Techno-Industrial
	Electronic			  Pop-Folk				Eurodance			   Dream
	{Southern Rock} Comedy				  Cult					Gangsta
	{Top 40}				{Christian Rap}		 Pop/Funk				Jungle
	{Native American}	   Cabaret				 {New Wave}			  Psychadelic
	Rave					Showtunes			   Trailer				 Lo-Fi
	Tribal				  {Acid Punk}			 {Acid Jazz}			 Polka
	Retro				   Musical				 {Rock & Roll}		   {Hard Rock}
	Folk					Folk-Rock			   {National Folk}		 Swing
	{Fast Fusion}		   Bebob				   Latin				   Revival
	Celtic				  Bluegrass			   Avantgarde			  {Gothic Rock}
	{Progressive Rock}	  {Psychedelic Rock}	  {Symphonic Rock}		{Slow Rock}
	{Big Band}			  Chorus				  {Easy Listening}		Acoustic
	Humour				  Speech				  Chanson				 Opera
	{Chamber Music} Sonata				  Symphony				{Booty Brass}
	Primus				  {Porn Groove}		   Satire				  {Slow Jam}
	Club					Tango				   Samba				   Folklore
	Ballad				  {Power Ballad}		  {Rhytmic Soul}		  Freestyle
	Duet					{Punk Rock}			 {Drum Solo}			 {A Capela}
	Euro-House			  {Dance Hall}
}

proc mpegBin {byte2} {
   return [expr {($byte2 >> 3) & 0x3}];
}

proc mpeg {byte2} {
   switch -exact -- [mpegBin $byte2] {
	  0 {return 2.5;}
	  2 {return 2;}
	  3 {return 1;}
   }

   return 0;
}

proc layerBin {byte2} {
   return [expr {($byte2 >> 1) & 0x3}];
}

proc layer {byte2} {
   set layer [expr {4 - [layerBin $byte2]}];

   if {$layer > 3} {
	  return 0;
   }

   return $layer
}

proc protection {byte2} {
   return [expr {($byte2 & 0x1) == 0}];
}

proc bitRateBin {byte3} {
   return [expr {($byte3 >> 4) & 0xF}];
}

proc bitRate {byte2 byte3} {
   if {[set bitRateIdx [bitRateBin $byte3]] == 0xF} {
	  return -1;
   }

   if {[set layerIdx [layerBin $byte2]] == 0} {
	  return -1;
   }

   if {[set mpegIdx [mpegBin $byte2]] == -1} {
	  return -1;
   } elseif {$mpegIdx == 2} {
	  if {$layerIdx == 2} {
		 set layerIdx 1;
	  }

	  set mpegIdx 0;
   }

   variable bitRateTable;

   return $bitRateTable($mpegIdx.$layerIdx.$bitRateIdx);
}

proc sampleRateBin {byte3} {
   return [expr {($byte3 >> 2) & 0x3}];
}

proc sampleRate {byte2 byte3} {
   if {[set sampleRateIdx [sampleRateBin $byte3]] == 0x3} {
	  return 0;
   }

   if {[set mpegIdx [mpegBin $byte2]] == 1} {
	  return 0;
   }

   variable sampleRateTable;

   return $sampleRateTable($mpegIdx.$sampleRateIdx);
}

proc private {byte3} {
   return [expr {($byte3 & 0x1) == 1}];
}

proc padding {byte3} {
   return [expr {(($byte3 >> 1) & 0x1) == 1}];
}

proc channelModeBin {byte4} {
   return [expr {($byte4 >> 6) & 0x3}];
}

proc channelMode {byte2 byte4} {
   switch -exact -- [channelModeBin $byte4] {
	  3 {return "single";}
	  2 {return "dual";}
	  0 {return "stereo";}
   }

   if {[set layerIdx [layerBin $byte2]] == 0} {
	  return "joint";
   } elseif {$layerIdx == 2} {
	  set layerIdx 3;
   }

   variable channelModeTable;

   return [list "joint" $channelModeTable($layerIdx.[expr {($byte4 >> 4) & 0x3}])];
}

proc copyright {byte4} {
   return [expr {(($byte4 >> 3) & 0x1) == 1}];
}

proc original {byte4} {
   return [expr {(($byte4 >> 2) & 0x1) == 1}];
}

proc emphasisBin {byte4} {
   return [expr {$byte4 & 0x3}];
}

proc emphasisDesc {byte4} {
   switch -exact -- [emphasisBin $byte4] {
	  3 {return "CCIT J.17";}
	  2 {return "reserved";}
	  1 {return "50/15 ms";}
   }

   return "none";
}

proc frameLength {byte1 byte2 byte3} {
   set mpeg	   [mpegBin $byte2];
   set layer	  [layerBin $byte2];
   set protection [protection $byte2];
   set padding	[padding $byte3];

   set bitRate	[bitRate $byte2 $byte3];
   set sampleRate [sampleRate $byte2 $byte3];

   if {!$bitRate} {
	  # (Free bit rate) This will move the scanner one step forward
	  #
	  set frameLength 1;
   } else {
	  if {$layer == 3} {
		 set frameLength [expr {(12 * $bitRate * 1000 / $sampleRate) + (4 * $padding) + (2 * $protection)}]
	  } else {
		 set frameLength [expr {(144 * $bitRate * 1000 / $sampleRate) + $padding + (2 * $protection)}]
	  }
   }

   return $frameLength;
}

proc isValidFrameHeader {byte1 byte2 byte3 byte4} {
   # 1. MPEG version not unknown
   # 2. layer not reserved
   # 2. sample rate index, 3 not allowed
   # 3. bitrate, 15 not allowed
   #
   if {([mpegBin $byte2]	   != 0x1) &&
	   ([layer $byte2]		 != 0x0) &&
	   ((($byte3 >> 2) & 0x3)  != 0x3) &&
	   ((($byte3 >> 4) & 0xF)  != 0xf)} {
	  return 1;
   }

   return 0;
}

proc mp3InfoReader {fileName arrayVar {debug 0}} {
   upvar $arrayVar info;
   variable genres; #PWQ 26 Nov 04
   catch {unset info;};

   if {[catch {set fd [open $fileName r];} reason]} {
	  error $reason $::errorInfo $::errorCode;
   }

   fconfigure $fd -encoding binary -translation binary -buffering full -buffersize 1000000;

   set idx		  1;
   set result	  "";

   while {![eof $fd]} {
	  # read until frame header is complete and valid
	  #
	  while {![eof $fd]} {
		 scan [read $fd 1] %c byte1;

		 if {($byte1 & 0xFF) == 0xFF} {
			scan [read $fd 1] %c byte2;

			if {($byte2 & 0xE0) == 0xE0} {
			   scan [read $fd 2] %c%c byte3 byte4;

			   if {[isValidFrameHeader $byte1 $byte2 $byte3 $byte4]} {
				  break;
			   }
			}
		 }
	  }

	  # recognize all (normally) frame independent header data
	  #
	  set info($idx.mpeg)		[mpeg $byte2];
	  set info($idx.layer)	   [layer $byte2];
	  set info($idx.protection)  [protection $byte2];
	  set info($idx.sampleRate)  [sampleRate $byte2 $byte3];
	  set info($idx.bitRate)	 [bitRate $byte2 $byte3];
	  set info($idx.private)	 [private $byte3];
	  set info($idx.channelMode) [channelMode $byte2 $byte4];
	  set info($idx.copyright)   [copyright $byte4];
	  set info($idx.original)	[original $byte4];
	  set info($idx.emphasis)	[emphasisDesc $byte4];
	  set info($idx.padding)	 [padding $byte3];

	  if {$info($idx.layer) == 1} {
		 set info($idx.samplesPerFrame) 384;
	  } else {
		 set info($idx.samplesPerFrame) 1152;
	  }

	  if {$idx == 1} {
		 # looking for a Xing VBR header (variable bitrate)
		 #
		 set info(vbr)   0;

		 if {$info($idx.mpeg) == 1} {
			set xingHeaderStart [expr {$info($idx.channelMode) != "single" ? 32 : 17}];
		 } else {
			set xingHeaderStart [expr {$info($idx.channelMode) != "single" ? 17 : 9}];
		 }

		 seek $fd $xingHeaderStart current;

		 if {[read $fd 4] == "Xing"} {
			# found a Xing VBR header - looking for the average bit rate
			#
			set info(vbr) 1;
			set xingFrames 0;
			set xingBytes  0;

			if {[set xingHeadFlags [readI4 $fd]] & 0x0001} {
			   set xingFrames [readI4 $fd];
			}

			if {$xingHeadFlags & 0x0002} {
			   set xingBytes  [readI4 $fd];
			}

			if {($xingFrames > 0) &&
				($xingBytes  > 0) &&
				($xingHeadFlags & (0x0002 | 0x0001))} {
			   set info(bitRate)   [expr {(($xingBytes / $xingFrames) * $info($idx.sampleRate)) / ($info($idx.mpeg) == 1 ? 144000 : 72000)}];
			}
		 } else {
			# first recognized bit rate is assumed to be the global one
			#
			set info(bitRate)	  $info($idx.bitRate);
			set info(bitRate.calc) 0;
		 }
	  } elseif {!$info(vbr) && (!$info($idx.bitRate) || ($info(bitRate) != $info($idx.bitRate)))} {
		 # another bit rate is not identical to the global (first) one
		 # => calculate bit rate later on!
		 #
		 set info(bitRate.calc) 1;
		 set info(bitRate.list) [list $info(bitRate) $info($idx.bitRate)];
	  }

	  # jump over audio data, if frame length calculated
	  #
	  seek $fd [frameLength $byte1 $byte2 $byte3] current;

	  if {$idx == 2} {
		 break;
	  }

	  incr idx;
   }

	# Now reread the last 128 bytes to decode the MP3 Tag
	if {[catch {seek $fd -128 end}]} {
		set tag ""
	} else {
		set tag [read $fd]
	}
  close $fd;

   # setting or calculating the bit rate
   #
   if {!$info(vbr)} {
	  if {$info(bitRate.calc)} {
		 # calculating the mean bit rate
		 #
		 set result		"warning: variable bit rate - published approximated duration and average bit rate!";
		 set info(bitRate) 0;

		 foreach value [set info(bitRate.list) [lsort -unique $info(bitRate.list)]] {
			incr info(bitRate) $value;
		 }

		 set info(bitRate) [expr {int($info(bitRate) / double($idx))}];
	  }
   }

   # calculating the durating using the bit rate and the file size
   #
   set info(duration) [expr {int([file size $fileName]*8 / double(1000*$info(bitRate)))}];

   # copy all frame independent data into the return array
   #
   foreach {name value} [array get info 1.*] {
	  set name   [join [lrange [split $name "."] 1 end] "."];

	  if {[string match "bitRate*" $name] ||
		  ($name == "crc")				||
		  ($name == "duration")		   ||
		  ($name == "frameLength")		||
		  ($name == "padding")			||
		  ($name == "protection")} {
		 continue;
	  }

	  set info($name) $value;
   }

   if {!$debug} {
	  array unset info {[0-9]*};
   }

	binary scan $tag A3 id
	if {[string equal $id TAG]} {
		set info(hastag) 1
		set info(genre) 12
		binary scan $tag a3a30a30a30a4a28ccc id info(title) info(artist) info(album) info(year) info(comment) zero info(track) info(genreid)
	} else {
		array set info {
			hastag 0
			title ""
			artist ""
			album ""
			year ""
			comment ""
			track 0
			genreid -1
		}
	}
	set info(genre) [lindex $genres $info(genreid)]

   return $result;
}

namespace export -clear mp3InfoReader;
}

 

 

Heres something I got off google.

Posted

I honestly don't know what you want, but since you said that you are a newbie at programming, how about you go here and look at Visual Basic section and try to learn about it from there.

 

I really don't understand your question.

Posted
I honestly don't know what you want, but since you said that you are a newbie at programming, how about you go here and look at Visual Basic section and try to learn about it from there.

 

I really don't understand your question.

 

my question is I want to make a file renamer where I click a button to open the file dialog choose the file and it renames it by the info in the properties like artist, year, album, comment that section but in this order Artist - Album - Track # - Song.format

 

I'm using Visual basic 2008 not C# just to make that clear.

Posted (edited)
I couldn't' find anything for vb.net for reading ID3 tags or setting them. Sorry.

 

thanks for your help anyways I appreciate it.

 

I tried putting the C# code in a convertor to visual basic but it said it was missing } at line 2 column 1. or something like that.

Edited by ColinMc
Posted
thanks for your help anyways I appreciate it.

 

I tried putting the C# code in a convertor to visual basic but it said it was missing } at line 2 column 1. or something like that.

 

That code was too easy to understand, Pretty much there nothing but Arrays of string[] and Peaches put everything inside of them.

  • 1 month later...
Posted

I didn't write that, just in case that comes back to bite me.

 

Got it off google.

 

ok I'm still working on this but I just started using C# today and I already made everything except for the auto rename button IBotPeaches can you link me to where you got that if you remember?

Posted

class MusicID3Tag

{

   public byte[] TAGID = new byte[3];      //  3
   public byte[] Title = new byte[30];     //  30
   public byte[] Artist = new byte[30];    //  30 
   public byte[] Album = new byte[30];     //  30 
   public byte[] Year = new byte[4];       //  4 
   public byte[] Comment = new byte[30];   //  30 
   public byte[] Genre = new byte[1];      //  1

}

string filePath = @"C:\Documents and Settings\All Users\Documents\My Music\Sample Music\041105.mp3";

       using (FileStream fs = File.OpenRead(filePath))
       {
           if (fs.Length >= 128)
           {
               MusicID3Tag tag = new MusicID3Tag();
               fs.Seek(-128, SeekOrigin.End);
               fs.Read(tag.TAGID, 0, tag.TAGID.Length);
               fs.Read(tag.Title, 0, tag.Title.Length);
               fs.Read(tag.Artist, 0, tag.Artist.Length);
               fs.Read(tag.Album, 0, tag.Album.Length);
               fs.Read(tag.Year, 0, tag.Year.Length);
               fs.Read(tag.Comment, 0, tag.Comment.Length);
               fs.Read(tag.Genre, 0, tag.Genre.Length);
               string theTAGID = Encoding.Default.GetString(tag.TAGID);

               if (theTAGID.Equals("TAG"))
               {
                   string Title = Encoding.Default.GetString(tag.Title);
                   string Artist = Encoding.Default.GetString(tag.Artist);
                   string Album = Encoding.Default.GetString(tag.Album);
                   string Year = Encoding.Default.GetString(tag.Year);
                   string Comment = Encoding.Default.GetString(tag.Comment);
                   string Genre = Encoding.Default.GetString(tag.Genre);

                   Console.WriteLine(Title);
                   Console.WriteLine(Artist);
                   Console.WriteLine(Album);
                   Console.WriteLine(Year);
                   Console.WriteLine(Comment);
                   Console.WriteLine(Genre);
                   Console.WriteLine();
               }
           }
       }

 

 

This looks 10x easier in C#.

 

Found here: http://stackoverflow.com/questions/68283/view-edit-mp3-id3-data-in-c

Posted (edited)

Code Snippet
class MusicID3Tag

   {

       public byte[] TAGID = new byte[3];      //  3

       public byte[] Title = new byte[30];     //  30

       public byte[] Artist = new byte[30];    //  30  

       public byte[] Album = new byte[30];     //  30  

       public byte[] Year = new byte[4];       //  4  

       public byte[] Comment = new byte[30];   //  30  

       public byte[] Genre = new byte[1];      //  1 

   }


Code Snippet
string filePath = @"C:\Documents and Settings\All Users\Documents\My Music\Sample Music\041105.mp3";

           using (FileStream fs = File.OpenRead(filePath))

           {

               if (fs.Length >= 128)

               {

                   MusicID3Tag tag = new MusicID3Tag();

                   fs.Seek(-128, SeekOrigin.End);

                   fs.Read(tag.TAGID, 0, tag.TAGID.Length);

                   fs.Read(tag.Title, 0, tag.Title.Length);

                   fs.Read(tag.Artist, 0, tag.Artist.Length);

                   fs.Read(tag.Album, 0, tag.Album.Length);

                   fs.Read(tag.Year, 0, tag.Year.Length);

                   fs.Read(tag.Comment, 0, tag.Comment.Length);

                   fs.Read(tag.Genre, 0, tag.Genre.Length);

                   string theTAGID = Encoding.Default.GetString(tag.TAGID);

                   if (theTAGID.Equals("TAG"))

                   {

                       string Title = Encoding.Default.GetString(tag.Title);

                       string Artist = Encoding.Default.GetString(tag.Artist);

                       string Album = Encoding.Default.GetString(tag.Album);

                       string Year = Encoding.Default.GetString(tag.Year);

                       string Comment = Encoding.Default.GetString(tag.Comment);

                       string Genre = Encoding.Default.GetString(tag.Genre);



                       Console.WriteLine(Title);

                       Console.WriteLine(Artist);

                       Console.WriteLine(Album);

                       Console.WriteLine(Year);

                       Console.WriteLine(Comment);

                       Console.WriteLine(Genre);

                       Console.WriteLine();

                   }

               }

           }

I used this code instead that I found got it working for auto rename except when I click auto rename button and in the textboxs 3 out of the 4 show Artist,Album, and Song show but I added track to that same way of code and it doesn't show up or if I put it for byte one which I found was it's byte 1 or 0 it takes the first char of Album.

Edited by ColinMc
Posted
I got everything working with my code not the one I posted lol but for the track # when I click auto rename and the track textbox only has 1 digit and I want it to have two like 01 - 09 and so on. I tried "0" + MusicFile etc.. but when it came to a 10 in the music files header for the track number it would be 010 which I didn't want I just wanted it to have 01 - 09 without the user manually adding the zero.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...