Ignore:
Timestamp:
10/11/06 00:55:36 (6 years ago)
Author:
sys
Message:

ModelingSound...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Jav_Audio/com/scenari/s/audio/Util.java

    r6850 r6853  
    55import java.util.StringTokenizer; 
    66 
     7import org.w3c.dom.Element; 
     8import org.w3c.dom.Node; 
     9 
    710public 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 
    918        /** 
    10          * Parsing d'un timeCode. 
    11          * TODO Format à décider. 
     19         * Mode d'une track : contigue : une seule source, mais segments 
     20         * discontinus. 
    1221         */ 
    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) { 
    1434                try { 
    1535                        return Float.parseFloat(pTc); 
    16                 }catch (NumberFormatException e) { 
     36                } catch (NumberFormatException e) { 
    1737                        return pDefault; 
    1838                } 
    1939        } 
    20          
     40 
    2141        /** 
    2242         * Parsing d'un float (volume). 
    2343         */ 
    24         public static float parseFloat(String pFloat, float pDefault){ 
     44        public static float parseFloat(String pFloat, float pDefault) { 
    2545                try { 
    2646                        return Float.parseFloat(pFloat); 
    27                 }catch (NumberFormatException e) { 
     47                } catch (NumberFormatException e) { 
    2848                        return pDefault; 
    2949                } 
    3050        } 
     51 
    3152        /** 
    3253         * Sérialize d'un timeCode. 
    3354         */ 
    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"; 
    3657                return Float.toString(pTc); 
    3758        } 
    38          
     59 
    3960        /** 
    4061         * Parsing d'un float (volume). 
    4162         */ 
    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"; 
    4566                return Float.toString(pFloat); 
    4667        } 
    47          
    4868 
    4969        /** 
    50          * Gestion des listes de codes de tracks 
    51          * Construit un tableau. 
     70         * Gestion des listes de codes de tracks Construit un tableau. 
    5271         */ 
    5372        public static List split(String pVal) { 
     
    6887 
    6988        /** 
    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. 
    7290         */ 
    7391        public static List intersect(List p1, List p2) { 
     
    83101 
    84102        /** 
    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. 
    87106         */ 
    88107        public static String joinMap(List pList, List pKeys, List pValues) { 
     
    98117                return vBuf.toString(); 
    99118        } 
     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        } 
    100173} 
Note: See TracChangeset for help on using the changeset viewer.