2
* @author : Paul Taylor
5
* Version @version:$Id: FrameBodyTIPL.java,v 1.13 2009/11/12 13:25:22 paultaylor Exp $
7
* MusicTag Copyright (C)2003,2004
9
* This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser
10
* General Public License as published by the Free Software Foundation; either version 2.1 of the License,
11
* or (at your option) any later version.
13
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
14
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
* See the GNU Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public License along with this library; if not,
18
* you can get a copy from http://www.opensource.org/licenses/lgpl-license.php or write to the Free Software
19
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
package org.jaudiotagger.tag.id3.framebody;
27
import org.jaudiotagger.tag.InvalidTagException;
28
import org.jaudiotagger.tag.datatype.DataTypes;
29
import org.jaudiotagger.tag.datatype.PairedTextEncodedStringNullTerminated;
30
import org.jaudiotagger.tag.id3.ID3v24Frames;
32
import java.nio.ByteBuffer;
36
* The 'Involved people list' is intended as a mapping between functions like producer and names. Every odd field is a
37
* function and every even is an name or a comma delimited list of names.
39
* TODO currently just reads the first String when directly from file, this will be fixed when we add support for
40
* multiple Strings for all ID3v24Frames
42
* TODO currently just reads all the values when converted from the corresponding ID3v23 Frame IPLS as a single value
43
* (the individual fields from the IPLS frame will be seperated by commas)
45
public class FrameBodyTIPL extends AbstractFrameBodyTextInfo implements ID3v24FrameBody
48
* Creates a new FrameBodyTIPL datatype.
50
public FrameBodyTIPL()
54
public FrameBodyTIPL(FrameBodyTIPL body)
60
* Convert from V3 to V4 Frame
63
public FrameBodyTIPL(FrameBodyIPLS body)
65
setObjectValue(DataTypes.OBJ_TEXT_ENCODING, body.getTextEncoding());
67
PairedTextEncodedStringNullTerminated.ValuePairs value = (PairedTextEncodedStringNullTerminated.ValuePairs) body.getObjectValue(DataTypes.OBJ_TEXT);
68
setObjectValue(DataTypes.OBJ_TEXT, value.toString());
72
* Creates a new FrameBodyTIPL datatype.
77
public FrameBodyTIPL(byte textEncoding, String text)
79
super(textEncoding, text);
83
* Creates a new FrameBodyTIPL datatype.
87
* @throws InvalidTagException
89
public FrameBodyTIPL(ByteBuffer byteBuffer, int frameSize) throws InvalidTagException
91
super(byteBuffer, frameSize);
95
* The ID3v2 frame identifier
97
* @return the ID3v2 frame identifier for this frame type
99
public String getIdentifier()
101
return ID3v24Frames.FRAME_ID_INVOLVED_PEOPLE;
2
* @author : Paul Taylor
5
* Version @version:$Id: FrameBodyTIPL.java 929 2010-11-17 12:36:46Z paultaylor $
7
* MusicTag Copyright (C)2003,2004
9
* This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser
10
* General Public License as published by the Free Software Foundation; either version 2.1 of the License,
11
* or (at your option) any later version.
13
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
14
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
* See the GNU Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public License along with this library; if not,
18
* you can get a copy from http://www.opensource.org/licenses/lgpl-license.php or write to the Free Software
19
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
package org.jaudiotagger.tag.id3.framebody;
27
import org.jaudiotagger.tag.InvalidTagException;
28
import org.jaudiotagger.tag.datatype.DataTypes;
29
import org.jaudiotagger.tag.datatype.NumberHashMap;
30
import org.jaudiotagger.tag.datatype.Pair;
31
import org.jaudiotagger.tag.datatype.PairedTextEncodedStringNullTerminated;
32
import org.jaudiotagger.tag.id3.ID3v24Frames;
33
import org.jaudiotagger.tag.id3.valuepair.TextEncoding;
35
import java.io.ByteArrayOutputStream;
36
import java.nio.ByteBuffer;
38
import java.util.StringTokenizer;
42
* The 'Involved people list' is intended as a mapping between functions like producer and names. Every odd field is a
43
* function and every even is an name or a comma delimited list of names.
46
public class FrameBodyTIPL extends AbstractID3v2FrameBody implements ID3v24FrameBody
48
//Standard function names, taken from Picard Mapping
49
public static final String ENGINEER = "engineer";
50
public static final String MIXER = "mix";
51
public static final String DJMIXER = "DJ-mix";
52
public static final String PRODUCER = "producer";
53
public static final String ARRANGER = "arranger";
56
* Creates a new FrameBodyTIPL datatype.
58
public FrameBodyTIPL()
60
setObjectValue(DataTypes.OBJ_TEXT_ENCODING, TextEncoding.ISO_8859_1);
64
* Creates a new FrameBodyTIPL data type.
69
public FrameBodyTIPL(byte textEncoding, String text)
71
setObjectValue(DataTypes.OBJ_TEXT_ENCODING, textEncoding);
76
* Creates a new FrameBodyTIPL data type.
80
* @throws InvalidTagException
82
public FrameBodyTIPL(ByteBuffer byteBuffer, int frameSize) throws InvalidTagException
84
super(byteBuffer, frameSize);
88
* Convert from V3 to V4 Frame
92
public FrameBodyTIPL(FrameBodyIPLS body)
94
setObjectValue(DataTypes.OBJ_TEXT_ENCODING, body.getTextEncoding());
95
setObjectValue(DataTypes.OBJ_TEXT, body.getPairing());
99
* The ID3v2 frame identifier
101
* @return the ID3v2 frame identifier for this frame type
103
public String getIdentifier()
105
return ID3v24Frames.FRAME_ID_INVOLVED_PEOPLE;
109
* Set the text, decoded as pairs of involvee - involvment
113
public void setText(String text)
115
PairedTextEncodedStringNullTerminated.ValuePairs value = new PairedTextEncodedStringNullTerminated.ValuePairs();
116
StringTokenizer stz = new StringTokenizer(text, "\0");
118
while (stz.hasMoreTokens())
120
String key =stz.nextToken();
121
if(stz.hasMoreTokens())
123
value.add(key, stz.nextToken());
127
setObjectValue(DataTypes.OBJ_TEXT, value);
130
public void addPair(String text)
132
PairedTextEncodedStringNullTerminated.ValuePairs value = ((PairedTextEncodedStringNullTerminated) getObject(DataTypes.OBJ_TEXT)).getValue();
133
StringTokenizer stz = new StringTokenizer(text, "\0");
134
if (stz.hasMoreTokens())
136
value.add(stz.nextToken(),stz.nextToken());
141
* Because have a text encoding we need to check the data values do not contain characters that cannot be encoded in
142
* current encoding before we write data. If they do change the encoding.
144
public void write(ByteArrayOutputStream tagBuffer)
146
if (!((PairedTextEncodedStringNullTerminated) getObject(DataTypes.OBJ_TEXT)).canBeEncoded())
148
this.setTextEncoding(TextEncoding.UTF_16);
150
super.write(tagBuffer);
154
* Consists of a text encoding , and then a series of null terminated Strings, there should be an even number
155
* of Strings as they are paired as involvement/involvee
157
protected void setupObjectList()
159
objectList.add(new NumberHashMap(DataTypes.OBJ_TEXT_ENCODING, this, TextEncoding.TEXT_ENCODING_FIELD_SIZE));
160
objectList.add(new PairedTextEncodedStringNullTerminated(DataTypes.OBJ_TEXT, this));
163
public PairedTextEncodedStringNullTerminated.ValuePairs getPairing()
165
return (PairedTextEncodedStringNullTerminated.ValuePairs) getObject(DataTypes.OBJ_TEXT).getValue();
172
* @return value at index
174
public String getKeyAtIndex(int index)
176
PairedTextEncodedStringNullTerminated text = (PairedTextEncodedStringNullTerminated) getObject(DataTypes.OBJ_TEXT);
177
return (String) text.getValue().getMapping().get(index).getKey();
184
* @return value at index
186
public String getValueAtIndex(int index)
188
PairedTextEncodedStringNullTerminated text = (PairedTextEncodedStringNullTerminated) getObject(DataTypes.OBJ_TEXT);
189
return (String) text.getValue().getMapping().get(index).getValue();
193
* @return number of text pairs
195
public int getNumberOfPairs()
197
PairedTextEncodedStringNullTerminated text = (PairedTextEncodedStringNullTerminated) getObject(DataTypes.OBJ_TEXT);
198
return text.getValue().getNumberOfPairs();
201
public String getText()
203
PairedTextEncodedStringNullTerminated text = (PairedTextEncodedStringNullTerminated) getObject(DataTypes.OBJ_TEXT);
204
StringBuilder sb = new StringBuilder();
206
for (Pair entry : text.getValue().getMapping())
208
sb.append(entry.getKey() + '\0' + entry.getValue());
209
if (count != getNumberOfPairs())
215
return sb.toString();
218
public String getUserFriendlyValue()