User Tools

Site Tools


software:sheetmusic_animator

Animation with sheetmusic

This page describes how to create a project with Adobe After Effects that animates a magnifier which hovers over multiple pages of sheetmusic. The result of this can be seen here: https://www.youtube.com/watch?v=4j2L8rP-GHA

t.b.d.

script

{
    if(!app.project) {
        var myProject = app.newProject();
    } else {
        var myProject = app.project;
    }
    String.prototype.trim = trimSpaces;       // method usage: .trim()       removes leading and trailing spaces
    String.prototype.parse = parseLine;      // method usage: .parse(_character_)   beginning at position 0, search for = character, return what's after = character
    String.prototype.cntData = countData;		// method usage: .cntFfDat()		returns the amount of numbers on this line. (e.g. "[1.0,5.4]".cntFfDat()=2)
    String.prototype.getnData = getIndexedData;	// method usage: .getIndexedData(_index_) returns the n-th number on this line. (e.g. "[1.0,5.4]".getFfIDat(2)=5.4)
    var newPreComp;
    // Path of audio file
    var audioFolder ="/ADD/YOUR/PATH/HERE/Projects/Bartok/"
    // Filename of audiofile
    var theFile = "Bartok_Hartmut_all.wav";
    var totalDuration;
    // Path where images reside
    var imgFolder = "/ADD/YOUR/PATH/HERE/Projects/Bartok/images/"
    // format: filename,time (in seconds from where to show)
    var imgFile = [ ["BartokScan-150101-0002.tif", 0],
                          ["BartokScan-150101-0003.tif", 72],
                          ["BartokScan-150101-0004.tif", 122.4],
                          ["BartokScan-150101-0005.tif", 170],
                          ["BartokScan-150101-0006.tif", 282.7],
                          ["BartokScan-150101-0007.tif", 370.8],
                          ["BartokScan-150101-0008.tif", 465.2],
                          ["BartokScan-150101-0009.tif", 530.1],
                          ["BartokScan-150101-0010.tif", 666.2],
                          ["BartokScan-150101-0011.tif", 775.7],
                          ["BartokScan-150101-0012.tif", 1009],
                          ["BartokScan-150101-0013.tif", 1068],
                          ["BartokScan-150101-0014.tif", 1120],
                          ["BartokScan-150101-0015.tif", 1216],
                          ["BartokScan-150101-0016.tif", 1251.8]
                        ];
    var imgScale = new Array(imgFile.length);
    var imgDimH = new Array(imgFile.length);
    var imgDimV = new Array(imgFile.length);
    // format: Command, time (in seconds)
    // G0 means invisible move. Must start with this command
    // G1 means move to position at time
    // X is horizontal coordinate (Top: 0, bottom: 100)
    // Y is vertical coordinate (Left: 0, right: 100)
    // Easy method to find X and Y coordinates is to take a transparent sheet and write the divisions on this.
    // Then place the sheet over the music and write down the numbers while listening to the music.
    // The position from the magnifier will be interpolated. Ideally it suffices to only write G0 for each line and omit G1 commands
    // -------------------------
    // ! (0,0)             (100,0) !
    // !                                !
    // !                                !
    // !                                !
    // !           (X,Y)              !
    // !                                !
    // !                                !
    // !                                !
    // ! (0,100)      (100,100) !
    // -------------------------
    // NB:
    //  * if two G0 commands follow each other, then the first G0 will hold the magnifier on that position
    //  * if a G0 time corresponds with previous element G1 time, then G1 time is G1 time minus one frame
    var magPos = [ ["G0 X50 Y12", 0],
    /* Page 02 (This is sheetmusic page 1) */
    ["G0 X15 Y22", 7.4],["G1 X21 Y22", 8.1],["G1 X30 Y22", 9.5],["G1 X36 Y22", 10.2],["G1 X44 Y22", 13],["G1 X65 Y22", 15.8],["G1 X77 Y22", 19.1],["G1 X93 Y22", 21.1],
    ["G0 X12 Y30", 21.1],["G1 X35 Y30", 22],["G1 X74 Y30", 23.4],["G1 X93 Y30", 24.4],
    ["G0 X12 Y40", 24.4],["G1 X32 Y40", 25.5],["G1 X47 Y40", 26.1],["G1 X64 Y40", 26.8],["G1 X93 Y40", 28.1],
    ["G0 X12 Y49", 28.1],["G1 X43 Y49", 29.4],["G1 X58 Y49", 30.7],["G1 X63 Y49", 31.8],["G1 X68 Y49", 33.7],["G1 X77 Y49", 34.4],["G1 X85 Y49", 34.9],["G1 X93 Y49", 35.3],
    ["G0 X12 Y57", 35.3],["G1 X22 Y57", 37.4],["G1 X45 Y57", 39.3],["G1 X54 Y57", 41.1],["G1 X93 Y57", 46.5],
    ["G0 X12 Y67", 46.5],["G1 X52 Y67", 50.8],["G1 X77 Y67", 55.3],["G1 X93 Y67", 56.4],
    ["G0 X12 Y76", 56.4],["G1 X25 Y76", 59.3],["G1 X51 Y76", 60.6],["G1 X58 Y76", 61.6],["G1 X93 Y76", 63.4],
    ["G0 X12 Y88", 63.4],["G1 X75 Y88", 67.4],["G1 X93 Y88", 72],
    /* Page 03 (This is sheetmusic page 2) */
    ["G0 X10 Y10", 72],["G1 X30 Y10", 75],["G1 X49 Y10", 76.8],["G1 X56 Y10", 77.4],["G1 X90 Y10", 80],
    ["G0 X10 Y20", 80],["G1 X44 Y20", 83],["G1 X68 Y20", 85.4],["G1 X82 Y20", 86.6],["G1 X90 Y20", 88],
    ["G0 X10 Y30", 88],["G1 X61 Y30", 93.5],["G1 X90 Y30", 96.5],
    ["G0 X10 Y39", 96.5],["G1 X52 Y39", 98.9],["G1 X79 Y39", 100.4],["G1 X90 Y39", 101],
    ["G0 X10 Y50", 101],["G1 X26 Y50", 102.5],["G1 X49 Y50", 104.0],["G1 X62 Y50", 105.5],["G1 X90 Y50", 107.5],
    ["G0 X10 Y59", 107.5],["G1 X90 Y59", 111.2],
    ["G0 X10 Y68", 111.2],["G1 X85 Y68", 115.2],["G1 X90 Y68", 116.2],
    ["G0 X10 Y78", 116.2],["G1 X26 Y78", 117.4],["G1 X90 Y78", 119.4],
    ["G0 X10 Y87", 119.4],["G1 X26 Y87", 120.3],["G1 X90 Y87", 122.4],
    /* Page 04 (This is sheetmusic page 3) */
    ["G0 X12 Y10", 122.4],["G1 X30 Y10", 123.2],["G1 X90 Y10", 125.5],
    ["G0 X12 Y20", 125.5],["G1 X60 Y20", 126.9],["G1 X87 Y20", 128.1],["G1 X92 Y20", 128.4],
    ["G0 X12 Y30", 128.4],["G1 X30 Y30", 129.3],["G1 X86 Y30", 131.1],["G1 X92 Y30", 131.5],
    ["G0 X12 Y40", 131.5],["G1 X31 Y40", 132.3],["G1 X87 Y40", 134.1],["G1 X92 Y40", 134.4],
    ["G0 X12 Y50", 134.4],["G1 X32 Y50", 135.2],["G1 X50 Y50", 136.0],["G1 X70 Y50", 136.7],["G1 X90 Y50", 137.5],
    ["G0 X12 Y60", 137.5],["G1 X29 Y60", 138.5],["G1 X90 Y60", 141.1],
    ["G0 X12 Y68", 141.1],["G1 X25 Y68", 142.2],["G1 X58 Y68", 143.7],["G1 X90 Y68", 145.1],
    ["G0 X12 Y77", 145.1],["G1 X25 Y77", 146.2],["G1 X61 Y77", 147.9],["G1 X90 Y77", 149.5],
    ["G0 X12 Y87", 149.5],["G1 X20 Y87", 150.4],["G1 X31 Y87", 151.9],["G1 X51 Y87", 153.8],["G1 X90 Y87", 170],
    /* Page 05 (This is sheetmusic page 4) */
    ["G0 X8 Y10", 170],["G1 X24 Y10", 171.6],["G1 X40 Y10", 174.3],["G1 X70 Y10", 178.4],["G1 X88 Y10", 181.4],
    ["G0 X9 Y19", 181.4],["G1 X31 Y19", 185.2],["G1 X57 Y19", 187.7],["G1 X75 Y19", 190.8],["G1 X89 Y19", 192.4],
    ["G0 X9 Y27", 192.4],["G1 X16 Y27", 194.4],["G1 X27 Y27", 195.2],["G1 X38 Y27", 197.1],["G1 X73 Y27", 200.1],["G1 X89 Y27", 201.7],
    ["G0 X9 Y37", 201.7],["G1 X16 Y37", 203.8],["G1 X28 Y37", 204.8],["G1 X42 Y37", 208.5],["G1 X50 Y37", 209.5],["G1 X60 Y37", 211.5],["G1 X89 Y37", 215],
    ["G0 X9 Y45", 215],["G1 X38 Y45", 218.2],["G1 X90 Y45", 223],
    ["G0 X9 Y55", 223],["G1 X38 Y55", 225.4],["G1 X70 Y55", 228],["G1 X80 Y55", 232],["G1 X89 Y55", 233],
    ["G0 X9 Y64", 233],["G1 X20 Y64", 235.7],["G1 X28 Y64", 237.7],["G1 X58 Y64", 240.8],["G1 X70 Y64", 243.0],["G1 X89 Y64", 249],
    ["G0 X9 Y72", 249],["G1 X18 Y72", 251.6],["G1 X24 Y72", 252.3],["G1 X27 Y72", 253],["G1 X32 Y72", 255],["G1 X35 Y72", 256],["G1 X46 Y72", 257.7],["G1 X65 Y72", 260.5],["G1 X88 Y72", 262.8],
    ["G0 X10 Y81", 262.8],["G1 X57 Y81", 265.2],["G1 X90 Y81", 266.9],
    ["G0 X8 Y90", 266.9],["G1 X39 Y90", 269.3],["G1 X65 Y90", 271],["G1 X76 Y90", 273.2],["G1 X82 Y90", 279.4],["G1 X90 Y90", 282.7],
    /* Page 06 (This is sheetmusic page 5) */
    ["G0 X12 Y10", 282.7],["G1 X25 Y10", 285],["G1 X30 Y10", 285.7],["G1 X56 Y10", 290.5],["G1 X64 Y10", 291.1],["G1 X94 Y10", 296.9],
    ["G0 X12 Y20", 296.9],["G1 X30 Y20", 299],["G1 X50 Y20", 301.2],["G1 X63 Y20", 303.4],["G1 X68 Y20", 304.2],["G1 X94 Y20", 306.7],
    ["G0 X12 Y30", 306.7],["G1 X93 Y30", 312.5],
    ["G0 X12 Y41", 312.5],["G1 X93 Y41", 320.5],
    ["G0 X12 Y52", 320.5],["G1 X41 Y52", 323.0],["G1 X52 Y52", 324.5],["G1 X80 Y52", 333],["G1 X94 Y52", 335.5],
    ["G0 X12 Y62", 335.5],["G1 X50 Y62", 337.9],["G1 X56 Y62", 339.3],["G1 X95 Y62", 342.6],
    ["G0 X12 Y71", 342.6],["G1 X29 Y71", 345.0],["G1 X71 Y71", 347.5],["G1 X71 Y71", 347.5],["G1 X81 Y71", 348.8],["G1 X94 Y71", 349.5],
    ["G0 X12 Y80", 349.5],["G1 X45 Y80", 352.5],["G1 X93 Y80", 357],
    ["G0 X12 Y89", 357],["G1 X80 Y89", 363.4],["G1 X95 Y89", 370.8],
    /* Page 07 (This is sheetmusic page 6) */
    ["G0 X10 Y9", 370.8],["G1 X55 Y9", 375.7],["G1 X68 Y9", 377.9],["G1 X80 Y9", 379.8],["G1 X90 Y9", 380.5],
    ["G0 X10 Y17", 380.5],["G1 X35 Y17", 383.3],["G1 X70 Y17", 385.4],["G1 X91 Y17", 388.9],
    ["G0 X10 Y27", 388.9],["G1 X18 Y27", 389.4],["G1 X27 Y27", 390.3],["G1 X27 Y27", 390.8],["G1 X40 Y27", 391.6],["G1 X47 Y27", 392.5],["G1 X58 Y27", 394.3],["G1 X82 Y27", 396.1],["G1 X86 Y27", 398.6],["G1 X90 Y27", 399.7],
    ["G0 X10 Y36", 399.7],["G1 X38 Y36", 404],["G1 X65 Y36", 408],["G1 X79 Y36", 409],["G1 X90 Y36", 411],
    ["G0 X10 Y45", 411],["G1 X31 Y45", 415],["G1 X35 Y45", 416],["G1 X40 Y45", 417],["G1 X64 Y45", 419],["G1 X68 Y45", 419.5],["G1 X79 Y45", 420.9],["G1 X91 Y45", 422.5],
    ["G0 X10 Y53", 422.5],["G1 X90 Y53", 427],
    ["G0 X10 Y63", 427],["G1 X90 Y63", 431],
    ["G0 X10 Y72", 431],["G1 X90 Y72", 437],
    ["G0 X10 Y80", 437],["G1 X39 Y80", 439.3],["G1 X41 Y80", 440.1],["G1 X57 Y80", 441.1],["G1 X64 Y80", 441.7],["G1 X90 Y80", 443.9],
    ["G0 X10 Y88", 443.9],["G1 X21 Y88", 445.1],["G1 X30 Y88", 446.3],["G1 X50 Y88", 463.0],["G1 X90 Y88", 465.2],
    /* Page 08 (This is sheetmusic page 7) */
    ["G0 X12 Y10", 465.2],["G1 X43 Y10", 467],["G1 X51 Y10", 468],["G1 X60 Y10", 469.2],["G1 X96 Y10", 471.3],
    ["G0 X12 Y19", 471.3],["G1 X24 Y19", 471.8],["G1 X32 Y19", 472.2],["G1 X93 Y19", 474.4],
    ["G0 X12 Y28", 474.4],["G1 X32 Y28", 475.3],["G1 X94 Y28", 477.5],
    ["G0 X12 Y37", 477.5],["G1 X78 Y37", 479.9],["G1 X91 Y37", 480.5],
    ["G0 X12 Y46", 480.5],["G1 X90 Y46", 483.7],
    ["G0 X12 Y55", 483.7],["G1 X90 Y55", 486.8],
    ["G0 X12 Y65", 486.8],["G1 X28 Y65", 488.1],["G1 X75 Y65", 490.1],["G1 X91 Y65", 490.9],
    ["G0 X12 Y73", 490.9],["G1 X26 Y73", 491.9],["G1 X55 Y73", 492.9],["G1 X70 Y73", 494.1],["G1 X90 Y73", 494.8],
    ["G0 X12 Y82", 494.8],["G1 X24 Y82", 495.9],["G1 X39 Y82", 496.5],["G1 X52 Y82", 497.2],["G1 X61 Y82", 497.9],["G1 X82 Y82", 499.2],["G1 X95 Y82", 501.7],
    ["G0 X12 Y91", 501.7],["G1 X19 Y91", 502.6],["G1 X30 Y91", 503.9],["G1 X38 Y91", 504.7],["G1 X50 Y91", 505.7],["G1 X60 Y91", 506.6],["G1 X68 Y91", 507.4],["G1 X79 Y91", 509.7],["G1 X88 Y91", 518.8],["G1 X95 Y91", 530.1],
    /* Page 09 (This is sheetmusic page 8) */
    ["G0 X11 Y11", 530.1],["G1 X31 Y11", 535.6],["G1 X64 Y11", 541.1],["G1 X77 Y11", 542.3],["G1 X83 Y11", 543.4],["G1 X87 Y11", 544],["G1 X94 Y11", 545.8],
    ["G0 X11 Y22", 545.8],["G1 X20 Y22", 550.2],["G1 X51 Y22", 555.2],["G1 X69 Y22", 557.7],["G1 X75 Y22", 559.1],["G1 X90 Y22", 565.1],
    ["G0 X12 Y31", 565.1],["G1 X20 Y31", 567.4],["G1 X32 Y31", 568.7],["G1 X40 Y31", 570.3],["G1 X50 Y31", 571.1],["G1 X62 Y31", 573.4],["G1 X91 Y31", 575.6],
    ["G0 X11 Y41", 575.6],["G1 X48 Y41", 578.7],["G1 X66 Y41", 580.9],["G1 X77 Y41", 581.8],["G1 X90 Y41", 583.4],
    ["G0 X11 Y51", 583.4],["G1 X29 Y51", 585.4],["G1 X40 Y51", 586.7],["G1 X69 Y51", 589.5],["G1 X78 Y51", 590.8], ["G1 X90 Y51", 592.2],
    ["G0 X11 Y61", 592.2],["G1 X82 Y61", 599.0],["G1 X89 Y61", 600],
    ["G0 X11 Y71", 600],["G1 X36 Y71", 604.8],["G1 X50 Y71", 620.0],["G1 X64 Y71", 631.5],["G1 X75 Y71", 632.3],["G1 X91 Y71", 635.3],
    ["G0 X10 Y80", 635.3],["G1 X14 Y80", 635.7],["G1 X23 Y80", 636.7],["G1 X28 Y80", 637.9],["G1 X35 Y80", 638.4],["G1 X44 Y80", 639.3],["G1 X47 Y80", 639.8],["G1 X51 Y80", 640.7],["G1 X71 Y80", 642.9],["G1 X81 Y80", 645.4],["G1 X90 Y80", 650.8],
    ["G0 X10 Y90", 650.8],["G1 X36 Y90", 655.3],["G1 X45 Y90", 656.6],["G1 X56 Y90", 658.8],["G1 X65 Y90", 661.5],["G1 X90 Y90", 666.2],
    /* Page 10 (This is sheetmusic page 9) */
    ["G0 X11 Y11", 666.2],["G1 X26 Y11", 668.7],["G1 X42 Y11", 671.8],["G1 X45 Y11", 672.3],["G1 X53 Y11", 673.6],["G1 X65 Y11", 674.5],["G1 X71 Y11", 675.2],["G1 X77 Y11", 676.3],["G1 X93 Y11", 678.6],
    ["G0 X11 Y21", 678.6],["G1 X21 Y21", 683.5],["G1 X30 Y21", 687.6],["G1 X44 Y21", 691.9],["G1 X59 Y21", 695.5],["G1 X69 Y21", 701.0],["G1 X70 Y21", 702.4],["G1 X74 Y21", 702.5],["G1 X82 Y21", 707.8],["G1 X90 Y21", 709.3],["G1 X94 Y21", 709.9],
    ["G0 X11 Y31", 709.9],["G1 X21 Y31", 711.1],["G1 X40 Y31", 715.6],["G1 X50 Y31", 717.0],["G1 X60 Y31", 720.0],["G1 X68 Y31", 720.6],["G1 X81 Y31", 723.9],["G1 X91 Y31", 727.0],
    ["G0 X11 Y39", 727.0],["G1 X35 Y39", 729.4],["G1 X49 Y39", 731.9],["G1 X68 Y39", 734.3],["G1 X91 Y39", 735.3],
    ["G0 X11 Y49", 735.3],["G1 X40 Y49", 737],["G1 X50 Y49", 739],["G1 X66 Y49", 739.7],["G1 X72 Y49", 740.7],["G1 X91 Y49", 741.2],
    ["G0 X11 Y59", 741.2],["G1 X50 Y59", 742.1],["G1 X90 Y59", 742.8],
    ["G0 X11 Y68", 742.8],["G1 X52 Y68", 743.8],["G1 X90 Y68", 744.5],
    ["G0 X11 Y78", 744.5],["G1 X91 Y78", 746.4],
    ["G0 X11 Y88", 746.4],["G1 X54 Y88", 747.7],["G1 X54 Y88", 747.7],["G1 X64 Y88", 749.5],["G1 X72 Y88", 754.6],["G1 X85 Y88", 758.5],["G1 X93 Y88", 775.7],
    /* Page 11 (This is sheetmusic page 10) */
    ["G0 X15 Y12", 775.7],["G1 X20 Y12", 777.4],["G1 X31 Y12", 783.3],["G1 X44 Y12", 787.3],["G1 X55 Y12", 792.3],["G1 X62 Y12", 794],["G1 X72 Y12", 800.2],["G1 X87 Y12", 804.3],["G1 X91 Y12", 808.9],
    ["G0 X11 Y21", 808.9],["G1 X24 Y21", 814.3],["G1 X37 Y21", 818.9],["G1 X45 Y21", 820.5],["G1 X54 Y21", 821.8],["G1 X68 Y21", 827],["G1 X86 Y21", 830],["G1 X91 Y21", 834.1],
    ["G0 X11 Y28", 834.1],["G1 X15 Y28", 835.4],["G1 X31 Y28", 840],["G1 X40 Y28", 842.5],["G1 X52 Y28", 846.8],["G1 X60 Y28", 849.4],["G1 X77 Y28", 856.0],["G1 X85 Y28", 857.8],["G1 X92 Y28", 863],
    ["G0 X11 Y37", 863],["G1 X18 Y37", 866.5],["G1 X28 Y37", 868.6],["G1 X32 Y37", 869.9],["G1 X36 Y37", 871.3],["G1 X44 Y37", 875.2],["G1 X47 Y37", 876.2],["G1 X54 Y37", 879.4],["G1 X76 Y37", 883.6],["G1 X82 Y37", 888.4],["G1 X93 Y37", 893.1],
    ["G0 X11 Y45", 893.1],["G1 X15 Y45", 894.6],["G1 X28 Y45", 897.9],["G1 X28 Y45", 897.9],["G1 X37 Y45", 899.6],["G1 X47 Y45", 904.1],["G1 X73 Y45", 913.3],["G1 X77 Y45", 914.3],["G1 X92 Y45", 917.2],
    ["G0 X11 Y54", 917.2],["G1 X42 Y54", 919.4],["G1 X53 Y54", 920.6],["G1 X59 Y54", 922.1],["G1 X71 Y54", 923.5],["G1 X93 Y54", 926.2],
    ["G0 X11 Y63", 926.2],["G1 X16 Y63", 926.9],["G1 X37 Y63", 931.0],["G1 X45 Y63", 931.8],["G1 X67 Y63", 935.0],["G1 X83 Y63", 937.8],["G1 X87 Y63", 938.5],["G1 X93 Y63", 939.8],
    ["G0 X11 Y72", 939.8],["G1 X21 Y72", 941.2],["G1 X25 Y72", 941.8],["G1 X28 Y72", 942.3],["G1 X33 Y72", 942.5],["G1 X35 Y72", 942.9],["G1 X42 Y72", 943.4],["G1 X50 Y72", 944.2],["G1 X54 Y72", 944.9],["G1 X66 Y72", 950.0],["G1 X81 Y72", 955.2],["G1 X86 Y72", 957.5],["G1 X94 Y72", 960.2],
    ["G0 X11 Y80", 960.2],["G1 X26 Y80", 964.8],["G1 X26 Y80", 964.8],["G1 X37 Y80", 967.1],["G1 X54 Y80", 973.1],["G1 X63 Y80", 974.1],["G1 X72 Y80", 976.9],["G1 X82 Y80", 979.9],["G1 X82 Y80", 979.9],["G1 X88 Y80", 982],["G1 X93 Y80", 982.9],
    ["G0 X11 Y88", 982.9],["G1 X20 Y88", 985.1],["G1 X30 Y88", 989.9],["G1 X36 Y88", 991.9],["G1 X41 Y88", 992.2],["G1 X47 Y88", 996],["G1 X56 Y88", 998.4],["G1 X62 Y88", 999.4],["G1 X72 Y88", 1002.7],["G1 X88 Y88", 1009],
    /* Page 12 (This is sheetmusic page 11) */
    ["G0 X11 Y10", 1009],["G1 X21 Y10", 1010.3],["G1 X64 Y10", 1012.8],["G1 X75 Y10", 1013.6],["G1 X93 Y10", 1014.4],
    ["G0 X11 Y17", 1014.4],["G1 X82 Y17", 1017.2],["G1 X92 Y17", 1018.7],
    ["G0 X15 Y28", 1018.7],["G1 X73 Y28", 1026.7],["G1 X92 Y28", 1028.5],
    ["G0 X11 Y37", 1028.5],["G1 X31 Y37", 1030.4],["G1 X45 Y37", 1031.5],["G1 X58 Y37", 1032.1],["G1 X71 Y37", 1033.3],["G1 X86 Y37", 1034],["G1 X93 Y37", 1034.9],
    ["G0 X11 Y47", 1034.9],["G1 X59 Y47", 1037.6],["G1 X68 Y47", 1038.7],["G1 X88 Y47", 1040],["G1 X94 Y47", 1040.5],
    ["G0 X11 Y55", 1040.5],["G1 X19 Y55", 1040.9],["G1 X22 Y55", 1041.2],["G1 X32 Y55", 1041.6],["G1 X44 Y55", 1042.6],["G1 X48 Y55", 1042.9],["G1 X52 Y55", 1043.1],["G1 X65 Y55", 1043.8],["G1 X67 Y55", 1044],["G1 X82 Y55", 1044.7],["G1 X91 Y55", 1045.7],
    ["G0 X15 Y65", 1045.7],["G1 X23 Y65", 1046.4],["G1 X35 Y65", 1049.1],["G1 X92 Y65", 1051.4],
    ["G0 X11 Y73", 1051.4],["G1 X21 Y73", 1051.9],["G1 X45 Y73", 1053],["G1 X56 Y73", 1053.9],["G1 X93 Y73", 1055.5],
    ["G0 X11 Y81", 1055.5],["G1 X63 Y81", 1057.4],["G1 X72 Y81", 1058.6],["G1 X93 Y81", 1059.4],
    ["G0 X11 Y90", 1059.4],["G1 X23 Y90", 1059.8],["G1 X76 Y90", 1062.6],["G1 X92 Y90", 1068],
    /* Page 13 (This is sheetmusic page 12) */
    ["G0 X11 Y12", 1068],["G1 X34 Y12", 1069.6],["G1 X51 Y12", 1070.6],["G1 X60 Y12", 1071.4],["G1 X92 Y12", 1073.1],
    ["G0 X11 Y22", 1073.1],["G1 X93 Y22", 1077.3],
    ["G0 X11 Y31", 1077.3],["G1 X38 Y31", 1078.7],["G1 X43 Y31", 1079.1],["G1 X93 Y31", 1081.6],
    ["G0 X11 Y41", 1081.6],["G1 X88 Y41", 1085.3],["G1 X93 Y41", 1085.8],
    ["G0 X11 Y50", 1085.8],["G1 X21 Y50", 1086.8],["G1 X27 Y50", 1088],["G1 X43 Y50", 1102],["G1 X93 Y50", 1104.6],
    ["G0 X11 Y60", 1104.6],["G1 X93 Y60", 1108],
    ["G0 X11 Y70", 1108],["G1 X93 Y70", 1111.3],
    ["G0 X11 Y79", 1111.3],["G1 X93 Y79", 1114.7],
    ["G0 X11 Y89", 1114.7],["G1 X32 Y89", 1115.6],["G1 X46 Y89", 1116.5],["G1 X56 Y89", 1118.2],["G1 X92 Y89", 1120],
    /* Page 14 (This is sheetmusic page 13) */
    ["G0 X11 Y11", 1120],["G1 X58 Y11", 1122.5],["G1 X92 Y11", 1124.2],
    ["G0 X11 Y20", 1124.2],["G1 X38 Y20", 1125.9],["G1 X92 Y20", 1128.3],
    ["G0 X11 Y31", 1128.3],["G1 X93 Y31", 1132.6],
    ["G0 X11 Y40", 1132.6],["G1 X93 Y40", 1136.8],
    ["G0 X11 Y50", 1136.8],["G1 X50 Y50", 1139],["G1 X66 Y50", 1139.8],["G1 X74 Y50", 1140.3],["G1 X83 Y50", 1141.3],["G1 X93 Y50", 1144],
    ["G0 X11 Y60", 1144],["G1 X27 Y60", 1146.3],["G1 X46 Y60", 1155.6],["G1 X67 Y60", 1158.1],["G1 X79 Y60", 1159.3],["G1 X88 Y60", 1160.5],["G1 X93 Y60", 1161.5],
    ["G0 X11 Y70", 1161.5],["G1 X35 Y70", 1164],["G1 X52 Y70", 1165.3],["G1 X63 Y70", 1166.3],["G1 X75 Y70", 1174.6],["G1 X94 Y70", 1177.2],
    ["G0 X11 Y80", 1177.2],["G1 X65 Y80", 1181.8],["G1 X78 Y80", 1183.8],["G1 X92 Y80", 1185.2],
    ["G0 X11 Y90", 1185.2],["G1 X26 Y90", 1186.9],["G1 X46 Y90", 1188],["G1 X56 Y90", 1189],["G1 X69 Y90", 1198.7],["G1 X81 Y90", 1209.2],["G1 X93 Y90", 1216],
    /* Page 15 (This is sheetmusic page 14) */
    ["G0 X11 Y11", 1216],["G1 X19 Y11", 1217.4],["G1 X25 Y11", 1217.8],["G1 X52 Y11", 1219.2],["G1 X69 Y11", 1220],["G1 X92 Y11", 1220.9],
    ["G0 X11 Y20", 1220.9],["G1 X56 Y20", 1222.6],["G1 X71 Y20", 1223.6],["G1 X81 Y20", 1224.4],["G1 X92 Y20", 1225.3],
    ["G0 X10 Y30", 1225.3],["G1 X68 Y30", 1228],["G1 X83 Y30", 1229.6],["G1 X93 Y30", 1230.5],
    ["G0 X10 Y39", 1230.5],["G1 X53 Y39", 1233.2],["G1 X93 Y39", 1234.8],
    ["G0 X10 Y49", 1234.8],["G1 X93 Y49", 1238.2],
    ["G0 X10 Y60", 1238.2],["G1 X93 Y60", 1242.5],
    ["G0 X10 Y70", 1242.5],["G1 X93 Y70", 1245.5],
    ["G0 X10 Y80", 1245.5],["G1 X62 Y80", 1246.8],["G1 X74 Y80", 1247.6],["G1 X92 Y80", 1248.5],
    ["G0 X10 Y90", 1248.5],["G1 X92 Y90", 1251.8],
    /* Page 16 (This is sheetmusic page 15) */
    ["G0 X11 Y12", 1251.8],["G1 X94 Y12", 1255.2],
    ["G0 X11 Y20", 1255.2],["G1 X20 Y20", 1255.7],["G1 X63 Y20", 1258.3],["G1 X94 Y20", 1259.8],
    ["G0 X11 Y28", 1259.8],["G1 X37 Y28", 1261.6],["G1 X94 Y28", 1264.1],
    ["G0 X11 Y37", 1264.1],["G1 X94 Y37", 1268.3],
    ["G0 X11 Y47", 1268.3],["G1 X25 Y47", 1269.2],["G1 X40 Y47", 1269.9],["G1 X53 Y47", 1270.8],["G1 X67 Y47", 1271.7],["G1 X71 Y47", 1272.1],["G1 X94 Y47", 1273.3],
    ["G0 X11 Y55", 1273.3],["G1 X93 Y55", 1276.7],
    ["G0 X11 Y64", 1276.7],["G1 X93 Y64", 1280.1],
    ["G0 X11 Y72", 1280.1],["G1 X93 Y72", 1283.6],
    ["G0 X11 Y81", 1283.6],["G1 X27 Y81", 1284.4],["G1 X44 Y81", 1285.3],["G1 X60 Y81", 1286.2],["G1 X74 Y81", 1287.4],["G1 X82 Y81", 1288.3],["G1 X93 Y81", 1290.3],
    ["G0 X11 Y89", 1290.3],["G1 X17 Y89", 1290.8],["G1 X70 Y89", 1293.1],["G1 X70 Y89", 1293.1],["G1 X84 Y89", 1293.8],["G1 X84 Y89", 1293.8],["G1 X93 Y89", 1295.6],["G0 X94 Y89", 1295.6]
    ];
 
    var time = new Date();
    var compWidth=1280; // create a composition with a large dimension to reduce scaling effect afterwards
    var compHeight=720;
    var compPixelAspect=1;
    var compFrameRate=25.0;   
    var resize=4; // multiplication factor for the composition to allow sheetmusic to appear without any pixel loss
    var renderComp = "main"; // name of main composition
    var pre_compose = "__PreComposed";
    var magnifier_size = 2.7; // factor for magnifier size relative to comp dimension
    var BulgeHeight = 1.9; // how much does the view through the magnifier should bulge
    var magnify_effect_size = 0.07; // How strong does the magnification needs to be
    var circle_tangent_value = 3.621;
    var magnify_border_thickness = 0.0173
    var imgScalingFactor = 0.6;
   //var tmpFile = "~/AEtmp"+time.getFullYear()+time.getMonth()+time.getDay()+time.getHours()+time.getMinutes()+time.getSeconds()+".mp4";
 
    var importOptions = new ImportOptions (new File (audioFolder + theFile));
    var imgImportOptions = new Array(imgFile.length);
 
    if (importOptions.canImportAs(ImportAsType.FOOTAGE)) {
        try {
            var myItem;
            var myImg;
            var i;
            myItem = myProject.importFile(importOptions);
            var newComp = myProject.items.addComp(renderComp,compWidth * resize, compHeight * resize, compPixelAspect,myItem.duration, compFrameRate);
            var myImportedImg;
            var imgLayers = new Array(imgFile.length);
            var start;
            var stop;
            var scale_array;
            var scaling = new Array(2);
            var scale_factor
            for (i=0; i<imgFile.length; i++) {
                myImg = imgFolder + imgFile[i][0];
                start = quantize(imgFile[i][1]);
                if (i<imgFile.length-1) {
                    stop = imgFile[i+1][1];
                } else {
                    stop = myItem.duration;
                }
                imgImportOptions[i] = new ImportOptions (new File (myImg));
                myImportedImg = myProject.importFile(imgImportOptions[i]);
 
                scaling[0] = compWidth*resize/myImportedImg.width;
                scaling[1] = compHeight*resize/myImportedImg.height;
                scale_factor = Math.min( scaling[0], scaling[1]) * imgScalingFactor ;
                imgScale[i] = scale_factor ;
                imgDimH[i] = myImportedImg.width;
                imgDimV[i] = myImportedImg.height;
 
                imgLayers[i] = newComp.layers.add(myImportedImg);
                scale_array = imgLayers[i].transform.scale.value;
                scale_array[0] = scale_array[0] * scale_factor ; // this will make sure the image always fits and has a border around it
                scale_array[1] = scale_array[1] * scale_factor ;
                imgLayers[i].scale.setValue(scale_array);
 
                imgLayers[i].inPoint = start;
                imgLayers[i].outPoint = stop;
            }
 
            var AudioLayer = newComp.layers.add(myItem);
            AudioLayer.audioEnabled = true;
            totalDuration = newComp.duration;
 
            // Build array for precomposed layers and precomposed composition
            var layerIndices = new Array();
            for (i = 0; i < imgFile.length+1; i++){
                layerIndices[i] = i + 1;
            }
            newPreComp = newComp.layers.precompose(layerIndices, pre_compose,true);        
 
            // Add adjustment layer to pre composed layer
            var adj_obj = newPreComp.layers.addSolid([0,0,0], "Adjustment Layer", newComp.width, newComp.height,1);
            adj_obj.adjustmentLayer = true;
 
            // Add round mask to adjustment layer
            var myShape = new Shape() ;
            var a=compWidth * resize/2; // center position of round mask with size magnifier_size
            var b=compHeight * resize/2;
            var tv=compWidth*resize*magnifier_size/circle_tangent_value; // tangent value to make a perfect circle
 
            myShape.vertices = [[a,b-compWidth*resize*magnifier_size/2],[a-compWidth*resize*magnifier_size/2,b],[a,b+compWidth*resize*magnifier_size/2],[a+compWidth*resize*magnifier_size/2,b]];
            myShape.inTangents = [[tv,0],[0,-tv],[-tv,0],[0,tv]];
            myShape.outTangents = [[-tv,0],[0,tv],[tv,0],[0,-tv]];
            myShape.closed = true;
 
            var maskGroup = newPreComp.layer(1).property("Masks");
            var mask = maskGroup.addProperty("Mask");	// Create a new mask
            maskShape = mask.property("maskShape");
            maskShape.setValue(myShape);
            //adj_obj.property("Position").setValue([a,b]); // <-------- ANIMATE THIS
 
            var topLayer = newPreComp.layer(1);
            // add effect bulge to adjustment layer. See Generator.jsx file to find out all methods.
            var FFbase1= topLayer.property("Effects").addProperty("ADBE Bulge");
            FFbase1.property("Horizontal Radius").setValue(compWidth*resize*magnifier_size/2);
            FFbase1.property("Vertical Radius").setValue(compWidth*resize*magnifier_size/2);
            FFbase1.property("Bulge Height").setValue(BulgeHeight);
            //FFbase1.property("Bulge Center").setValue([a,b]); // <-------- ANIMATE THIS
            FFbase1.property("Taper Radius").setValue(0);
            FFbase1.property("Antialiasing (Best Qual Only)").setValue(1);
            FFbase1.property("Pinning").setValue(0);
            // add effect bulge to adjustment layer. See Generator.jsx file to find out all methods.
            var FFbase2= topLayer.property("Effects").addProperty("ADBE Magnify");
            FFbase2.property("Shape").setValue(1);
            //FFbase2.property("Center").setValue([a,b]); // <-------- ANIMATE THIS
            FFbase2.property("Magnification").setValue(compWidth*resize*magnifier_size*magnify_effect_size);
            FFbase2.property("Link").setValue(1);
            FFbase2.property("Size").setValue(compWidth*resize*magnifier_size/2);
            FFbase2.property("Feather").setValue(0);
            FFbase2.property("Opacity").setValue(100);
            FFbase2.property("Scaling").setValue(1);
            FFbase2.property("Blending Mode").setValue(2);
            FFbase2.property("Resize Layer").setValue(0);
            // add effect bulge to adjustment layer. See Generator.jsx file to find out all methods.
            var FFbase3=newPreComp.layer(1).Effects.addProperty("CC Toner");
            FFbase3.property("Highlights").setValue([1,1,1,1]);
            FFbase3.property("Midtones").setValue([0.498,0.392,0.275,1]);
            FFbase3.property("Shadows").setValue([0,0,0,1]);
            FFbase3.property("Blend w. Original").setValue(0);
 
            // drawing black circle on top
            var myShapeLayer = newPreComp.layers.addShape();
            myShapeLayer.name = ("Circle");
            var circle_obj = newPreComp.layer(1)
            //circle_obj.property("Position").setValue([a,b]); // <-------- ANIMATE THIS
            var shapeGroup = myShapeLayer.property("Contents").addProperty("ADBE Vector Group");
            var myEllipse = shapeGroup.property("Contents").addProperty("ADBE Vector Shape - Ellipse");
            myEllipse.property("Size").setValue([compWidth*resize*magnifier_size,compWidth*resize*magnifier_size]);
            var myStroke = shapeGroup.property("Contents").addProperty("ADBE Vector Graphic - Stroke"); 
            myStroke.property("Color").setValue([0.2,0.2,0.2]);
            myStroke.property("Opacity").setValue([100]);
            myStroke.property("Stroke Width").setValue([compWidth*resize*magnifier_size*magnify_border_thickness]);
 
            // Layer order changed, so new object required for effects
            var eff_obj = newPreComp.layer(2).property("Effects");
 
            //move_to(0,0,0,eff_obj,adj_obj,circle_obj,0); // <---- move magnifier from the top left corner
            //move_to(3,100,100,eff_obj,adj_obj,circle_obj,0); // <---- to the bottom right corner
 
            // Process all gcode
            i=0;
            var mt;
            var gcmd,gcmd2;
            var gc, gc2;
            var mx;
            var my;
 
            do {
                mt = quantize(magPos[i][1]);
                gcmd = magPos[i][0];
                if (magPos.length-1 == i)
                {
                    // last command
                    gcmd2 = magPos[i][0];
                    mt2 = quantize(totalDuration);
                } else {
                    gcmd2 = magPos[i+1][0];
                    mt2 = quantize(magPos[i+1][1]);
                }
 
                if (3==gcmd.cntData() && 3==gcmd2.cntData()) // We need 3 parameters per line
                {
                    gc = get_cmd(gcmd);
                    gc2 = get_cmd(gcmd2);
                    if (gc < 0 || gc2 < 0)
                    {
                        alert("Gcode problem at or after line: " + i);
                        break;
                    }
                    mx = gcmd.parse("x").getnData(1);
                    my = gcmd.parse("y").getnData(1);
 
                    if (gc == gc2 && 0 == gc)
                    {
                        // two G0 commands following eachother, first G0 command is of type: KeyframeInterpolationType.HOLD
                        move_to(mt,mx,my,eff_obj,adj_obj,circle_obj,1);
                    } else {
                        if (mt == mt2 && 0 != mt)
                        {
                            mt=mt-(1/compFrameRate); // two consecutive G commands have the same time,
                            move_to(mt, mx, my, eff_obj, adj_obj, circle_obj, 1);
                            mt=mt-(1/compFrameRate); // two consecutive G commands have the same time,
                            move_to(mt, mx, my, eff_obj, adj_obj, circle_obj, 0);
                        } else {
                            move_to(mt, mx, my, eff_obj, adj_obj, circle_obj, 0);
                        }
                    }
                }
                i++;
            } while (i < magPos.length);
 
            // for time offset:
            //VideoLayer.enabled = false;
            //AudioLayer.startTime = AudioLayer.startTime - 3*(1/myItem.frameRate);
 
            // partial code for adding to the render queue automatically:
            //var rendQueue = myProject.renderQueue.items.add(newComp);
            //var thisQueue = myProject.renderQueue.item(myProject.renderQueue.numItems);
            //thisQueue.outputModules[1].applyTemplate("Adobe Flash Video");
            //thisQueue.outputModule(1).file = new File(tmpFile);
            //thisQueue.applyTemplate("Best Settings");
            //myProject.renderQueue.render();
            //newComp.remove();
            //myItem.remove();
            //var tempFile = File(tmpFile);
            //tempFile.copy(outFile+cs+".fmp4");
            //tempFile.remove();
            alert("The composition " + renderComp + " contains your final project.\nWhen adding this to your render queue, set the following to maintain correct aspect ratio and encoding:\n * Output module: select H.264.\n * Enable resize option:\n    * Disable Lock aspect ratio\n    * Resize to 1280x720 (select preset HD 720)");
        }
        catch(e) {
            $.writeln ("Not all ok");
        }
    }
 
    app.exitCode=0;
 
    function move_to(time,x_prc,y_prc,effObj,adjObj,circleObj,hold)
	{
        var xy = new Array(2);
        var n;
        var index = lookup_img_index(time);
        xy[0]=(compWidth*resize- imgDimH[index] * imgScale[index])/2 + imgDimH[index]*imgScale[index]*x_prc/100;
        xy[1]=(compHeight*resize- imgDimV[index] * imgScale[index])/2 + imgDimV[index]*imgScale[index]*y_prc/100;
 
        effObj.property("ADBE Bulge").property("Bulge Center").setValueAtTime(time,xy);
        effObj.property("ADBE Magnify").property("Center").setValueAtTime(time,xy);
        adjObj.property("Position").setValueAtTime(time,xy);
        circleObj.property("Position").setValueAtTime(time,xy);
        if (1 == hold)
        {
            n = effObj.property("ADBE Bulge").property("Bulge Center").nearestKeyIndex(time);
            effObj.property("ADBE Bulge").property("Bulge Center").setInterpolationTypeAtKey(n, KeyframeInterpolationType.HOLD);
            n = effObj.property("ADBE Magnify").property("Center").nearestKeyIndex(time);
            effObj.property("ADBE Magnify").property("Center").setInterpolationTypeAtKey(n, KeyframeInterpolationType.HOLD);
            n = adjObj.property("Position").nearestKeyIndex(time);
            adjObj.property("Position").setInterpolationTypeAtKey(n, KeyframeInterpolationType.HOLD);
            n = circleObj.property("Position").nearestKeyIndex(time);
            circleObj.property("Position").setInterpolationTypeAtKey(n, KeyframeInterpolationType.HOLD);
        } else {
            n = effObj.property("ADBE Bulge").property("Bulge Center").nearestKeyIndex(time);
            effObj.property("ADBE Bulge").property("Bulge Center").setInterpolationTypeAtKey(n, KeyframeInterpolationType.BEZIER);
            effObj.property("ADBE Bulge").property("Bulge Center").setTemporalAutoBezierAtKey(n, KeyframeInterpolationType.BEZIER);
            n = effObj.property("ADBE Magnify").property("Center").nearestKeyIndex(time);
            effObj.property("ADBE Magnify").property("Center").setInterpolationTypeAtKey(n, KeyframeInterpolationType.BEZIER);
            effObj.property("ADBE Magnify").property("Center").setTemporalAutoBezierAtKey(n, KeyframeInterpolationType.BEZIER);
            n = adjObj.property("Position").nearestKeyIndex(time);
            adjObj.property("Position").setInterpolationTypeAtKey(n, KeyframeInterpolationType.BEZIER);
            adjObj.property("Position").setTemporalAutoBezierAtKey(n, KeyframeInterpolationType.BEZIER);
            n = circleObj.property("Position").nearestKeyIndex(time);
            circleObj.property("Position").setInterpolationTypeAtKey(n, KeyframeInterpolationType.BEZIER);
            circleObj.property("Position").setTemporalAutoBezierAtKey(n, KeyframeInterpolationType.BEZIER);
        }
        return;
     }
 
    function lookup_img_index(time)
    {
        var i;
        var start;
        var end;
        var scaling_factor;
        for (i=0; i<imgFile.length; i++) {
            start = imgFile[i][1];
            if (imgFile.length-1==i)
            {
                end = totalDuration;
            } else {
                end = imgFile[i+1][1];
            }
            if (time >= start && time < end)
            {
                return i;
            }
        }
        return 1;
    }
 
    function get_cmd(g)
    {
        var ret;
        ret = g.trim().toLowerCase();
        if (ret.length > 5)
        {
            if (ret.charAt(0) == 'g') {
                ret = ret.charAt(1);
                if (ret == '0' || ret == '1')
                {
                    return parseInt(ret);
                }
            }
        }
        return -1;
    }
 
    function trimSpaces() // remove spaces
	{
        var tSstr=this; // 'this' is only readable...
        while (tSstr.charAt(0) == ' ') tSstr = tSstr.substring(1);
        while (tSstr.charAt(tSstr.length - 1) == ' ') tSstr = tSstr.substring(0, tSstr.length - 1);
        return tSstr.toString(); // force stringtype. We'll get a lot of troubles if we return the object tSstr instead of the string.
	}
 
    function parseLine(pLq) // extract part after character pLq
    {
        var pLstr=this.toLowerCase(); // 'this' is only readable...
        if (pLstr.indexOf(pLq.toLowerCase()) == -1 ) return -1;
        while ( (pLstr.charAt(0) != pLq.toLowerCase()) && (pLstr.length>0)) pLstr = pLstr.substring(1);
        return pLstr.substring(1);
    }
 
    function countData() // count the amount of numbers in a string
    {
        var sq=false; // digit or dot qualifier
        var nd=0; // number of dots
        var cd=0; // number of consecutive digits or dots
        var nc=0; // number of numbers in a string
        if (this.length==0) return 0;
        var j=false;
        for (j=0; j<this.length; j++) // check for invalid characters or invalid structure
        {
            if (sq == false)
            {
                if ( ("0123456789.".indexOf(this.charAt(j)) ) != -1 )
                {
                    sq=true;
                    cd=0;
                    nd=0;
                    nc++;
                }
            }
 
            if (sq == true)
            {
                cd++;
                if (this.charAt(j) == ".") nd++;
                if (nd > 1) return -1; // cannot have two dots in a number
                if ( ("0123456789.".indexOf(this.charAt(j)) ) == -1 )
                {
                    if (1==cd && 1==nd) return -1;
                    sq=false;
                } else {
                    cd++;
                }
            }
        }
        return nc;
    }
 
	function getIndexedData(n) // will return the n-th number on this line (Where n starts from 1)
	{
        var sq=false; // digit or dot qualifier
        var nd; // number of dots
        var cd; // number of consecutive digits or dots
        var nc=0; // number of numbers in a string
        var sb; // string build of a number
        if (this.length==0) return 0;
        var j=false;
        for (j=0; j<this.length; j++) // check for invalid characters or invalid structure
        {
            if (sq == false)
            {
                if ( ("0123456789.".indexOf(this.charAt(j)) ) != -1 )
                {
                    sq=true;
                    cd=0;
                    nd=0;
                    nc++;
                    sb="";
                }
            }
 
            if (sq == true)
            {
                cd++;
                if (this.charAt(j) == ".") nd++;
                if (nd > 1) return -1; // cannot have two dots in a number
                if ( ("0123456789.".indexOf(this.charAt(j)) ) == -1 )
                {
                    if (1==cd && 1==nd) return -1;
                    sq=false;
                    if (nc == n) {
                    if (nd > 0) return parseFloat(sb);
                    return parseInt(sb);
                    }
                } else {
                    sb=sb+this.charAt(j);
                    cd++;
                }
            }
        }
        if (sq == true)
        {
            cd++;
            if (this.charAt(j) == ".") nd++;
            if (nd > 1) return -1; // cannot have two dots in a number
            if ( ("0123456789.".indexOf(this.charAt(j)) ) == -1 )
            {
                if (1==cd && 1==nd) return -1;
                sq=false;
                if (nc == j) {
                    if (nd > 0) return parseFloat(sb);
                    return parseInt(sb);
                }
            } else {
                sb=sb+this.charAt(j);
                if (nc == n) {
                    if (nd > 0) return parseFloat(sb);
                    return parseInt(sb);
                }
            }
        }
 
        return -1;
    }
 
    function quantize(otime)
    {
        return Math.floor(otime*compFrameRate)/compFrameRate;
    }
}

Generator.jsx

The code below finds all properties which belong to a selected effect. This helps finding out what property and value must be used for scripting. For using this script, create a composition containing only one effect, select this and run the script. It will output a txt file, which can be used for scripting.
Please note that the effect name can not be 100% correct. When it outputs 'Bulge', it may be necessary to use 'ADBE Bulge' instead.

//###############################################################################
//# Original file name: GenerateTFX.jsx
//# Generate EffectTemplateFile script
//# What it does basically:
//# Just creates a .tfx (effect template file; text file) from a certain selected
//# effect. The file helps finding out which property x and value y belongs to
//# effect z.
//#
//# Another purpose for a .tfx file is it can be read in directly with the Apply.tfx
//# script. Once read in adding this effect to a layer is very easy.
//###############################################################################
//# _The structure of a .tfx file is:_
//#
//# -Each line is seperated with cr/lf
//# -everything following a semicolon (;) is regarded as comment
//# -comment should be on a seperate line
//# -before all properties and data, there should be ADOBE_EffectName=
//#    for example: ADOBE_EffectName=Grain Surgery
//# -Effectproperties must start with "ADOBE_Property_" continued by a number and "="
//#    for example: ADOBE_Property_4=Width
//# -single values are written without brackets, just plain numbers
//#    for example: 1.523
//# -arrays are in the format [x,y,..,z]
//#    for example: [0.5,1.0,0.8]
//#
//# To have more insight, just produce one with the GenerateTFX script, and analyze it
//###############################################################################
//# Written in July 2005, by Marc Nijdam. Though probably lot's of useful code
//# from others can be found in here as well.
//# Updated in July 2015 to support After Effects CS 5.5
//###############################################################################
//# For reading out the following applies:
//# number of applied effects on this layer:
//# app.project.activeItem.selectedLayers[0]("Effects").numProperties;
//# name of first effect:
//# app.project.activeItem.selectedLayers[0]("Effects")(1).name;
//# number of properties from the (first) effect:
//# app.project.activeItem.selectedLayers[0]("Effects")(1).numProperties;
//# name of the i-th property from the (first) effect
//# app.project.activeItem.selectedLayers[0]("Effects")(1)(i).name;
//# query which kind of property from the i-th property this is
//# app.project.activeItem.selectedLayers[0]("Effects")(1)(i).propertyValueType;
//# possible values: PropertyValueType.NO_VALUE
//#                  PropertyValueType.TwoD_SPATIAL
//#                  PropertyValueType.TwoD
//#                  PropertyValueType.OneD
//#                  PropertyValueType.COLOR
//#                  PropertyValueType.CUSTOM_VALUE
//# number of elements in array from the i-th element (if it's an array)
//# app.project.activeItem.selectedLayers[0]("Effects")(1)(i).value.length;
//# Value from the i-th property; (if it ain't an array)
//# app.project.activeItem.selectedLayers[0]("Effects")(1)(i).value;
//# Value from the j-th array element from the i-th property (if an array it is)
//# app.project.activeItem.selectedLayers[0]("Effects")(1)(i).value[j];
//###############################################################################
{
// some kind of constants
   var _EFFSTR   = "ADOBE_Property_";
   var _EFFNAME   = "ADOBE_EffectName";
// variables
   var proj    = app.project;                  //set project
   var projClt    = proj.items;                  //list of items in project
   var projAi;
   var fileName;                        //output filename
   var thisLayer;
   var thisEffectsLayer;
   var thisEffect;
   var i;
   var j;
   if (proj)
   {
      if (proj.numItems != 0) // select the active item in the project window, make sure it's footage
      {
         projAi=proj.activeItem;
         if ( (projAi != null) && (projAi instanceof CompItem) && (projAi.selectedLayers.length == 1) )
         {
            thisLayer=projAi.selectedLayers[0];
            thisEffectsLayer=thisLayer("Effects");
            if (thisEffectsLayer != null) // this layer might have effects...
            {
                if (thisEffectsLayer.numProperties == 1)
                {
                    thisEffect=thisEffectsLayer(1); // Only one effect available, so it's safe to take the first
                    var TmpFile = new File("Selected_Effects_Info.txt");
                    var Fstr = TmpFile.saveDlg("Save");
                    if (Fstr != null)
                    {
                        Fstr.open("w","TEXT","????");
                        Fstr.writeln(_EFFNAME + "=" + thisEffect.name);
 
                        for (i = 1; i <= thisEffect.numProperties; i++) // iterate through all properties
                        {
                            if (thisEffect.property(i).name != "") // A
                            {
                                switch (thisEffect(i).propertyValueType)
                                {
                                    case PropertyValueType.NO_VALUE: // property without a value
                                    {
                                        Fstr.writeln(";*** " + thisEffect.property(i).name + " ***");
                                        Fstr.writeln(_EFFSTR + i + "=" + thisEffect.property(i).name);
                                        break;
                                    }
                                    case PropertyValueType.OneD: // property with a single value
                                    {
                                        Fstr.writeln(_EFFSTR + i + "=" + thisEffect(i).name);
                                        Fstr.writeln(thisEffect.property(i).value);
                                        break;
                                    }
                                    case PropertyValueType.TwoD: // property with an array
                                    {
                                        Fstr.writeln(_EFFSTR + i + "=" + thisEffect.property(i).name);
                                        str="[";
                                        for (j = 1; j < thisEffect.property(i).value.length ; j++)
                                        {
                                            str+=thisEffect.property(i).value[j-1] + ",";
                                        }
                                        str+=thisEffect.property(i).value[thisEffect.property(i).value.length-1] + "]";
                                        Fstr.writeln(str);
                                        break;
                                    }
                                    case PropertyValueType.TwoD_SPATIAL:
                                    {
                                        Fstr.writeln(_EFFSTR + i + "=" + thisEffect.property(i).name);
                                        str="[";
                                        for (j = 1; j < thisEffect.property(i).value.length ; j++)
                                        {
                                            str+=thisEffect.property(i).value[j-1] + ",";
                                        }
                                        str+=thisEffect.property(i).value[thisEffect.property(i).value.length-1] + "]";
                                        Fstr.writeln(str);
                                        break;
                                    }
                                    case PropertyValueType.ThreeD:
                                    {
                                        Fstr.writeln(_EFFSTR + i + "=" + thisEffect.property(i).name);
                                        str="[";
                                        for (j = 1; j < thisEffect.property(i).value.length ; j++)
                                        {
                                            str+=thisEffect.property(i).value[j-1] + ",";
                                        }
                                        str+=thisEffect.property(i).value[thisEffect.property(i).value.length-1] + "]";
                                        Fstr.writeln(str);
                                        break;
                                    }
                                    case PropertyValueType.ThreeD_SPATIAL:
                                    {
                                        Fstr.writeln(_EFFSTR + i + "=" + thisEffect.property(i).name);
                                        str="[";
                                        for (j = 1; j < thisEffect.property(i).value.length ; j++)
                                        {
                                            str+=thisEffect.property(i).value[j-1] + ",";
                                        }
                                        str+=thisEffect.property(i).value[thisEffect.property(i).value.length-1] + "]";
                                        Fstr.writeln(str);
                                        break;
                                    }
                                    case PropertyValueType.COLOR: // property with a color
                                    {
                                        Fstr.writeln(_EFFSTR + i + "=" + thisEffect.property(i).name);
                                        str="[";
                                        for (j = 1; j < thisEffect.property(i).value.length ; j++)
                                        {
                                            str+=thisEffect.property(i).value[j-1] + ",";
                                        }
                                        str+=thisEffect.property(i).value[thisEffect.property(i).value.length-1] + "]";
                                        Fstr.writeln(str);
                                        break;
                                    }
                                    case PropertyValueType.CUSTOM_VALUE: // property with a custom value
                                    {
                                        Fstr.writeln(_EFFSTR + i + "=" + thisEffect(i).name);
                                        break;
                                    }
                                    default:;
                                } // End of switch
                            } // End of A
                        }// End of For
                        Fstr.close();
                     } // End of if if Fstr == NULL
                     else
                     {
                        alert("Sorry, there had been a problem writing the file");
                     }
               }
               else
               {
                  alert("Sorry, this layer should have (only) one effect applied");
               }
            }
            else
            {
               alert("Sorry, this layer has no effect applied...");
            }
         }
         else
         {
            alert("select (only) one layer in a composition please...");
         }
      }
      else
      {
         alert("Can't process an empty project, please put some footage into it");
      }
   }
   else
   {
      alert("In order to use this script, Please create a project (with some footage)");
   }
}
software/sheetmusic_animator.txt · Last modified: 2017/09/02 14:15 by admin