~ubuntu-branches/ubuntu/karmic/hipo/karmic

« back to all changes in this revision

Viewing changes to taglib-sharp/TagLib/Ogg/Vorbis/File.cs

  • Committer: Bazaar Package Importer
  • Author(s): Arthur Loiret
  • Date: 2007-09-30 21:51:29 UTC
  • mto: (2.1.1 lenny)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20070930215129-aphjk24c8h30r9d1
Tags: upstream-0.5
ImportĀ upstreamĀ versionĀ 0.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
    copyright            : (C) 2005 by Brian Nickel
3
 
    email                : brian.nickel@gmail.com
4
 
    based on             : oggfile.cpp from TagLib
5
 
 ***************************************************************************/
6
 
 
7
 
/***************************************************************************
8
 
 *   This library is free software; you can redistribute it and/or modify  *
9
 
 *   it  under the terms of the GNU Lesser General Public License version  *
10
 
 *   2.1 as published by the Free Software Foundation.                     *
11
 
 *                                                                         *
12
 
 *   This library is distributed in the hope that it will be useful, but   *
13
 
 *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
14
 
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
15
 
 *   Lesser General Public License for more details.                       *
16
 
 *                                                                         *
17
 
 *   You should have received a copy of the GNU Lesser General Public      *
18
 
 *   License along with this library; if not, write to the Free Software   *
19
 
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
20
 
 *   USA                                                                   *
21
 
 ***************************************************************************/
22
 
 
23
 
using System.Collections;
24
 
using System;
25
 
 
26
 
namespace TagLib.Ogg.Vorbis
27
 
{
28
 
   [SupportedMimeType("taglib/ogg", "ogg")]
29
 
   [SupportedMimeType("application/ogg")]
30
 
   [SupportedMimeType("application/x-ogg")]
31
 
   [SupportedMimeType("audio/vorbis")]
32
 
   [SupportedMimeType("audio/x-vorbis")]
33
 
   [SupportedMimeType("audio/x-vorbis+ogg")]
34
 
   [SupportedMimeType("audio/ogg")]
35
 
   [SupportedMimeType("audio/x-ogg")]
36
 
   public class File : Ogg.File
37
 
   {
38
 
      //////////////////////////////////////////////////////////////////////////
39
 
      // private properties
40
 
      //////////////////////////////////////////////////////////////////////////
41
 
      private Ogg.XiphComment comment;
42
 
      private Properties      properties;
43
 
      
44
 
      private static byte [] vorbis_comment_header_id = {0x03, (byte)'v', (byte)'o', (byte)'r', (byte)'b', (byte)'i', (byte)'s'};
45
 
      
46
 
      
47
 
      //////////////////////////////////////////////////////////////////////////
48
 
      // public methods
49
 
      //////////////////////////////////////////////////////////////////////////
50
 
      public File (string file, Properties.ReadStyle properties_style) : base (file)
51
 
      {
52
 
         comment = null;
53
 
         properties = null;
54
 
         
55
 
         try {Mode = AccessMode.Read;}
56
 
         catch {return;}
57
 
         
58
 
         Read (properties_style);
59
 
         
60
 
         Mode = AccessMode.Closed;
61
 
      }
62
 
      
63
 
      public File (string file) : this (file, Properties.ReadStyle.Average)
64
 
      {
65
 
      }
66
 
      
67
 
      public override void Save ()
68
 
      {
69
 
         ClearPageData (); // Force re-reading of the file.
70
 
 
71
 
         ByteVector v = vorbis_comment_header_id;
72
 
 
73
 
         GetTag (TagTypes.Xiph, true);
74
 
            
75
 
         v.Add (comment.Render ());
76
 
 
77
 
         SetPacket (1, v);
78
 
 
79
 
         base.Save ();
80
 
      }
81
 
      
82
 
      public override TagLib.Tag GetTag (TagTypes type, bool create)
83
 
      {
84
 
         if (type == TagTypes.Xiph)
85
 
         {
86
 
            if (comment == null && create)
87
 
               comment = new Ogg.XiphComment ();
88
 
            
89
 
            return comment;
90
 
         }
91
 
         
92
 
         return null;
93
 
      }
94
 
      
95
 
      
96
 
      //////////////////////////////////////////////////////////////////////////
97
 
      // public properties
98
 
      //////////////////////////////////////////////////////////////////////////
99
 
      public override Tag Tag {get {return GetTag (TagTypes.Xiph, true);}}
100
 
      
101
 
      public override AudioProperties AudioProperties {get {return properties;}}      
102
 
      
103
 
      //////////////////////////////////////////////////////////////////////////
104
 
      // private methods
105
 
      //////////////////////////////////////////////////////////////////////////
106
 
      private void Read (Properties.ReadStyle properties_style)
107
 
      {
108
 
         ByteVector comment_header_data = GetPacket (1);
109
 
 
110
 
         if (comment_header_data.Mid (0, 7) != vorbis_comment_header_id)
111
 
            throw new CorruptFileException ("Could not find the Vorbis Comment header.");
112
 
 
113
 
         comment = new Ogg.XiphComment (comment_header_data.Mid (7));
114
 
 
115
 
         if(properties_style != Properties.ReadStyle.None)
116
 
            properties = new Properties (this, properties_style);
117
 
      }
118
 
   }
119
 
}