Changeset 6853 for trunk/Jav_Audio/com/scenari/s/audio/Util.java
- Timestamp:
- 10/11/06 00:55:36 (6 years ago)
- File:
-
- 1 edited
-
trunk/Jav_Audio/com/scenari/s/audio/Util.java (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Jav_Audio/com/scenari/s/audio/Util.java
r6850 r6853 5 5 import java.util.StringTokenizer; 6 6 7 import org.w3c.dom.Element; 8 import org.w3c.dom.Node; 9 7 10 public class Util { 8 11 12 /** Mode d'une track : track vide (aucun segment). */ 13 public static final String TRACKMODE_EMPTY = "empty"; 14 15 /** Mode d'une track : contigue : une seule source, segments adjacents. */ 16 public static final String TRACKMODE_CONTIGUOUS = "contiguous"; 17 9 18 /** 10 * Parsing d'un timeCode.11 * TODO Format à décider.19 * Mode d'une track : contigue : une seule source, mais segments 20 * discontinus. 12 21 */ 13 public static float parseTc(String pTc, float pDefault){ 22 public static final String TRACKMODE_DISCONTINUOUS = "discontinuous"; 23 24 /** Mode d'une track : assemblage de différentes sources. */ 25 public static final String TRACKMODE_ASSEMB = "assemb"; 26 27 /** Mode d'une track : track d'auto-segmentation. */ 28 public static final String TRACKMODE_SELFSEG = "selfSeg"; 29 30 /** 31 * Parsing d'un timeCode. TODO Format à décider. 32 */ 33 public static float parseTc(String pTc, float pDefault) { 14 34 try { 15 35 return Float.parseFloat(pTc); 16 } catch (NumberFormatException e) {36 } catch (NumberFormatException e) { 17 37 return pDefault; 18 38 } 19 39 } 20 40 21 41 /** 22 42 * Parsing d'un float (volume). 23 43 */ 24 public static float parseFloat(String pFloat, float pDefault) {44 public static float parseFloat(String pFloat, float pDefault) { 25 45 try { 26 46 return Float.parseFloat(pFloat); 27 } catch (NumberFormatException e) {47 } catch (NumberFormatException e) { 28 48 return pDefault; 29 49 } 30 50 } 51 31 52 /** 32 53 * Sérialize d'un timeCode. 33 54 */ 34 public static String serializeTc(float pTc) {35 if (pTc == 0) return "0";55 public static String serializeTc(float pTc) { 56 if (pTc == 0) return "0"; 36 57 return Float.toString(pTc); 37 58 } 38 59 39 60 /** 40 61 * Parsing d'un float (volume). 41 62 */ 42 public static String serializeFloat(float pFloat) {43 if (pFloat == 0) return "0";44 if (pFloat == 1) return "1";63 public static String serializeFloat(float pFloat) { 64 if (pFloat == 0) return "0"; 65 if (pFloat == 1) return "1"; 45 66 return Float.toString(pFloat); 46 67 } 47 48 68 49 69 /** 50 * Gestion des listes de codes de tracks 51 * Construit un tableau. 70 * Gestion des listes de codes de tracks Construit un tableau. 52 71 */ 53 72 public static List split(String pVal) { … … 68 87 69 88 /** 70 * Gestion des listes de codes de tracks 71 * intersection de 2 listes de tracks. 89 * Gestion des listes de codes de tracks intersection de 2 listes de tracks. 72 90 */ 73 91 public static List intersect(List p1, List p2) { … … 83 101 84 102 /** 85 * Gestion des listes de codes de tracks : 86 * reconstruit une sous-liste de pValues en fonction des entrées dans pList correspondant aux keys de pKeys. 103 * Gestion des listes de codes de tracks : reconstruit une sous-liste de 104 * pValues en fonction des entrées dans pList correspondant aux keys de 105 * pKeys. 87 106 */ 88 107 public static String joinMap(List pList, List pKeys, List pValues) { … … 98 117 return vBuf.toString(); 99 118 } 119 120 public static String getTrackMode(Node pNode) { 121 String vPreviousUri = null; 122 String vPreviousEnd = null; 123 boolean vIsEmpty = true; 124 boolean vIsSameSrc = true; 125 boolean vIsContiguous = true; 126 for (Node vNode = pNode; vNode != null; vNode = vNode.getNextSibling()) { 127 if (vNode.getNodeName().equals("selfSeg")) { 128 return TRACKMODE_SELFSEG; 129 } else if (vNode.getNodeName().equals("seg")) { 130 if (vPreviousUri != null) { 131 if (vIsSameSrc) { 132 String vUri = ((Element) vNode).getAttribute("refUri"); 133 if (vUri != null && vUri.length() > 0) { 134 if (!vUri.equals(vPreviousUri)) { 135 vIsSameSrc = false; 136 continue; 137 } 138 if (vIsContiguous) { 139 String vStart = ((Element) vNode).getAttribute("start"); 140 if (vPreviousEnd == null || vStart == null || !vPreviousEnd.equals(vStart)) vIsContiguous = false; 141 vPreviousEnd = ((Element) vNode).getAttribute("end"); 142 } 143 } 144 } 145 } else { 146 // 1er segment 147 if (vIsEmpty) vIsEmpty = false; 148 vPreviousUri = ((Element) vNode).getAttribute("refUri"); 149 String vStart = ((Element) vNode).getAttribute("start"); 150 if (parseTc(vStart, 0) != 0) vIsContiguous = false; 151 vPreviousEnd = ((Element) vNode).getAttribute("end"); 152 } 153 } 154 } 155 if (vIsEmpty) return TRACKMODE_EMPTY; 156 if (!vIsSameSrc) return TRACKMODE_ASSEMB; 157 return vIsContiguous ? TRACKMODE_CONTIGUOUS : TRACKMODE_DISCONTINUOUS; 158 } 159 160 /** 161 * Pour les tracks de type TRACKMODE_DISCONTINUOUS ou TRACKMODE_CONTIGUOUS, 162 * retourne la source unique. 163 */ 164 public static String getTrackRefUri(Node pNode) { 165 for (Node vNode = pNode; vNode != null; vNode = vNode.getNextSibling()) { 166 if (vNode.getNodeName().equals("seg")) { 167 String vUri = ((Element) vNode).getAttribute("refUri"); 168 if (vUri != null && vUri.length() > 0) return vUri; 169 } 170 } 171 return ""; 172 } 100 173 }
Note: See TracChangeset
for help on using the changeset viewer.