差分発生行の前後
無視リスト:
更新日時:
2010/05/11 20:15:55 (2 年 前)
更新者:
h
ログメッセージ:

refs #2 #8 #9 #7 #6
現状のソースをコミット。一部完了。一部未完了。
関連づいてない完了チケットのチェンジセットもまとめて。
パッケージ階層も大幅に変更。

ファイル:
1 移動

凡例:

変更なし
追加
削除
  • trunk/src/org/rayflood/mikuvat/Utilities.java

    r2 r4  
    1 package org.rayflood.mikuvat.io; 
     1package org.rayflood.mikuvat; 
    22 
    3 import java.io.BufferedReader; 
    4 import java.io.StringReader; 
    53import java.math.BigDecimal; 
    6 import java.nio.charset.Charset; 
    74import java.util.ArrayList; 
    8 import java.util.LinkedHashMap; 
    95import java.util.List; 
    10 import java.util.Map; 
    116import java.util.SortedMap; 
    127import java.util.TreeMap; 
    138import java.util.regex.Pattern; 
    149 
    15 import javax.sound.midi.MetaMessage; 
    16 import javax.sound.midi.MidiEvent; 
    17 import javax.sound.midi.MidiMessage; 
    18 import javax.sound.midi.Track; 
     10import org.rayflood.mikuvat.io.vsq.VibratoBP; 
    1911 
    20 public class VSQDecoder{ 
     12public class Utilities{ 
    2113        public static final Pattern SPLITEQUAL = Pattern.compile("="); 
    2214        public static final Pattern SPLITCOMMA = Pattern.compile(","); 
    2315        public static final Pattern SPLITDQUOTE = Pattern.compile("\\\""); 
    24         public static final Pattern MMHEADER = Pattern.compile("^DM:\\d+:$"); 
    25         public static final Pattern SECTIONLINE = Pattern.compile("^\\[.+\\]$"); 
    26         public static final Charset WIN31J = Charset.forName("Windows-31J"); 
    27         public static final int TEXTLENGTH = 119; 
    2816 
    2917        public static String[] splitEqual(String s){ 
     
    8674 
    8775        public static String getByteArrayString(byte[] data){ 
    88                 StringBuffer sb = new StringBuffer(); 
     76                StringBuilder sb = new StringBuilder(); 
    8977                if(data != null && data.length > 0){ 
    9078                        sb.append(String.format("%X", data[0])); 
     
    9482                } 
    9583                return sb.toString(); 
    96         } 
    97  
    98         public static Map<String, List<String>> decode(Track tr) throws Exception{ 
    99                 List<Byte> v = new ArrayList<Byte>(); 
    100                 for(int i = 1; i < tr.size(); i++){ 
    101                         MidiMessage m = tr.get(i).getMessage(); 
    102                         if(m instanceof MetaMessage){ 
    103                                 byte b[] = ((MetaMessage)m).getData(); 
    104                                 if(b.length == 0){ 
    105                                         continue; 
    106                                 } 
    107                                 int h = 1; 
    108                                 String mmheader; 
    109                                 do{ 
    110                                         h++; 
    111                                         mmheader = new String(b, 0, h * 4, WIN31J); 
    112                                 }while(!MMHEADER.matcher(mmheader).matches()); 
    113                                 for(int k = h * 4; k < b.length; k++){ 
    114                                         if(b[k] != 0x00){ 
    115                                                 v.add(new Byte(b[k])); 
    116                                         } 
    117                                 } 
    118                         } 
    119                 } 
    120                 byte b[] = new byte[v.size()]; 
    121                 for(int i = 0; i < v.size(); i++){ 
    122                         b[i] = v.get(i); 
    123                 } 
    124                 String textevent = new String(b, WIN31J); 
    125  
    126                 Map<String, List<String>> sections = new LinkedHashMap<String, List<String>>(); 
    127                 BufferedReader br = new BufferedReader(new StringReader(textevent)); 
    128                 String bf; 
    129                 String sn = ""; 
    130                 List<String> sv = new ArrayList<String>(); 
    131                 do{ 
    132                         bf = br.readLine(); 
    133                         if(bf == null || SECTIONLINE.matcher(bf).matches()){ 
    134                                 if(sn.length() > 0 && !sections.containsKey(sn)){ 
    135                                         sections.put(sn.substring(1, sn.length() - 1), sv); 
    136                                 } 
    137                                 sn = bf; 
    138                                 sv = new ArrayList<String>(); 
    139                         } 
    140                         else if(bf.length() > 0){ 
    141                                 sv.add(bf); 
    142                         } 
    143                 }while(bf != null); 
    144  
    145                 return sections; 
    146         } 
    147  
    148         public static List<MidiEvent> encode(List<String> trackSections) throws Exception{ 
    149                 String te = ""; 
    150                 for(int i = 0; i < trackSections.size(); i++){ 
    151                         String vts = trackSections.get(i); 
    152                         te += vts + "\n"; 
    153                 } 
    154  
    155                 List<MidiEvent> tme = new ArrayList<MidiEvent>(); 
    156                 byte b[] = te.getBytes(WIN31J); 
    157                 for(int j = 0; j <= b.length / TEXTLENGTH; j++){ 
    158                         int h = (int)StrictMath.ceil((double)Integer.toString(j).length() / 4.0); 
    159                         String mef = "DM:%0" + h * 4 + "d:"; 
    160                         byte header[] = String.format(mef, j).getBytes(WIN31J); 
    161                         List<Byte> mbl = new ArrayList<Byte>(); 
    162                         for(int k = 0; k < header.length; k++){ 
    163                                 mbl.add(header[k]); 
    164                         } 
    165                         for(int k = 0; k < TEXTLENGTH; k++){ 
    166                                 int bi = j * TEXTLENGTH + k; 
    167                                 if(bi >= b.length){ 
    168                                         break; 
    169                                 } 
    170                                 mbl.add(b[bi]); 
    171                         } 
    172                         byte mb[] = new byte[mbl.size()]; 
    173                         for(int k = 0; k < mbl.size(); k++){ 
    174                                 mb[k] = mbl.get(k); 
    175                         } 
    176                         MetaMessage mm = new MetaMessage(); 
    177                         mm.setMessage(1, mb, mb.length); 
    178                         tme.add(new MidiEvent(mm, 0L)); 
    179                 } 
    180  
    181                 return tme; 
    18284        } 
    18385