File: randomizeAnalysis.cs

package info (click to toggle)
cadencii 3.3.9%2Bsvn20110818.r1732-6.1
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye
  • size: 35,916 kB
  • sloc: cs: 160,836; java: 42,449; javascript: 7,966; cpp: 7,605; ansic: 1,728; perl: 1,087; makefile: 236; php: 142; xml: 117; sh: 21
file content (66 lines) | stat: -rw-r--r-- 2,687 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System;
using System.Collections.Generic;
using org.kbinani;
using org.kbinani.vsq;
using org.kbinani.java.util;

class randomizeAnalysis{
    [STAThread]
    public static void Main( string[] args ){
        int unit = int.Parse( args[0] );
        System.Windows.Forms.OpenFileDialog d = new System.Windows.Forms.OpenFileDialog();
        if ( d.ShowDialog() == System.Windows.Forms.DialogResult.OK ) {
            string f = d.FileName;
            string dir = System.IO.Path.GetDirectoryName( f );
            string name = System.IO.Path.GetFileNameWithoutExtension( f );
            Console.WriteLine( "name=" + name );
            int index = name.IndexOf( "-001" );
            string basename = "";
            if ( index >= 0 ) {
                basename = name.Substring( 0, index );
            }
            int count = 0;
            Dictionary<int, int> dict = new Dictionary<int, int>();
            while ( true ) {
                count++;
                string open = PortUtil.combinePath( dir, basename + "-" + PortUtil.formatDecimal( "000", count ) + ".vsq" );
                Console.WriteLine( "open=" + open );
                if ( !PortUtil.isFileExists( open ) ) {
                    break;
                }
                VsqFile vsq = new VsqFile( open, "Shift_JIS" );
                int i = -1;
                int b = 3840;
                for ( Iterator itr = vsq.Track.get( 1 ).getNoteEventIterator(); itr.hasNext(); ) {
                    i++;
                    VsqEvent item = (VsqEvent)itr.next();
                    if ( i == 0 ){
                        continue;
                    }
                    int ideal_start = b + i * unit;
                    int shift = item.Clock - ideal_start;
                    if( dict.ContainsKey( shift ) ){
                        dict[shift] = dict[shift] + 1;
                    }else{
                        dict.Add( shift, 1 );
                    }
                }
            }
            int max = 0;
            int min = 0;
            foreach( int key in dict.Keys ){
                max = Math.Max( max, key );
                min = Math.Min( min, key );
            }
            using ( System.IO.StreamWriter sw = new System.IO.StreamWriter( PortUtil.combinePath( dir, basename + ".txt" ) ) ) {
                for( int i = min; i <= max; i++ ){
                    if ( dict.ContainsKey( i ) ){
                        sw.WriteLine( i + "\t" + dict[i] );
                    }else{
                        sw.WriteLine( i + "\t0" );
                    }
                }
            }
        }
    }
}