/*
 * MATLAB Compiler: 3.0
 * Date: Mon Nov 03 13:00:57 2003
 * Arguments: "-B" "macro_default" "-O" "all" "-O" "fold_scalar_mxarrays:on"
 * "-O" "fold_non_scalar_mxarrays:on" "-O" "optimize_integer_for_loops:on" "-O"
 * "array_indexing:on" "-O" "optimize_conditionals:on" "-m" "-W" "main" "-L"
 * "C" "-t" "-T" "link:exe" "-h" "libmmfile.mlib" "DancingMonkeys" 
 */
#include "dancingmonkeys.h"
#include "mwservices.h"
#include "butter.h"
#include "hamming.h"
#include "kmkdir.h"
#include "libmatlbm.h"
#include "libmmfile.h"
#include "maximalcliques.h"
#include "prctile.h"
#include "wavread.h"
#include "wavwrite.h"

static mxChar _array1_[3] = { 'o', 'f', 'f' };
static mxArray * _mxarray0_;

static mxChar _array3_[43] = { 'D', 'a', 'n', 'c', 'i', 'n', 'g', ' ', 'M',
                               'o', 'n', 'k', 'e', 'y', 's', ' ', 'b', 'y',
                               ' ', 'K', 'a', 'r', 'l', ' ', 'O', 0x0027,
                               'K', 'e', 'e', 'f', 'f', 'e', ' ', '-', ' ',
                               '2', '8', '/', '0', '6', '/', '0', '3' };
static mxArray * _mxarray2_;

static mxChar _array5_[1] = { ' ' };
static mxArray * _mxarray4_;

static mxChar _array7_[14] = { 'A', 'r', 'g', 'u', 'm', 'e', 'n',
                               't', 's', ' ', 'a', 'r', 'e', ':' };
static mxArray * _mxarray6_;

static mxChar _array9_[48] = { ' ', ' ', ' ', ' ', '*', ' ', 'F', 'i', 'l', 'e',
                               'n', 'a', 'm', 'e', ' ', 'o', 'f', ' ', 'm', 'u',
                               's', 'i', 'c', ' ', 't', 'o', ' ', 'c', 'r', 'e',
                               'a', 't', 'e', ' ', 's', 't', 'e', 'p', ' ', 'f',
                               'i', 'l', 'e', ' ', 'f', 'o', 'r', '.' };
static mxArray * _mxarray8_;

static mxChar _array11_[45] = { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'e',
                                '.', 'g', '.', ' ', 'C', ':', 0x005c, 'M', 'u',
                                's', 'i', 'c', 0x005c, 'P', 'r', 'o', 'd', 'i',
                                'g', 'y', 0x005c, 'F', 'i', 'r', 'e', 's', 't',
                                'a', 'r', 't', 'e', 'r', '.', 'm', 'p', '3' };
static mxArray * _mxarray10_;

static mxChar _array13_[38] = { ' ', ' ', ' ', ' ', '*', ' ', 'E', 'a',
                                's', 'y', ' ', 'd', 'i', 'f', 'f', 'i',
                                'c', 'u', 'l', 't', 'y', ' ', 'r', 'a',
                                't', 'i', 'n', 'g', ' ', '(', 'i', 'n',
                                ' ', 'f', 'e', 'e', 't', ')' };
static mxArray * _mxarray12_;

static mxChar _array15_[40] = { ' ', ' ', ' ', ' ', '*', ' ', 'M', 'e',
                                'd', 'i', 'u', 'm', ' ', 'd', 'i', 'f',
                                'f', 'i', 'c', 'u', 'l', 't', 'y', ' ',
                                'r', 'a', 't', 'i', 'n', 'g', ' ', '(',
                                'i', 'n', ' ', 'f', 'e', 'e', 't', ')' };
static mxArray * _mxarray14_;

static mxChar _array17_[38] = { ' ', ' ', ' ', ' ', '*', ' ', 'H', 'a',
                                'r', 'd', ' ', 'd', 'i', 'f', 'f', 'i',
                                'c', 'u', 'l', 't', 'y', ' ', 'r', 'a',
                                't', 'i', 'n', 'g', ' ', '(', 'i', 'n',
                                ' ', 'f', 'e', 'e', 't', ')' };
static mxArray * _mxarray16_;

static mxChar _array19_[38] = { ' ', ' ', ' ', ' ', '*', ' ', 'D', 'i',
                                'r', 'e', 'c', 't', 'o', 'r', 'y', ' ',
                                't', 'o', ' ', 'o', 'u', 't', 'p', 'u',
                                't', ' ', 'r', 'e', 's', 'u', 'l', 't',
                                's', ' ', 'e', '.', 'g', '.' };
static mxArray * _mxarray18_;

static mxChar _array21_[54] = { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
                                'e', '.', 'g', '.', ' ', 'C', ':', 0x005c,
                                'S', 't', 'e', 'p', 'M', 'a', 'n', 'i',
                                'a', 0x005c, 'S', 'o', 'n', 'g', 's',
                                0x005c, 'D', 'a', 'n', 'c', 'i', 'n', 'g',
                                ' ', 'M', 'o', 'n', 'k', 'e', 'y', 's',
                                ' ', 'G', 'r', 'o', 'u', 'p', 0x005c };
static mxArray * _mxarray20_;
static mxArray * _mxarray22_;
static mxArray * _mxarray23_;
static mxArray * _mxarray24_;

static mxChar _array26_[13] = { '.', '.', 0x005c, '.', '.', 0x005c,
                                'O', 'u', 't', 'p', 'u', 't', 0x005c };
static mxArray * _mxarray25_;

static mxChar _array28_[19] = { '.', '.', 0x005c, '.', '.', 0x005c,
                                'L', 'a', 'm', 'e', 0x005c, 'L',
                                'a', 'm', 'e', '.', 'e', 'x', 'e' };
static mxArray * _mxarray27_;

static mxChar _array30_[30] = { '.', '.', 0x005c, '.', '.', 0x005c, 'T',
                                'e', 'm', 'p', ' ', 'M', 'u', 's', 'i',
                                'c', 0x005c, 'T', 'e', 'm', 'p', ' ',
                                'S', 'o', 'n', 'g', '.', 'w', 'a', 'v' };
static mxArray * _mxarray29_;
static mxArray * _mxarray31_;
static mxArray * _mxarray32_;
static mxArray * _mxarray33_;
static mxArray * _mxarray34_;
static mxArray * _mxarray35_;
static mxArray * _mxarray36_;
static mxArray * _mxarray37_;
static mxArray * _mxarray38_;
static mxArray * _mxarray39_;
static mxArray * _mxarray40_;
static mxArray * _mxarray41_;

static mxChar _array43_[5] = { 's', 't', 'e', 'p', 's' };
static mxArray * _mxarray42_;
static mxArray * _mxarray44_;
static mxArray * _mxarray45_;

static mxChar _array47_[4] = { 'f', 'i', 'l', 'e' };
static mxArray * _mxarray46_;

static mxChar _array49_[26] = { 'U', 'n', 'a', 'b', 'l', 'e', ' ', 't', 'o',
                                ' ', 'f', 'i', 'n', 'd', ' ', 'm', 'u', 's',
                                'i', 'c', ' ', 'f', 'i', 'l', 'e', '.' };
static mxArray * _mxarray48_;

static mxChar _array51_[32] = { 'U', 'n', 'a', 'b', 'l', 'e', ' ', 't',
                                'o', ' ', 'f', 'i', 'n', 'd', ' ', 'L',
                                'A', 'M', 'E', ' ', 'm', 'p', '3', ' ',
                                'd', 'e', 'c', 'o', 'd', 'e', 'r', '.' };
static mxArray * _mxarray50_;

static mxChar _array53_[4] = { '.', 'w', 'a', 'v' };
static mxArray * _mxarray52_;

static mxChar _array55_[1] = { 0x005c };
static mxArray * _mxarray54_;

static mxChar _array57_[12] = { 'I', 'n', 'i', 't', 'i', 'a',
                                'l', 'i', 's', 'e', 'd', '.' };
static mxArray * _mxarray56_;

static mxChar _array59_[4] = { '.', 'm', 'p', '3' };
static mxArray * _mxarray58_;

static mxChar _array61_[16] = { 0x005c, 'L', 'a', 'm', 'e', ' ', '-', '-',
                                'd', 'e', 'c', 'o', 'd', 'e', ' ', '"' };
static mxArray * _mxarray60_;

static mxChar _array63_[3] = { '"', ' ', '"' };
static mxArray * _mxarray62_;

static mxChar _array65_[1] = { '"' };
static mxArray * _mxarray64_;

static mxChar _array67_[21] = { 'E', 'r', 'r', 'o', 'r', ' ', 'd',
                                'e', 'c', 'o', 'd', 'i', 'n', 'g',
                                ' ', 'm', 'u', 's', 'i', 'c', '.' };
static mxArray * _mxarray66_;

static mxChar _array69_[17] = { 'u', 'n', 'k', 'n', 'o', 'w', 'n', ' ', 'e',
                                'x', 't', 'e', 'n', 's', 'i', 'o', 'n' };
static mxArray * _mxarray68_;

static mxChar _array71_[24] = { 'D', 'e', 'c', 'o', 'd', 'e', 'd', ' ',
                                'M', 'p', '3', ' ', '/', ' ', 'C', 'o',
                                'p', 'i', 'e', 'd', ' ', 'W', 'a', 'v' };
static mxArray * _mxarray70_;

static mxChar _array73_[4] = { 's', 'i', 'z', 'e' };
static mxArray * _mxarray72_;

static mxChar _array75_[12] = { 'L', 'o', 'a', 'd', 'e', 'd',
                                ' ', 's', 'o', 'n', 'g', '.' };
static mxArray * _mxarray74_;
static mxArray * _mxarray76_;
static mxArray * _mxarray77_;
static mxArray * _mxarray78_;

static mxChar _array80_[16] = { 'N', 'o', 'r', 'm', 'a', 'l', 'i', 's',
                                'e', 'd', ' ', 's', 'o', 'n', 'g', '.' };
static mxArray * _mxarray79_;

static mxChar _array82_[94] = { 'W', 'A', 'R', 'N', 'I', 'N', 'G', ':', ' ',
                                'U', 'n', 'a', 'b', 'l', 'e', ' ', 't', 'o',
                                ' ', 'O', 'u', 't', 'p', 'u', 't', ' ', 't',
                                'r', 'u', 'n', 'c', 'a', 't', 'e', 'd', ' ',
                                'v', 'e', 'r', 's', 'i', 'o', 'n', ' ', 'o',
                                'f', ' ', 's', 'o', 'n', 'g', '.', ' ', 'P',
                                'l', 'e', 'a', 's', 'e', ' ', 'c', 'o', 'p',
                                'y', ' ', 'o', 'r', 'i', 'g', 'i', 'n', 'a',
                                'l', ' ', 't', 'o', ' ', 'o', 'u', 't', 'p',
                                'u', 't', ' ', 'd', 'i', 'r', 'e', 'c', 't',
                                'o', 'r', 'y', '.' };
static mxArray * _mxarray81_;

static mxChar _array84_[36] = { 'O', 'u', 't', 'p', 'u', 't', 't', 'e', 'd',
                                ' ', 't', 'r', 'u', 'n', 'c', 'a', 't', 'e',
                                'd', ' ', 'n', 'o', 'r', 'm', 'a', 'l', 'i',
                                's', 'e', 'd', ' ', 's', 'o', 'n', 'g', '.' };
static mxArray * _mxarray83_;

static mxChar _array86_[12] = { 'M', 'o', 'n', 'o', 'e', 'd',
                                ' ', 's', 'o', 'n', 'g', '.' };
static mxArray * _mxarray85_;

static mxChar _array88_[14] = { 'S', 'm', 'o', 'o', 't', 'h', 'e',
                                'd', ' ', 's', 'o', 'n', 'g', '.' };
static mxArray * _mxarray87_;

static mxChar _array90_[34] = { 'N', 'o', 'r', 'm', 'a', 'l', 'i', 's', 'e',
                                'd', ' ', 'm', 'o', 'n', 'o', ' ', 'a', 'n',
                                'd', ' ', 's', 'm', 'o', 'o', 't', 'h', 'e',
                                'd', ' ', 'd', 'a', 't', 'a', '.' };
static mxArray * _mxarray89_;
static mxArray * _mxarray91_;

static mxChar _array93_[16] = { 'T', 'h', 'r', 'e', 's', 'h', 'o', 'l',
                                'd', 'e', 'd', ' ', 'd', 'a', 't', 'a' };
static mxArray * _mxarray92_;
static mxArray * _mxarray94_;

static mxChar _array96_[24] = { 'F', 'o', 'u', 'n', 'd', ' ', 'p', 'e',
                                'a', 'k', 's', ' ', 'a', 'n', 'd', ' ',
                                't', 'r', 'o', 'u', 'g', 'h', 's', '.' };
static mxArray * _mxarray95_;
static mxArray * _mxarray97_;

static mxChar _array99_[21] = { 'F', 'o', 'u', 'n', 'd', ' ', 'b',
                                'e', 'a', 't', ' ', 'p', 'o', 's',
                                'i', 't', 'i', 'o', 'n', 's', '.' };
static mxArray * _mxarray98_;

static mxChar _array101_[31] = { 'C', 'a', 'l', 'c', 'u', 'l', 'a', 't',
                                 'e', 'd', ' ', 'p', 'e', 'a', 'k', ' ',
                                 't', 'o', ' ', 'b', 'e', 'a', 't', ' ',
                                 'o', 'f', 'f', 's', 'e', 't', '.' };
static mxArray * _mxarray100_;
static mxArray * _mxarray102_;
static mxArray * _mxarray103_;
static mxArray * _mxarray104_;
static mxArray * _mxarray105_;

static mxChar _array107_[32] = { 'B', 'r', 'u', 't', 'e', ' ', 'f', 'o',
                                 'r', 'c', 'e', 'd', ' ', 't', 'h', 'e',
                                 ' ', 'i', 'n', 't', 'e', 'r', 'v', 'a',
                                 'l', ' ', 't', 'e', 's', 't', 's', '.' };
static mxArray * _mxarray106_;

static mxChar _array109_[23] = { 'C', 'a', 'l', 'c', 'u', 'a', 'l', 't',
                                 'e', 'd', ' ', 'G', 'a', 'p', ' ', 'a',
                                 'n', 'd', ' ', 'B', 'P', 'M', '.' };
static mxArray * _mxarray108_;

static mxChar _array111_[31] = { 'U', 'n', 'a', 'b', 'l', 'e', ' ', 't',
                                 'o', ' ', 'c', 'o', 'n', 'f', 'i', 'd',
                                 'e', 'n', 't', 'l', 'y', ' ', 'f', 'i',
                                 'n', 'd', ' ', 'B', 'P', 'M', '.' };
static mxArray * _mxarray110_;

static mxChar _array113_[17] = { 'C', 'a', 'l', 'c', 'u', 'l', 'a', 't', 'e',
                                 'd', ' ', 'E', 'n', 'e', 'r', 'g', 'y' };
static mxArray * _mxarray112_;
static mxArray * _mxarray114_;

static mxChar _array116_[26] = { ' ', '*', '*', '*', ' ', 'G', 'a', 'p', ' ',
                                 'h', 'a', 'l', 'f', ' ', 'b', 'e', 'a', 't',
                                 ' ', 'o', 'u', 't', ' ', '*', '*', '*' };
static mxArray * _mxarray115_;

static mxChar _array118_[24] = { 'C', 'o', 'm', 'p', 'u', 't', 'e', 'd',
                                 ' ', 'S', 'e', 'l', 'f', ' ', 'S', 'i',
                                 'm', 'i', 'l', 'a', 'r', 'i', 't', 'y' };
static mxArray * _mxarray117_;

static mxChar _array120_[26] = { 'C', 'a', 'l', 'c', 'u', 'l', 'a', 't', 'e',
                                 'd', ' ', 'B', 'a', 'r', ' ', 'S', 'i', 'm',
                                 'i', 'l', 'a', 'r', 'i', 't', 'y', '.' };
static mxArray * _mxarray119_;
static mxArray * _mxarray121_;

static mxChar _array123_[27] = { 'I', 'g', 'n', 'o', 'r', 'i', 'n', 'g', ' ',
                                 'a', ' ', 't', 'o', 'o', ' ', 'l', 'a', 'r',
                                 'g', 'e', ' ', 'c', 'l', 'i', 'q', 'u', 'e' };
static mxArray * _mxarray122_;

static mxChar _array125_[25] = { 'D', 'i', 'v', 'i', 'd', 'e', 'd', ' ', 's',
                                 'o', 'n', 'g', ' ', 'i', 'n', 't', 'o', ' ',
                                 'g', 'r', 'o', 'u', 'p', 's', '.' };
static mxArray * _mxarray124_;
static mxArray * _mxarray126_;
static mxArray * _mxarray127_;

static mxChar _array129_[13] = { 'F', 'o', 'u', 'n', 'd', ' ', 'p',
                                 'a', 'u', 's', 'e', 's', '.' };
static mxArray * _mxarray128_;
static mxArray * _mxarray130_;
static mxArray * _mxarray131_;

static mxChar _array133_[29] = { 'F', 'o', 'u', 'n', 'd', ' ', 'f', 'r',
                                 'e', 'e', 'z', 'e', ' ', 'a', 'r', 'r',
                                 'o', 'w', ' ', 'p', 'o', 's', 'i', 't',
                                 'i', 'o', 'n', 's', '.' };
static mxArray * _mxarray132_;

static double _array135_[9] = { 0.0, 0.0, 0.0, .2, .5, .6, .7, .8, .9 };
static mxArray * _mxarray134_;

static double _array137_[8] = { 107.0, 137.0, 170.0, 194.0,
                                228.0, 262.0, 305.0, 366.0 };
static mxArray * _mxarray136_;

static double _array139_[12] = { 1.0, 0.0, 1.0, 1.0, 1.0, 0.0,
                                 1.0, 1.0, 0.0, 0.0, 1.0, 2.0 };
static mxArray * _mxarray138_;

static double _array141_[12] = { 1.0, .1, 0.0, 1.0, 1.0, 0.0,
                                 1.0, 0.0, 1.0, 0.0, 1.0, 2.0 };
static mxArray * _mxarray140_;

static double _array143_[12] = { 1.0, 0.0, 1.0, 1.0, 1.0, 0.0,
                                 0.0, 1.0, 2.0, .1, 1.0, 0.0 };
static mxArray * _mxarray142_;

static double _array145_[12] = { 1.0, .1, 0.0, 1.0, 0.0, 1.0,
                                 1.0, 1.0, 0.0, 0.0, 1.0, 2.0 };
static mxArray * _mxarray144_;

static double _array147_[12] = { 1.0, 0.0, 1.0, 0.0, 1.0, 2.0,
                                 1.0, 1.0, 0.0, .1, 1.0, 0.0 };
static mxArray * _mxarray146_;

static double _array149_[12] = { 1.0, .1, 0.0, 1.0, 0.0, 1.0,
                                 0.0, 1.0, 2.0, .1, 1.0, 0.0 };
static mxArray * _mxarray148_;
static mxArray * _mxarray150_;

static double _array152_[12] = { 1.0, .1, 0.0, 0.0, 1.0, 2.0,
                                 1.0, 0.0, 1.0, .1, 1.0, 0.0 };
static mxArray * _mxarray151_;

static double _array154_[12] = { 1.0, 0.0, 0.0, 0.0, 1.0, 2.0,
                                 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 };
static mxArray * _mxarray153_;

static double _array156_[12] = { 1.0, 0.0, 0.0, 1.0, 0.0, 0.0,
                                 0.0, 1.0, 2.0, 0.0, 0.0, 1.0 };
static mxArray * _mxarray155_;

static double _array158_[12] = { 0.0, 0.0, 2.0, 0.0, 1.0, 0.0,
                                 1.0, 0.0, 1.0, 0.0, 1.0, 0.0 };
static mxArray * _mxarray157_;
static mxArray * _mxarray159_;

static double _array161_[12] = { 0.0, 0.0, 2.0, 0.0, 0.0, 1.0,
                                 1.0, 1.0, 0.0, 0.0, 1.0, 0.0 };
static mxArray * _mxarray160_;
static mxArray * _mxarray162_;

static double _array164_[4] = { 1.0, 0.0, 0.0, 2.0 };
static mxArray * _mxarray163_;
static mxArray * _mxarray165_;
static mxArray * _mxarray166_;
static mxArray * _mxarray167_;

static double _array169_[4] = { 0.0, 0.0, 0.0, 0.0 };
static mxArray * _mxarray168_;

static mxChar _array171_[23] = { 'N', 'o', ' ', 'p', 'o', 's', 's', 'i',
                                 'b', 'l', 'e', ' ', 'm', 'o', 'v', 'e',
                                 's', ' ', 'f', 'o', 'u', 'n', 'd' };
static mxArray * _mxarray170_;
static mxArray * _mxarray172_;

static double _array174_[4] = { 0.0, 1.0, 1.0, 0.0 };
static mxArray * _mxarray173_;

static double _array176_[4] = { 0.0, 1.0, 2.0, 0.0 };
static mxArray * _mxarray175_;

static double _array178_[4] = { 0.0, 2.0, 1.0, 0.0 };
static mxArray * _mxarray177_;

static double _array180_[4] = { 1.0, 0.0, 0.0, 1.0 };
static mxArray * _mxarray179_;

static double _array182_[4] = { 1.0, 1.0, 0.0, 0.0 };
static mxArray * _mxarray181_;

static double _array184_[4] = { 1.0, 2.0, 0.0, 0.0 };
static mxArray * _mxarray183_;

static double _array186_[4] = { 0.0, 0.0, 1.0, 1.0 };
static mxArray * _mxarray185_;

static double _array188_[4] = { 0.0, 0.0, 1.0, 2.0 };
static mxArray * _mxarray187_;

static double _array190_[4] = { 1.0, 0.0, 1.0, 0.0 };
static mxArray * _mxarray189_;

static double _array192_[4] = { 1.0, 0.0, 2.0, 0.0 };
static mxArray * _mxarray191_;

static double _array194_[4] = { 0.0, 1.0, 0.0, 1.0 };
static mxArray * _mxarray193_;

static double _array196_[4] = { 0.0, 1.0, 0.0, 2.0 };
static mxArray * _mxarray195_;
static mxArray * _mxarray197_;

static mxChar _array199_[13] = { 'F', 'o', 'o', 't', ' ', 'R', 'a',
                                 't', 'i', 'n', 'g', ':', ' ' };
static mxArray * _mxarray198_;

static mxChar _array201_[49] = { 'C', 'r', 'e', 'a', 't', 'e', 'd', ' ', 'a',
                                 'r', 'r', 'o', 'w', ' ', 'p', 'a', 't', 't',
                                 'e', 'r', 'n', 's', ' ', 'f', 'o', 'r', ' ',
                                 'e', 'a', 'c', 'h', ' ', 'd', 'i', 'f', 'f',
                                 'i', 'c', 'u', 'l', 't', 'y', ' ', 'l', 'e',
                                 'v', 'e', 'l', '.' };
static mxArray * _mxarray200_;

static mxChar _array203_[4] = { '.', 'd', 'w', 'i' };
static mxArray * _mxarray202_;

static mxChar _array205_[2] = { 'w', 't' };
static mxArray * _mxarray204_;

static mxChar _array207_[12] = { '#', 'T', 'I', 'T', 'L', 'E', ':',
                                 '%', 's', ';', 0x005c, 'n' };
static mxArray * _mxarray206_;

static mxChar _array209_[38] = { '#', 'A', 'R', 'T', 'I', 'S', 'T', ':',
                                 'T', 'h', 'e', ' ', 'D', 'a', 'n', 'c',
                                 'i', 'n', 'g', ' ', 'M', 'o', 'n', 'k',
                                 'e', 'y', 's', ' ', 'P', 'r', 'o', 'j',
                                 'e', 'c', 't', ';', 0x005c, 'n' };
static mxArray * _mxarray208_;

static mxChar _array211_[10] = { '#', 'G', 'A', 'P', ':', '%',
                                 'f', ';', 0x005c, 'n' };
static mxArray * _mxarray210_;

static mxChar _array213_[10] = { '#', 'B', 'P', 'M', ':', '%',
                                 'f', ';', 0x005c, 'n' };
static mxArray * _mxarray212_;

static mxChar _array215_[11] = { '#', 'F', 'I', 'L', 'E', ':',
                                 '%', 's', ';', 0x005c, 'n' };
static mxArray * _mxarray214_;

static mxChar _array217_[8] = { '#', 'F', 'R', 'E', 'E', 'Z', 'E', ':' };
static mxArray * _mxarray216_;

static mxChar _array219_[1] = { ',' };
static mxArray * _mxarray218_;

static mxChar _array221_[5] = { '%', 'd', '=', '%', 'd' };
static mxArray * _mxarray220_;

static mxChar _array223_[3] = { ';', 0x005c, 'n' };
static mxArray * _mxarray222_;

static mxChar _array225_[21] = { 0x005c, 'n', '/', '/', ' ', '-', '-',
                                 '-', ' ', 'A', 'r', 'r', 'o', 'w', 's',
                                 ' ', '-', '-', '-', 0x005c, 'n' };
static mxArray * _mxarray224_;

static mxChar _array229_[5] = { 'B', 'A', 'S', 'I', 'C' };
static mxArray * _mxarray228_;

static mxChar _array231_[7] = { 'A', 'N', 'O', 'T', 'H', 'E', 'R' };
static mxArray * _mxarray230_;

static mxChar _array233_[6] = { 'M', 'A', 'N', 'I', 'A', 'C' };
static mxArray * _mxarray232_;

static mxArray * _array227_[3] = { NULL /*_mxarray228_*/, NULL /*_mxarray230_*/,
                                   NULL /*_mxarray232_*/ };
static mxArray * _mxarray226_;

static mxChar _array235_[16] = { '#', 'S', 'I', 'N', 'G', 'L', 'E', ':', '%',
                                 's', ':', '%', 'd', ':', 0x005c, 'n' };
static mxArray * _mxarray234_;

static double _array237_[4] = { -1.0, -1.0, -1.0, -1.0 };
static mxArray * _mxarray236_;

static mxChar _array239_[1] = { '0' };
static mxArray * _mxarray238_;

static double _array241_[4] = { 1.0, 0.0, 0.0, 0.0 };
static mxArray * _mxarray240_;

static mxChar _array243_[1] = { '4' };
static mxArray * _mxarray242_;

static double _array245_[4] = { 0.0, 1.0, 0.0, 0.0 };
static mxArray * _mxarray244_;

static mxChar _array247_[1] = { '2' };
static mxArray * _mxarray246_;

static double _array249_[4] = { 0.0, 0.0, 1.0, 0.0 };
static mxArray * _mxarray248_;

static mxChar _array251_[1] = { '8' };
static mxArray * _mxarray250_;

static double _array253_[4] = { 0.0, 0.0, 0.0, 1.0 };
static mxArray * _mxarray252_;

static mxChar _array255_[1] = { '6' };
static mxArray * _mxarray254_;

static mxChar _array257_[1] = { 'B' };
static mxArray * _mxarray256_;

static mxChar _array259_[1] = { 'A' };
static mxArray * _mxarray258_;

static mxChar _array261_[1] = { '9' };
static mxArray * _mxarray260_;

static mxChar _array263_[1] = { '3' };
static mxArray * _mxarray262_;

static mxChar _array265_[1] = { '7' };
static mxArray * _mxarray264_;

static mxChar _array267_[1] = { '1' };
static mxArray * _mxarray266_;

static mxChar _array269_[2] = { '%', 'c' };
static mxArray * _mxarray268_;

static mxChar _array271_[3] = { '!', '%', 'c' };
static mxArray * _mxarray270_;

static mxChar _array273_[5] = { ';', 0x005c, 'n', 0x005c, 'n' };
static mxArray * _mxarray272_;

static mxChar _array275_[23] = { 'C', 'r', 'e', 'a', 't', 'e', 'd', ' ',
                                 '.', 'd', 'w', 'i', ' ', 's', 't', 'e',
                                 'p', ' ', 'f', 'i', 'l', 'e', '.' };
static mxArray * _mxarray274_;

static mxChar _array277_[3] = { '.', 's', 'm' };
static mxArray * _mxarray276_;

static mxChar _array279_[13] = { '#', 'O', 'F', 'F', 'S', 'E', 'T',
                                 ':', '%', 'f', ';', 0x005c, 'n' };
static mxArray * _mxarray278_;

static mxChar _array281_[13] = { '#', 'B', 'P', 'M', 'S', ':', '0',
                                 '=', '%', 'f', ';', 0x005c, 'n' };
static mxArray * _mxarray280_;

static mxChar _array283_[12] = { '#', 'M', 'U', 'S', 'I', 'C', ':',
                                 '%', 's', ';', 0x005c, 'n' };
static mxArray * _mxarray282_;

static mxChar _array285_[7] = { '#', 'S', 'T', 'O', 'P', 'S', ':' };
static mxArray * _mxarray284_;

static mxChar _array287_[5] = { '%', 'f', '=', '%', 'f' };
static mxArray * _mxarray286_;

static mxChar _array291_[5] = { 'B', 'a', 's', 'i', 'c' };
static mxArray * _mxarray290_;

static mxChar _array293_[8] = { 'S', 't', 'a', 'n', 'd', 'a', 'r', 'd' };
static mxArray * _mxarray292_;

static mxChar _array295_[5] = { 'H', 'e', 'a', 'v', 'y' };
static mxArray * _mxarray294_;

static mxChar _array297_[4] = { 'e', 'a', 's', 'y' };
static mxArray * _mxarray296_;

static mxChar _array299_[6] = { 'm', 'e', 'd', 'i', 'u', 'm' };
static mxArray * _mxarray298_;

static mxChar _array301_[4] = { 'h', 'a', 'r', 'd' };
static mxArray * _mxarray300_;

static mxArray * _array289_[6] = { NULL /*_mxarray290_*/, NULL /*_mxarray292_*/,
                                   NULL /*_mxarray294_*/, NULL /*_mxarray296_*/,
                                   NULL /*_mxarray298_*/,
                                   NULL /*_mxarray300_*/ };
static mxArray * _mxarray288_;

static mxChar _array303_[52] = { '#', 'N', 'O', 'T', 'E', 'S', ':', 0x005c,
                                 'n', 0x005c, 't', 'd', 'a', 'n', 'c', 'e',
                                 '-', 's', 'i', 'n', 'g', 'l', 'e', ':',
                                 0x005c, 'n', 0x005c, 't', '%', 's', ':',
                                 0x005c, 'n', 0x005c, 't', '%', 's', ':',
                                 0x005c, 'n', 0x005c, 't', '%', 'd', ':',
                                 0x005c, 'n', 0x005c, 't', ':', 0x005c, 'n' };
static mxArray * _mxarray302_;

static mxChar _array305_[10] = { '%', 'd', '%', 'd', '%', 'd',
                                 '%', 'd', 0x005c, 'n' };
static mxArray * _mxarray304_;

static mxChar _array307_[3] = { ',', 0x005c, 'n' };
static mxArray * _mxarray306_;

static mxChar _array309_[22] = { 'C', 'r', 'e', 'a', 't', 'e', 'd', ' ',
                                 '.', 's', 'm', ' ', 's', 't', 'e', 'p',
                                 ' ', 'f', 'i', 'l', 'e', '.' };
static mxArray * _mxarray308_;

static mxChar _array311_[9] = { 'R', 'e', 's', 'u', 'l', 't', 's', ':', ' ' };
static mxArray * _mxarray310_;

static mxChar _array313_[12] = { ' ', ' ', 'S', 'o', 'n', 'g',
                                 ' ', 'n', 'a', 'm', 'e', ':' };
static mxArray * _mxarray312_;

static mxChar _array315_[6] = { ' ', ' ', 'B', 'P', 'M', ':' };
static mxArray * _mxarray314_;

static mxChar _array317_[6] = { ' ', ' ', 'G', 'a', 'p', ':' };
static mxArray * _mxarray316_;

static mxChar _array319_[13] = { ' ', ' ', 'C', 'o', 'n', 'f', 'i',
                                 'd', 'e', 'n', 'c', 'e', ':' };
static mxArray * _mxarray318_;

void InitializeModule_dancingmonkeys(void) {
    _mxarray0_ = mclInitializeString(3, _array1_);
    _mxarray2_ = mclInitializeString(43, _array3_);
    _mxarray4_ = mclInitializeString(1, _array5_);
    _mxarray6_ = mclInitializeString(14, _array7_);
    _mxarray8_ = mclInitializeString(48, _array9_);
    _mxarray10_ = mclInitializeString(45, _array11_);
    _mxarray12_ = mclInitializeString(38, _array13_);
    _mxarray14_ = mclInitializeString(40, _array15_);
    _mxarray16_ = mclInitializeString(38, _array17_);
    _mxarray18_ = mclInitializeString(38, _array19_);
    _mxarray20_ = mclInitializeString(54, _array21_);
    _mxarray22_ = mclInitializeDouble(1.0);
    _mxarray23_ = mclInitializeDouble(3.0);
    _mxarray24_ = mclInitializeDouble(6.0);
    _mxarray25_ = mclInitializeString(13, _array26_);
    _mxarray27_ = mclInitializeString(19, _array28_);
    _mxarray29_ = mclInitializeString(30, _array30_);
    _mxarray31_ = mclInitializeDouble(10.0);
    _mxarray32_ = mclInitializeDouble(5.0);
    _mxarray33_ = mclInitializeDouble(90.0);
    _mxarray34_ = mclInitializeDouble(.01);
    _mxarray35_ = mclInitializeDouble(.7);
    _mxarray36_ = mclInitializeDouble(89.0);
    _mxarray37_ = mclInitializeDouble(205.0);
    _mxarray38_ = mclInitializeDouble(20.0);
    _mxarray39_ = mclInitializeDouble(8.0);
    _mxarray40_ = mclInitializeDouble(4.0);
    _mxarray41_ = mclInitializeDouble(2.0);
    _mxarray42_ = mclInitializeString(5, _array43_);
    _mxarray44_ = mclInitializeDouble(0.0);
    _mxarray45_ = mclInitializeDouble(105.0);
    _mxarray46_ = mclInitializeString(4, _array47_);
    _mxarray48_ = mclInitializeString(26, _array49_);
    _mxarray50_ = mclInitializeString(32, _array51_);
    _mxarray52_ = mclInitializeString(4, _array53_);
    _mxarray54_ = mclInitializeString(1, _array55_);
    _mxarray56_ = mclInitializeString(12, _array57_);
    _mxarray58_ = mclInitializeString(4, _array59_);
    _mxarray60_ = mclInitializeString(16, _array61_);
    _mxarray62_ = mclInitializeString(3, _array63_);
    _mxarray64_ = mclInitializeString(1, _array65_);
    _mxarray66_ = mclInitializeString(21, _array67_);
    _mxarray68_ = mclInitializeString(17, _array69_);
    _mxarray70_ = mclInitializeString(24, _array71_);
    _mxarray72_ = mclInitializeString(4, _array73_);
    _mxarray74_ = mclInitializeString(12, _array75_);
    _mxarray76_ = mclInitializeDouble(44100.0);
    _mxarray77_ = mclInitializeDouble(99.999);
    _mxarray78_ = mclInitializeDouble(-1.0);
    _mxarray79_ = mclInitializeString(16, _array80_);
    _mxarray81_ = mclInitializeString(94, _array82_);
    _mxarray83_ = mclInitializeString(36, _array84_);
    _mxarray85_ = mclInitializeString(12, _array86_);
    _mxarray87_ = mclInitializeString(14, _array88_);
    _mxarray89_ = mclInitializeString(34, _array90_);
    _mxarray91_ = mclInitializeDouble(100.0);
    _mxarray92_ = mclInitializeString(16, _array93_);
    _mxarray94_ = mclInitializeDouble(.5);
    _mxarray95_ = mclInitializeString(24, _array96_);
    _mxarray97_ = mclInitializeDoubleVector(0, 0, (double *)NULL);
    _mxarray98_ = mclInitializeString(21, _array99_);
    _mxarray100_ = mclInitializeString(31, _array101_);
    _mxarray102_ = mclInitializeDouble(60.0);
    _mxarray103_ = mclInitializeDouble(1000.0);
    _mxarray104_ = mclInitializeDouble(50.0);
    _mxarray105_ = mclInitializeDouble(9.0);
    _mxarray106_ = mclInitializeString(32, _array107_);
    _mxarray108_ = mclInitializeString(23, _array109_);
    _mxarray110_ = mclInitializeString(31, _array111_);
    _mxarray112_ = mclInitializeString(17, _array113_);
    _mxarray114_ = mclInitializeDouble(.001);
    _mxarray115_ = mclInitializeString(26, _array116_);
    _mxarray117_ = mclInitializeString(24, _array118_);
    _mxarray119_ = mclInitializeString(26, _array120_);
    _mxarray121_ = mclInitializeDouble(.9);
    _mxarray122_ = mclInitializeString(27, _array123_);
    _mxarray124_ = mclInitializeString(25, _array125_);
    _mxarray126_ = mclInitializeDouble(150.0);
    _mxarray127_ = mclInitializeDouble(65.0);
    _mxarray128_ = mclInitializeString(13, _array129_);
    _mxarray130_ = mclInitializeDouble(8e-05);
    _mxarray131_ = mclInitializeDouble(3000.0);
    _mxarray132_ = mclInitializeString(29, _array133_);
    _mxarray134_ = mclInitializeDoubleVector(1, 9, _array135_);
    _mxarray136_ = mclInitializeDoubleVector(1, 8, _array137_);
    _mxarray138_ = mclInitializeDoubleVector(3, 4, _array139_);
    _mxarray140_ = mclInitializeDoubleVector(3, 4, _array141_);
    _mxarray142_ = mclInitializeDoubleVector(3, 4, _array143_);
    _mxarray144_ = mclInitializeDoubleVector(3, 4, _array145_);
    _mxarray146_ = mclInitializeDoubleVector(3, 4, _array147_);
    _mxarray148_ = mclInitializeDoubleVector(3, 4, _array149_);
    _mxarray150_ = mclInitializeDouble(7.0);
    _mxarray151_ = mclInitializeDoubleVector(3, 4, _array152_);
    _mxarray153_ = mclInitializeDoubleVector(3, 4, _array154_);
    _mxarray155_ = mclInitializeDoubleVector(3, 4, _array156_);
    _mxarray157_ = mclInitializeDoubleVector(3, 4, _array158_);
    _mxarray159_ = mclInitializeDouble(11.0);
    _mxarray160_ = mclInitializeDoubleVector(3, 4, _array161_);
    _mxarray162_ = mclInitializeDouble(420.0);
    _mxarray163_ = mclInitializeDoubleVector(1, 4, _array164_);
    _mxarray165_ = mclInitializeDouble(.95);
    _mxarray166_ = mclInitializeDouble(.03);
    _mxarray167_ = mclInitializeDouble(.4);
    _mxarray168_ = mclInitializeDoubleVector(1, 4, _array169_);
    _mxarray170_ = mclInitializeString(23, _array171_);
    _mxarray172_ = mclInitializeDouble(.2);
    _mxarray173_ = mclInitializeDoubleVector(1, 4, _array174_);
    _mxarray175_ = mclInitializeDoubleVector(1, 4, _array176_);
    _mxarray177_ = mclInitializeDoubleVector(1, 4, _array178_);
    _mxarray179_ = mclInitializeDoubleVector(1, 4, _array180_);
    _mxarray181_ = mclInitializeDoubleVector(1, 4, _array182_);
    _mxarray183_ = mclInitializeDoubleVector(1, 4, _array184_);
    _mxarray185_ = mclInitializeDoubleVector(1, 4, _array186_);
    _mxarray187_ = mclInitializeDoubleVector(1, 4, _array188_);
    _mxarray189_ = mclInitializeDoubleVector(1, 4, _array190_);
    _mxarray191_ = mclInitializeDoubleVector(1, 4, _array192_);
    _mxarray193_ = mclInitializeDoubleVector(1, 4, _array194_);
    _mxarray195_ = mclInitializeDoubleVector(1, 4, _array196_);
    _mxarray197_ = mclInitializeDouble(.02);
    _mxarray198_ = mclInitializeString(13, _array199_);
    _mxarray200_ = mclInitializeString(49, _array201_);
    _mxarray202_ = mclInitializeString(4, _array203_);
    _mxarray204_ = mclInitializeString(2, _array205_);
    _mxarray206_ = mclInitializeString(12, _array207_);
    _mxarray208_ = mclInitializeString(38, _array209_);
    _mxarray210_ = mclInitializeString(10, _array211_);
    _mxarray212_ = mclInitializeString(10, _array213_);
    _mxarray214_ = mclInitializeString(11, _array215_);
    _mxarray216_ = mclInitializeString(8, _array217_);
    _mxarray218_ = mclInitializeString(1, _array219_);
    _mxarray220_ = mclInitializeString(5, _array221_);
    _mxarray222_ = mclInitializeString(3, _array223_);
    _mxarray224_ = mclInitializeString(21, _array225_);
    _mxarray228_ = mclInitializeString(5, _array229_);
    _array227_[0] = _mxarray228_;
    _mxarray230_ = mclInitializeString(7, _array231_);
    _array227_[1] = _mxarray230_;
    _mxarray232_ = mclInitializeString(6, _array233_);
    _array227_[2] = _mxarray232_;
    _mxarray226_ = mclInitializeCellVector(1, 3, _array227_);
    _mxarray234_ = mclInitializeString(16, _array235_);
    _mxarray236_ = mclInitializeDoubleVector(1, 4, _array237_);
    _mxarray238_ = mclInitializeString(1, _array239_);
    _mxarray240_ = mclInitializeDoubleVector(1, 4, _array241_);
    _mxarray242_ = mclInitializeString(1, _array243_);
    _mxarray244_ = mclInitializeDoubleVector(1, 4, _array245_);
    _mxarray246_ = mclInitializeString(1, _array247_);
    _mxarray248_ = mclInitializeDoubleVector(1, 4, _array249_);
    _mxarray250_ = mclInitializeString(1, _array251_);
    _mxarray252_ = mclInitializeDoubleVector(1, 4, _array253_);
    _mxarray254_ = mclInitializeString(1, _array255_);
    _mxarray256_ = mclInitializeString(1, _array257_);
    _mxarray258_ = mclInitializeString(1, _array259_);
    _mxarray260_ = mclInitializeString(1, _array261_);
    _mxarray262_ = mclInitializeString(1, _array263_);
    _mxarray264_ = mclInitializeString(1, _array265_);
    _mxarray266_ = mclInitializeString(1, _array267_);
    _mxarray268_ = mclInitializeString(2, _array269_);
    _mxarray270_ = mclInitializeString(3, _array271_);
    _mxarray272_ = mclInitializeString(5, _array273_);
    _mxarray274_ = mclInitializeString(23, _array275_);
    _mxarray276_ = mclInitializeString(3, _array277_);
    _mxarray278_ = mclInitializeString(13, _array279_);
    _mxarray280_ = mclInitializeString(13, _array281_);
    _mxarray282_ = mclInitializeString(12, _array283_);
    _mxarray284_ = mclInitializeString(7, _array285_);
    _mxarray286_ = mclInitializeString(5, _array287_);
    _mxarray290_ = mclInitializeString(5, _array291_);
    _array289_[0] = _mxarray290_;
    _mxarray292_ = mclInitializeString(8, _array293_);
    _array289_[1] = _mxarray292_;
    _mxarray294_ = mclInitializeString(5, _array295_);
    _array289_[2] = _mxarray294_;
    _mxarray296_ = mclInitializeString(4, _array297_);
    _array289_[3] = _mxarray296_;
    _mxarray298_ = mclInitializeString(6, _array299_);
    _array289_[4] = _mxarray298_;
    _mxarray300_ = mclInitializeString(4, _array301_);
    _array289_[5] = _mxarray300_;
    _mxarray288_ = mclInitializeCellVector(3, 2, _array289_);
    _mxarray302_ = mclInitializeString(52, _array303_);
    _mxarray304_ = mclInitializeString(10, _array305_);
    _mxarray306_ = mclInitializeString(3, _array307_);
    _mxarray308_ = mclInitializeString(22, _array309_);
    _mxarray310_ = mclInitializeString(9, _array311_);
    _mxarray312_ = mclInitializeString(12, _array313_);
    _mxarray314_ = mclInitializeString(6, _array315_);
    _mxarray316_ = mclInitializeString(6, _array317_);
    _mxarray318_ = mclInitializeString(13, _array319_);
}

void TerminateModule_dancingmonkeys(void) {
    mxDestroyArray(_mxarray318_);
    mxDestroyArray(_mxarray316_);
    mxDestroyArray(_mxarray314_);
    mxDestroyArray(_mxarray312_);
    mxDestroyArray(_mxarray310_);
    mxDestroyArray(_mxarray308_);
    mxDestroyArray(_mxarray306_);
    mxDestroyArray(_mxarray304_);
    mxDestroyArray(_mxarray302_);
    mxDestroyArray(_mxarray288_);
    mxDestroyArray(_mxarray300_);
    mxDestroyArray(_mxarray298_);
    mxDestroyArray(_mxarray296_);
    mxDestroyArray(_mxarray294_);
    mxDestroyArray(_mxarray292_);
    mxDestroyArray(_mxarray290_);
    mxDestroyArray(_mxarray286_);
    mxDestroyArray(_mxarray284_);
    mxDestroyArray(_mxarray282_);
    mxDestroyArray(_mxarray280_);
    mxDestroyArray(_mxarray278_);
    mxDestroyArray(_mxarray276_);
    mxDestroyArray(_mxarray274_);
    mxDestroyArray(_mxarray272_);
    mxDestroyArray(_mxarray270_);
    mxDestroyArray(_mxarray268_);
    mxDestroyArray(_mxarray266_);
    mxDestroyArray(_mxarray264_);
    mxDestroyArray(_mxarray262_);
    mxDestroyArray(_mxarray260_);
    mxDestroyArray(_mxarray258_);
    mxDestroyArray(_mxarray256_);
    mxDestroyArray(_mxarray254_);
    mxDestroyArray(_mxarray252_);
    mxDestroyArray(_mxarray250_);
    mxDestroyArray(_mxarray248_);
    mxDestroyArray(_mxarray246_);
    mxDestroyArray(_mxarray244_);
    mxDestroyArray(_mxarray242_);
    mxDestroyArray(_mxarray240_);
    mxDestroyArray(_mxarray238_);
    mxDestroyArray(_mxarray236_);
    mxDestroyArray(_mxarray234_);
    mxDestroyArray(_mxarray226_);
    mxDestroyArray(_mxarray232_);
    mxDestroyArray(_mxarray230_);
    mxDestroyArray(_mxarray228_);
    mxDestroyArray(_mxarray224_);
    mxDestroyArray(_mxarray222_);
    mxDestroyArray(_mxarray220_);
    mxDestroyArray(_mxarray218_);
    mxDestroyArray(_mxarray216_);
    mxDestroyArray(_mxarray214_);
    mxDestroyArray(_mxarray212_);
    mxDestroyArray(_mxarray210_);
    mxDestroyArray(_mxarray208_);
    mxDestroyArray(_mxarray206_);
    mxDestroyArray(_mxarray204_);
    mxDestroyArray(_mxarray202_);
    mxDestroyArray(_mxarray200_);
    mxDestroyArray(_mxarray198_);
    mxDestroyArray(_mxarray197_);
    mxDestroyArray(_mxarray195_);
    mxDestroyArray(_mxarray193_);
    mxDestroyArray(_mxarray191_);
    mxDestroyArray(_mxarray189_);
    mxDestroyArray(_mxarray187_);
    mxDestroyArray(_mxarray185_);
    mxDestroyArray(_mxarray183_);
    mxDestroyArray(_mxarray181_);
    mxDestroyArray(_mxarray179_);
    mxDestroyArray(_mxarray177_);
    mxDestroyArray(_mxarray175_);
    mxDestroyArray(_mxarray173_);
    mxDestroyArray(_mxarray172_);
    mxDestroyArray(_mxarray170_);
    mxDestroyArray(_mxarray168_);
    mxDestroyArray(_mxarray167_);
    mxDestroyArray(_mxarray166_);
    mxDestroyArray(_mxarray165_);
    mxDestroyArray(_mxarray163_);
    mxDestroyArray(_mxarray162_);
    mxDestroyArray(_mxarray160_);
    mxDestroyArray(_mxarray159_);
    mxDestroyArray(_mxarray157_);
    mxDestroyArray(_mxarray155_);
    mxDestroyArray(_mxarray153_);
    mxDestroyArray(_mxarray151_);
    mxDestroyArray(_mxarray150_);
    mxDestroyArray(_mxarray148_);
    mxDestroyArray(_mxarray146_);
    mxDestroyArray(_mxarray144_);
    mxDestroyArray(_mxarray142_);
    mxDestroyArray(_mxarray140_);
    mxDestroyArray(_mxarray138_);
    mxDestroyArray(_mxarray136_);
    mxDestroyArray(_mxarray134_);
    mxDestroyArray(_mxarray132_);
    mxDestroyArray(_mxarray131_);
    mxDestroyArray(_mxarray130_);
    mxDestroyArray(_mxarray128_);
    mxDestroyArray(_mxarray127_);
    mxDestroyArray(_mxarray126_);
    mxDestroyArray(_mxarray124_);
    mxDestroyArray(_mxarray122_);
    mxDestroyArray(_mxarray121_);
    mxDestroyArray(_mxarray119_);
    mxDestroyArray(_mxarray117_);
    mxDestroyArray(_mxarray115_);
    mxDestroyArray(_mxarray114_);
    mxDestroyArray(_mxarray112_);
    mxDestroyArray(_mxarray110_);
    mxDestroyArray(_mxarray108_);
    mxDestroyArray(_mxarray106_);
    mxDestroyArray(_mxarray105_);
    mxDestroyArray(_mxarray104_);
    mxDestroyArray(_mxarray103_);
    mxDestroyArray(_mxarray102_);
    mxDestroyArray(_mxarray100_);
    mxDestroyArray(_mxarray98_);
    mxDestroyArray(_mxarray97_);
    mxDestroyArray(_mxarray95_);
    mxDestroyArray(_mxarray94_);
    mxDestroyArray(_mxarray92_);
    mxDestroyArray(_mxarray91_);
    mxDestroyArray(_mxarray89_);
    mxDestroyArray(_mxarray87_);
    mxDestroyArray(_mxarray85_);
    mxDestroyArray(_mxarray83_);
    mxDestroyArray(_mxarray81_);
    mxDestroyArray(_mxarray79_);
    mxDestroyArray(_mxarray78_);
    mxDestroyArray(_mxarray77_);
    mxDestroyArray(_mxarray76_);
    mxDestroyArray(_mxarray74_);
    mxDestroyArray(_mxarray72_);
    mxDestroyArray(_mxarray70_);
    mxDestroyArray(_mxarray68_);
    mxDestroyArray(_mxarray66_);
    mxDestroyArray(_mxarray64_);
    mxDestroyArray(_mxarray62_);
    mxDestroyArray(_mxarray60_);
    mxDestroyArray(_mxarray58_);
    mxDestroyArray(_mxarray56_);
    mxDestroyArray(_mxarray54_);
    mxDestroyArray(_mxarray52_);
    mxDestroyArray(_mxarray50_);
    mxDestroyArray(_mxarray48_);
    mxDestroyArray(_mxarray46_);
    mxDestroyArray(_mxarray45_);
    mxDestroyArray(_mxarray44_);
    mxDestroyArray(_mxarray42_);
    mxDestroyArray(_mxarray41_);
    mxDestroyArray(_mxarray40_);
    mxDestroyArray(_mxarray39_);
    mxDestroyArray(_mxarray38_);
    mxDestroyArray(_mxarray37_);
    mxDestroyArray(_mxarray36_);
    mxDestroyArray(_mxarray35_);
    mxDestroyArray(_mxarray34_);
    mxDestroyArray(_mxarray33_);
    mxDestroyArray(_mxarray32_);
    mxDestroyArray(_mxarray31_);
    mxDestroyArray(_mxarray29_);
    mxDestroyArray(_mxarray27_);
    mxDestroyArray(_mxarray25_);
    mxDestroyArray(_mxarray24_);
    mxDestroyArray(_mxarray23_);
    mxDestroyArray(_mxarray22_);
    mxDestroyArray(_mxarray20_);
    mxDestroyArray(_mxarray18_);
    mxDestroyArray(_mxarray16_);
    mxDestroyArray(_mxarray14_);
    mxDestroyArray(_mxarray12_);
    mxDestroyArray(_mxarray10_);
    mxDestroyArray(_mxarray8_);
    mxDestroyArray(_mxarray6_);
    mxDestroyArray(_mxarray4_);
    mxDestroyArray(_mxarray2_);
    mxDestroyArray(_mxarray0_);
}

static void Mdancingmonkeys(mxArray * MusicFullFilename,
                            mxArray * EasyDifficulty,
                            mxArray * MedDifficulty,
                            mxArray * HardDifficulty,
                            mxArray * RootDirectory,
                            mxArray * LameFullFilename,
                            mxArray * TempFile);

_mexLocalFunctionTable _local_function_table_dancingmonkeys
  = { 0, (mexFunctionTableEntry *)NULL };

/*
 * The function "mlfDancingmonkeys" contains the normal interface for the
 * "dancingmonkeys" M-function from file "c:\matlab65\work\dancingmonkeys.m"
 * (lines 1-1328). This function processes any input arguments and passes them
 * to the implementation version of the function, appearing above.
 */
void mlfDancingmonkeys(mxArray * MusicFullFilename,
                       mxArray * EasyDifficulty,
                       mxArray * MedDifficulty,
                       mxArray * HardDifficulty,
                       mxArray * RootDirectory,
                       mxArray * LameFullFilename,
                       mxArray * TempFile) {
    mlfEnterNewContext(
      0,
      7,
      MusicFullFilename,
      EasyDifficulty,
      MedDifficulty,
      HardDifficulty,
      RootDirectory,
      LameFullFilename,
      TempFile);
    Mdancingmonkeys(
      MusicFullFilename,
      EasyDifficulty,
      MedDifficulty,
      HardDifficulty,
      RootDirectory,
      LameFullFilename,
      TempFile);
    mlfRestorePreviousContext(
      0,
      7,
      MusicFullFilename,
      EasyDifficulty,
      MedDifficulty,
      HardDifficulty,
      RootDirectory,
      LameFullFilename,
      TempFile);
}

/*
 * The function "mlxDancingmonkeys" contains the feval interface for the
 * "dancingmonkeys" M-function from file "c:\matlab65\work\dancingmonkeys.m"
 * (lines 1-1328). The feval function calls the implementation version of
 * dancingmonkeys through this function. This function processes any input
 * arguments and passes them to the implementation version of the function,
 * appearing above.
 */
void mlxDancingmonkeys(int nlhs, mxArray * plhs[], int nrhs, mxArray * prhs[]) {
    mxArray * mprhs[7];
    int i;
    if (nlhs > 0) {
        mlfError(
          mxCreateString(
            "Run-time Error: File: dancingmonkeys Line: 4 Colum"
            "n: 1 The function \"dancingmonkeys\" was called wi"
            "th more than the declared number of outputs (0)."),
          NULL);
    }
    if (nrhs > 7) {
        mlfError(
          mxCreateString(
            "Run-time Error: File: dancingmonkeys Line: 4 Colum"
            "n: 1 The function \"dancingmonkeys\" was called wi"
            "th more than the declared number of inputs (7)."),
          NULL);
    }
    for (i = 0; i < 7 && i < nrhs; ++i) {
        mprhs[i] = prhs[i];
    }
    for (; i < 7; ++i) {
        mprhs[i] = NULL;
    }
    mlfEnterNewContext(
      0,
      7,
      mprhs[0],
      mprhs[1],
      mprhs[2],
      mprhs[3],
      mprhs[4],
      mprhs[5],
      mprhs[6]);
    Mdancingmonkeys(
      mprhs[0], mprhs[1], mprhs[2], mprhs[3], mprhs[4], mprhs[5], mprhs[6]);
    mlfRestorePreviousContext(
      0,
      7,
      mprhs[0],
      mprhs[1],
      mprhs[2],
      mprhs[3],
      mprhs[4],
      mprhs[5],
      mprhs[6]);
}

/*
 * The function "Mdancingmonkeys" is the implementation version of the
 * "dancingmonkeys" M-function from file "c:\matlab65\work\dancingmonkeys.m"
 * (lines 1-1328). It contains the actual compiled code for that M-function. It
 * is a static function and must only be called from one of the interface
 * functions, appearing below.
 */
/*
 * % Dancing Monkeys Project
 * %   Karl O'Keeffe
 * 
 * function DancingMonkeys( MusicFullFilename, EasyDifficulty, MedDifficulty, HardDifficulty, RootDirectory, LameFullFilename, TempFile )
 */
static void Mdancingmonkeys(mxArray * MusicFullFilename,
                            mxArray * EasyDifficulty,
                            mxArray * MedDifficulty,
                            mxArray * HardDifficulty,
                            mxArray * RootDirectory,
                            mxArray * LameFullFilename,
                            mxArray * TempFile) {
    mexLocalFunctionTable save_local_function_table_
      = mclSetCurrentLocalFunctionTable(&_local_function_table_dancingmonkeys);
    int nargin_
      = mclNargin(
          7,
          MusicFullFilename,
          EasyDifficulty,
          MedDifficulty,
          HardDifficulty,
          RootDirectory,
          LameFullFilename,
          TempFile,
          NULL);
    mxArray * DifficultyNames = NULL;
    mxArray * Character = NULL;
    mxArray * ThisBeat = NULL;
    mxArray * DWIDifficultyNames = NULL;
    mxArray * fid = NULL;
    mxArray * FootRating = NULL;
    mxArray * CurrentBeat = NULL;
    mxArray * ChangeUpDownProbability = NULL;
    mxArray * ChangeLeftRightProbability = NULL;
    mxArray * ArrowIndex = NULL;
    mxArray * BarSection = NULL;
    mxArray * JumpType = NULL;
    mxArray * FreezeArrow = NULL;
    mxArray * NewArrow = NULL;
    mxArray * ProbMoves = NULL;
    mxArray * ct3 = NULL;
    mxArray * PossibleMoves = NULL;
    mxArray * ArrowType = NULL;
    mxArray * BarArrows = NULL;
    mxArray * PrevBeatEnergy = NULL;
    mxArray * FreezeOn = NULL;
    mxArray * NumArrowsToHave = NULL;
    mxArray * PlaceArrow = NULL;
    mxArray * BarFreezes = NULL;
    mxArray * BarEnergy = NULL;
    mxArray * BarModdedEnergy = NULL;
    mxArray * TempFreezes = NULL;
    mxArray * TempEnergy = NULL;
    mxArray * TempModdedEnergy = NULL;
    mxArray * SectionArrowData = NULL;
    mxArray * JumpThreshold = NULL;
    mxArray * InFreeze = NULL;
    mxArray * ArrowTrack = NULL;
    mxArray * FootPlacement = NULL;
    mxArray * CurrentFoot = NULL;
    mxArray * ct0 = NULL;
    mxArray * FullBarEnergy = NULL;
    mxArray * ModdedEnergy = NULL;
    mxArray * ArrowsPerBar = NULL;
    mxArray * NumArrows = NULL;
    mxArray * AvgArrowsPerLevel = NULL;
    mxArray * OffbeatModifier = NULL;
    mxArray * UserDifficultyRating = NULL;
    mxArray * ArrowSet = NULL;
    mxArray * FootRatings = NULL;
    mxArray * ArrowTracks = NULL;
    mxArray * ArrowTrackSize = NULL;
    mxArray * EnergyDiff = NULL;
    mxArray * AllowableMoves = NULL;
    mxArray * NumBars = NULL;
    mxArray * DifficultyRatings = NULL;
    mxArray * DifficultyOffbeatModifier = NULL;
    mxArray * FreezeBeats = NULL;
    mxArray * LongFreezes = NULL;
    mxArray * FreezeEnd = NULL;
    mxArray * WaveformEnd = NULL;
    mxArray * WaveformStart = NULL;
    mxArray * FreezeStarted = NULL;
    mxArray * Freezes = NULL;
    mxArray * A = NULL;
    mxArray * BarAbsoluteEnergy = NULL;
    mxArray * Pauses = NULL;
    mxArray * LastMajorEnergy = NULL;
    mxArray * FirstMajorEnergy = NULL;
    mxArray * PauseThreshold = NULL;
    mxArray * SimilarityOnBeats = NULL;
    mxArray * Next = NULL;
    mxArray * NodeInClique = NULL;
    mxArray * SelectedClique = NULL;
    mxArray * Index = NULL;
    mxArray * Junk = NULL;
    mxArray * X2 = NULL;
    mxArray * NextSection = NULL;
    mxArray * SimilarSections = NULL;
    mxArray * CliqueSize = NULL;
    mxArray * ThisClique = NULL;
    mxArray * CurrentMax = NULL;
    mxArray * Z = NULL;
    mxArray * BarStart = NULL;
    mxArray * BestBarStarts = NULL;
    mxArray * Pos2 = NULL;
    mxArray * Pos1 = NULL;
    mxArray * Num2 = NULL;
    mxArray * Num1 = NULL;
    mxArray * BarSimilarity = NULL;
    mxArray * FirstBarStart = NULL;
    mxArray * BarSizeInHalfBeats = NULL;
    mxArray * BarSimilarities = NULL;
    mxArray * PossibleBarStarts = NULL;
    mxArray * ct2 = NULL;
    mxArray * SelfSimilarity = NULL;
    mxArray * SizeBeatData = NULL;
    mxArray * BeatData = NULL;
    mxArray * Energy = NULL;
    mxArray * AbsoluteEnergy = NULL;
    mxArray * WindowNum = NULL;
    mxArray * BPM = NULL;
    mxArray * GapInSeconds = NULL;
    mxArray * GapInSamples = NULL;
    mxArray * Interval = NULL;
    mxArray * Confidence = NULL;
    mxArray * FitnessIndex = NULL;
    mxArray * NormalisedIntervalFitness = NULL;
    mxArray * X = NULL;
    mxArray * Range = NULL;
    mxArray * Y = NULL;
    mxArray * LookAt = NULL;
    mxArray * DoMoreWorkOn = NULL;
    mxArray * GapPeaks = NULL;
    mxArray * OffBeatValue = NULL;
    mxArray * OffbeatPos = NULL;
    mxArray * GapsConfidence = NULL;
    mxArray * xPos = NULL;
    mxArray * PosVal = NULL;
    mxArray * Centre = NULL;
    mxArray * Area = NULL;
    mxArray * GapsFiltered = NULL;
    mxArray * SortedIndex = NULL;
    mxArray * SortedGaps = NULL;
    mxArray * FullGaps = NULL;
    mxArray * ExtraGaps = NULL;
    mxArray * Gaps = NULL;
    mxArray * i = NULL;
    mxArray * NumBeats = NULL;
    mxArray * GapWindow = NULL;
    mxArray * HalfGapWindowSize = NULL;
    mxArray * IntervalGap = NULL;
    mxArray * IntervalFitness = NULL;
    mxArray * MinimumInterval = NULL;
    mxArray * MaximumInterval = NULL;
    mxArray * Beats = NULL;
    mxArray * Offset = NULL;
    mxArray * Offsets = NULL;
    mxArray * BeatPos = NULL;
    mxArray * Pos = NULL;
    mxArray * CandidatesPos = NULL;
    mxArray * Candidates = NULL;
    mxArray * Threshold = NULL;
    mxArray * TroughSize = NULL;
    mxArray * PeakSize = NULL;
    mxArray * HalfHeightWindow = NULL;
    mxArray * HeightWindow = NULL;
    mxArray * NearestTrough = NULL;
    mxArray * TroughsLessThanPeak = NULL;
    mxArray * Peak = NULL;
    mxArray * ct1 = NULL;
    mxArray * BeatPositions = NULL;
    mxArray * BeatStrengths = NULL;
    mxArray * Troughs = NULL;
    mxArray * Peaks = NULL;
    mxArray * IndexToPeakData = NULL;
    mxArray * IndexToNonZeroData = NULL;
    mxArray * NonZeroData = NULL;
    mxArray * PeakData = NULL;
    mxArray * Limit = NULL;
    mxArray * SortedData = NULL;
    mxArray * Window = NULL;
    mxArray * Position = NULL;
    mxArray * NormalisedSmoothData = NULL;
    mxArray * NormalisedMonoData = NULL;
    mxArray * WindowShape = NULL;
    mxArray * WindowSizeInSamples = NULL;
    mxArray * SmoothedData = NULL;
    mxArray * n = NULL;
    mxArray * m = NULL;
    mxArray * Mono = NULL;
    mxArray * NumTracks = NULL;
    mxArray * Mask = NULL;
    mxArray * SongLength = NULL;
    mxArray * NumBits = NULL;
    mxArray * SongData = NULL;
    mxArray * SongSizeLimit = NULL;
    mxArray * NumSamples = NULL;
    mxArray * Temp2 = NULL;
    mxArray * Frequency = NULL;
    mxArray * Temp1 = NULL;
    mxArray * Result = NULL;
    mxArray * Status = NULL;
    mxArray * OutputFullFilename = NULL;
    mxArray * OutputDirectory = NULL;
    mxArray * OutputFile = NULL;
    mxArray * MaxSongLengthInSeconds = NULL;
    mxArray * FadeSeconds = NULL;
    mxArray * StepFileFudgeFactor = NULL;
    mxArray * StepFilename = NULL;
    mxArray * BarsEndPadding = NULL;
    mxArray * BarsBeginningPadding = NULL;
    mxArray * BarSize = NULL;
    mxArray * MaxArrowsPerBar = NULL;
    mxArray * IntervalGradientLimit = NULL;
    mxArray * MaximumBPM = NULL;
    mxArray * MinimumBPM = NULL;
    mxArray * BeatPositioningThreshold = NULL;
    mxArray * HeightWindowSize = NULL;
    mxArray * PeakThreshold = NULL;
    mxArray * WindowLength = NULL;
    mxArray * SmoothingFilrerLowpassFrequency = NULL;
    mxArray * SmoothingFilterOrder = NULL;
    mxArray * LameExe = NULL;
    mxArray * LameFileExt = NULL;
    mxArray * LameFilename = NULL;
    mxArray * LamePath = NULL;
    mxArray * ChosenDifficultyRatings = NULL;
    mxArray * Temp = NULL;
    mxArray * FileExt = NULL;
    mxArray * FileName = NULL;
    mxArray * Directory = NULL;
    mxArray * ans = NULL;
    mclCopyArray(&MusicFullFilename);
    mclCopyArray(&EasyDifficulty);
    mclCopyArray(&MedDifficulty);
    mclCopyArray(&HardDifficulty);
    mclCopyArray(&RootDirectory);
    mclCopyArray(&LameFullFilename);
    mclCopyArray(&TempFile);
    /*
     * % Difficulty levels must be given as strings and not integers
     * 
     * % Remove warnings for things such as existing directories or clipped
     * % waveforms
     * warning off
     */
    mclPrintAns(&ans, mlfNWarning(0, NULL, _mxarray0_, NULL));
    /*
     * tic;
     */
    mlfTic();
    /*
     * 
     * if ( nargin < 1 )
     */
    if (nargin_ < 1) {
        /*
         * disp( 'Dancing Monkeys by Karl O''Keeffe - 28/06/03' );
         */
        mlfDisp(_mxarray2_);
        /*
         * disp( ' ' );
         */
        mlfDisp(_mxarray4_);
        /*
         * disp( 'Arguments are:' );
         */
        mlfDisp(_mxarray6_);
        /*
         * disp( '    * Filename of music to create step file for.' );
         */
        mlfDisp(_mxarray8_);
        /*
         * disp( '        e.g. C:\Music\Prodigy\Firestarter.mp3' );
         */
        mlfDisp(_mxarray10_);
        /*
         * disp( '    * Easy difficulty rating (in feet)' );
         */
        mlfDisp(_mxarray12_);
        /*
         * disp( '    * Medium difficulty rating (in feet)' );
         */
        mlfDisp(_mxarray14_);
        /*
         * disp( '    * Hard difficulty rating (in feet)' );
         */
        mlfDisp(_mxarray16_);
        /*
         * disp( '    * Directory to output results e.g.' );
         */
        mlfDisp(_mxarray18_);
        /*
         * disp( '        e.g. C:\StepMania\Songs\Dancing Monkeys Group\' );
         */
        mlfDisp(_mxarray20_);
        /*
         * return;
         */
        goto return_;
    /*
     * end
     */
    }
    /*
     * 
     * % Split music filename into parts
     * [ Directory , FileName , FileExt , Temp ] = Fileparts( MusicFullFilename );
     */
    mlfAssign(
      &Directory,
      mlfFileparts(
        &FileName,
        &FileExt,
        &Temp,
        mclVa(MusicFullFilename, "MusicFullFilename")));
    /*
     * 
     * % Randomly generate difficulty levels if they are not given
     * if ( nargin < 2 )
     */
    if (nargin_ < 2) {
        /*
         * EasyDifficulty = int2str( ceil( rand(1)*3 ) );
         */
        mlfAssign(
          &EasyDifficulty,
          mlfInt2str(
            mlfCeil(mclMtimes(mlfNRand(1, _mxarray22_, NULL), _mxarray23_))));
    /*
     * end
     */
    }
    /*
     * if ( nargin < 3 )
     */
    if (nargin_ < 3) {
        /*
         * MedDifficulty  = int2str( 3 + ceil( rand(1)*3 ) );
         */
        mlfAssign(
          &MedDifficulty,
          mlfInt2str(
            mclPlus(
              _mxarray23_,
              mlfCeil(
                mclMtimes(mlfNRand(1, _mxarray22_, NULL), _mxarray23_)))));
    /*
     * end
     */
    }
    /*
     * if ( nargin < 4 )
     */
    if (nargin_ < 4) {
        /*
         * HardDifficulty = int2str( 6 + ceil( rand(1)*3 ) );
         */
        mlfAssign(
          &HardDifficulty,
          mlfInt2str(
            mclPlus(
              _mxarray24_,
              mlfCeil(
                mclMtimes(mlfNRand(1, _mxarray22_, NULL), _mxarray23_)))));
    /*
     * end
     */
    }
    /*
     * 
     * ChosenDifficultyRatings = [ str2num( EasyDifficulty ), str2num(MedDifficulty), str2num(HardDifficulty) ];
     */
    mlfAssign(
      &ChosenDifficultyRatings,
      mlfHorzcat(
        mlfStr2num(NULL, mclVa(EasyDifficulty, "EasyDifficulty")),
        mlfStr2num(NULL, mclVa(MedDifficulty, "MedDifficulty")),
        mlfStr2num(NULL, mclVa(HardDifficulty, "HardDifficulty")),
        NULL));
    /*
     * 
     * if ( nargin < 5 )
     */
    if (nargin_ < 5) {
        /*
         * RootDirectory = '..\..\Output\';
         */
        mlfAssign(&RootDirectory, _mxarray25_);
    /*
     * end
     */
    }
    /*
     * 
     * if ( nargin < 6 )
     */
    if (nargin_ < 6) {
        /*
         * LameFullFilename = '..\..\Lame\Lame.exe';    
         */
        mlfAssign(&LameFullFilename, _mxarray27_);
    /*
     * end
     */
    }
    /*
     * [ LamePath , LameFilename , LameFileExt , Temp ] = Fileparts( LameFullFilename );
     */
    mlfAssign(
      &LamePath,
      mlfFileparts(
        &LameFilename,
        &LameFileExt,
        &Temp,
        mclVa(LameFullFilename, "LameFullFilename")));
    /*
     * LameExe = [ LameFilename LameFileExt ];
     */
    mlfAssign(
      &LameExe,
      mlfHorzcat(
        mclVv(LameFilename, "LameFilename"),
        mclVv(LameFileExt, "LameFileExt"),
        NULL));
    /*
     * 
     * if ( nargin < 7 )
     */
    if (nargin_ < 7) {
        /*
         * TempFile = '..\..\Temp Music\Temp Song.wav';        
         */
        mlfAssign(&TempFile, _mxarray29_);
    /*
     * end
     */
    }
    /*
     * 
     * % Constants
     * SmoothingFilterOrder = 3;               % Order for the smoothing filter.
     */
    mlfAssign(&SmoothingFilterOrder, _mxarray23_);
    /*
     * SmoothingFilrerLowpassFrequency = 10;   % Frequency above which to discard data.
     */
    mlfAssign(&SmoothingFilrerLowpassFrequency, _mxarray31_);
    /*
     * WindowLength = 5;                       % Length of the window used for normalising, in seconds.
     */
    mlfAssign(&WindowLength, _mxarray32_);
    /*
     * PeakThreshold = 90;                     % Threshold for throwing away data before peak picking, in percent.
     */
    mlfAssign(&PeakThreshold, _mxarray33_);
    /*
     * HeightWindowSize = 0.01;                % When estimating the height of a peak or through on the original waveform, this gives the size of window to use, in seconds.
     */
    mlfAssign(&HeightWindowSize, _mxarray34_);
    /*
     * BeatPositioningThreshold = 0.7;         % Between 0 and 1. How close to the calculated peak value the data must be to be considered the onset point.
     */
    mlfAssign(&BeatPositioningThreshold, _mxarray35_);
    /*
     * MinimumBPM = 89;                        % The minimum BPM value that will be tested.
     */
    mlfAssign(&MinimumBPM, _mxarray36_);
    /*
     * MaximumBPM = 205;                       % The maximum BPM value that will be tested.
     */
    mlfAssign(&MaximumBPM, _mxarray37_);
    /*
     * IntervalGradientLimit = 20;             % The maximum difference between values for gaps to be considered the same.
     */
    mlfAssign(&IntervalGradientLimit, _mxarray38_);
    /*
     * MaxArrowsPerBar = 8;                    % The number of arrows per bar.
     */
    mlfAssign(&MaxArrowsPerBar, _mxarray39_);
    /*
     * BarSize = 4;                            % The number of beats per bar.
     */
    mlfAssign(&BarSize, _mxarray40_);
    /*
     * BarsBeginningPadding = 2;               % The number of bars we should pad the beginning of the arrow track with.
     */
    mlfAssign(&BarsBeginningPadding, _mxarray41_);
    /*
     * BarsEndPadding = 1;                     % The number of bars we should pad the end of the arrow track with.
     */
    mlfAssign(&BarsEndPadding, _mxarray22_);
    /*
     * StepFilename = 'steps';                 % Name to output the step file.         
     */
    mlfAssign(&StepFilename, _mxarray42_);
    /*
     * StepFileFudgeFactor = 0;                % Amount to alter the gap value by, in seconds.
     */
    mlfAssign(&StepFileFudgeFactor, _mxarray44_);
    /*
     * FadeSeconds = 5;                        % How far from the end to start fading out the music
     */
    mlfAssign(&FadeSeconds, _mxarray32_);
    /*
     * MaxSongLengthInSeconds = 105;           % Maximum length of music in seconds
     */
    mlfAssign(&MaxSongLengthInSeconds, _mxarray45_);
    /*
     * 
     * 
     * % Check music file exists
     * if ( ~exist( MusicFullFilename, 'file' ) )
     */
    if (mclNotBool(
          mlfExist(
            mclVa(MusicFullFilename, "MusicFullFilename"), _mxarray46_))) {
        /*
         * error( 'Unable to find music file.' );    
         */
        mlfError(_mxarray48_, NULL);
    /*
     * end
     */
    }
    /*
     * 
     * % Check LAME decoder exists
     * if ( ~exist( LameFullFilename, 'file' ) )
     */
    if (mclNotBool(
          mlfExist(mclVa(LameFullFilename, "LameFullFilename"), _mxarray46_))) {
        /*
         * error( 'Unable to find LAME mp3 decoder.' );    
         */
        mlfError(_mxarray50_, NULL);
    /*
     * end
     */
    }
    /*
     * 
     * 
     * OutputFile = [ FileName '.wav' ];
     */
    mlfAssign(
      &OutputFile, mlfHorzcat(mclVv(FileName, "FileName"), _mxarray52_, NULL));
    /*
     * OutputDirectory = [ RootDirectory FileName '\' ];
     */
    mlfAssign(
      &OutputDirectory,
      mlfHorzcat(
        mclVa(RootDirectory, "RootDirectory"),
        mclVv(FileName, "FileName"),
        _mxarray54_,
        NULL));
    /*
     * 
     * % Create Output Directory
     * kmkdir( RootDirectory, FileName );
     */
    mclAssignAns(
      &ans,
      mlfNKmkdir(
        0,
        mclAnsVarargout(),
        mclVa(RootDirectory, "RootDirectory"),
        mclVv(FileName, "FileName"),
        NULL));
    /*
     * 
     * % Create filename
     * OutputFullFilename = strcat( OutputDirectory, OutputFile );
     */
    mlfAssign(
      &OutputFullFilename,
      mlfStrcat(
        mclVv(OutputDirectory, "OutputDirectory"),
        mclVv(OutputFile, "OutputFile"),
        NULL));
    /*
     * disp( 'Initialised.' );
     */
    mlfDisp(_mxarray56_);
    /*
     * 
     * 
     * % Decode Mp3
     * if ( strcmpi( FileExt, '.wav') ) 
     */
    if (mlfTobool(mlfStrcmpi(mclVv(FileExt, "FileExt"), _mxarray52_))) {
        /*
         * TempFile = MusicFullFilename;
         */
        mlfAssign(&TempFile, mclVa(MusicFullFilename, "MusicFullFilename"));
    /*
     * elseif ( strcmpi( FileExt, '.mp3') )
     */
    } else if (mlfTobool(mlfStrcmpi(mclVv(FileExt, "FileExt"), _mxarray58_))) {
        /*
         * %LastDirectory = cd;
         * %cd( LamePath );
         * [ Status  Result ] = dos( [ LamePath '\Lame --decode "' MusicFullFilename '" "' TempFile '"' ] );
         */
        mlfAssign(
          &Status,
          mlfDos(
            &Result,
            mlfHorzcat(
              mclVv(LamePath, "LamePath"),
              _mxarray60_,
              mclVa(MusicFullFilename, "MusicFullFilename"),
              _mxarray62_,
              mclVa(TempFile, "TempFile"),
              _mxarray64_,
              NULL),
            NULL));
        /*
         * 
         * if ( Status < 0 )
         */
        if (mclLtBool(mclVv(Status, "Status"), _mxarray44_)) {
            /*
             * error( 'Error decoding music.' );    
             */
            mlfError(_mxarray66_, NULL);
        /*
         * end
         */
        }
    /*
     * 
     * %cd( LastDirectory );
     * else
     */
    } else {
        /*
         * error( 'unknown extension' );    
         */
        mlfError(_mxarray68_, NULL);
    /*
     * end
     */
    }
    /*
     * disp( 'Decoded Mp3 / Copied Wav' );
     */
    mlfDisp(_mxarray70_);
    /*
     * 
     * % Get Frequency of Wav File
     * [ Temp1, Frequency, Temp2 ] = wavread( TempFile, 1 );
     */
    mlfAssign(
      &Temp1,
      mlfWavread(
        &Frequency, &Temp2, NULL, mclVa(TempFile, "TempFile"), _mxarray22_));
    /*
     * 
     * % Get Size of Wav File
     * Temp = wavread( TempFile, 'size' );
     */
    mlfAssign(
      &Temp,
      mlfWavread(NULL, NULL, NULL, mclVa(TempFile, "TempFile"), _mxarray72_));
    /*
     * NumSamples = Temp( 1 );
     */
    mlfAssign(&NumSamples, mclIntArrayRef1(mclVv(Temp, "Temp"), 1));
    /*
     * 
     * % Load wav file
     * SongSizeLimit = Frequency * MaxSongLengthInSeconds;
     */
    mlfAssign(
      &SongSizeLimit,
      mclMtimes(
        mclVv(Frequency, "Frequency"),
        mclVv(MaxSongLengthInSeconds, "MaxSongLengthInSeconds")));
    /*
     * [ SongData, Frequency, NumBits ] = wavread( TempFile, min( [SongSizeLimit NumSamples] ) );
     */
    mlfAssign(
      &SongData,
      mlfWavread(
        &Frequency,
        &NumBits,
        NULL,
        mclVa(TempFile, "TempFile"),
        mlfMin(
          NULL,
          mlfHorzcat(
            mclVv(SongSizeLimit, "SongSizeLimit"),
            mclVv(NumSamples, "NumSamples"),
            NULL),
          NULL,
          NULL)));
    /*
     * SongLength = size( SongData, 1 );
     */
    mlfAssign(
      &SongLength,
      mlfSize(mclValueVarargout(), mclVv(SongData, "SongData"), _mxarray22_));
    /*
     * disp( 'Loaded song.' )
     */
    mlfDisp(_mxarray74_);
    /*
     * 
     * % If we had to truncate the song fade it out at the end
     * if ( SongLength == SongSizeLimit )
     */
    if (mclEqBool(
          mclVv(SongLength, "SongLength"),
          mclVv(SongSizeLimit, "SongSizeLimit"))) {
        /*
         * Mask(:,1) = [1:-(1/((44100 * FadeSeconds) - 1)):0]';
         */
        mclArrayAssign2(
          &Mask,
          mlfCtranspose(
            mlfColon(
              _mxarray22_,
              mclUminus(
                mclMrdivide(
                  _mxarray22_,
                  mclMinus(
                    mclMtimes(_mxarray76_, mclVv(FadeSeconds, "FadeSeconds")),
                    _mxarray22_))),
              _mxarray44_)),
          mlfCreateColonIndex(),
          _mxarray22_);
        /*
         * Mask(:, size(SongData, 2 ) ) = Mask(:,1);             % Need to fix for possible greater than 2 tracks.
         */
        mclArrayAssign2(
          &Mask,
          mclArrayRef2(mclVv(Mask, "Mask"), mlfCreateColonIndex(), _mxarray22_),
          mlfCreateColonIndex(),
          mlfSize(
            mclValueVarargout(), mclVv(SongData, "SongData"), _mxarray41_));
        /*
         * SongData( end - ((44100 * FadeSeconds) - 1):end, : ) = SongData( end - ((44100 * FadeSeconds) - 1):end, : ) .* Mask;
         */
        mclArrayAssign2(
          &SongData,
          mclTimes(
            mclArrayRef2(
              mclVv(SongData, "SongData"),
              mlfColon(
                mclMinus(
                  mlfEnd(mclVv(SongData, "SongData"), _mxarray22_, _mxarray41_),
                  mclMinus(
                    mclMtimes(_mxarray76_, mclVv(FadeSeconds, "FadeSeconds")),
                    _mxarray22_)),
                mlfEnd(mclVv(SongData, "SongData"), _mxarray22_, _mxarray41_),
                NULL),
              mlfCreateColonIndex()),
            mclVv(Mask, "Mask")),
          mlfColon(
            mclMinus(
              mlfEnd(mclVv(SongData, "SongData"), _mxarray22_, _mxarray41_),
              mclMinus(
                mclMtimes(_mxarray76_, mclVv(FadeSeconds, "FadeSeconds")),
                _mxarray22_)),
            mlfEnd(mclVv(SongData, "SongData"), _mxarray22_, _mxarray41_),
            NULL),
          mlfCreateColonIndex());
    /*
     * end
     */
    }
    /*
     * 
     * % Normalise Song
     * SongData = SongData ./ prctile( abs( SongData(:) ), 99.999 );
     */
    mlfAssign(
      &SongData,
      mclRdivide(
        mclVv(SongData, "SongData"),
        mlfPrctile(
          mlfAbs(
            mclArrayRef1(mclVv(SongData, "SongData"), mlfCreateColonIndex())),
          _mxarray77_)));
    /*
     * SongData( SongData > 1 ) = 1;
     */
    mclArrayAssign1(
      &SongData, _mxarray22_, mclGt(mclVv(SongData, "SongData"), _mxarray22_));
    /*
     * SongData( SongData < -1 ) = -1;
     */
    mclArrayAssign1(
      &SongData, _mxarray78_, mclLt(mclVv(SongData, "SongData"), _mxarray78_));
    /*
     * disp( 'Normalised song.' );
     */
    mlfDisp(_mxarray79_);
    /*
     * 
     * % Output the new shorter song to the StepMania or DWI songs directory
     * try
     */
    mlfTry {
        /*
         * wavwrite( SongData, Frequency, NumBits, OutputFullFilename );
         */
        mlfWavwrite(
          mclVv(SongData, "SongData"),
          mclVv(Frequency, "Frequency"),
          mclVv(NumBits, "NumBits"),
          mclVv(OutputFullFilename, "OutputFullFilename"));
    /*
     * catch
     */
    } mlfCatch {
        /*
         * disp( 'WARNING: Unable to Output truncated version of song. Please copy original to output directory.' );
         */
        mlfDisp(_mxarray81_);
    /*
     * end
     */
    } mlfEndCatch
    /*
     * disp( 'Outputted truncated normalised song.' );
     */
    mlfDisp(_mxarray83_);
    /*
     * 
     * % Convert song to mono
     * NumTracks = size( SongData, 2 );
     */
    mlfAssign(
      &NumTracks,
      mlfSize(mclValueVarargout(), mclVv(SongData, "SongData"), _mxarray41_));
    /*
     * Mono = sum( SongData' ./ NumTracks, 1 )';
     */
    mlfAssign(
      &Mono,
      mlfCtranspose(
        mlfSum(
          mclRdivide(
            mlfCtranspose(mclVv(SongData, "SongData")),
            mclVv(NumTracks, "NumTracks")),
          _mxarray22_)));
    /*
     * SongLength = size( SongData, 1 );
     */
    mlfAssign(
      &SongLength,
      mlfSize(mclValueVarargout(), mclVv(SongData, "SongData"), _mxarray22_));
    /*
     * disp( 'Monoed song.' )
     */
    mlfDisp(_mxarray85_);
    /*
     * 
     * 
     * % Lowpass filter the song. This removes any high frequency data, and makes 
     * % it possible to peak pick the data.
     * 
     * % Create the Butterworth lowpass filter.
     * [m,n] = butter( SmoothingFilterOrder, SmoothingFilrerLowpassFrequency * 2 / Frequency );
     */
    mlfAssign(
      &m,
      mlfNButter(
        2,
        &n,
        NULL,
        NULL,
        mclVv(SmoothingFilterOrder, "SmoothingFilterOrder"),
        mclMrdivide(
          mclMtimes(
            mclVv(
              SmoothingFilrerLowpassFrequency,
              "SmoothingFilrerLowpassFrequency"),
            _mxarray41_),
          mclVv(Frequency, "Frequency")),
        NULL));
    /*
     * 
     * % Filter the data both forwards and backwards in order to remove the phase
     * % shifts generated by filtering.
     * SmoothedData = filter( m, n, abs( Mono ) );
     */
    mlfAssign(
      &SmoothedData,
      mlfFilter(
        NULL,
        mclVv(m, "m"),
        mclVv(n, "n"),
        mlfAbs(mclVv(Mono, "Mono")),
        NULL,
        NULL));
    /*
     * disp( 'Smoothed song.' );
     */
    mlfDisp(_mxarray87_);
    /*
     * 
     * 
     * % Normalise the mono and smoothed song data. This is done by taking hamming windows along
     * % the mono and smoothed data and normalising each window to a peak of amplitude
     * % 1. The windows are then added back together to make a normalied version 
     * % of the smoothed data. This allows for more robust peak picking.
     * 
     * % Length of window in seconds. Windows overlap by half the length of a
     * % window.
     * WindowSizeInSamples = round( WindowLength * Frequency );
     */
    mlfAssign(
      &WindowSizeInSamples,
      mlfRound(
        mclMtimes(
          mclVv(WindowLength, "WindowLength"), mclVv(Frequency, "Frequency"))));
    /*
     * WindowShape = hamming( WindowSizeInSamples );
     */
    mlfAssign(
      &WindowShape,
      mlfHamming(mclVv(WindowSizeInSamples, "WindowSizeInSamples"), NULL));
    /*
     * 
     * % Create blank versions of the normalised data.
     * NormalisedMonoData   = zeros( size( Mono ) );
     */
    mlfAssign(
      &NormalisedMonoData,
      mlfZeros(mlfSize(mclValueVarargout(), mclVv(Mono, "Mono"), NULL), NULL));
    /*
     * NormalisedSmoothData = zeros( size( Mono ) );
     */
    mlfAssign(
      &NormalisedSmoothData,
      mlfZeros(mlfSize(mclValueVarargout(), mclVv(Mono, "Mono"), NULL), NULL));
    /*
     * 
     * % Loop through each window, moving the start point of by the length of half
     * % a window each time.
     * Position = 1;
     */
    mlfAssign(&Position, _mxarray22_);
    /*
     * while ( Position + WindowSizeInSamples < SongLength )
     */
    while (mclLtBool(
             mclPlus(
               mclVv(Position, "Position"),
               mclVv(WindowSizeInSamples, "WindowSizeInSamples")),
             mclVv(SongLength, "SongLength"))) {
        /*
         * % We take the absolute value of the window in order to half wave
         * % rectify the mono data. The smoothed data is already rectified.
         * Window = abs( Mono( Position:(Position+WindowSizeInSamples)-1 ) );
         */
        mlfAssign(
          &Window,
          mlfAbs(
            mclArrayRef1(
              mclVv(Mono, "Mono"),
              mlfColon(
                mclVv(Position, "Position"),
                mclMinus(
                  mclPlus(
                    mclVv(Position, "Position"),
                    mclVv(WindowSizeInSamples, "WindowSizeInSamples")),
                  _mxarray22_),
                NULL))));
        /*
         * Window = Window ./ max( Window );
         */
        mlfAssign(
          &Window,
          mclRdivide(
            mclVv(Window, "Window"),
            mlfMax(NULL, mclVv(Window, "Window"), NULL, NULL)));
        /*
         * NormalisedMonoData( Position:(Position+WindowSizeInSamples)-1 )   = NormalisedMonoData( Position:(Position+WindowSizeInSamples)-1 )   + (Window .* WindowShape);
         */
        mclArrayAssign1(
          &NormalisedMonoData,
          mclPlus(
            mclArrayRef1(
              mclVv(NormalisedMonoData, "NormalisedMonoData"),
              mlfColon(
                mclVv(Position, "Position"),
                mclMinus(
                  mclPlus(
                    mclVv(Position, "Position"),
                    mclVv(WindowSizeInSamples, "WindowSizeInSamples")),
                  _mxarray22_),
                NULL)),
            mclTimes(
              mclVv(Window, "Window"), mclVv(WindowShape, "WindowShape"))),
          mlfColon(
            mclVv(Position, "Position"),
            mclMinus(
              mclPlus(
                mclVv(Position, "Position"),
                mclVv(WindowSizeInSamples, "WindowSizeInSamples")),
              _mxarray22_),
            NULL));
        /*
         * 
         * Window = SmoothedData( Position:(Position+WindowSizeInSamples)-1 );
         */
        mlfAssign(
          &Window,
          mclArrayRef1(
            mclVv(SmoothedData, "SmoothedData"),
            mlfColon(
              mclVv(Position, "Position"),
              mclMinus(
                mclPlus(
                  mclVv(Position, "Position"),
                  mclVv(WindowSizeInSamples, "WindowSizeInSamples")),
                _mxarray22_),
              NULL)));
        /*
         * Window = Window ./ max( Window );
         */
        mlfAssign(
          &Window,
          mclRdivide(
            mclVv(Window, "Window"),
            mlfMax(NULL, mclVv(Window, "Window"), NULL, NULL)));
        /*
         * NormalisedSmoothData( Position:(Position+WindowSizeInSamples)-1 ) = NormalisedSmoothData( Position:(Position+WindowSizeInSamples)-1 ) + (Window .* WindowShape);
         */
        mclArrayAssign1(
          &NormalisedSmoothData,
          mclPlus(
            mclArrayRef1(
              mclVv(NormalisedSmoothData, "NormalisedSmoothData"),
              mlfColon(
                mclVv(Position, "Position"),
                mclMinus(
                  mclPlus(
                    mclVv(Position, "Position"),
                    mclVv(WindowSizeInSamples, "WindowSizeInSamples")),
                  _mxarray22_),
                NULL)),
            mclTimes(
              mclVv(Window, "Window"), mclVv(WindowShape, "WindowShape"))),
          mlfColon(
            mclVv(Position, "Position"),
            mclMinus(
              mclPlus(
                mclVv(Position, "Position"),
                mclVv(WindowSizeInSamples, "WindowSizeInSamples")),
              _mxarray22_),
            NULL));
        /*
         * 
         * Position = Position + ( WindowSizeInSamples / 2 );
         */
        mlfAssign(
          &Position,
          mclPlus(
            mclVv(Position, "Position"),
            mclMrdivide(
              mclVv(WindowSizeInSamples, "WindowSizeInSamples"), _mxarray41_)));
    /*
     * end
     */
    }
    /*
     * 
     * % At the end of the song we can't fit the full length of a window so just
     * % multiply by the part of the window shape that will fit.
     * Window = Mono( Position:SongLength );
     */
    mlfAssign(
      &Window,
      mclArrayRef1(
        mclVv(Mono, "Mono"),
        mlfColon(
          mclVv(Position, "Position"), mclVv(SongLength, "SongLength"), NULL)));
    /*
     * Window = Window ./ max( Window );
     */
    mlfAssign(
      &Window,
      mclRdivide(
        mclVv(Window, "Window"),
        mlfMax(NULL, mclVv(Window, "Window"), NULL, NULL)));
    /*
     * NormalisedMonoData( Position:SongLength )   = NormalisedMonoData( Position:SongLength )   + ( Window .* WindowShape( 1:(SongLength - Position) + 1 ) );
     */
    mclArrayAssign1(
      &NormalisedMonoData,
      mclPlus(
        mclArrayRef1(
          mclVv(NormalisedMonoData, "NormalisedMonoData"),
          mlfColon(
            mclVv(Position, "Position"),
            mclVv(SongLength, "SongLength"),
            NULL)),
        mclTimes(
          mclVv(Window, "Window"),
          mclArrayRef1(
            mclVv(WindowShape, "WindowShape"),
            mlfColon(
              _mxarray22_,
              mclPlus(
                mclMinus(
                  mclVv(SongLength, "SongLength"), mclVv(Position, "Position")),
                _mxarray22_),
              NULL)))),
      mlfColon(
        mclVv(Position, "Position"), mclVv(SongLength, "SongLength"), NULL));
    /*
     * 
     * Window = SmoothedData( Position:SongLength );
     */
    mlfAssign(
      &Window,
      mclArrayRef1(
        mclVv(SmoothedData, "SmoothedData"),
        mlfColon(
          mclVv(Position, "Position"), mclVv(SongLength, "SongLength"), NULL)));
    /*
     * Window = Window ./ max( Window );
     */
    mlfAssign(
      &Window,
      mclRdivide(
        mclVv(Window, "Window"),
        mlfMax(NULL, mclVv(Window, "Window"), NULL, NULL)));
    /*
     * NormalisedSmoothData( Position:SongLength ) = NormalisedSmoothData( Position:SongLength ) + ( Window .* WindowShape( 1:(SongLength - Position) + 1 ) );
     */
    mclArrayAssign1(
      &NormalisedSmoothData,
      mclPlus(
        mclArrayRef1(
          mclVv(NormalisedSmoothData, "NormalisedSmoothData"),
          mlfColon(
            mclVv(Position, "Position"),
            mclVv(SongLength, "SongLength"),
            NULL)),
        mclTimes(
          mclVv(Window, "Window"),
          mclArrayRef1(
            mclVv(WindowShape, "WindowShape"),
            mlfColon(
              _mxarray22_,
              mclPlus(
                mclMinus(
                  mclVv(SongLength, "SongLength"), mclVv(Position, "Position")),
                _mxarray22_),
              NULL)))),
      mlfColon(
        mclVv(Position, "Position"), mclVv(SongLength, "SongLength"), NULL));
    /*
     * 
     * 
     * NormalisedMonoData   = NormalisedMonoData   ./ max( NormalisedMonoData   );
     */
    mlfAssign(
      &NormalisedMonoData,
      mclRdivide(
        mclVv(NormalisedMonoData, "NormalisedMonoData"),
        mlfMax(
          NULL, mclVv(NormalisedMonoData, "NormalisedMonoData"), NULL, NULL)));
    /*
     * NormalisedSmoothData = NormalisedSmoothData ./ max( NormalisedSmoothData );
     */
    mlfAssign(
      &NormalisedSmoothData,
      mclRdivide(
        mclVv(NormalisedSmoothData, "NormalisedSmoothData"),
        mlfMax(
          NULL,
          mclVv(NormalisedSmoothData, "NormalisedSmoothData"),
          NULL,
          NULL)));
    /*
     * disp( 'Normalised mono and smoothed data.' );
     */
    mlfDisp(_mxarray89_);
    /*
     * 
     * % Now we throw away any samples not in the top 10% of the normalised
     * % smoothed data.
     * 
     * % Sort the smooted data, and take the value at the 90% percent mark as the
     * % limit for discarding the data.
     * SortedData = sort( NormalisedSmoothData );
     */
    mlfAssign(
      &SortedData,
      mlfSort(NULL, mclVv(NormalisedSmoothData, "NormalisedSmoothData"), NULL));
    /*
     * Limit = SortedData( round( (SongLength/100) * PeakThreshold ) );
     */
    mlfAssign(
      &Limit,
      mclArrayRef1(
        mclVv(SortedData, "SortedData"),
        mlfRound(
          mclMtimes(
            mclMrdivide(mclVv(SongLength, "SongLength"), _mxarray91_),
            mclVv(PeakThreshold, "PeakThreshold")))));
    /*
     * 
     * 
     * % Set any element below the limit value to 0.
     * PeakData = NormalisedSmoothData;
     */
    mlfAssign(&PeakData, mclVv(NormalisedSmoothData, "NormalisedSmoothData"));
    /*
     * PeakData( find( PeakData < Limit ) ) = 0;
     */
    mclArrayAssign1(
      &PeakData,
      _mxarray44_,
      mlfFind(
        NULL, NULL, mclLt(mclVv(PeakData, "PeakData"), mclVv(Limit, "Limit"))));
    /*
     * disp( 'Thresholded data' );
     */
    mlfDisp(_mxarray92_);
    /*
     * 
     * 
     * % Find peaks in thresholded smoothed track.
     * NonZeroData = PeakData( PeakData ~= 0 );
     */
    mlfAssign(
      &NonZeroData,
      mclArrayRef1(
        mclVv(PeakData, "PeakData"),
        mclNe(mclVv(PeakData, "PeakData"), _mxarray44_)));
    /*
     * % The expression on the right finds all peaks in the NonZeroData.
     * IndexToNonZeroData = find(sign(-sign(diff(sign(diff( NonZeroData )))+0.5)+1))+1;
     */
    mlfAssign(
      &IndexToNonZeroData,
      mclPlus(
        mlfFind(
          NULL,
          NULL,
          mlfSign(
            mclPlus(
              mclUminus(
                mlfSign(
                  mclPlus(
                    mlfDiff(
                      mlfSign(
                        mlfDiff(mclVv(NonZeroData, "NonZeroData"), NULL, NULL)),
                      NULL,
                      NULL),
                    _mxarray94_))),
              _mxarray22_))),
        _mxarray22_));
    /*
     * IndexToPeakData = find( PeakData ~=0 );
     */
    mlfAssign(
      &IndexToPeakData,
      mlfFind(NULL, NULL, mclNe(mclVv(PeakData, "PeakData"), _mxarray44_)));
    /*
     * Peaks = IndexToPeakData( IndexToNonZeroData );
     */
    mlfAssign(
      &Peaks,
      mclArrayRef1(
        mclVv(IndexToPeakData, "IndexToPeakData"),
        mclVv(IndexToNonZeroData, "IndexToNonZeroData")));
    /*
     * 
     * 
     * % Find all the troughs in the unthresholded smoothed data.
     * Troughs = find(sign(-sign(diff(sign(diff( NormalisedSmoothData )))-0.5)-1))+1;
     */
    mlfAssign(
      &Troughs,
      mclPlus(
        mlfFind(
          NULL,
          NULL,
          mlfSign(
            mclMinus(
              mclUminus(
                mlfSign(
                  mclMinus(
                    mlfDiff(
                      mlfSign(
                        mlfDiff(
                          mclVv(NormalisedSmoothData, "NormalisedSmoothData"),
                          NULL,
                          NULL)),
                      NULL,
                      NULL),
                    _mxarray94_))),
              _mxarray22_))),
        _mxarray22_));
    /*
     * disp( 'Found peaks and troughs.' );
     */
    mlfDisp(_mxarray95_);
    /*
     * 
     * % Compute the normalised strengths of each beat from 0 to 1
     * BeatStrengths = NormalisedSmoothData( Peaks );
     */
    mlfAssign(
      &BeatStrengths,
      mclArrayRef1(
        mclVv(NormalisedSmoothData, "NormalisedSmoothData"),
        mclVv(Peaks, "Peaks")));
    /*
     * BeatStrengths = BeatStrengths - min( BeatStrengths );
     */
    mlfAssign(
      &BeatStrengths,
      mclMinus(
        mclVv(BeatStrengths, "BeatStrengths"),
        mlfMin(NULL, mclVv(BeatStrengths, "BeatStrengths"), NULL, NULL)));
    /*
     * BeatStrengths = BeatStrengths ./ max( BeatStrengths );
     */
    mlfAssign(
      &BeatStrengths,
      mclRdivide(
        mclVv(BeatStrengths, "BeatStrengths"),
        mlfMax(NULL, mclVv(BeatStrengths, "BeatStrengths"), NULL, NULL)));
    /*
     * 
     * 
     * % Now we try and find how much the peaks have been shifted by.
     * 
     * % Create a blank holder for the positions of the beats
     * BeatPositions = ones( size( Peaks ) );
     */
    mlfAssign(
      &BeatPositions,
      mlfOnes(mlfSize(mclValueVarargout(), mclVv(Peaks, "Peaks"), NULL), NULL));
    /*
     * 
     * % Loop through each peak we have found. Find the trough to the left of it.
     * % Now try and find the sharp onset of the beat by looking at the normalised
     * % rectified mono data.
     * for ct1 = 1 : size( Peaks, 1 )
     */
    {
        int v_ = mclForIntStart(1);
        int e_
          = mclForIntEnd(
              mlfSize(
                mclValueVarargout(), mclVv(Peaks, "Peaks"), _mxarray22_));
        if (v_ > e_) {
            mlfAssign(&ct1, _mxarray97_);
        } else {
            /*
             * Peak = Peaks( ct1 ); 
             * 
             * TroughsLessThanPeak = Troughs( Troughs < Peak );
             * 
             * if ( size( TroughsLessThanPeak, 1 ) > 0 ) 
             * NearestTrough = TroughsLessThanPeak( end );
             * 
             * % TODO: Improve the method of estimating peak/trough height, use
             * % some emperical evidence to find what works best. Also make sure
             * % that it won't break at the ends of the data. Need a better way to
             * % quantify which element of PeakSize we pick and why.
             * 
             * HeightWindow = round(Frequency * HeightWindowSize);
             * HalfHeightWindow = round( HeightWindow / 2 );
             * 
             * % Find the rough height around the peak on the normalised mono data.
             * Temp = sort( abs( NormalisedMonoData( Peak - HalfHeightWindow : Peak + HalfHeightWindow ) ) );
             * PeakSize   = Temp( end - round( HeightWindow / 100 ) );
             * 
             * % Find the rough height around the trough on the normalised mono data.
             * Temp = sort( abs( NormalisedMonoData( NearestTrough - HalfHeightWindow :NearestTrough + HalfHeightWindow ) ) );
             * TroughSize = Temp( end - round( HeightWindow / 100 ) );
             * 
             * % Calculate the threshold at which a value is considered to be the
             * % onset point.
             * Threshold = ( ( PeakSize - TroughSize ) * BeatPositioningThreshold ) + TroughSize;
             * 
             * Candidates = NormalisedMonoData( NearestTrough : Peak );
             * CandidatesPos = find( Candidates >= Threshold );
             * 
             * if ( size( CandidatesPos, 1 ) < 1 )
             * Pos = 1;    % If no candidates are good enough, then take the trough as the beat position.
             * else
             * Pos = CandidatesPos( 1 );
             * end
             * BeatPos = NearestTrough + Pos - 1;
             * 
             * BeatPositions( ct1 ) = BeatPos;
             * end
             * end
             */
            for (; ; ) {
                mlfAssign(&Peak, mclIntArrayRef1(mclVv(Peaks, "Peaks"), v_));
                mlfAssign(
                  &TroughsLessThanPeak,
                  mclArrayRef1(
                    mclVv(Troughs, "Troughs"),
                    mclLt(mclVv(Troughs, "Troughs"), mclVv(Peak, "Peak"))));
                if (mclGtBool(
                      mlfSize(
                        mclValueVarargout(),
                        mclVv(TroughsLessThanPeak, "TroughsLessThanPeak"),
                        _mxarray22_),
                      _mxarray44_)) {
                    mlfAssign(
                      &NearestTrough,
                      mclArrayRef1(
                        mclVv(TroughsLessThanPeak, "TroughsLessThanPeak"),
                        mlfEnd(
                          mclVv(TroughsLessThanPeak, "TroughsLessThanPeak"),
                          _mxarray22_,
                          _mxarray22_)));
                    mlfAssign(
                      &HeightWindow,
                      mlfRound(
                        mclMtimes(
                          mclVv(Frequency, "Frequency"),
                          mclVv(HeightWindowSize, "HeightWindowSize"))));
                    mlfAssign(
                      &HalfHeightWindow,
                      mlfRound(
                        mclMrdivide(
                          mclVv(HeightWindow, "HeightWindow"), _mxarray41_)));
                    mlfAssign(
                      &Temp,
                      mlfSort(
                        NULL,
                        mlfAbs(
                          mclArrayRef1(
                            mclVv(NormalisedMonoData, "NormalisedMonoData"),
                            mlfColon(
                              mclMinus(
                                mclVv(Peak, "Peak"),
                                mclVv(HalfHeightWindow, "HalfHeightWindow")),
                              mclPlus(
                                mclVv(Peak, "Peak"),
                                mclVv(HalfHeightWindow, "HalfHeightWindow")),
                              NULL))),
                        NULL));
                    mlfAssign(
                      &PeakSize,
                      mclArrayRef1(
                        mclVv(Temp, "Temp"),
                        mclMinus(
                          mlfEnd(mclVv(Temp, "Temp"), _mxarray22_, _mxarray22_),
                          mlfRound(
                            mclMrdivide(
                              mclVv(HeightWindow, "HeightWindow"),
                              _mxarray91_)))));
                    mlfAssign(
                      &Temp,
                      mlfSort(
                        NULL,
                        mlfAbs(
                          mclArrayRef1(
                            mclVv(NormalisedMonoData, "NormalisedMonoData"),
                            mlfColon(
                              mclMinus(
                                mclVv(NearestTrough, "NearestTrough"),
                                mclVv(HalfHeightWindow, "HalfHeightWindow")),
                              mclPlus(
                                mclVv(NearestTrough, "NearestTrough"),
                                mclVv(HalfHeightWindow, "HalfHeightWindow")),
                              NULL))),
                        NULL));
                    mlfAssign(
                      &TroughSize,
                      mclArrayRef1(
                        mclVv(Temp, "Temp"),
                        mclMinus(
                          mlfEnd(mclVv(Temp, "Temp"), _mxarray22_, _mxarray22_),
                          mlfRound(
                            mclMrdivide(
                              mclVv(HeightWindow, "HeightWindow"),
                              _mxarray91_)))));
                    mlfAssign(
                      &Threshold,
                      mclPlus(
                        mclMtimes(
                          mclMinus(
                            mclVv(PeakSize, "PeakSize"),
                            mclVv(TroughSize, "TroughSize")),
                          mclVv(
                            BeatPositioningThreshold,
                            "BeatPositioningThreshold")),
                        mclVv(TroughSize, "TroughSize")));
                    mlfAssign(
                      &Candidates,
                      mclArrayRef1(
                        mclVv(NormalisedMonoData, "NormalisedMonoData"),
                        mlfColon(
                          mclVv(NearestTrough, "NearestTrough"),
                          mclVv(Peak, "Peak"),
                          NULL)));
                    mlfAssign(
                      &CandidatesPos,
                      mlfFind(
                        NULL,
                        NULL,
                        mclGe(
                          mclVv(Candidates, "Candidates"),
                          mclVv(Threshold, "Threshold"))));
                    if (mclLtBool(
                          mlfSize(
                            mclValueVarargout(),
                            mclVv(CandidatesPos, "CandidatesPos"),
                            _mxarray22_),
                          _mxarray22_)) {
                        mlfAssign(&Pos, _mxarray22_);
                    } else {
                        mlfAssign(
                          &Pos,
                          mclIntArrayRef1(
                            mclVv(CandidatesPos, "CandidatesPos"), 1));
                    }
                    mlfAssign(
                      &BeatPos,
                      mclMinus(
                        mclPlus(
                          mclVv(NearestTrough, "NearestTrough"),
                          mclVv(Pos, "Pos")),
                        _mxarray22_));
                    mclIntArrayAssign1(
                      &BeatPositions, mclVv(BeatPos, "BeatPos"), v_);
                }
                if (v_ == e_) {
                    break;
                }
                ++v_;
            }
            mlfAssign(&ct1, mlfScalar(v_));
        }
    }
    /*
     * disp( 'Found beat positions.' );
     */
    mlfDisp(_mxarray98_);
    /*
     * 
     * 
     * % Find the average difference between the peaks and what we think are the
     * % onsets. Shifting all the peak data by the same amount, rather than using
     * % the calculated beat positions for each one gives us much better accuracy
     * % in computing the BPM.
     * 
     * Offsets = Peaks - BeatPositions;
     */
    mlfAssign(
      &Offsets,
      mclMinus(mclVv(Peaks, "Peaks"), mclVv(BeatPositions, "BeatPositions")));
    /*
     * Offset = median( Offsets );
     */
    mlfAssign(&Offset, mlfMedian(mclVv(Offsets, "Offsets"), NULL));
    /*
     * 
     * % Beats = Peaks - round( Offset );
     * Beats = BeatPositions;
     */
    mlfAssign(&Beats, mclVv(BeatPositions, "BeatPositions"));
    /*
     * disp( 'Calculated peak to beat offset.' );
     */
    mlfDisp(_mxarray100_);
    /*
     * 
     * 
     * % Now we brute force all possible BPMS from a very high value to a very low
     * % value. This involves testing each possible interval between beats and
     * % rating them by the amount of data that supports them being the correct
     * % BPM.
     * 
     * % The minimum BPM becomes the maximum interval, because the less beats per
     * % minute the longer the gap between them.
     * MaximumInterval = round( Frequency / ( MinimumBPM / 60 ) );
     */
    mlfAssign(
      &MaximumInterval,
      mlfRound(
        mclMrdivide(
          mclVv(Frequency, "Frequency"),
          mclMrdivide(mclVv(MinimumBPM, "MinimumBPM"), _mxarray102_))));
    /*
     * MinimumInterval = round( Frequency / ( MaximumBPM / 60 ) );
     */
    mlfAssign(
      &MinimumInterval,
      mlfRound(
        mclMrdivide(
          mclVv(Frequency, "Frequency"),
          mclMrdivide(mclVv(MaximumBPM, "MaximumBPM"), _mxarray102_))));
    /*
     * 
     * IntervalFitness  = zeros( [ (MaximumInterval - MinimumInterval + 1) 1 ] );
     */
    mlfAssign(
      &IntervalFitness,
      mlfZeros(
        mlfHorzcat(
          mclPlus(
            mclMinus(
              mclVv(MaximumInterval, "MaximumInterval"),
              mclVv(MinimumInterval, "MinimumInterval")),
            _mxarray22_),
          _mxarray22_,
          NULL),
        NULL));
    /*
     * IntervalGap      = zeros( [ (MaximumInterval - MinimumInterval + 1) 1 ] );
     */
    mlfAssign(
      &IntervalGap,
      mlfZeros(
        mlfHorzcat(
          mclPlus(
            mclMinus(
              mclVv(MaximumInterval, "MaximumInterval"),
              mclVv(MinimumInterval, "MinimumInterval")),
            _mxarray22_),
          _mxarray22_,
          NULL),
        NULL));
    /*
     * 
     * % Loop through every 10th possible BPM, later we will fill in those that
     * % look interesting
     * HalfGapWindowSize = 1000;
     */
    mlfAssign(&HalfGapWindowSize, _mxarray103_);
    /*
     * GapWindow = hamming( HalfGapWindowSize*2 );
     */
    mlfAssign(
      &GapWindow,
      mlfHamming(
        mclMtimes(mclVv(HalfGapWindowSize, "HalfGapWindowSize"), _mxarray41_),
        NULL));
    /*
     * NumBeats = size( Beats,1 ) * 2;
     */
    mlfAssign(
      &NumBeats,
      mclMtimes(
        mlfSize(mclValueVarargout(), mclVv(Beats, "Beats"), _mxarray22_),
        _mxarray41_));
    /*
     * for i = MinimumInterval : 10 : MaximumInterval
     */
    {
        mclForLoopIterator viter__;
        for (mclForStart(
               &viter__,
               mclVv(MinimumInterval, "MinimumInterval"),
               _mxarray31_,
               mclVv(MaximumInterval, "MaximumInterval"));
             mclForNext(&viter__, &i);
             ) {
            /*
             * %     disp( sprintf( 'Started %d', i ) );
             * 
             * Gaps = mod( Beats, i );
             */
            mlfAssign(&Gaps, mlfMod(mclVv(Beats, "Beats"), mclVv(i, "i")));
            /*
             * ExtraGaps = Gaps + i;
             */
            mlfAssign(&ExtraGaps, mclPlus(mclVv(Gaps, "Gaps"), mclVv(i, "i")));
            /*
             * 
             * FullGaps = [ Gaps ExtraGaps ]';
             */
            mlfAssign(
              &FullGaps,
              mlfCtranspose(
                mlfHorzcat(
                  mclVv(Gaps, "Gaps"), mclVv(ExtraGaps, "ExtraGaps"), NULL)));
            /*
             * FullGaps = FullGaps(:);
             */
            mlfAssign(
              &FullGaps,
              mclArrayRef1(mclVv(FullGaps, "FullGaps"), mlfCreateColonIndex()));
            /*
             * [ SortedGaps SortedIndex ] = sort( FullGaps );
             */
            mlfAssign(
              &SortedGaps,
              mlfSort(&SortedIndex, mclVv(FullGaps, "FullGaps"), NULL));
            /*
             * 
             * 
             * % Here we take a hamming window over a small window of Gap positions
             * % and record the amount of support we get from gap values within that
             * % hamming window, based on the strength of the beat predictiting each
             * % gap and the distance of the gap from the centre of the hamming
             * % window.
             * GapsFiltered = zeros( NumBeats, 1 );
             */
            mlfAssign(
              &GapsFiltered,
              mlfZeros(mclVv(NumBeats, "NumBeats"), _mxarray22_, NULL));
            /*
             * for ct1 = 1 : NumBeats
             */
            {
                int v_ = mclForIntStart(1);
                int e_ = mclForIntEnd(mclVv(NumBeats, "NumBeats"));
                if (v_ > e_) {
                    mlfAssign(&ct1, _mxarray97_);
                } else {
                    /*
                     * Area = 0;
                     * 
                     * Centre = SortedGaps( ct1 );
                     * 
                     * Pos = ct1;
                     * PosVal = SortedGaps( Pos );
                     * while ( PosVal > Centre - HalfGapWindowSize )
                     * 
                     * if Pos <= 1 
                     * break;
                     * end
                     * xPos = SortedIndex( Pos );
                     * if ( xPos > size( Beats,1 ) ) 
                     * xPos = xPos - size( Beats,1 );
                     * end
                     * Area = Area + ( BeatStrengths( xPos ) * GapWindow( PosVal - (Centre - HalfGapWindowSize) ) );
                     * Pos = Pos - 1;
                     * PosVal = SortedGaps( Pos );
                     * end
                     * 
                     * Pos = ct1;
                     * PosVal = SortedGaps( Pos );
                     * while ( PosVal <= Centre + HalfGapWindowSize )
                     * 
                     * if Pos >= NumBeats
                     * break;
                     * end
                     * xPos = SortedIndex( Pos );
                     * if ( xPos > size( Beats,1 ) ) 
                     * xPos = xPos - size( Beats,1 );
                     * end
                     * Area = Area + ( BeatStrengths( xPos ) * GapWindow( PosVal - (Centre - HalfGapWindowSize) ) );
                     * Pos = Pos + 1;
                     * PosVal = SortedGaps( Pos );
                     * end
                     * 
                     * GapsFiltered( ct1 ) = Area;
                     * 
                     * end
                     */
                    for (; ; ) {
                        mlfAssign(&Area, _mxarray44_);
                        mlfAssign(
                          &Centre,
                          mclIntArrayRef1(mclVv(SortedGaps, "SortedGaps"), v_));
                        mlfAssign(&Pos, mlfScalar(v_));
                        mlfAssign(
                          &PosVal,
                          mclArrayRef1(
                            mclVv(SortedGaps, "SortedGaps"),
                            mclVv(Pos, "Pos")));
                        while (mclGtBool(
                                 mclVv(PosVal, "PosVal"),
                                 mclMinus(
                                   mclVv(Centre, "Centre"),
                                   mclVv(
                                     HalfGapWindowSize,
                                     "HalfGapWindowSize")))) {
                            if (mclLeBool(mclVv(Pos, "Pos"), _mxarray22_)) {
                                break;
                            }
                            mlfAssign(
                              &xPos,
                              mclArrayRef1(
                                mclVv(SortedIndex, "SortedIndex"),
                                mclVv(Pos, "Pos")));
                            if (mclGtBool(
                                  mclVv(xPos, "xPos"),
                                  mlfSize(
                                    mclValueVarargout(),
                                    mclVv(Beats, "Beats"),
                                    _mxarray22_))) {
                                mlfAssign(
                                  &xPos,
                                  mclMinus(
                                    mclVv(xPos, "xPos"),
                                    mlfSize(
                                      mclValueVarargout(),
                                      mclVv(Beats, "Beats"),
                                      _mxarray22_)));
                            }
                            mlfAssign(
                              &Area,
                              mclPlus(
                                mclVv(Area, "Area"),
                                mclMtimes(
                                  mclArrayRef1(
                                    mclVv(BeatStrengths, "BeatStrengths"),
                                    mclVv(xPos, "xPos")),
                                  mclArrayRef1(
                                    mclVv(GapWindow, "GapWindow"),
                                    mclMinus(
                                      mclVv(PosVal, "PosVal"),
                                      mclMinus(
                                        mclVv(Centre, "Centre"),
                                        mclVv(
                                          HalfGapWindowSize,
                                          "HalfGapWindowSize")))))));
                            mlfAssign(
                              &Pos, mclMinus(mclVv(Pos, "Pos"), _mxarray22_));
                            mlfAssign(
                              &PosVal,
                              mclArrayRef1(
                                mclVv(SortedGaps, "SortedGaps"),
                                mclVv(Pos, "Pos")));
                        }
                        mlfAssign(&Pos, mlfScalar(v_));
                        mlfAssign(
                          &PosVal,
                          mclArrayRef1(
                            mclVv(SortedGaps, "SortedGaps"),
                            mclVv(Pos, "Pos")));
                        while (mclLeBool(
                                 mclVv(PosVal, "PosVal"),
                                 mclPlus(
                                   mclVv(Centre, "Centre"),
                                   mclVv(
                                     HalfGapWindowSize,
                                     "HalfGapWindowSize")))) {
                            if (mclGeBool(
                                  mclVv(Pos, "Pos"),
                                  mclVv(NumBeats, "NumBeats"))) {
                                break;
                            }
                            mlfAssign(
                              &xPos,
                              mclArrayRef1(
                                mclVv(SortedIndex, "SortedIndex"),
                                mclVv(Pos, "Pos")));
                            if (mclGtBool(
                                  mclVv(xPos, "xPos"),
                                  mlfSize(
                                    mclValueVarargout(),
                                    mclVv(Beats, "Beats"),
                                    _mxarray22_))) {
                                mlfAssign(
                                  &xPos,
                                  mclMinus(
                                    mclVv(xPos, "xPos"),
                                    mlfSize(
                                      mclValueVarargout(),
                                      mclVv(Beats, "Beats"),
                                      _mxarray22_)));
                            }
                            mlfAssign(
                              &Area,
                              mclPlus(
                                mclVv(Area, "Area"),
                                mclMtimes(
                                  mclArrayRef1(
                                    mclVv(BeatStrengths, "BeatStrengths"),
                                    mclVv(xPos, "xPos")),
                                  mclArrayRef1(
                                    mclVv(GapWindow, "GapWindow"),
                                    mclMinus(
                                      mclVv(PosVal, "PosVal"),
                                      mclMinus(
                                        mclVv(Centre, "Centre"),
                                        mclVv(
                                          HalfGapWindowSize,
                                          "HalfGapWindowSize")))))));
                            mlfAssign(
                              &Pos, mclPlus(mclVv(Pos, "Pos"), _mxarray22_));
                            mlfAssign(
                              &PosVal,
                              mclArrayRef1(
                                mclVv(SortedGaps, "SortedGaps"),
                                mclVv(Pos, "Pos")));
                        }
                        mclIntArrayAssign1(
                          &GapsFiltered, mclVv(Area, "Area"), v_);
                        if (v_ == e_) {
                            break;
                        }
                        ++v_;
                    }
                    mlfAssign(&ct1, mlfScalar(v_));
                }
            }
            /*
             * 
             * 
             * % Here we work out how much evidence there is to support each gap
             * % by the GapFiltered value for each gap and a portion of the
             * % GapFiltered value from offbeats.
             * 
             * % Need to take care of end cases better
             * GapsConfidence = zeros( NumBeats, 1 );
             */
            mlfAssign(
              &GapsConfidence,
              mlfZeros(mclVv(NumBeats, "NumBeats"), _mxarray22_, NULL));
            /*
             * for ct1 = 1 : NumBeats -1 
             */
            {
                int v_ = mclForIntStart(1);
                int e_
                  = mclForIntEnd(
                      mclMinus(mclVv(NumBeats, "NumBeats"), _mxarray22_));
                if (v_ > e_) {
                    mlfAssign(&ct1, _mxarray97_);
                } else {
                    /*
                     * 
                     * OffbeatPos = SortedGaps( ct1 ) + round(i / 2);
                     * 
                     * % We know the position of where an offbeat gap value would be but
                     * % we need to work out its index in the SortedGaps array
                     * Pos = ct1;
                     * PosVal = SortedGaps( Pos );
                     * while ( PosVal < OffbeatPos )
                     * if Pos >= NumBeats - 1
                     * break;
                     * end
                     * Pos = Pos + 1;
                     * PosVal = SortedGaps( Pos );
                     * end
                     * 
                     * % Not sure why I have this taking the average of the two nearest
                     * % gaps. Might give some improvement to accuracy, but most probably
                     * % pointless.
                     * OffBeatValue = ( GapsFiltered( Pos ) + GapsFiltered( Pos + 1 ) ) / 2;
                     * 
                     * GapsConfidence( ct1 ) = GapsFiltered( ct1 ) + ( OffBeatValue * 0.5 );        
                     * end
                     */
                    for (; ; ) {
                        mlfAssign(
                          &OffbeatPos,
                          mclPlus(
                            mclIntArrayRef1(
                              mclVv(SortedGaps, "SortedGaps"), v_),
                            mlfRound(mclMrdivide(mclVv(i, "i"), _mxarray41_))));
                        mlfAssign(&Pos, mlfScalar(v_));
                        mlfAssign(
                          &PosVal,
                          mclArrayRef1(
                            mclVv(SortedGaps, "SortedGaps"),
                            mclVv(Pos, "Pos")));
                        while (mclLtBool(
                                 mclVv(PosVal, "PosVal"),
                                 mclVv(OffbeatPos, "OffbeatPos"))) {
                            if (mclGeBool(
                                  mclVv(Pos, "Pos"),
                                  mclMinus(
                                    mclVv(NumBeats, "NumBeats"),
                                    _mxarray22_))) {
                                break;
                            }
                            mlfAssign(
                              &Pos, mclPlus(mclVv(Pos, "Pos"), _mxarray22_));
                            mlfAssign(
                              &PosVal,
                              mclArrayRef1(
                                mclVv(SortedGaps, "SortedGaps"),
                                mclVv(Pos, "Pos")));
                        }
                        mlfAssign(
                          &OffBeatValue,
                          mclMrdivide(
                            mclPlus(
                              mclArrayRef1(
                                mclVv(GapsFiltered, "GapsFiltered"),
                                mclVv(Pos, "Pos")),
                              mclArrayRef1(
                                mclVv(GapsFiltered, "GapsFiltered"),
                                mclPlus(mclVv(Pos, "Pos"), _mxarray22_))),
                            _mxarray41_));
                        mclIntArrayAssign1(
                          &GapsConfidence,
                          mclPlus(
                            mclIntArrayRef1(
                              mclVv(GapsFiltered, "GapsFiltered"), v_),
                            mclMtimes(
                              mclVv(OffBeatValue, "OffBeatValue"),
                              _mxarray94_)),
                          v_);
                        if (v_ == e_) {
                            break;
                        }
                        ++v_;
                    }
                    mlfAssign(&ct1, mlfScalar(v_));
                }
            }
            /*
             * 
             * GapPeaks = SortedGaps( find( GapsConfidence == max( GapsConfidence ) ) );
             */
            mlfAssign(
              &GapPeaks,
              mclArrayRef1(
                mclVv(SortedGaps, "SortedGaps"),
                mlfFind(
                  NULL,
                  NULL,
                  mclEq(
                    mclVv(GapsConfidence, "GapsConfidence"),
                    mlfMax(
                      NULL,
                      mclVv(GapsConfidence, "GapsConfidence"),
                      NULL,
                      NULL)))));
            /*
             * 
             * IntervalFitness( (i + 1) - MinimumInterval ) = max( GapsConfidence );
             */
            mclArrayAssign1(
              &IntervalFitness,
              mlfMax(NULL, mclVv(GapsConfidence, "GapsConfidence"), NULL, NULL),
              mclMinus(
                mclPlus(mclVv(i, "i"), _mxarray22_),
                mclVv(MinimumInterval, "MinimumInterval")));
            /*
             * IntervalGap( (i+1) - MinimumInterval )       = GapPeaks( 1 );
             */
            mclArrayAssign1(
              &IntervalGap,
              mclIntArrayRef1(mclVv(GapPeaks, "GapPeaks"), 1),
              mclMinus(
                mclPlus(mclVv(i, "i"), _mxarray22_),
                mclVv(MinimumInterval, "MinimumInterval")));
        /*
         * 
         * end
         */
        }
        mclDestroyForLoopIterator(viter__);
    }
    /*
     * 
     * % Find the top 50 possible BPMs that look interesting and compute the
     * % fitness of every interval around them
     * Temp = sort( IntervalFitness );
     */
    mlfAssign(
      &Temp, mlfSort(NULL, mclVv(IntervalFitness, "IntervalFitness"), NULL));
    /*
     * DoMoreWorkOn = find( IntervalFitness >= Temp( end-50 ) );
     */
    mlfAssign(
      &DoMoreWorkOn,
      mlfFind(
        NULL,
        NULL,
        mclGe(
          mclVv(IntervalFitness, "IntervalFitness"),
          mclArrayRef1(
            mclVv(Temp, "Temp"),
            mclMinus(
              mlfEnd(mclVv(Temp, "Temp"), _mxarray22_, _mxarray22_),
              _mxarray104_)))));
    /*
     * for ct1 = 1 : 50
     */
    {
        int v_ = mclForIntStart(1);
        int e_ = 50;
        if (v_ > e_) {
            mlfAssign(&ct1, _mxarray97_);
        } else {
            /*
             * LookAt = DoMoreWorkOn( ct1 );
             * 
             * if ( LookAt >= 10 )
             * IntervalFitness( LookAt - 9 : LookAt - 1 ) = -1;
             * end
             * if ( LookAt <= (MaximumInterval - MinimumInterval + 1) - 10 )
             * IntervalFitness( LookAt + 1 : LookAt + 9 ) = -1;
             * end
             * end
             */
            for (; ; ) {
                mlfAssign(
                  &LookAt,
                  mclIntArrayRef1(mclVv(DoMoreWorkOn, "DoMoreWorkOn"), v_));
                if (mclGeBool(mclVv(LookAt, "LookAt"), _mxarray31_)) {
                    mclArrayAssign1(
                      &IntervalFitness,
                      _mxarray78_,
                      mlfColon(
                        mclMinus(mclVv(LookAt, "LookAt"), _mxarray105_),
                        mclMinus(mclVv(LookAt, "LookAt"), _mxarray22_),
                        NULL));
                }
                if (mclLeBool(
                      mclVv(LookAt, "LookAt"),
                      mclMinus(
                        mclPlus(
                          mclMinus(
                            mclVv(MaximumInterval, "MaximumInterval"),
                            mclVv(MinimumInterval, "MinimumInterval")),
                          _mxarray22_),
                        _mxarray31_))) {
                    mclArrayAssign1(
                      &IntervalFitness,
                      _mxarray78_,
                      mlfColon(
                        mclPlus(mclVv(LookAt, "LookAt"), _mxarray22_),
                        mclPlus(mclVv(LookAt, "LookAt"), _mxarray105_),
                        NULL));
                }
                if (v_ == e_) {
                    break;
                }
                ++v_;
            }
            mlfAssign(&ct1, mlfScalar(v_));
        }
    }
    /*
     * 
     * for i = MinimumInterval : MaximumInterval
     */
    {
        mclForLoopIterator viter__;
        for (mclForStart(
               &viter__,
               mclVv(MinimumInterval, "MinimumInterval"),
               mclVv(MaximumInterval, "MaximumInterval"),
               NULL);
             mclForNext(&viter__, &i);
             ) {
            /*
             * 
             * if ( IntervalFitness( (i + 1) - MinimumInterval ) == -1 )
             */
            if (mclEqBool(
                  mclArrayRef1(
                    mclVv(IntervalFitness, "IntervalFitness"),
                    mclMinus(
                      mclPlus(mclVv(i, "i"), _mxarray22_),
                      mclVv(MinimumInterval, "MinimumInterval"))),
                  _mxarray78_)) {
                /*
                 * 
                 * Gaps = mod( Beats, i );
                 */
                mlfAssign(&Gaps, mlfMod(mclVv(Beats, "Beats"), mclVv(i, "i")));
                /*
                 * ExtraGaps = Gaps + i;
                 */
                mlfAssign(
                  &ExtraGaps, mclPlus(mclVv(Gaps, "Gaps"), mclVv(i, "i")));
                /*
                 * 
                 * FullGaps = [ Gaps ExtraGaps ]';
                 */
                mlfAssign(
                  &FullGaps,
                  mlfCtranspose(
                    mlfHorzcat(
                      mclVv(Gaps, "Gaps"),
                      mclVv(ExtraGaps, "ExtraGaps"),
                      NULL)));
                /*
                 * FullGaps = FullGaps(:);
                 */
                mlfAssign(
                  &FullGaps,
                  mclArrayRef1(
                    mclVv(FullGaps, "FullGaps"), mlfCreateColonIndex()));
                /*
                 * [ SortedGaps SortedIndex ] = sort( FullGaps );
                 */
                mlfAssign(
                  &SortedGaps,
                  mlfSort(&SortedIndex, mclVv(FullGaps, "FullGaps"), NULL));
                /*
                 * 
                 * GapsFiltered = zeros( NumBeats, 1 );
                 */
                mlfAssign(
                  &GapsFiltered,
                  mlfZeros(mclVv(NumBeats, "NumBeats"), _mxarray22_, NULL));
                /*
                 * for ct1 = 1 : NumBeats
                 */
                {
                    int v_ = mclForIntStart(1);
                    int e_ = mclForIntEnd(mclVv(NumBeats, "NumBeats"));
                    if (v_ > e_) {
                        mlfAssign(&ct1, _mxarray97_);
                    } else {
                        /*
                         * Area = 0;
                         * 
                         * Centre = SortedGaps( ct1 );
                         * 
                         * Pos = ct1;
                         * PosVal = SortedGaps( Pos );
                         * while ( PosVal > Centre - HalfGapWindowSize )
                         * 
                         * if Pos <= 1 
                         * break;
                         * end
                         * xPos = SortedIndex( Pos );
                         * if ( xPos > size( Beats,1 ) ) 
                         * xPos = xPos - size( Beats,1 );
                         * end
                         * Area = Area + ( BeatStrengths( xPos ) * GapWindow( PosVal - (Centre - HalfGapWindowSize) ) );
                         * Pos = Pos - 1;
                         * PosVal = SortedGaps( Pos );
                         * end
                         * 
                         * Pos = ct1;
                         * PosVal = SortedGaps( Pos );
                         * while ( PosVal <= Centre + HalfGapWindowSize )
                         * 
                         * if Pos >= NumBeats
                         * break;
                         * end
                         * xPos = SortedIndex( Pos );
                         * if ( xPos > size( Beats,1 ) ) 
                         * xPos = xPos - size( Beats,1 );
                         * end
                         * Area = Area + ( BeatStrengths( xPos ) * GapWindow( PosVal - (Centre - HalfGapWindowSize) ) );
                         * Pos = Pos + 1;
                         * PosVal = SortedGaps( Pos );
                         * end
                         * 
                         * GapsFiltered( ct1 ) = Area;
                         * 
                         * end
                         */
                        for (; ; ) {
                            mlfAssign(&Area, _mxarray44_);
                            mlfAssign(
                              &Centre,
                              mclIntArrayRef1(
                                mclVv(SortedGaps, "SortedGaps"), v_));
                            mlfAssign(&Pos, mlfScalar(v_));
                            mlfAssign(
                              &PosVal,
                              mclArrayRef1(
                                mclVv(SortedGaps, "SortedGaps"),
                                mclVv(Pos, "Pos")));
                            while (mclGtBool(
                                     mclVv(PosVal, "PosVal"),
                                     mclMinus(
                                       mclVv(Centre, "Centre"),
                                       mclVv(
                                         HalfGapWindowSize,
                                         "HalfGapWindowSize")))) {
                                if (mclLeBool(mclVv(Pos, "Pos"), _mxarray22_)) {
                                    break;
                                }
                                mlfAssign(
                                  &xPos,
                                  mclArrayRef1(
                                    mclVv(SortedIndex, "SortedIndex"),
                                    mclVv(Pos, "Pos")));
                                if (mclGtBool(
                                      mclVv(xPos, "xPos"),
                                      mlfSize(
                                        mclValueVarargout(),
                                        mclVv(Beats, "Beats"),
                                        _mxarray22_))) {
                                    mlfAssign(
                                      &xPos,
                                      mclMinus(
                                        mclVv(xPos, "xPos"),
                                        mlfSize(
                                          mclValueVarargout(),
                                          mclVv(Beats, "Beats"),
                                          _mxarray22_)));
                                }
                                mlfAssign(
                                  &Area,
                                  mclPlus(
                                    mclVv(Area, "Area"),
                                    mclMtimes(
                                      mclArrayRef1(
                                        mclVv(BeatStrengths, "BeatStrengths"),
                                        mclVv(xPos, "xPos")),
                                      mclArrayRef1(
                                        mclVv(GapWindow, "GapWindow"),
                                        mclMinus(
                                          mclVv(PosVal, "PosVal"),
                                          mclMinus(
                                            mclVv(Centre, "Centre"),
                                            mclVv(
                                              HalfGapWindowSize,
                                              "HalfGapWindowSize")))))));
                                mlfAssign(
                                  &Pos,
                                  mclMinus(mclVv(Pos, "Pos"), _mxarray22_));
                                mlfAssign(
                                  &PosVal,
                                  mclArrayRef1(
                                    mclVv(SortedGaps, "SortedGaps"),
                                    mclVv(Pos, "Pos")));
                            }
                            mlfAssign(&Pos, mlfScalar(v_));
                            mlfAssign(
                              &PosVal,
                              mclArrayRef1(
                                mclVv(SortedGaps, "SortedGaps"),
                                mclVv(Pos, "Pos")));
                            while (mclLeBool(
                                     mclVv(PosVal, "PosVal"),
                                     mclPlus(
                                       mclVv(Centre, "Centre"),
                                       mclVv(
                                         HalfGapWindowSize,
                                         "HalfGapWindowSize")))) {
                                if (mclGeBool(
                                      mclVv(Pos, "Pos"),
                                      mclVv(NumBeats, "NumBeats"))) {
                                    break;
                                }
                                mlfAssign(
                                  &xPos,
                                  mclArrayRef1(
                                    mclVv(SortedIndex, "SortedIndex"),
                                    mclVv(Pos, "Pos")));
                                if (mclGtBool(
                                      mclVv(xPos, "xPos"),
                                      mlfSize(
                                        mclValueVarargout(),
                                        mclVv(Beats, "Beats"),
                                        _mxarray22_))) {
                                    mlfAssign(
                                      &xPos,
                                      mclMinus(
                                        mclVv(xPos, "xPos"),
                                        mlfSize(
                                          mclValueVarargout(),
                                          mclVv(Beats, "Beats"),
                                          _mxarray22_)));
                                }
                                mlfAssign(
                                  &Area,
                                  mclPlus(
                                    mclVv(Area, "Area"),
                                    mclMtimes(
                                      mclArrayRef1(
                                        mclVv(BeatStrengths, "BeatStrengths"),
                                        mclVv(xPos, "xPos")),
                                      mclArrayRef1(
                                        mclVv(GapWindow, "GapWindow"),
                                        mclMinus(
                                          mclVv(PosVal, "PosVal"),
                                          mclMinus(
                                            mclVv(Centre, "Centre"),
                                            mclVv(
                                              HalfGapWindowSize,
                                              "HalfGapWindowSize")))))));
                                mlfAssign(
                                  &Pos,
                                  mclPlus(mclVv(Pos, "Pos"), _mxarray22_));
                                mlfAssign(
                                  &PosVal,
                                  mclArrayRef1(
                                    mclVv(SortedGaps, "SortedGaps"),
                                    mclVv(Pos, "Pos")));
                            }
                            mclIntArrayAssign1(
                              &GapsFiltered, mclVv(Area, "Area"), v_);
                            if (v_ == e_) {
                                break;
                            }
                            ++v_;
                        }
                        mlfAssign(&ct1, mlfScalar(v_));
                    }
                }
                /*
                 * 
                 * % Need to take care of end cases better
                 * % Here we work out how much evidence there is to support each gap
                 * % by the GapFiltered value for each gap and a portion of the
                 * % GapFiltered value from offbeats.
                 * 
                 * % Need to take care of end cases better
                 * GapsConfidence = zeros( NumBeats, 1 );
                 */
                mlfAssign(
                  &GapsConfidence,
                  mlfZeros(mclVv(NumBeats, "NumBeats"), _mxarray22_, NULL));
                /*
                 * for ct1 = 1 : NumBeats -1 
                 */
                {
                    int v_ = mclForIntStart(1);
                    int e_
                      = mclForIntEnd(
                          mclMinus(mclVv(NumBeats, "NumBeats"), _mxarray22_));
                    if (v_ > e_) {
                        mlfAssign(&ct1, _mxarray97_);
                    } else {
                        /*
                         * 
                         * OffbeatPos = SortedGaps( ct1 ) + round(i / 2);
                         * 
                         * % We know the position of where an offbeat gap value would be but
                         * % we need to work out its index in the SortedGaps array
                         * Pos = ct1;
                         * PosVal = SortedGaps( Pos );
                         * while ( PosVal < OffbeatPos )
                         * if Pos >= NumBeats - 1
                         * break;
                         * end
                         * Pos = Pos + 1;
                         * PosVal = SortedGaps( Pos );
                         * end
                         * 
                         * % Not sure why I have this taking the average of the two nearest
                         * % gaps. Might give some improvement to accuracy, but most probably
                         * % pointless.
                         * OffBeatValue = ( GapsFiltered( Pos ) + GapsFiltered( Pos + 1 ) ) / 2;
                         * 
                         * GapsConfidence( ct1 ) = GapsFiltered( ct1 ) + ( OffBeatValue * 0.5 );        
                         * end
                         */
                        for (; ; ) {
                            mlfAssign(
                              &OffbeatPos,
                              mclPlus(
                                mclIntArrayRef1(
                                  mclVv(SortedGaps, "SortedGaps"), v_),
                                mlfRound(
                                  mclMrdivide(mclVv(i, "i"), _mxarray41_))));
                            mlfAssign(&Pos, mlfScalar(v_));
                            mlfAssign(
                              &PosVal,
                              mclArrayRef1(
                                mclVv(SortedGaps, "SortedGaps"),
                                mclVv(Pos, "Pos")));
                            while (mclLtBool(
                                     mclVv(PosVal, "PosVal"),
                                     mclVv(OffbeatPos, "OffbeatPos"))) {
                                if (mclGeBool(
                                      mclVv(Pos, "Pos"),
                                      mclMinus(
                                        mclVv(NumBeats, "NumBeats"),
                                        _mxarray22_))) {
                                    break;
                                }
                                mlfAssign(
                                  &Pos,
                                  mclPlus(mclVv(Pos, "Pos"), _mxarray22_));
                                mlfAssign(
                                  &PosVal,
                                  mclArrayRef1(
                                    mclVv(SortedGaps, "SortedGaps"),
                                    mclVv(Pos, "Pos")));
                            }
                            mlfAssign(
                              &OffBeatValue,
                              mclMrdivide(
                                mclPlus(
                                  mclArrayRef1(
                                    mclVv(GapsFiltered, "GapsFiltered"),
                                    mclVv(Pos, "Pos")),
                                  mclArrayRef1(
                                    mclVv(GapsFiltered, "GapsFiltered"),
                                    mclPlus(mclVv(Pos, "Pos"), _mxarray22_))),
                                _mxarray41_));
                            mclIntArrayAssign1(
                              &GapsConfidence,
                              mclPlus(
                                mclIntArrayRef1(
                                  mclVv(GapsFiltered, "GapsFiltered"), v_),
                                mclMtimes(
                                  mclVv(OffBeatValue, "OffBeatValue"),
                                  _mxarray94_)),
                              v_);
                            if (v_ == e_) {
                                break;
                            }
                            ++v_;
                        }
                        mlfAssign(&ct1, mlfScalar(v_));
                    }
                }
                /*
                 * 
                 * GapPeaks = SortedGaps( find( GapsConfidence == max( GapsConfidence ) ) );
                 */
                mlfAssign(
                  &GapPeaks,
                  mclArrayRef1(
                    mclVv(SortedGaps, "SortedGaps"),
                    mlfFind(
                      NULL,
                      NULL,
                      mclEq(
                        mclVv(GapsConfidence, "GapsConfidence"),
                        mlfMax(
                          NULL,
                          mclVv(GapsConfidence, "GapsConfidence"),
                          NULL,
                          NULL)))));
                /*
                 * 
                 * IntervalFitness( (i + 1) - MinimumInterval ) = max( GapsConfidence );
                 */
                mclArrayAssign1(
                  &IntervalFitness,
                  mlfMax(
                    NULL, mclVv(GapsConfidence, "GapsConfidence"), NULL, NULL),
                  mclMinus(
                    mclPlus(mclVv(i, "i"), _mxarray22_),
                    mclVv(MinimumInterval, "MinimumInterval")));
                /*
                 * IntervalGap( (i+1) - MinimumInterval )       = GapPeaks( 1 );
                 */
                mclArrayAssign1(
                  &IntervalGap,
                  mclIntArrayRef1(mclVv(GapPeaks, "GapPeaks"), 1),
                  mclMinus(
                    mclPlus(mclVv(i, "i"), _mxarray22_),
                    mclVv(MinimumInterval, "MinimumInterval")));
            /*
             * 
             * end
             */
            }
        /*
         * end
         */
        }
        mclDestroyForLoopIterator(viter__);
    }
    /*
     * disp( 'Brute forced the interval tests.' );
     */
    mlfDisp(_mxarray106_);
    /*
     * 
     * % Fit a polynomial to the fitness value in order to normalise the results
     * % to remove bias towards high BPMs
     * Y = IntervalFitness( 1:10:end );
     */
    mlfAssign(
      &Y,
      mclArrayRef1(
        mclVv(IntervalFitness, "IntervalFitness"),
        mlfColon(
          _mxarray22_,
          _mxarray31_,
          mlfEnd(
            mclVv(IntervalFitness, "IntervalFitness"),
            _mxarray22_,
            _mxarray22_))));
    /*
     * Range = (MinimumInterval:MaximumInterval)';
     */
    mlfAssign(
      &Range,
      mlfCtranspose(
        mlfColon(
          mclVv(MinimumInterval, "MinimumInterval"),
          mclVv(MaximumInterval, "MaximumInterval"),
          NULL)));
    /*
     * X = Range(1:10:end);
     */
    mlfAssign(
      &X,
      mclArrayRef1(
        mclVv(Range, "Range"),
        mlfColon(
          _mxarray22_,
          _mxarray31_,
          mlfEnd(mclVv(Range, "Range"), _mxarray22_, _mxarray22_))));
    /*
     * NormalisedIntervalFitness = IntervalFitness - polyval( polyfit( X, Y, 3 ), Range );
     */
    mlfAssign(
      &NormalisedIntervalFitness,
      mclMinus(
        mclVv(IntervalFitness, "IntervalFitness"),
        mlfNPolyval(
          1,
          NULL,
          mlfNPolyfit(1, NULL, NULL, mclVv(X, "X"), mclVv(Y, "Y"), _mxarray23_),
          mclVv(Range, "Range"),
          NULL,
          NULL)));
    /*
     * 
     * 
     * % Now we do a bit of calculations to find the best interval, BPM and Gap
     * % value.
     * FitnessIndex = find( NormalisedIntervalFitness == max( NormalisedIntervalFitness ) );
     */
    mlfAssign(
      &FitnessIndex,
      mlfFind(
        NULL,
        NULL,
        mclEq(
          mclVv(NormalisedIntervalFitness, "NormalisedIntervalFitness"),
          mlfMax(
            NULL,
            mclVv(NormalisedIntervalFitness, "NormalisedIntervalFitness"),
            NULL,
            NULL))));
    /*
     * 
     * Confidence   = max( NormalisedIntervalFitness );
     */
    mlfAssign(
      &Confidence,
      mlfMax(
        NULL,
        mclVv(NormalisedIntervalFitness, "NormalisedIntervalFitness"),
        NULL,
        NULL));
    /*
     * Interval     = FitnessIndex(end) + (MinimumInterval - 1);
     */
    mlfAssign(
      &Interval,
      mclPlus(
        mclArrayRef1(
          mclVv(FitnessIndex, "FitnessIndex"),
          mlfEnd(
            mclVv(FitnessIndex, "FitnessIndex"), _mxarray22_, _mxarray22_)),
        mclMinus(mclVv(MinimumInterval, "MinimumInterval"), _mxarray22_)));
    /*
     * GapInSamples = IntervalGap( FitnessIndex(end) );
     */
    mlfAssign(
      &GapInSamples,
      mclArrayRef1(
        mclVv(IntervalGap, "IntervalGap"),
        mclArrayRef1(
          mclVv(FitnessIndex, "FitnessIndex"),
          mlfEnd(
            mclVv(FitnessIndex, "FitnessIndex"), _mxarray22_, _mxarray22_))));
    /*
     * GapInSeconds = GapInSamples / Frequency;
     */
    mlfAssign(
      &GapInSeconds,
      mclMrdivide(
        mclVv(GapInSamples, "GapInSamples"), mclVv(Frequency, "Frequency")));
    /*
     * BPM = ( Frequency / Interval ) * 60;
     */
    mlfAssign(
      &BPM,
      mclMtimes(
        mclMrdivide(mclVv(Frequency, "Frequency"), mclVv(Interval, "Interval")),
        _mxarray102_));
    /*
     * disp( 'Calcualted Gap and BPM.' );
     */
    mlfDisp(_mxarray108_);
    /*
     * 
     * if ( Confidence < 10 )
     */
    if (mclLtBool(mclVv(Confidence, "Confidence"), _mxarray31_)) {
        /*
         * error( 'Unable to confidently find BPM.' );
         */
        mlfError(_mxarray110_, NULL);
    /*
     * end
     */
    }
    /*
     * 
     * 
     * % Calculate the energy of each beat. It is simple the sum of the squared
     * % values of each sample in the waveform.
     * Position = round( GapInSamples ); 
     */
    mlfAssign(&Position, mlfRound(mclVv(GapInSamples, "GapInSamples")));
    /*
     * WindowNum = 1;
     */
    mlfAssign(&WindowNum, _mxarray22_);
    /*
     * AbsoluteEnergy = [];
     */
    mlfAssign(&AbsoluteEnergy, _mxarray97_);
    /*
     * Energy = [];
     */
    mlfAssign(&Energy, _mxarray97_);
    /*
     * while ( Position + Interval < SongLength )
     */
    while (mclLtBool(
             mclPlus(mclVv(Position, "Position"), mclVv(Interval, "Interval")),
             mclVv(SongLength, "SongLength"))) {
        /*
         * 
         * Window = Mono( Position:(Position+round(Interval/2))-1 );
         */
        mlfAssign(
          &Window,
          mclArrayRef1(
            mclVv(Mono, "Mono"),
            mlfColon(
              mclVv(Position, "Position"),
              mclMinus(
                mclPlus(
                  mclVv(Position, "Position"),
                  mlfRound(
                    mclMrdivide(mclVv(Interval, "Interval"), _mxarray41_))),
                _mxarray22_),
              NULL)));
        /*
         * AbsoluteEnergy( WindowNum ) = sum( Window .^ 2 );
         */
        mclArrayAssign1(
          &AbsoluteEnergy,
          mlfSum(mlfPower(mclVv(Window, "Window"), _mxarray41_), NULL),
          mclVv(WindowNum, "WindowNum"));
        /*
         * WindowNum = WindowNum + 1;
         */
        mlfAssign(
          &WindowNum, mclPlus(mclVv(WindowNum, "WindowNum"), _mxarray22_));
        /*
         * 
         * Window = Mono( (Position+round(Interval/2)):(Position+Interval) );
         */
        mlfAssign(
          &Window,
          mclArrayRef1(
            mclVv(Mono, "Mono"),
            mlfColon(
              mclPlus(
                mclVv(Position, "Position"),
                mlfRound(
                  mclMrdivide(mclVv(Interval, "Interval"), _mxarray41_))),
              mclPlus(mclVv(Position, "Position"), mclVv(Interval, "Interval")),
              NULL)));
        /*
         * AbsoluteEnergy( WindowNum ) = sum( Window .^ 2 );
         */
        mclArrayAssign1(
          &AbsoluteEnergy,
          mlfSum(mlfPower(mclVv(Window, "Window"), _mxarray41_), NULL),
          mclVv(WindowNum, "WindowNum"));
        /*
         * WindowNum = WindowNum + 1;
         */
        mlfAssign(
          &WindowNum, mclPlus(mclVv(WindowNum, "WindowNum"), _mxarray22_));
        /*
         * 
         * Position = Position + Interval;
         */
        mlfAssign(
          &Position,
          mclPlus(mclVv(Position, "Position"), mclVv(Interval, "Interval")));
    /*
     * end
     */
    }
    /*
     * 
     * Energy = AbsoluteEnergy ./ max( AbsoluteEnergy );
     */
    mlfAssign(
      &Energy,
      mclRdivide(
        mclVv(AbsoluteEnergy, "AbsoluteEnergy"),
        mlfMax(NULL, mclVv(AbsoluteEnergy, "AbsoluteEnergy"), NULL, NULL)));
    /*
     * disp( 'Calculated Energy' );
     */
    mlfDisp(_mxarray112_);
    /*
     * % bar( Energy, 'r' );
     * 
     * 
     * % If the offbeats consistently have more energy than the beats themselves
     * % we have probably incorrectly computed the gap value. Shift the gap by
     * % half a beat.
     * if ( mean( Energy( 2:2:end ) ) > mean( Energy( 1:2:end ) ) + 0.001 )
     */
    if (mclGtBool(
          mlfMean(
            mclArrayRef1(
              mclVv(Energy, "Energy"),
              mlfColon(
                _mxarray41_,
                _mxarray41_,
                mlfEnd(mclVv(Energy, "Energy"), _mxarray22_, _mxarray22_))),
            NULL),
          mclPlus(
            mlfMean(
              mclArrayRef1(
                mclVv(Energy, "Energy"),
                mlfColon(
                  _mxarray22_,
                  _mxarray41_,
                  mlfEnd(mclVv(Energy, "Energy"), _mxarray22_, _mxarray22_))),
              NULL),
            _mxarray114_))) {
        /*
         * disp( ' *** Gap half beat out ***' );
         */
        mlfDisp(_mxarray115_);
        /*
         * 
         * GapInSamples = GapInSamples + round(Interval / 2);
         */
        mlfAssign(
          &GapInSamples,
          mclPlus(
            mclVv(GapInSamples, "GapInSamples"),
            mlfRound(mclMrdivide(mclVv(Interval, "Interval"), _mxarray41_))));
        /*
         * GapInSeconds = GapInSamples / Frequency;
         */
        mlfAssign(
          &GapInSeconds,
          mclMrdivide(
            mclVv(GapInSamples, "GapInSamples"),
            mclVv(Frequency, "Frequency")));
        /*
         * Energy = Energy(2:end);
         */
        mlfAssign(
          &Energy,
          mclArrayRef1(
            mclVv(Energy, "Energy"),
            mlfColon(
              _mxarray41_,
              mlfEnd(mclVv(Energy, "Energy"), _mxarray22_, _mxarray22_),
              NULL)));
    /*
     * 
     * end
     */
    }
    /*
     * 
     * 
     * 
     * % Now compute a matrix of the similarity of each half beat to every other
     * % half beat.
     * BeatData = Energy;
     */
    mlfAssign(&BeatData, mclVv(Energy, "Energy"));
    /*
     * SizeBeatData = size( BeatData, 2 );
     */
    mlfAssign(
      &SizeBeatData,
      mlfSize(mclValueVarargout(), mclVv(BeatData, "BeatData"), _mxarray41_));
    /*
     * 
     * SelfSimilarity = zeros(  SizeBeatData  );
     */
    mlfAssign(
      &SelfSimilarity, mlfZeros(mclVv(SizeBeatData, "SizeBeatData"), NULL));
    /*
     * for ct1 = 1 : SizeBeatData
     */
    {
        int v_ = mclForIntStart(1);
        int e_ = mclForIntEnd(mclVv(SizeBeatData, "SizeBeatData"));
        if (v_ > e_) {
            mlfAssign(&ct1, _mxarray97_);
        } else {
            /*
             * for ct2 = ct1 : SizeBeatData
             * SelfSimilarity( ct1, ct2 ) = 1 - ( sqrt( sum( (BeatData( :, ct1 ) - BeatData( :, ct2 )).^2 ) ) / sqrt( size( BeatData, 1 ) ) );
             * SelfSimilarity( ct2, ct1 ) = SelfSimilarity( ct1, ct2 );
             * end
             * end
             */
            for (; ; ) {
                int v_0 = mclForIntStart(v_);
                int e_0 = mclForIntEnd(mclVv(SizeBeatData, "SizeBeatData"));
                if (v_0 > e_0) {
                    mlfAssign(&ct2, _mxarray97_);
                } else {
                    for (; ; ) {
                        mclIntArrayAssign2(
                          &SelfSimilarity,
                          mclMinus(
                            _mxarray22_,
                            mclMrdivide(
                              mlfSqrt(
                                mlfSum(
                                  mlfPower(
                                    mclMinus(
                                      mclArrayRef2(
                                        mclVv(BeatData, "BeatData"),
                                        mlfCreateColonIndex(),
                                        mlfScalar(v_)),
                                      mclArrayRef2(
                                        mclVv(BeatData, "BeatData"),
                                        mlfCreateColonIndex(),
                                        mlfScalar(v_0))),
                                    _mxarray41_),
                                  NULL)),
                              mlfSqrt(
                                mlfSize(
                                  mclValueVarargout(),
                                  mclVv(BeatData, "BeatData"),
                                  _mxarray22_)))),
                          v_,
                          v_0);
                        mclIntArrayAssign2(
                          &SelfSimilarity,
                          mclIntArrayRef2(
                            mclVv(SelfSimilarity, "SelfSimilarity"), v_, v_0),
                          v_0,
                          v_);
                        if (v_0 == e_0) {
                            break;
                        }
                        ++v_0;
                    }
                    mlfAssign(&ct2, mlfScalar(v_0));
                }
                if (v_ == e_) {
                    break;
                }
                ++v_;
            }
            mlfAssign(&ct1, mlfScalar(v_));
        }
    }
    /*
     * disp( 'Computed Self Similarity' );
     */
    mlfDisp(_mxarray117_);
    /*
     * 
     * 
     * % Now try and divide the music in bars of four notes. This requires picking
     * % the best position to start the division of bars. This is found by
     * % computing a self-similarity matrix for each possible bar start and taking
     * % the sharpest image.
     * X = 1;
     */
    mlfAssign(&X, _mxarray22_);
    /*
     * PossibleBarStarts = zeros( BarSize, 1 );
     */
    mlfAssign(
      &PossibleBarStarts,
      mlfZeros(mclVv(BarSize, "BarSize"), _mxarray22_, NULL));
    /*
     * BarSimilarities = [];
     */
    mlfAssign(&BarSimilarities, _mxarray97_);
    /*
     * BarSizeInHalfBeats = BarSize * 2;
     */
    mlfAssign(
      &BarSizeInHalfBeats, mclMtimes(mclVv(BarSize, "BarSize"), _mxarray41_));
    /*
     * for FirstBarStart = 1 : 1 :  BarSizeInHalfBeats
     */
    {
        int v_ = mclForIntStart(1);
        int i_ = 1;
        int e_
          = mclForIntIntEnd(
              v_, i_, mclVv(BarSizeInHalfBeats, "BarSizeInHalfBeats"));
        if (e_ == mclIntMin()) {
            mlfAssign(&FirstBarStart, _mxarray97_);
        } else {
            /*
             * 
             * BarSimilarity = zeros( ceil( (SizeBeatData - ( BarSizeInHalfBeats - 1) - (BarSizeInHalfBeats-1)) / BarSizeInHalfBeats ) ); 
             * Num1 = 1;
             * Num2 = 1;
             * 
             * % Produce self-similarity matrix.
             * for ct1 = 1 : size( BarSimilarity, 1 )
             * for ct2 = 1 : size( BarSimilarity, 2 )
             * Pos1 = FirstBarStart + (ct1-1)*BarSizeInHalfBeats;
             * Pos2 = FirstBarStart + (ct2-1)*BarSizeInHalfBeats;
             * 
             * BarSimilarity( ct1, ct2 ) = mean( diag( SelfSimilarity( Pos1:Pos1 + ( BarSizeInHalfBeats - 1), ...
             * Pos2:Pos2 + ( BarSizeInHalfBeats - 1) ) ) );
             * BarSimilarity( ct2, ct1 ) = BarSimilarity( ct1, ct2 );
             * end
             * end
             * 
             * % Compute the 'sharpness' as a measure of the mean difference between
             * % the similarity of adjacent bars.
             * BarSimilarity( 1, 1 ) = 0;
             * BarSimilarities( :, :, FirstBarStart ) = BarSimilarity;
             * Temp = BarSimilarity( 3:end-2, 3:end-2 );
             * Temp = abs( diff( Temp ) );
             * PossibleBarStarts( FirstBarStart ) = mean( Temp(:) );
             * end
             */
            for (; ; ) {
                mlfAssign(
                  &BarSimilarity,
                  mlfZeros(
                    mlfCeil(
                      mclMrdivide(
                        mclMinus(
                          mclMinus(
                            mclVv(SizeBeatData, "SizeBeatData"),
                            mclMinus(
                              mclVv(BarSizeInHalfBeats, "BarSizeInHalfBeats"),
                              _mxarray22_)),
                          mclMinus(
                            mclVv(BarSizeInHalfBeats, "BarSizeInHalfBeats"),
                            _mxarray22_)),
                        mclVv(BarSizeInHalfBeats, "BarSizeInHalfBeats"))),
                    NULL));
                mlfAssign(&Num1, _mxarray22_);
                mlfAssign(&Num2, _mxarray22_);
                {
                    int v_1 = mclForIntStart(1);
                    int e_1
                      = mclForIntEnd(
                          mlfSize(
                            mclValueVarargout(),
                            mclVv(BarSimilarity, "BarSimilarity"),
                            _mxarray22_));
                    if (v_1 > e_1) {
                        mlfAssign(&ct1, _mxarray97_);
                    } else {
                        for (; ; ) {
                            int v_2 = mclForIntStart(1);
                            int e_2
                              = mclForIntEnd(
                                  mlfSize(
                                    mclValueVarargout(),
                                    mclVv(BarSimilarity, "BarSimilarity"),
                                    _mxarray41_));
                            if (v_2 > e_2) {
                                mlfAssign(&ct2, _mxarray97_);
                            } else {
                                for (; ; ) {
                                    mlfAssign(
                                      &Pos1,
                                      mclPlus(
                                        mlfScalar(v_),
                                        mclMtimes(
                                          mlfScalar(v_1 - 1),
                                          mclVv(
                                            BarSizeInHalfBeats,
                                            "BarSizeInHalfBeats"))));
                                    mlfAssign(
                                      &Pos2,
                                      mclPlus(
                                        mlfScalar(v_),
                                        mclMtimes(
                                          mlfScalar(v_2 - 1),
                                          mclVv(
                                            BarSizeInHalfBeats,
                                            "BarSizeInHalfBeats"))));
                                    mclIntArrayAssign2(
                                      &BarSimilarity,
                                      mlfMean(
                                        mlfDiag(
                                          mclArrayRef2(
                                            mclVv(
                                              SelfSimilarity, "SelfSimilarity"),
                                            mlfColon(
                                              mclVv(Pos1, "Pos1"),
                                              mclPlus(
                                                mclVv(Pos1, "Pos1"),
                                                mclMinus(
                                                  mclVv(
                                                    BarSizeInHalfBeats,
                                                    "BarSizeInHalfBeats"),
                                                  _mxarray22_)),
                                              NULL),
                                            mlfColon(
                                              mclVv(Pos2, "Pos2"),
                                              mclPlus(
                                                mclVv(Pos2, "Pos2"),
                                                mclMinus(
                                                  mclVv(
                                                    BarSizeInHalfBeats,
                                                    "BarSizeInHalfBeats"),
                                                  _mxarray22_)),
                                              NULL)),
                                          NULL),
                                        NULL),
                                      v_1,
                                      v_2);
                                    mclIntArrayAssign2(
                                      &BarSimilarity,
                                      mclIntArrayRef2(
                                        mclVv(BarSimilarity, "BarSimilarity"),
                                        v_1,
                                        v_2),
                                      v_2,
                                      v_1);
                                    if (v_2 == e_2) {
                                        break;
                                    }
                                    ++v_2;
                                }
                                mlfAssign(&ct2, mlfScalar(v_2));
                            }
                            if (v_1 == e_1) {
                                break;
                            }
                            ++v_1;
                        }
                        mlfAssign(&ct1, mlfScalar(v_1));
                    }
                }
                mclIntArrayAssign2(&BarSimilarity, _mxarray44_, 1, 1);
                mlfIndexAssign(
                  &BarSimilarities,
                  "(?,?,?)",
                  mlfCreateColonIndex(),
                  mlfCreateColonIndex(),
                  mlfScalar(v_),
                  mclVv(BarSimilarity, "BarSimilarity"));
                mlfAssign(
                  &Temp,
                  mclArrayRef2(
                    mclVv(BarSimilarity, "BarSimilarity"),
                    mlfColon(
                      _mxarray23_,
                      mclMinus(
                        mlfEnd(
                          mclVv(BarSimilarity, "BarSimilarity"),
                          _mxarray22_,
                          _mxarray41_),
                        _mxarray41_),
                      NULL),
                    mlfColon(
                      _mxarray23_,
                      mclMinus(
                        mlfEnd(
                          mclVv(BarSimilarity, "BarSimilarity"),
                          _mxarray41_,
                          _mxarray41_),
                        _mxarray41_),
                      NULL)));
                mlfAssign(
                  &Temp, mlfAbs(mlfDiff(mclVv(Temp, "Temp"), NULL, NULL)));
                mclIntArrayAssign1(
                  &PossibleBarStarts,
                  mlfMean(
                    mclArrayRef1(mclVv(Temp, "Temp"), mlfCreateColonIndex()),
                    NULL),
                  v_);
                if (v_ == e_) {
                    break;
                }
                v_ += i_;
            }
            mlfAssign(&FirstBarStart, mlfScalar(v_));
        }
    }
    /*
     * 
     * % Now pick the best bar start. If it is on an offbeat, choose the next beat
     * % as the correct bar start.
     * BestBarStarts = find( PossibleBarStarts == max( PossibleBarStarts ) );
     */
    mlfAssign(
      &BestBarStarts,
      mlfFind(
        NULL,
        NULL,
        mclEq(
          mclVv(PossibleBarStarts, "PossibleBarStarts"),
          mlfMax(
            NULL, mclVv(PossibleBarStarts, "PossibleBarStarts"), NULL, NULL))));
    /*
     * BarStart = BestBarStarts(1);
     */
    mlfAssign(
      &BarStart, mclIntArrayRef1(mclVv(BestBarStarts, "BestBarStarts"), 1));
    /*
     * if ( mod( BarStart, 2 ) == 0 )
     */
    if (mclEqBool(
          mlfMod(mclVv(BarStart, "BarStart"), _mxarray41_), _mxarray44_)) {
        /*
         * BarStart = mod( BarStart + 1, BarSize );
         */
        mlfAssign(
          &BarStart,
          mlfMod(
            mclPlus(mclVv(BarStart, "BarStart"), _mxarray22_),
            mclVv(BarSize, "BarSize")));
    /*
     * end
     */
    }
    /*
     * 
     * BarSimilarity = BarSimilarities( :, :, BarStart );
     */
    mlfAssign(
      &BarSimilarity,
      mlfIndexRef(
        mclVv(BarSimilarities, "BarSimilarities"),
        "(?,?,?)",
        mlfCreateColonIndex(),
        mlfCreateColonIndex(),
        mclVv(BarStart, "BarStart")));
    /*
     * disp( 'Calculated Bar Similarity.' );
     */
    mlfDisp(_mxarray119_);
    /*
     * 
     * % Now we know when the first bar occurs we can shift the Gap values,
     * % Similarity, Energy data etc to start at that point.
     * GapInSamples = GapInSamples + ((BarStart - 1)/2)*Interval;
     */
    mlfAssign(
      &GapInSamples,
      mclPlus(
        mclVv(GapInSamples, "GapInSamples"),
        mclMtimes(
          mclMrdivide(
            mclMinus(mclVv(BarStart, "BarStart"), _mxarray22_), _mxarray41_),
          mclVv(Interval, "Interval"))));
    /*
     * GapInSeconds = GapInSamples / Frequency;
     */
    mlfAssign(
      &GapInSeconds,
      mclMrdivide(
        mclVv(GapInSamples, "GapInSamples"), mclVv(Frequency, "Frequency")));
    /*
     * Energy = Energy( BarStart:end );
     */
    mlfAssign(
      &Energy,
      mclArrayRef1(
        mclVv(Energy, "Energy"),
        mlfColon(
          mclVv(BarStart, "BarStart"),
          mlfEnd(mclVv(Energy, "Energy"), _mxarray22_, _mxarray22_),
          NULL)));
    /*
     * AbsoluteEnergy = AbsoluteEnergy( BarStart:end );
     */
    mlfAssign(
      &AbsoluteEnergy,
      mclArrayRef1(
        mclVv(AbsoluteEnergy, "AbsoluteEnergy"),
        mlfColon(
          mclVv(BarStart, "BarStart"),
          mlfEnd(
            mclVv(AbsoluteEnergy, "AbsoluteEnergy"), _mxarray22_, _mxarray22_),
          NULL)));
    /*
     * BeatData = BeatData( BarStart:end, BarStart:end );
     */
    mlfAssign(
      &BeatData,
      mclArrayRef2(
        mclVv(BeatData, "BeatData"),
        mlfColon(
          mclVv(BarStart, "BarStart"),
          mlfEnd(mclVv(BeatData, "BeatData"), _mxarray22_, _mxarray41_),
          NULL),
        mlfColon(
          mclVv(BarStart, "BarStart"),
          mlfEnd(mclVv(BeatData, "BeatData"), _mxarray41_, _mxarray41_),
          NULL)));
    /*
     * 
     * 
     * % Now we want to use the self-similarity matrix of bars to compute a linear
     * % grouping of the music. First we find all the maximal cliques of similar
     * % bars and then use a greedy algorithm to choose a linear combination of
     * % these.
     * 
     * % Threshold the self-similarity matrix
     * Z = BarSimilarity;
     */
    mlfAssign(&Z, mclVv(BarSimilarity, "BarSimilarity"));
    /*
     * Z(1,1) = 1;
     */
    mclIntArrayAssign2(&Z, _mxarray22_, 1, 1);
    /*
     * Z( Z > 0.90 ) = 1;
     */
    mclArrayAssign1(&Z, _mxarray22_, mclGt(mclVv(Z, "Z"), _mxarray121_));
    /*
     * Z( Z < 1 ) = 0;
     */
    mclArrayAssign1(&Z, _mxarray44_, mclLt(mclVv(Z, "Z"), _mxarray22_));
    /*
     * 
     * % Find the maximalcliques
     * Y = maximalcliques( Z );
     */
    mlfAssign(&Y, mlfMaximalcliques(mclVv(Z, "Z")));
    /*
     * 
     * % Place the returned cliques into a matrix representation
     * X = [];
     */
    mlfAssign(&X, _mxarray97_);
    /*
     * CurrentMax = 0;
     */
    mlfAssign(&CurrentMax, _mxarray44_);
    /*
     * for ct1 = 1 : size( Y, 2 )
     */
    {
        int v_ = mclForIntStart(1);
        int e_
          = mclForIntEnd(
              mlfSize(mclValueVarargout(), mclVv(Y, "Y"), _mxarray41_));
        if (v_ > e_) {
            mlfAssign(&ct1, _mxarray97_);
        } else {
            /*
             * ThisClique = Y{ct1};
             * CliqueSize = size( ThisClique, 2 );
             * if ( CurrentMax < CliqueSize  )
             * CurrentMax = CliqueSize;
             * end
             * 
             * X( ct1, 1:CurrentMax ) = [ ThisClique zeros( 1, CurrentMax - CliqueSize ) ];
             * end
             */
            for (; ; ) {
                mlfAssign(
                  &ThisClique,
                  mlfIndexRef(mclVv(Y, "Y"), "{?}", mlfScalar(v_)));
                mlfAssign(
                  &CliqueSize,
                  mlfSize(
                    mclValueVarargout(),
                    mclVv(ThisClique, "ThisClique"),
                    _mxarray41_));
                if (mclLtBool(
                      mclVv(CurrentMax, "CurrentMax"),
                      mclVv(CliqueSize, "CliqueSize"))) {
                    mlfAssign(&CurrentMax, mclVv(CliqueSize, "CliqueSize"));
                }
                mclArrayAssign2(
                  &X,
                  mlfHorzcat(
                    mclVv(ThisClique, "ThisClique"),
                    mlfZeros(
                      _mxarray22_,
                      mclMinus(
                        mclVv(CurrentMax, "CurrentMax"),
                        mclVv(CliqueSize, "CliqueSize")),
                      NULL),
                    NULL),
                  mlfScalar(v_),
                  mlfColon(_mxarray22_, mclVv(CurrentMax, "CurrentMax"), NULL));
                if (v_ == e_) {
                    break;
                }
                ++v_;
            }
            mlfAssign(&ct1, mlfScalar(v_));
        }
    }
    /*
     * 
     * % Greedily choose the biggest cliques. We make sure cliques whoch are very
     * % large are not chosen in order to keep the grouping interesting.
     * SimilarSections = zeros( size( BarSimilarity, 2), 1 );
     */
    mlfAssign(
      &SimilarSections,
      mlfZeros(
        mlfSize(
          mclValueVarargout(),
          mclVv(BarSimilarity, "BarSimilarity"),
          _mxarray41_),
        _mxarray22_,
        NULL));
    /*
     * NextSection = 1;
     */
    mlfAssign(&NextSection, _mxarray22_);
    /*
     * X2 = X;
     */
    mlfAssign(&X2, mclVv(X, "X"));
    /*
     * while( any( X2(:) ~= 0 ) )
     */
    while (mlfTobool(
             mlfAny(
               mclNe(
                 mclArrayRef1(mclVv(X2, "X2"), mlfCreateColonIndex()),
                 _mxarray44_),
               NULL))) {
        /*
         * [ Junk, Index ] = sort( sum( X2 ~= 0, 2 ) );
         */
        mlfAssign(
          &Junk,
          mlfSort(
            &Index,
            mlfSum(mclNe(mclVv(X2, "X2"), _mxarray44_), _mxarray41_),
            NULL));
        /*
         * 
         * % Find the biggest clique, which is not too big
         * ct1 = 0;
         */
        mlfAssign(&ct1, _mxarray44_);
        /*
         * i = Index( end );
         */
        mlfAssign(
          &i,
          mclArrayRef1(
            mclVv(Index, "Index"),
            mlfEnd(mclVv(Index, "Index"), _mxarray22_, _mxarray22_)));
        /*
         * SelectedClique = X2( i, : );
         */
        mlfAssign(
          &SelectedClique,
          mclArrayRef2(mclVv(X2, "X2"), mclVv(i, "i"), mlfCreateColonIndex()));
        /*
         * while( (sum(SelectedClique ~= 0 ) > size( BarSimilarity, 2) * 0.5) && (size(Index, 1)-ct1 > 0) )
         */
        while (mclScalarToBool(
                 mclGt(
                   mlfSum(
                     mclNe(
                       mclVv(SelectedClique, "SelectedClique"), _mxarray44_),
                     NULL),
                   mclMtimes(
                     mlfSize(
                       mclValueVarargout(),
                       mclVv(BarSimilarity, "BarSimilarity"),
                       _mxarray41_),
                     _mxarray94_)))
               && mclScalarToBool(
                    mclGt(
                      mclMinus(
                        mlfSize(
                          mclValueVarargout(),
                          mclVv(Index, "Index"),
                          _mxarray22_),
                        mclVv(ct1, "ct1")),
                      _mxarray44_))) {
            /*
             * disp( 'Ignoring a too large clique' );
             */
            mlfDisp(_mxarray122_);
            /*
             * ct1 = ct1 + 1;
             */
            mlfAssign(&ct1, mclPlus(mclVv(ct1, "ct1"), _mxarray22_));
            /*
             * i = Index( end - ct1 );
             */
            mlfAssign(
              &i,
              mclArrayRef1(
                mclVv(Index, "Index"),
                mclMinus(
                  mlfEnd(mclVv(Index, "Index"), _mxarray22_, _mxarray22_),
                  mclVv(ct1, "ct1"))));
            /*
             * SelectedClique = X2( i, : );
             */
            mlfAssign(
              &SelectedClique,
              mclArrayRef2(
                mclVv(X2, "X2"), mclVv(i, "i"), mlfCreateColonIndex()));
        /*
         * end
         */
        }
        /*
         * 
         * % Break out of the loop if only single element cliques are left.
         * if ( sum(SelectedClique ~= 0 ) <= 1 )
         */
        if (mclLeBool(
              mlfSum(
                mclNe(mclVv(SelectedClique, "SelectedClique"), _mxarray44_),
                NULL),
              _mxarray22_)) {
            /*
             * break;    
             */
            break;
        /*
         * end
         */
        }
        /*
         * 
         * SimilarSections( SelectedClique( SelectedClique ~= 0 ) ) = NextSection;
         */
        mclArrayAssign1(
          &SimilarSections,
          mclVv(NextSection, "NextSection"),
          mclArrayRef1(
            mclVv(SelectedClique, "SelectedClique"),
            mclNe(mclVv(SelectedClique, "SelectedClique"), _mxarray44_)));
        /*
         * NextSection = NextSection + 1;
         */
        mlfAssign(
          &NextSection,
          mclPlus(mclVv(NextSection, "NextSection"), _mxarray22_));
        /*
         * 
         * % Remove the chosen elements from any remaining cliques
         * for ct1 = 1 : size( SelectedClique, 2 )
         */
        {
            int v_ = mclForIntStart(1);
            int e_
              = mclForIntEnd(
                  mlfSize(
                    mclValueVarargout(),
                    mclVv(SelectedClique, "SelectedClique"),
                    _mxarray41_));
            if (v_ > e_) {
                mlfAssign(&ct1, _mxarray97_);
            } else {
                /*
                 * NodeInClique = SelectedClique( ct1 );
                 * X2( X2 == NodeInClique ) = 0;          
                 * end
                 */
                for (; ; ) {
                    mlfAssign(
                      &NodeInClique,
                      mclIntArrayRef1(
                        mclVv(SelectedClique, "SelectedClique"), v_));
                    mclArrayAssign1(
                      &X2,
                      _mxarray44_,
                      mclEq(
                        mclVv(X2, "X2"), mclVv(NodeInClique, "NodeInClique")));
                    if (v_ == e_) {
                        break;
                    }
                    ++v_;
                }
                mlfAssign(&ct1, mlfScalar(v_));
            }
        }
    /*
     * end
     */
    }
    /*
     * 
     * % Now give any remaining bars their own sections.
     * Next = max( SimilarSections ) + 1;
     */
    mlfAssign(
      &Next,
      mclPlus(
        mlfMax(NULL, mclVv(SimilarSections, "SimilarSections"), NULL, NULL),
        _mxarray22_));
    /*
     * for ct1 = 1 : size( SimilarSections, 1 )
     */
    {
        int v_ = mclForIntStart(1);
        int e_
          = mclForIntEnd(
              mlfSize(
                mclValueVarargout(),
                mclVv(SimilarSections, "SimilarSections"),
                _mxarray22_));
        if (v_ > e_) {
            mlfAssign(&ct1, _mxarray97_);
        } else {
            /*
             * if ( SimilarSections( ct1 ) == 0 )
             * SimilarSections( ct1 ) = Next;
             * Next = Next + 1;
             * end
             * end
             */
            for (; ; ) {
                if (mclEqBool(
                      mclIntArrayRef1(
                        mclVv(SimilarSections, "SimilarSections"), v_),
                      _mxarray44_)) {
                    mclIntArrayAssign1(
                      &SimilarSections, mclVv(Next, "Next"), v_);
                    mlfAssign(&Next, mclPlus(mclVv(Next, "Next"), _mxarray22_));
                }
                if (v_ == e_) {
                    break;
                }
                ++v_;
            }
            mlfAssign(&ct1, mlfScalar(v_));
        }
    }
    /*
     * 
     * % For each beat we store which section it is in.
     * SimilarityOnBeats = zeros( size( Energy, 2 ) );
     */
    mlfAssign(
      &SimilarityOnBeats,
      mlfZeros(
        mlfSize(mclValueVarargout(), mclVv(Energy, "Energy"), _mxarray41_),
        NULL));
    /*
     * for ct1 = 1 : size( SimilarSections, 1 )
     */
    {
        int v_ = mclForIntStart(1);
        int e_
          = mclForIntEnd(
              mlfSize(
                mclValueVarargout(),
                mclVv(SimilarSections, "SimilarSections"),
                _mxarray22_));
        if (v_ > e_) {
            mlfAssign(&ct1, _mxarray97_);
        } else {
            /*
             * Range = ( 1 + (ct1 - 1)*BarSizeInHalfBeats : 1 + (ct1*BarSizeInHalfBeats) -1 );
             * SimilarityOnBeats( Range ) = SimilarSections( ct1 );
             * end
             */
            for (; ; ) {
                mlfAssign(
                  &Range,
                  mlfColon(
                    mclPlus(
                      _mxarray22_,
                      mclMtimes(
                        mlfScalar(v_ - 1),
                        mclVv(BarSizeInHalfBeats, "BarSizeInHalfBeats"))),
                    mclMinus(
                      mclPlus(
                        _mxarray22_,
                        mclMtimes(
                          mlfScalar(v_),
                          mclVv(BarSizeInHalfBeats, "BarSizeInHalfBeats"))),
                      _mxarray22_),
                    NULL));
                mclArrayAssign1(
                  &SimilarityOnBeats,
                  mclIntArrayRef1(
                    mclVv(SimilarSections, "SimilarSections"), v_),
                  mclVv(Range, "Range"));
                if (v_ == e_) {
                    break;
                }
                ++v_;
            }
            mlfAssign(&ct1, mlfScalar(v_));
        }
    }
    /*
     * disp( 'Divided song into groups.' );
     */
    mlfDisp(_mxarray124_);
    /*
     * 
     * 
     * % Extract pauses from the music. Simply find bars which are very quiet.
     * PauseThreshold = 150;
     */
    mlfAssign(&PauseThreshold, _mxarray126_);
    /*
     * Temp = find( AbsoluteEnergy >= PauseThreshold );
     */
    mlfAssign(
      &Temp,
      mlfFind(
        NULL,
        NULL,
        mclGe(
          mclVv(AbsoluteEnergy, "AbsoluteEnergy"),
          mclVv(PauseThreshold, "PauseThreshold"))));
    /*
     * FirstMajorEnergy  = Temp(1);
     */
    mlfAssign(&FirstMajorEnergy, mclIntArrayRef1(mclVv(Temp, "Temp"), 1));
    /*
     * LastMajorEnergy = Temp(end);
     */
    mlfAssign(
      &LastMajorEnergy,
      mclArrayRef1(
        mclVv(Temp, "Temp"),
        mlfEnd(mclVv(Temp, "Temp"), _mxarray22_, _mxarray22_)));
    /*
     * Pauses = [];
     */
    mlfAssign(&Pauses, _mxarray97_);
    /*
     * 
     * for ct1 = 1 : size( BarSimilarity, 1 )
     */
    {
        int v_ = mclForIntStart(1);
        int e_
          = mclForIntEnd(
              mlfSize(
                mclValueVarargout(),
                mclVv(BarSimilarity, "BarSimilarity"),
                _mxarray22_));
        if (v_ > e_) {
            mlfAssign(&ct1, _mxarray97_);
        } else {
            /*
             * Range = ( 1 + (ct1 - 1)*BarSizeInHalfBeats : 1 + (ct1*BarSizeInHalfBeats) -1 );
             * BarAbsoluteEnergy = AbsoluteEnergy( Range );
             * 
             * if ( prctile( BarAbsoluteEnergy, 65 ) < PauseThreshold && Range(1) > FirstMajorEnergy && Range(end) < LastMajorEnergy )
             * Pauses = [ Pauses ; [ ((Range(1)-1)/2)-1, BarSize * (Interval / Frequency ) ] ];        
             * end
             * end
             */
            for (; ; ) {
                mlfAssign(
                  &Range,
                  mlfColon(
                    mclPlus(
                      _mxarray22_,
                      mclMtimes(
                        mlfScalar(v_ - 1),
                        mclVv(BarSizeInHalfBeats, "BarSizeInHalfBeats"))),
                    mclMinus(
                      mclPlus(
                        _mxarray22_,
                        mclMtimes(
                          mlfScalar(v_),
                          mclVv(BarSizeInHalfBeats, "BarSizeInHalfBeats"))),
                      _mxarray22_),
                    NULL));
                mlfAssign(
                  &BarAbsoluteEnergy,
                  mclArrayRef1(
                    mclVv(AbsoluteEnergy, "AbsoluteEnergy"),
                    mclVv(Range, "Range")));
                if (mclScalarToBool(
                      mclLt(
                        mlfPrctile(
                          mclVv(BarAbsoluteEnergy, "BarAbsoluteEnergy"),
                          _mxarray127_),
                        mclVv(PauseThreshold, "PauseThreshold")))
                    && mclScalarToBool(
                         mclGt(
                           mclIntArrayRef1(mclVv(Range, "Range"), 1),
                           mclVv(FirstMajorEnergy, "FirstMajorEnergy")))
                    && mclScalarToBool(
                         mclLt(
                           mclArrayRef1(
                             mclVv(Range, "Range"),
                             mlfEnd(
                               mclVv(Range, "Range"),
                               _mxarray22_,
                               _mxarray22_)),
                           mclVv(LastMajorEnergy, "LastMajorEnergy")))) {
                    mlfAssign(
                      &Pauses,
                      mlfVertcat(
                        mclVv(Pauses, "Pauses"),
                        mlfHorzcat(
                          mclMinus(
                            mclMrdivide(
                              mclMinus(
                                mclIntArrayRef1(mclVv(Range, "Range"), 1),
                                _mxarray22_),
                              _mxarray41_),
                            _mxarray22_),
                          mclMtimes(
                            mclVv(BarSize, "BarSize"),
                            mclMrdivide(
                              mclVv(Interval, "Interval"),
                              mclVv(Frequency, "Frequency"))),
                          NULL),
                        NULL));
                }
                if (v_ == e_) {
                    break;
                }
                ++v_;
            }
            mlfAssign(&ct1, mlfScalar(v_));
        }
    }
    /*
     * disp( 'Found pauses.' );
     */
    mlfDisp(_mxarray128_);
    /*
     * 
     * 
     * % Find good positions for freeze arrows. This is done by finding areas in
     * % the song with no large onsets.
     * Z = SmoothedData ./ max( SmoothedData );
     */
    mlfAssign(
      &Z,
      mclRdivide(
        mclVv(SmoothedData, "SmoothedData"),
        mlfMax(NULL, mclVv(SmoothedData, "SmoothedData"), NULL, NULL)));
    /*
     * A = gradient( Z );
     */
    mlfAssign(&A, mlfGradient(mclValueVarargout(), mclVv(Z, "Z"), NULL));
    /*
     * 
     * Freezes = [];
     */
    mlfAssign(&Freezes, _mxarray97_);
    /*
     * FreezeStarted = 0;
     */
    mlfAssign(&FreezeStarted, _mxarray44_);
    /*
     * for ct1 = FirstMajorEnergy : LastMajorEnergy
     */
    {
        mclForLoopIterator viter__;
        for (mclForStart(
               &viter__,
               mclVv(FirstMajorEnergy, "FirstMajorEnergy"),
               mclVv(LastMajorEnergy, "LastMajorEnergy"),
               NULL);
             mclForNext(&viter__, &ct1);
             ) {
            /*
             * WaveformStart = round( GapInSamples + ((ct1 - 1)/2)*Interval );
             */
            mlfAssign(
              &WaveformStart,
              mlfRound(
                mclPlus(
                  mclVv(GapInSamples, "GapInSamples"),
                  mclMtimes(
                    mclMrdivide(
                      mclMinus(mclVv(ct1, "ct1"), _mxarray22_), _mxarray41_),
                    mclVv(Interval, "Interval")))));
            /*
             * WaveformEnd   = round( GapInSamples + ((ct1)/2)*Interval - 1 );    
             */
            mlfAssign(
              &WaveformEnd,
              mlfRound(
                mclMinus(
                  mclPlus(
                    mclVv(GapInSamples, "GapInSamples"),
                    mclMtimes(
                      mclMrdivide(mclVv(ct1, "ct1"), _mxarray41_),
                      mclVv(Interval, "Interval"))),
                  _mxarray22_)));
            /*
             * 
             * if ( ~isempty( Pauses ) & any( ( ((Pauses( :, 1 )+1).*2)+1  <= ct1  ) & ( ((Pauses( :, 1 )+1).*2)+BarSizeInHalfBeats+1  >= ct1 ) ) )
             */
            {
                mxArray * a_
                  = mclInitialize(mclNot(mlfIsempty(mclVv(Pauses, "Pauses"))));
                if (mlfTobool(a_)
                    && mlfTobool(
                         mclAnd(
                           a_,
                           mlfAny(
                             mclAnd(
                               mclLe(
                                 mclPlus(
                                   mclTimes(
                                     mclPlus(
                                       mclArrayRef2(
                                         mclVv(Pauses, "Pauses"),
                                         mlfCreateColonIndex(),
                                         _mxarray22_),
                                       _mxarray22_),
                                     _mxarray41_),
                                   _mxarray22_),
                                 mclVv(ct1, "ct1")),
                               mclGe(
                                 mclPlus(
                                   mclPlus(
                                     mclTimes(
                                       mclPlus(
                                         mclArrayRef2(
                                           mclVv(Pauses, "Pauses"),
                                           mlfCreateColonIndex(),
                                           _mxarray22_),
                                         _mxarray22_),
                                       _mxarray41_),
                                     mclVv(
                                       BarSizeInHalfBeats,
                                       "BarSizeInHalfBeats")),
                                   _mxarray22_),
                                 mclVv(ct1, "ct1"))),
                             NULL)))) {
                    mxDestroyArray(a_);
                    /*
                     * FreezeStarted = 0;
                     */
                    mlfAssign(&FreezeStarted, _mxarray44_);
                    /*
                     * continue;
                     */
                    continue;
                } else {
                    mxDestroyArray(a_);
                }
            /*
             * end
             */
            }
            /*
             * 
             * if ( max( A(WaveformStart:WaveformEnd) ) < 8e-5 && AbsoluteEnergy( ct1 ) < 3000 && AbsoluteEnergy( ct1 ) > 0 )
             */
            if (mclScalarToBool(
                  mclLt(
                    mlfMax(
                      NULL,
                      mclArrayRef1(
                        mclVv(A, "A"),
                        mlfColon(
                          mclVv(WaveformStart, "WaveformStart"),
                          mclVv(WaveformEnd, "WaveformEnd"),
                          NULL)),
                      NULL,
                      NULL),
                    _mxarray130_))
                && mclScalarToBool(
                     mclLt(
                       mclArrayRef1(
                         mclVv(AbsoluteEnergy, "AbsoluteEnergy"),
                         mclVv(ct1, "ct1")),
                       _mxarray131_))
                && mclScalarToBool(
                     mclGt(
                       mclArrayRef1(
                         mclVv(AbsoluteEnergy, "AbsoluteEnergy"),
                         mclVv(ct1, "ct1")),
                       _mxarray44_))) {
                /*
                 * if ( FreezeStarted == 0 )
                 */
                if (mclEqBool(
                      mclVv(FreezeStarted, "FreezeStarted"), _mxarray44_)) {
                    /*
                     * FreezeStarted = ( floor( ct1 / 2 ) * 2 ) - 1;
                     */
                    mlfAssign(
                      &FreezeStarted,
                      mclMinus(
                        mclMtimes(
                          mlfFloor(mclMrdivide(mclVv(ct1, "ct1"), _mxarray41_)),
                          _mxarray41_),
                        _mxarray22_));
                /*
                 * end
                 */
                }
            /*
             * else
             */
            } else {
                /*
                 * if ( FreezeStarted > 0 )
                 */
                if (mclGtBool(
                      mclVv(FreezeStarted, "FreezeStarted"), _mxarray44_)) {
                    /*
                     * if ( FreezeStarted < ct1-6 )
                     */
                    if (mclLtBool(
                          mclVv(FreezeStarted, "FreezeStarted"),
                          mclMinus(mclVv(ct1, "ct1"), _mxarray24_))) {
                        /*
                         * FreezeEnd = ct1;
                         */
                        mlfAssign(&FreezeEnd, mclVv(ct1, "ct1"));
                        /*
                         * if ( mod( FreezeEnd, 2 ) == 0 )
                         */
                        if (mclEqBool(
                              mlfMod(
                                mclVv(FreezeEnd, "FreezeEnd"), _mxarray41_),
                              _mxarray44_)) {
                            /*
                             * FreezeEnd = FreezeEnd - 1;    
                             */
                            mlfAssign(
                              &FreezeEnd,
                              mclMinus(
                                mclVv(FreezeEnd, "FreezeEnd"), _mxarray22_));
                        /*
                         * end
                         */
                        }
                        /*
                         * Freezes = [ Freezes ; FreezeStarted FreezeEnd ];
                         */
                        mlfAssign(
                          &Freezes,
                          mlfVertcat(
                            mclVv(Freezes, "Freezes"),
                            mlfHorzcat(
                              mclVv(FreezeStarted, "FreezeStarted"),
                              mclVv(FreezeEnd, "FreezeEnd"),
                              NULL),
                            NULL));
                    /*
                     * end
                     */
                    }
                /*
                 * end
                 */
                }
                /*
                 * FreezeStarted = 0;
                 */
                mlfAssign(&FreezeStarted, _mxarray44_);
            /*
             * end
             */
            }
        /*
         * end
         */
        }
        mclDestroyForLoopIterator(viter__);
    }
    /*
     * 
     * % Freezes longer than 8 half beats we deal with after placing the rest of
     * % the arrows.
     * LongFreezes = [];
     */
    mlfAssign(&LongFreezes, _mxarray97_);
    /*
     * FreezeBeats = zeros( size( Energy ) );
     */
    mlfAssign(
      &FreezeBeats,
      mlfZeros(
        mlfSize(mclValueVarargout(), mclVv(Energy, "Energy"), NULL), NULL));
    /*
     * for ct1 = 1 : size( Freezes, 1 )
     */
    {
        int v_ = mclForIntStart(1);
        int e_
          = mclForIntEnd(
              mlfSize(
                mclValueVarargout(), mclVv(Freezes, "Freezes"), _mxarray22_));
        if (v_ > e_) {
            mlfAssign(&ct1, _mxarray97_);
        } else {
            /*
             * if ( Freezes( ct1, 2 ) - Freezes( ct1, 1 ) < 8 )
             * FreezeBeats( Freezes( ct1, 1 ):Freezes( ct1, 2 ) ) = 1;
             * else
             * LongFreezes = [ LongFreezes ; Freezes( ct1, 1 ), Freezes( ct1, 2 ) ];           
             * end
             * end
             */
            for (; ; ) {
                if (mclLtBool(
                      mclMinus(
                        mclIntArrayRef2(mclVv(Freezes, "Freezes"), v_, 2),
                        mclIntArrayRef2(mclVv(Freezes, "Freezes"), v_, 1)),
                      _mxarray39_)) {
                    mclArrayAssign1(
                      &FreezeBeats,
                      _mxarray22_,
                      mlfColon(
                        mclIntArrayRef2(mclVv(Freezes, "Freezes"), v_, 1),
                        mclIntArrayRef2(mclVv(Freezes, "Freezes"), v_, 2),
                        NULL));
                } else {
                    mlfAssign(
                      &LongFreezes,
                      mlfVertcat(
                        mclVv(LongFreezes, "LongFreezes"),
                        mlfHorzcat(
                          mclIntArrayRef2(mclVv(Freezes, "Freezes"), v_, 1),
                          mclIntArrayRef2(mclVv(Freezes, "Freezes"), v_, 2),
                          NULL),
                        NULL));
                }
                if (v_ == e_) {
                    break;
                }
                ++v_;
            }
            mlfAssign(&ct1, mlfScalar(v_));
        }
    }
    /*
     * disp( 'Found freeze arrow positions.' );
     */
    mlfDisp(_mxarray132_);
    /*
     * 
     * 
     * % Here the patterns of arrows are created.
     * 
     * % Set variables which do not change when generating each set of arrows
     * DifficultyOffbeatModifier = [ 0 0 0 0.2 0.5 0.6 0.7 0.8 0.9 ];
     */
    mlfAssign(&DifficultyOffbeatModifier, _mxarray134_);
    /*
     * DifficultyRatings = [ 107 137 170 194 228 262 305 366 ];
     */
    mlfAssign(&DifficultyRatings, _mxarray136_);
    /*
     * NumBars = size( BarSimilarity, 2 );
     */
    mlfAssign(
      &NumBars,
      mlfSize(
        mclValueVarargout(),
        mclVv(BarSimilarity, "BarSimilarity"),
        _mxarray41_));
    /*
     * 
     * 
     * % The Allowable moves matrix stores which arrows can be placed depending
     * % on the position of the players feet and which foot they will move next.
     * AllowableMoves = [];
     */
    mlfAssign(&AllowableMoves, _mxarray97_);
    /*
     * %                            [    Left    ] [   Right   ] [ Index  ]
     * AllowableMoves( :, :, 1 )  = [ 1  1  1  0  ; 0  1  1  1  ; 1 0 0 2 ];
     */
    mlfIndexAssign(
      &AllowableMoves,
      "(?,?,?)",
      mlfCreateColonIndex(),
      mlfCreateColonIndex(),
      _mxarray22_,
      _mxarray138_);
    /*
     * AllowableMoves( :, :, 2 )  = [ 1  1  1  0  ; .1 1  0  1  ; 0 0 1 2 ];
     */
    mlfIndexAssign(
      &AllowableMoves,
      "(?,?,?)",
      mlfCreateColonIndex(),
      mlfCreateColonIndex(),
      _mxarray41_,
      _mxarray140_);
    /*
     * AllowableMoves( :, :, 3 )  = [ 1  1  0  .1 ; 0  1  1  1  ; 1 0 2 0 ];
     */
    mlfIndexAssign(
      &AllowableMoves,
      "(?,?,?)",
      mlfCreateColonIndex(),
      mlfCreateColonIndex(),
      _mxarray23_,
      _mxarray142_);
    /*
     * AllowableMoves( :, :, 4 )  = [ 1  1  1  0  ; .1 0  1  1  ; 0 1 0 2 ];
     */
    mlfIndexAssign(
      &AllowableMoves,
      "(?,?,?)",
      mlfCreateColonIndex(),
      mlfCreateColonIndex(),
      _mxarray40_,
      _mxarray144_);
    /*
     * AllowableMoves( :, :, 5 )  = [ 1  0  1  .1 ; 0  1  1  1  ; 1 2 0 0 ];
     */
    mlfIndexAssign(
      &AllowableMoves,
      "(?,?,?)",
      mlfCreateColonIndex(),
      mlfCreateColonIndex(),
      _mxarray32_,
      _mxarray146_);
    /*
     * AllowableMoves( :, :, 6 )  = [ 1  1  0  .1 ; .1 0  1  1  ; 0 1 2 0 ];
     */
    mlfIndexAssign(
      &AllowableMoves,
      "(?,?,?)",
      mlfCreateColonIndex(),
      mlfCreateColonIndex(),
      _mxarray24_,
      _mxarray148_);
    /*
     * AllowableMoves( :, :, 7 )  = [ 1  0  1  .1 ; .1 1  0  1  ; 0 2 1 0 ];
     */
    mlfIndexAssign(
      &AllowableMoves,
      "(?,?,?)",
      mlfCreateColonIndex(),
      mlfCreateColonIndex(),
      _mxarray150_,
      _mxarray151_);
    /*
     * AllowableMoves( :, :, 8 )  = [ 1  0  1  0  ; 0  1  0  0  ; 0 2 0 1 ];
     */
    mlfIndexAssign(
      &AllowableMoves,
      "(?,?,?)",
      mlfCreateColonIndex(),
      mlfCreateColonIndex(),
      _mxarray39_,
      _mxarray153_);
    /*
     * AllowableMoves( :, :, 9 )  = [ 1  1  0  0  ; 0  0  1  0  ; 0 0 2 1 ];
     */
    mlfIndexAssign(
      &AllowableMoves,
      "(?,?,?)",
      mlfCreateColonIndex(),
      mlfCreateColonIndex(),
      _mxarray105_,
      _mxarray155_);
    /*
     * AllowableMoves( :, :, 10 ) = [ 0  0  1  0  ; 0  1  0  1  ; 2 0 1 0 ];
     */
    mlfIndexAssign(
      &AllowableMoves,
      "(?,?,?)",
      mlfCreateColonIndex(),
      mlfCreateColonIndex(),
      _mxarray31_,
      _mxarray157_);
    /*
     * AllowableMoves( :, :, 11 ) = [ 0  0  1  0  ; 0  0  1  1  ; 2 1 0 0 ];
     */
    mlfIndexAssign(
      &AllowableMoves,
      "(?,?,?)",
      mlfCreateColonIndex(),
      mlfCreateColonIndex(),
      _mxarray159_,
      _mxarray160_);
    /*
     * 
     * 
     * EnergyDiff = diff( AbsoluteEnergy );
     */
    mlfAssign(
      &EnergyDiff,
      mlfDiff(mclVv(AbsoluteEnergy, "AbsoluteEnergy"), NULL, NULL));
    /*
     * EnergyDiff = [ 0 EnergyDiff ];
     */
    mlfAssign(
      &EnergyDiff,
      mlfHorzcat(_mxarray44_, mclVv(EnergyDiff, "EnergyDiff"), NULL));
    /*
     * 
     * ArrowTrackSize = size( BarSimilarity, 1 ) * MaxArrowsPerBar;
     */
    mlfAssign(
      &ArrowTrackSize,
      mclMtimes(
        mlfSize(
          mclValueVarargout(),
          mclVv(BarSimilarity, "BarSimilarity"),
          _mxarray22_),
        mclVv(MaxArrowsPerBar, "MaxArrowsPerBar")));
    /*
     * ArrowTracks = [];
     */
    mlfAssign(&ArrowTracks, _mxarray97_);
    /*
     * FootRatings = [];
     */
    mlfAssign(&FootRatings, _mxarray97_);
    /*
     * 
     * % For each of the three difficulty levels we will produce arrows for.
     * for ArrowSet = 1 : 3
     */
    {
        int v_ = mclForIntStart(1);
        int e_ = 3;
        if (v_ > e_) {
            mlfAssign(&ArrowSet, _mxarray97_);
        } else {
            /*
             * UserDifficultyRating = ChosenDifficultyRatings( ArrowSet );
             * 
             * OffbeatModifier = DifficultyOffbeatModifier( UserDifficultyRating );
             * AvgArrowsPerLevel = mean( [ DifficultyRatings 420 ; 0 DifficultyRatings ] );
             * 
             * NumArrows = AvgArrowsPerLevel( UserDifficultyRating );
             * ArrowsPerBar = NumArrows / NumBars;
             * ModdedEnergy = Energy;
             * ModdedEnergy( 2:2:end ) = ModdedEnergy( 2:2:end ) .* OffbeatModifier;
             * 
             * % Work out the spread of the arrows based on energy of each bar of
             * % music.
             * FullBarEnergy = [];
             * for ct1 = 1 : size( BarSimilarity, 1 )
             * Range = ( 1 + (ct1 - 1)*BarSizeInHalfBeats : 1 + (ct1*BarSizeInHalfBeats) -1 );
             * FullBarEnergy(ct1) = mean( ModdedEnergy( Range ) );
             * end
             * 
             * % Normalise this and ensure each bar does not have too many or too few
             * % arrows.
             * for ct0 = 1 : 10
             * FullBarEnergy = FullBarEnergy ./ ( sum( FullBarEnergy ) / NumArrows );
             * 
             * for ct1 = 3 : size( BarSimilarity, 1 )
             * if ( all( round( FullBarEnergy( ct1-2:ct1 ) ) < 1 ) ) 
             * FullBarEnergy(ct1) = 1;
             * end
             * if ( all( round( FullBarEnergy( ct1-2:ct1 ) ) >= 7 ) ) 
             * FullBarEnergy(ct1) = 6;
             * end
             * if ( round( FullBarEnergy( ct1 ) ) > 8 )
             * FullBarEnergy(ct1) = 8;    
             * end
             * end
             * 
             * end
             * 
             * CurrentFoot = 0;
             * FootPlacement = [ 1 0 0 2 ];
             * 
             * ArrowTrack = zeros( ArrowTrackSize, 4 );
             * InFreeze = false;
             * 
             * JumpThreshold = 0.95 - ( UserDifficultyRating * 0.03 );
             * 
             * %  For each group we have, compute an arrow pattern for that group
             * SectionArrowData = zeros( BarSizeInHalfBeats, 4,  max( SimilarSections ) ) - 1;
             * for ct1 = 1 : max( SimilarSections )
             * CurrentFoot = 0;
             * FootPlacement = [ 1 0 0 2 ];
             * 
             * % work out average energy and number of notes per bar in this section
             * TempModdedEnergy = ModdedEnergy( SimilarityOnBeats == ct1 );
             * TempEnergy = Energy( SimilarityOnBeats == ct1 );
             * TempFreezes = FreezeBeats( SimilarityOnBeats == ct1 );
             * 
             * BarModdedEnergy = zeros( BarSizeInHalfBeats, 1 );
             * BarEnergy = zeros( BarSizeInHalfBeats, 1 );
             * for ct2 = 1 : BarSizeInHalfBeats
             * BarModdedEnergy( ct2 ) = mean( TempModdedEnergy( ct2:BarSizeInHalfBeats:end ) );
             * BarEnergy( ct2 ) = mean( TempEnergy( ct2:BarSizeInHalfBeats:end ) );
             * BarFreezes( ct2 ) = mean( TempFreezes( ct2:BarSizeInHalfBeats:end ) );
             * end
             * 
             * NumArrows = round( mean( FullBarEnergy( SimilarSections == ct1 ) ) );
             * PlaceArrow = zeros( BarSizeInHalfBeats, 1 );
             * NumArrowsToHave = min( NumArrows, sum( BarModdedEnergy > 0 ) );
             * [ Temp Index ] = sort( BarModdedEnergy );
             * PlaceArrow( Index( end - (NumArrowsToHave - 1):end ) ) = 1;
             * 
             * % Now compute the arrows for that group
             * FreezeOn = false;
             * PrevBeatEnergy = 0.4;
             * BarArrows = zeros( BarSizeInHalfBeats, 4 );
             * for ct2 = 1 : BarSizeInHalfBeats
             * if ( ~FreezeOn & BarFreezes( ct2 ) >= 0.5 )
             * FreezeOn = true;
             * 
             * if ( CurrentFoot == 0 )
             * % Place a left or right arrow to get started.
             * CurrentFoot = ceil(rand(1) * 2); 
             * if ( CurrentFoot == 1 )
             * ArrowType = 1;   
             * else
             * ArrowType = 4;
             * end
             * else      
             * % Find allowable moves pattern for current foot
             * % placement.
             * CurrentFoot = mod( CurrentFoot, 2 ) + 1;
             * 
             * PossibleMoves = [ 0 0 0 0 ];
             * for ct3 = 1 : size( AllowableMoves, 3 )
             * if ( AllowableMoves( 3, :, ct3 ) == FootPlacement )
             * PossibleMoves = AllowableMoves( CurrentFoot, :, ct3 );
             * end
             * end
             * 
             * if ( PossibleMoves == [ 0 0 0 0 ] )
             * error( 'No possible moves found' );    
             * end
             * 
             * % Calculate Probabilities of new move.
             * ProbMoves = cumsum( PossibleMoves ./ sum( PossibleMoves ) );
             * 
             * % Choose arrow based on probabilities
             * Temp = find( ProbMoves >= rand(1) );
             * ArrowType = Temp(1);
             * 
             * end
             * 
             * NewArrow = [ 0 0 0 0 ];
             * NewArrow( ArrowType ) = 2;
             * BarArrows( ct2, : ) = NewArrow;
             * 
             * FootPlacement( FootPlacement == CurrentFoot ) = 0;
             * FootPlacement( NewArrow > 0 ) = CurrentFoot;
             * 
             * FreezeArrow = ArrowType;
             * 
             * elseif ( FreezeOn & mod( ct2, 2 ) == 1 & ( BarFreezes( ct2 ) < 0.5  | ct2 == BarSizeInHalfBeats-1 ) )
             * 
             * FreezeOn = false;
             * NewArrow = [ 0 0 0 0 ];
             * NewArrow( FreezeArrow ) = 3;
             * BarArrows( ct2, : ) = NewArrow;
             * 
             * elseif ( PlaceArrow( ct2 ) == 1 & ~( FreezeOn & ( mod(ct2,2) == 0 | UserDifficultyRating <= 3 | (UserDifficultyRating <= 6 & mod( ct2, 4 ) == 1) ) ) )
             * if ( ~FreezeOn & (BarEnergy(ct2) > PrevBeatEnergy + 0.2) & (BarEnergy(ct2) > JumpThreshold) & mod( ct2, 2 ) == 1 )  %%%% IMPROVE JUMP SELECTION STUFF %%%%
             * % A lot of energy so place a double jump
             * 
             * 
             * JumpType = ceil( rand(1) * 6 );
             * switch( JumpType )
             * case 1
             * BarArrows( ct2, : ) = [ 0 1 1 0 ];
             * % For this double jump foot placement
             * % depends on the previous foot placement.
             * if ( FootPlacement( 3 ) == 1 || FootPlacement( 2 ) == 2 )
             * FootPlacement = [ 0 1 2 0 ];
             * else
             * FootPlacement = [ 0 2 1 0 ];
             * end
             * case 2
             * BarArrows( ct2, : ) = [ 1 0 0 1 ];
             * FootPlacement = [ 1 0 0 2 ];
             * case 3
             * BarArrows( ct2, : ) = [ 1 1 0 0 ];
             * FootPlacement = [ 1 2 0 0 ];
             * case 4
             * BarArrows( ct2, : ) = [ 0 0 1 1 ];
             * FootPlacement = [ 0 0 1 2 ];
             * case 5
             * BarArrows( ct2, : ) = [ 1 0 1 0 ];
             * FootPlacement = [ 1 0 2 0 ];
             * case 6
             * BarArrows( ct2, : ) = [ 0 1 0 1 ];
             * FootPlacement = [ 0 1 0 2 ];
             * end
             * CurrentFoot = 0;
             * else
             * % Place a normal arrow.
             * if ( CurrentFoot == 0 )
             * % Place a left or right arrow to get started.
             * CurrentFoot = ceil(rand(1) * 2); %%%%%%% FIX RAND %%%%%
             * if ( CurrentFoot == 1 )
             * ArrowType = 1;   
             * else
             * ArrowType = 4;
             * end
             * elseif ( CurrentFoot > 0 & ct2 > 1 & abs( BarEnergy( ct2-1 ) - BarEnergy( ct2 ) ) < 0.02 )    
             * % Place the same arrow as last time, and
             * % keeps the same current foot as last time.
             * 
             * % Leave Current Foot and Arrow Type unchanged.
             * else      
             * % Find allowable moves pattern for current foot
             * % placement.
             * CurrentFoot = mod( CurrentFoot, 2 ) + 1;
             * 
             * PossibleMoves = [ 0 0 0 0 ];
             * for ct3 = 1 : size( AllowableMoves, 3 )
             * if ( AllowableMoves( 3, :, ct3 ) == FootPlacement )
             * PossibleMoves = AllowableMoves( CurrentFoot, :, ct3 );
             * end
             * end
             * 
             * if ( PossibleMoves == [ 0 0 0 0 ] )
             * error( 'No possible moves found' );    
             * end
             * 
             * % Calculate Probabilities of new move.
             * ProbMoves = cumsum( PossibleMoves ./ sum( PossibleMoves ) );
             * 
             * % Choose arrow based on probabilities
             * Temp = find( ProbMoves >= rand(1) );
             * ArrowType = Temp(1);
             * 
             * end
             * 
             * NewArrow = [ 0 0 0 0 ];
             * NewArrow( ArrowType ) = 1;
             * BarArrows( ct2, : ) = NewArrow;
             * 
             * FootPlacement( FootPlacement == CurrentFoot ) = 0;
             * FootPlacement( NewArrow > 0 ) = CurrentFoot;
             * 
             * end
             * end
             * 
             * if ( mod( ct2, 2 ) == 1 )
             * PrevBeatEnergy = BarEnergy( ct2 );    
             * end
             * end 
             * 
             * SectionArrowData( :, :, ct1 ) = BarArrows;        
             * end
             * 
             * 
             * 
             * 
             * 
             * FreezeOn = false;
             * FreezeArrow = -1;
             * for ct1 = 1 : size( BarSimilarity, 1 )
             * % This section has already had its arrows chosen, so just repeat
             * % them but with subtle modifications, eg. swap left/right or
             * % up/down.
             * BarSection = SimilarSections( ct1 );
             * ArrowIndex = (((1 + (ct1 - 1)*BarSizeInHalfBeats)-1)*(MaxArrowsPerBar/BarSizeInHalfBeats))+1;
             * 
             * 
             * % First check if we should have a pause here, if so write out -1
             * % for arrows instead
             * if ( ~isempty( Pauses ) & any( Pauses( :, 1 )  + 2 == ((ct1-1)*BarSize)+1 ) )
             * BarArrows( :, : ) = -1;    
             * else
             * 
             * % No pause so use data from sections
             * if ( ct1 > 1 && SimilarSections( ct1 - 1 ) == BarSection )
             * % Last bar was in the same section so alter the repeated arrows
             * ChangeLeftRightProbability = 0.5;
             * ChangeUpDownProbability = 0.5;
             * else
             * % Last bar was a different section so make in unlikely that the repeated arrows will be changed.
             * ChangeLeftRightProbability = 0.00;
             * ChangeUpDownProbability = 0.00;
             * end
             * 
             * BarArrows = SectionArrowData( :, :, BarSection );
             * if ( rand(1) > ChangeLeftRightProbability )
             * % Swap left and right arrows            
             * Temp = BarArrows( :, 1 );
             * BarArrows( :, 1 ) = BarArrows( :, 4 ); 
             * BarArrows( :, 4 ) = Temp;
             * end
             * if ( rand(1) > ChangeUpDownProbability )
             * % Swap up and down arrows            
             * Temp = BarArrows( :, 2 );
             * BarArrows( :, 2 ) = BarArrows( :, 3 ); 
             * BarArrows( :, 3 ) = Temp;
             * end
             * 
             * end
             * 
             * % Freeze arrow stuff
             * if ( ~isempty( LongFreezes ))
             * for ct2 = 1 : BarSizeInHalfBeats
             * CurrentBeat = ( (ct1-1)*BarSizeInHalfBeats ) + ct2;
             * 
             * if ( FreezeOn )
             * % Stop other arrows while freeze arrow going past.
             * if ( UserDifficultyRating <= 3 )
             * BarArrows( ct2, : ) = 0;    
             * end
             * if ( UserDifficultyRating <= 6 & mod( CurrentBeat, 4 ) == 1 )
             * BarArrows( ct2, : ) = 0;    
             * end
             * if ( mod( CurrentBeat, 2 ) == 0 )
             * BarArrows( ct2, : ) = 0;    
             * end
             * 
             * % Stop any jumps occuring
             * if ( sum( BarArrows( ct2, : ) > 0 ) > 1 )
             * BarArrows( ct2, : ) = 0;    
             * end
             * end
             * 
             * if ( any( LongFreezes( :, 2 ) == CurrentBeat ) & FreezeOn )
             * BarArrows( ct2, FreezeArrow ) = 3;
             * FreezeOn = false;
             * FreezeArrow = -1;
             * end
             * if ( any( LongFreezes( :, 1 ) == CurrentBeat ) & ~FreezeOn )
             * FreezeOn = true;
             * FreezeArrow = ceil( rand(1) * 4 );
             * Temp = BarArrows( ct2, : );
             * Temp( Temp == 1 ) = 0;
             * BarArrows( ct2, : ) = Temp;
             * BarArrows( ct2, FreezeArrow ) = 2;
             * end
             * end 
             * end
             * 
             * 
             * for ct2 = 1 : BarSizeInHalfBeats
             * Index = ArrowIndex + (ct2 - 1) * ( MaxArrowsPerBar / BarSizeInHalfBeats );    
             * ArrowTrack( Index, : ) = BarArrows( ct2, : );
             * end
             * 
             * end
             * 
             * for ct1 = 3 : 2 : size( ArrowTrack, 1 ) - 1
             * % If this is a jump
             * if ( sum( ArrowTrack( ct1, : ) == 1 ) > 1 )
             * % remove any offbeats around it
             * ArrowTrack( ct1 - 1, : ) = 0;
             * ArrowTrack( ct1 + 1, : ) = 0;
             * end
             * end
             * 
             * NumArrows = sum( ArrowTrack(:) > 0 );
             * FootRating = 9 - sum( DifficultyRatings > NumArrows );
             * disp( [ 'Foot Rating: ' int2str( FootRating ) ] );
             * 
             * FootRatings( ArrowSet ) = FootRating;
             * ArrowTracks( :, :, ArrowSet ) = ArrowTrack;
             * 
             * end
             */
            for (; ; ) {
                mlfAssign(
                  &UserDifficultyRating,
                  mclIntArrayRef1(
                    mclVv(ChosenDifficultyRatings, "ChosenDifficultyRatings"),
                    v_));
                mlfAssign(
                  &OffbeatModifier,
                  mclArrayRef1(
                    mclVv(
                      DifficultyOffbeatModifier, "DifficultyOffbeatModifier"),
                    mclVv(UserDifficultyRating, "UserDifficultyRating")));
                mlfAssign(
                  &AvgArrowsPerLevel,
                  mlfMean(
                    mlfVertcat(
                      mlfHorzcat(
                        mclVv(DifficultyRatings, "DifficultyRatings"),
                        _mxarray162_,
                        NULL),
                      mlfHorzcat(
                        _mxarray44_,
                        mclVv(DifficultyRatings, "DifficultyRatings"),
                        NULL),
                      NULL),
                    NULL));
                mlfAssign(
                  &NumArrows,
                  mclArrayRef1(
                    mclVv(AvgArrowsPerLevel, "AvgArrowsPerLevel"),
                    mclVv(UserDifficultyRating, "UserDifficultyRating")));
                mlfAssign(
                  &ArrowsPerBar,
                  mclMrdivide(
                    mclVv(NumArrows, "NumArrows"), mclVv(NumBars, "NumBars")));
                mlfAssign(&ModdedEnergy, mclVv(Energy, "Energy"));
                mclArrayAssign1(
                  &ModdedEnergy,
                  mclTimes(
                    mclArrayRef1(
                      mclVv(ModdedEnergy, "ModdedEnergy"),
                      mlfColon(
                        _mxarray41_,
                        _mxarray41_,
                        mlfEnd(
                          mclVv(ModdedEnergy, "ModdedEnergy"),
                          _mxarray22_,
                          _mxarray22_))),
                    mclVv(OffbeatModifier, "OffbeatModifier")),
                  mlfColon(
                    _mxarray41_,
                    _mxarray41_,
                    mlfEnd(
                      mclVv(ModdedEnergy, "ModdedEnergy"),
                      _mxarray22_,
                      _mxarray22_)));
                mlfAssign(&FullBarEnergy, _mxarray97_);
                {
                    int v_3 = mclForIntStart(1);
                    int e_3
                      = mclForIntEnd(
                          mlfSize(
                            mclValueVarargout(),
                            mclVv(BarSimilarity, "BarSimilarity"),
                            _mxarray22_));
                    if (v_3 > e_3) {
                        mlfAssign(&ct1, _mxarray97_);
                    } else {
                        for (; ; ) {
                            mlfAssign(
                              &Range,
                              mlfColon(
                                mclPlus(
                                  _mxarray22_,
                                  mclMtimes(
                                    mlfScalar(v_3 - 1),
                                    mclVv(
                                      BarSizeInHalfBeats,
                                      "BarSizeInHalfBeats"))),
                                mclMinus(
                                  mclPlus(
                                    _mxarray22_,
                                    mclMtimes(
                                      mlfScalar(v_3),
                                      mclVv(
                                        BarSizeInHalfBeats,
                                        "BarSizeInHalfBeats"))),
                                  _mxarray22_),
                                NULL));
                            mclIntArrayAssign1(
                              &FullBarEnergy,
                              mlfMean(
                                mclArrayRef1(
                                  mclVv(ModdedEnergy, "ModdedEnergy"),
                                  mclVv(Range, "Range")),
                                NULL),
                              v_3);
                            if (v_3 == e_3) {
                                break;
                            }
                            ++v_3;
                        }
                        mlfAssign(&ct1, mlfScalar(v_3));
                    }
                }
                {
                    int v_4 = mclForIntStart(1);
                    int e_4 = 10;
                    if (v_4 > e_4) {
                        mlfAssign(&ct0, _mxarray97_);
                    } else {
                        for (; ; ) {
                            mlfAssign(
                              &FullBarEnergy,
                              mclRdivide(
                                mclVv(FullBarEnergy, "FullBarEnergy"),
                                mclMrdivide(
                                  mlfSum(
                                    mclVv(FullBarEnergy, "FullBarEnergy"),
                                    NULL),
                                  mclVv(NumArrows, "NumArrows"))));
                            {
                                int v_5 = mclForIntStart(3);
                                int e_5
                                  = mclForIntEnd(
                                      mlfSize(
                                        mclValueVarargout(),
                                        mclVv(BarSimilarity, "BarSimilarity"),
                                        _mxarray22_));
                                if (v_5 > e_5) {
                                    mlfAssign(&ct1, _mxarray97_);
                                } else {
                                    for (; ; ) {
                                        if (mlfTobool(
                                              mlfAll(
                                                mclLt(
                                                  mlfRound(
                                                    mclArrayRef1(
                                                      mclVv(
                                                        FullBarEnergy,
                                                        "FullBarEnergy"),
                                                      mlfColon(
                                                        mlfScalar(v_5 - 2),
                                                        mlfScalar(v_5),
                                                        NULL))),
                                                  _mxarray22_),
                                                NULL))) {
                                            mclIntArrayAssign1(
                                              &FullBarEnergy, _mxarray22_, v_5);
                                        }
                                        if (mlfTobool(
                                              mlfAll(
                                                mclGe(
                                                  mlfRound(
                                                    mclArrayRef1(
                                                      mclVv(
                                                        FullBarEnergy,
                                                        "FullBarEnergy"),
                                                      mlfColon(
                                                        mlfScalar(v_5 - 2),
                                                        mlfScalar(v_5),
                                                        NULL))),
                                                  _mxarray150_),
                                                NULL))) {
                                            mclIntArrayAssign1(
                                              &FullBarEnergy, _mxarray24_, v_5);
                                        }
                                        if (mclGtBool(
                                              mlfRound(
                                                mclIntArrayRef1(
                                                  mclVv(
                                                    FullBarEnergy,
                                                    "FullBarEnergy"),
                                                  v_5)),
                                              _mxarray39_)) {
                                            mclIntArrayAssign1(
                                              &FullBarEnergy, _mxarray39_, v_5);
                                        }
                                        if (v_5 == e_5) {
                                            break;
                                        }
                                        ++v_5;
                                    }
                                    mlfAssign(&ct1, mlfScalar(v_5));
                                }
                            }
                            if (v_4 == e_4) {
                                break;
                            }
                            ++v_4;
                        }
                        mlfAssign(&ct0, mlfScalar(v_4));
                    }
                }
                mlfAssign(&CurrentFoot, _mxarray44_);
                mlfAssign(&FootPlacement, _mxarray163_);
                mlfAssign(
                  &ArrowTrack,
                  mlfZeros(
                    mclVv(ArrowTrackSize, "ArrowTrackSize"),
                    _mxarray40_,
                    NULL));
                mlfAssign(&InFreeze, mlfFalse(NULL));
                mlfAssign(
                  &JumpThreshold,
                  mclMinus(
                    _mxarray165_,
                    mclMtimes(
                      mclVv(UserDifficultyRating, "UserDifficultyRating"),
                      _mxarray166_)));
                mlfAssign(
                  &SectionArrowData,
                  mclMinus(
                    mlfZeros(
                      mclVv(BarSizeInHalfBeats, "BarSizeInHalfBeats"),
                      _mxarray40_,
                      mlfMax(
                        NULL,
                        mclVv(SimilarSections, "SimilarSections"),
                        NULL,
                        NULL),
                      NULL),
                    _mxarray22_));
                {
                    int v_6 = mclForIntStart(1);
                    int e_6
                      = mclForIntEnd(
                          mlfMax(
                            NULL,
                            mclVv(SimilarSections, "SimilarSections"),
                            NULL,
                            NULL));
                    if (v_6 > e_6) {
                        mlfAssign(&ct1, _mxarray97_);
                    } else {
                        for (; ; ) {
                            mlfAssign(&CurrentFoot, _mxarray44_);
                            mlfAssign(&FootPlacement, _mxarray163_);
                            mlfAssign(
                              &TempModdedEnergy,
                              mclArrayRef1(
                                mclVv(ModdedEnergy, "ModdedEnergy"),
                                mclEq(
                                  mclVv(SimilarityOnBeats, "SimilarityOnBeats"),
                                  mlfScalar(v_6))));
                            mlfAssign(
                              &TempEnergy,
                              mclArrayRef1(
                                mclVv(Energy, "Energy"),
                                mclEq(
                                  mclVv(SimilarityOnBeats, "SimilarityOnBeats"),
                                  mlfScalar(v_6))));
                            mlfAssign(
                              &TempFreezes,
                              mclArrayRef1(
                                mclVv(FreezeBeats, "FreezeBeats"),
                                mclEq(
                                  mclVv(SimilarityOnBeats, "SimilarityOnBeats"),
                                  mlfScalar(v_6))));
                            mlfAssign(
                              &BarModdedEnergy,
                              mlfZeros(
                                mclVv(BarSizeInHalfBeats, "BarSizeInHalfBeats"),
                                _mxarray22_,
                                NULL));
                            mlfAssign(
                              &BarEnergy,
                              mlfZeros(
                                mclVv(BarSizeInHalfBeats, "BarSizeInHalfBeats"),
                                _mxarray22_,
                                NULL));
                            {
                                int v_7 = mclForIntStart(1);
                                int e_7
                                  = mclForIntEnd(
                                      mclVv(
                                        BarSizeInHalfBeats,
                                        "BarSizeInHalfBeats"));
                                if (v_7 > e_7) {
                                    mlfAssign(&ct2, _mxarray97_);
                                } else {
                                    for (; ; ) {
                                        mclIntArrayAssign1(
                                          &BarModdedEnergy,
                                          mlfMean(
                                            mclArrayRef1(
                                              mclVv(
                                                TempModdedEnergy,
                                                "TempModdedEnergy"),
                                              mlfColon(
                                                mlfScalar(v_7),
                                                mclVv(
                                                  BarSizeInHalfBeats,
                                                  "BarSizeInHalfBeats"),
                                                mlfEnd(
                                                  mclVv(
                                                    TempModdedEnergy,
                                                    "TempModdedEnergy"),
                                                  _mxarray22_,
                                                  _mxarray22_))),
                                            NULL),
                                          v_7);
                                        mclIntArrayAssign1(
                                          &BarEnergy,
                                          mlfMean(
                                            mclArrayRef1(
                                              mclVv(TempEnergy, "TempEnergy"),
                                              mlfColon(
                                                mlfScalar(v_7),
                                                mclVv(
                                                  BarSizeInHalfBeats,
                                                  "BarSizeInHalfBeats"),
                                                mlfEnd(
                                                  mclVv(
                                                    TempEnergy, "TempEnergy"),
                                                  _mxarray22_,
                                                  _mxarray22_))),
                                            NULL),
                                          v_7);
                                        mclIntArrayAssign1(
                                          &BarFreezes,
                                          mlfMean(
                                            mclArrayRef1(
                                              mclVv(TempFreezes, "TempFreezes"),
                                              mlfColon(
                                                mlfScalar(v_7),
                                                mclVv(
                                                  BarSizeInHalfBeats,
                                                  "BarSizeInHalfBeats"),
                                                mlfEnd(
                                                  mclVv(
                                                    TempFreezes, "TempFreezes"),
                                                  _mxarray22_,
                                                  _mxarray22_))),
                                            NULL),
                                          v_7);
                                        if (v_7 == e_7) {
                                            break;
                                        }
                                        ++v_7;
                                    }
                                    mlfAssign(&ct2, mlfScalar(v_7));
                                }
                            }
                            mlfAssign(
                              &NumArrows,
                              mlfRound(
                                mlfMean(
                                  mclArrayRef1(
                                    mclVv(FullBarEnergy, "FullBarEnergy"),
                                    mclEq(
                                      mclVv(SimilarSections, "SimilarSections"),
                                      mlfScalar(v_6))),
                                  NULL)));
                            mlfAssign(
                              &PlaceArrow,
                              mlfZeros(
                                mclVv(BarSizeInHalfBeats, "BarSizeInHalfBeats"),
                                _mxarray22_,
                                NULL));
                            mlfAssign(
                              &NumArrowsToHave,
                              mlfMin(
                                NULL,
                                mclVv(NumArrows, "NumArrows"),
                                mlfSum(
                                  mclGt(
                                    mclVv(BarModdedEnergy, "BarModdedEnergy"),
                                    _mxarray44_),
                                  NULL),
                                NULL));
                            mlfAssign(
                              &Temp,
                              mlfSort(
                                &Index,
                                mclVv(BarModdedEnergy, "BarModdedEnergy"),
                                NULL));
                            mclArrayAssign1(
                              &PlaceArrow,
                              _mxarray22_,
                              mclArrayRef1(
                                mclVv(Index, "Index"),
                                mlfColon(
                                  mclMinus(
                                    mlfEnd(
                                      mclVv(Index, "Index"),
                                      _mxarray22_,
                                      _mxarray22_),
                                    mclMinus(
                                      mclVv(NumArrowsToHave, "NumArrowsToHave"),
                                      _mxarray22_)),
                                  mlfEnd(
                                    mclVv(Index, "Index"),
                                    _mxarray22_,
                                    _mxarray22_),
                                  NULL)));
                            mlfAssign(&FreezeOn, mlfFalse(NULL));
                            mlfAssign(&PrevBeatEnergy, _mxarray167_);
                            mlfAssign(
                              &BarArrows,
                              mlfZeros(
                                mclVv(BarSizeInHalfBeats, "BarSizeInHalfBeats"),
                                _mxarray40_,
                                NULL));
                            {
                                int v_8 = mclForIntStart(1);
                                int e_8
                                  = mclForIntEnd(
                                      mclVv(
                                        BarSizeInHalfBeats,
                                        "BarSizeInHalfBeats"));
                                if (v_8 > e_8) {
                                    mlfAssign(&ct2, _mxarray97_);
                                } else {
                                    for (; ; ) {
                                        mxArray * a_
                                          = mclInitialize(
                                              mclNot(
                                                mclVv(FreezeOn, "FreezeOn")));
                                        if (mlfTobool(a_)
                                            && mlfTobool(
                                                 mclAnd(
                                                   a_,
                                                   mclGe(
                                                     mclIntArrayRef1(
                                                       mclVv(
                                                         BarFreezes,
                                                         "BarFreezes"),
                                                       v_8),
                                                     _mxarray94_)))) {
                                            mxDestroyArray(a_);
                                            mlfAssign(&FreezeOn, mlfTrue(NULL));
                                            if (mclEqBool(
                                                  mclVv(
                                                    CurrentFoot, "CurrentFoot"),
                                                  _mxarray44_)) {
                                                mlfAssign(
                                                  &CurrentFoot,
                                                  mlfCeil(
                                                    mclMtimes(
                                                      mlfNRand(
                                                        1, _mxarray22_, NULL),
                                                      _mxarray41_)));
                                                if (mclEqBool(
                                                      mclVv(
                                                        CurrentFoot,
                                                        "CurrentFoot"),
                                                      _mxarray22_)) {
                                                    mlfAssign(
                                                      &ArrowType, _mxarray22_);
                                                } else {
                                                    mlfAssign(
                                                      &ArrowType, _mxarray40_);
                                                }
                                            } else {
                                                mlfAssign(
                                                  &CurrentFoot,
                                                  mclPlus(
                                                    mlfMod(
                                                      mclVv(
                                                        CurrentFoot,
                                                        "CurrentFoot"),
                                                      _mxarray41_),
                                                    _mxarray22_));
                                                mlfAssign(
                                                  &PossibleMoves, _mxarray168_);
                                                {
                                                    int v_9 = mclForIntStart(1);
                                                    int e_9
                                                      = mclForIntEnd(
                                                          mlfSize(
                                                            mclValueVarargout(),
                                                            mclVv(
                                                              AllowableMoves,
                                                              "Allowabl"
                                                              "eMoves"),
                                                            _mxarray23_));
                                                    if (v_9 > e_9) {
                                                        mlfAssign(
                                                          &ct3, _mxarray97_);
                                                    } else {
                                                        for (; ; ) {
                                                            if (mclEqBool(
                                                                  mlfIndexRef(
                                                                    mclVv(
                                                                      AllowableMoves,
                                                                      "Allowabl"
                                                                      "eMoves"),
                                                                    "(?,?,?)",
                                                                    _mxarray23_,
                                                                    mlfCreateColonIndex(),
                                                                    mlfScalar(
                                                                      v_9)),
                                                                  mclVv(
                                                                    FootPlacement,
                                                                    "FootPlace"
                                                                    "ment"))) {
                                                                mlfAssign(
                                                                  &PossibleMoves,
                                                                  mlfIndexRef(
                                                                    mclVv(
                                                                      AllowableMoves,
                                                                      "Allowabl"
                                                                      "eMoves"),
                                                                    "(?,?,?)",
                                                                    mclVv(
                                                                      CurrentFoot,
                                                                      "Current"
                                                                      "Foot"),
                                                                    mlfCreateColonIndex(),
                                                                    mlfScalar(
                                                                      v_9)));
                                                            }
                                                            if (v_9 == e_9) {
                                                                break;
                                                            }
                                                            ++v_9;
                                                        }
                                                        mlfAssign(
                                                          &ct3, mlfScalar(v_9));
                                                    }
                                                }
                                                if (mclEqBool(
                                                      mclVv(
                                                        PossibleMoves,
                                                        "PossibleMoves"),
                                                      _mxarray168_)) {
                                                    mlfError(
                                                      _mxarray170_, NULL);
                                                }
                                                mlfAssign(
                                                  &ProbMoves,
                                                  mlfCumsum(
                                                    mclRdivide(
                                                      mclVv(
                                                        PossibleMoves,
                                                        "PossibleMoves"),
                                                      mlfSum(
                                                        mclVv(
                                                          PossibleMoves,
                                                          "PossibleMoves"),
                                                        NULL)),
                                                    NULL));
                                                mlfAssign(
                                                  &Temp,
                                                  mlfFind(
                                                    NULL,
                                                    NULL,
                                                    mclGe(
                                                      mclVv(
                                                        ProbMoves, "ProbMoves"),
                                                      mlfNRand(
                                                        1,
                                                        _mxarray22_, NULL))));
                                                mlfAssign(
                                                  &ArrowType,
                                                  mclIntArrayRef1(
                                                    mclVv(Temp, "Temp"), 1));
                                            }
                                            mlfAssign(&NewArrow, _mxarray168_);
                                            mclArrayAssign1(
                                              &NewArrow,
                                              _mxarray41_,
                                              mclVv(ArrowType, "ArrowType"));
                                            mclArrayAssign2(
                                              &BarArrows,
                                              mclVv(NewArrow, "NewArrow"),
                                              mlfScalar(v_8),
                                              mlfCreateColonIndex());
                                            mclArrayAssign1(
                                              &FootPlacement,
                                              _mxarray44_,
                                              mclEq(
                                                mclVv(
                                                  FootPlacement,
                                                  "FootPlacement"),
                                                mclVv(
                                                  CurrentFoot, "CurrentFoot")));
                                            mclArrayAssign1(
                                              &FootPlacement,
                                              mclVv(CurrentFoot, "CurrentFoot"),
                                              mclGt(
                                                mclVv(NewArrow, "NewArrow"),
                                                _mxarray44_));
                                            mlfAssign(
                                              &FreezeArrow,
                                              mclVv(ArrowType, "ArrowType"));
                                        } else {
                                            mxDestroyArray(a_);
                                            {
                                                mxArray * a_0
                                                  = mclInitialize(
                                                      mclVv(
                                                        FreezeOn, "FreezeOn"));
                                                if (mlfTobool(a_0)) {
                                                    mlfAssign(
                                                      &a_0,
                                                      mclAnd(
                                                        a_0,
                                                        mclEq(
                                                          mlfScalar(
                                                            svDoubleScalarMod(
                                                              (double) v_8,
                                                              2.0)),
                                                          _mxarray22_)));
                                                } else {
                                                    mlfAssign(
                                                      &a_0, mlfScalar(0));
                                                }
                                                if (mlfTobool(a_0)) {
                                                    mxArray * b_
                                                      = mclInitialize(
                                                          mclLt(
                                                            mclIntArrayRef1(
                                                              mclVv(
                                                                BarFreezes,
                                                                "BarFreezes"),
                                                              v_8),
                                                            _mxarray94_));
                                                    if (mlfTobool(b_)) {
                                                        mlfAssign(
                                                          &b_, mlfScalar(1));
                                                    } else {
                                                        mlfAssign(
                                                          &b_,
                                                          mclOr(
                                                            b_,
                                                            mclEq(
                                                              mlfScalar(v_8),
                                                              mclMinus(
                                                                mclVv(
                                                                  BarSizeInHalfBeats,
                                                                  "BarSizeInH"
                                                                  "alfBeats"),
                                                                _mxarray22_))));
                                                    }
                                                    {
                                                        mxLogical c_0
                                                          = mlfTobool(
                                                              mclAnd(a_0, b_));
                                                        mxDestroyArray(b_);
                                                        if (c_0) {
                                                            mxDestroyArray(a_0);
                                                            mlfAssign(
                                                              &FreezeOn,
                                                              mlfFalse(NULL));
                                                            mlfAssign(
                                                              &NewArrow,
                                                              _mxarray168_);
                                                            mclArrayAssign1(
                                                              &NewArrow,
                                                              _mxarray23_,
                                                              mclVv(
                                                                FreezeArrow,
                                                                "FreezeArrow"));
                                                            mclArrayAssign2(
                                                              &BarArrows,
                                                              mclVv(
                                                                NewArrow,
                                                                "NewArrow"),
                                                              mlfScalar(v_8),
                                                              mlfCreateColonIndex());
                                                            goto done_;
                                                        }
                                                    }
                                                }
                                                mxDestroyArray(a_0);
                                                {
                                                    mxArray * a_1
                                                      = mclInitialize(
                                                          mclEq(
                                                            mclIntArrayRef1(
                                                              mclVv(
                                                                PlaceArrow,
                                                                "PlaceArrow"),
                                                              v_8),
                                                            _mxarray22_));
                                                    if (mlfTobool(a_1)
                                                        && mlfTobool(
                                                             mclAnd(
                                                               a_1,
                                                               mclNot(
                                                                 mclAnd(
                                                                   mclVv(
                                                                     FreezeOn,
                                                                     "Freez"
                                                                     "eOn"),
                                                                   mclOr(
                                                                     mclOr(
                                                                       mclEq(
                                                                         mlfScalar(
                                                                           svDoubleScalarMod(
                                                                             (double) v_8,
                                                                             2.0)),
                                                                         _mxarray44_),
                                                                       mclLe(
                                                                         mclVv(
                                                                           UserDifficultyRating,
                                                                           "Use"
                                                                           "rDi"
                                                                           "ffi"
                                                                           "cul"
                                                                           "tyR"
                                                                           "ati"
                                                                           "n"
                                                                           "g"),
                                                                         _mxarray23_)),
                                                                     mclAnd(
                                                                       mclLe(
                                                                         mclVv(
                                                                           UserDifficultyRating,
                                                                           "Use"
                                                                           "rDi"
                                                                           "ffi"
                                                                           "cul"
                                                                           "tyR"
                                                                           "ati"
                                                                           "n"
                                                                           "g"),
                                                                         _mxarray24_),
                                                                       mclEq(
                                                                         mlfScalar(
                                                                           svDoubleScalarMod(
                                                                             (double) v_8,
                                                                             4.0)),
                                                                         _mxarray22_)))))))) {
                                                        mxDestroyArray(a_1);
                                                        {
                                                            mxArray * a_2
                                                              = mclInitialize(
                                                                  mclNot(
                                                                    mclVv(
                                                                      FreezeOn,
                                                                      "Freeze"
                                                                      "On")));
                                                            if (mlfTobool(
                                                                  a_2)) {
                                                                mlfAssign(
                                                                  &a_2,
                                                                  mclAnd(
                                                                    a_2,
                                                                    mclGt(
                                                                      mclIntArrayRef1(
                                                                        mclVv(
                                                                          BarEnergy,
                                                                          "BarE"
                                                                          "nerg"
                                                                          "y"),
                                                                        v_8),
                                                                      mclPlus(
                                                                        mclVv(
                                                                          PrevBeatEnergy,
                                                                          "Prev"
                                                                          "Beat"
                                                                          "Ener"
                                                                          "gy"),
                                                                        _mxarray172_))));
                                                            } else {
                                                                mlfAssign(
                                                                  &a_2,
                                                                  mlfScalar(0));
                                                            }
                                                            if (mlfTobool(
                                                                  a_2)) {
                                                                mlfAssign(
                                                                  &a_2,
                                                                  mclAnd(
                                                                    a_2,
                                                                    mclGt(
                                                                      mclIntArrayRef1(
                                                                        mclVv(
                                                                          BarEnergy,
                                                                          "BarE"
                                                                          "nerg"
                                                                          "y"),
                                                                        v_8),
                                                                      mclVv(
                                                                        JumpThreshold,
                                                                        "JumpTh"
                                                                        "reshol"
                                                                        "d"))));
                                                            } else {
                                                                mlfAssign(
                                                                  &a_2,
                                                                  mlfScalar(0));
                                                            }
                                                            if (mlfTobool(a_2)
                                                                && mlfTobool(
                                                                     mclAnd(
                                                                       a_2,
                                                                       mclEq(
                                                                         mlfScalar(
                                                                           svDoubleScalarMod(
                                                                             (double) v_8,
                                                                             2.0)),
                                                                         _mxarray22_)))) {
                                                                mxDestroyArray(
                                                                  a_2);
                                                                mlfAssign(
                                                                  &JumpType,
                                                                  mlfCeil(
                                                                    mclMtimes(
                                                                      mlfNRand(
                                                                        1,
                                                                        _mxarray22_,
                                                                        NULL),
                                                                      _mxarray24_)));
                                                                {
                                                                    mxArray * v_00
                                                                      = mclInitialize(
                                                                          mclVv(
                                                                            JumpType,
                                                                            "Jump"
                                                                            "Typ"
                                                                            "e"));
                                                                    if (mclSwitchCompare(
                                                                          v_00,
                                                                          _mxarray22_)) {
                                                                        mclArrayAssign2(
                                                                          &BarArrows,
                                                                          _mxarray173_,
                                                                          mlfScalar(
                                                                            v_8),
                                                                          mlfCreateColonIndex());
                                                                        if (mclScalarToBool(
                                                                              mclEq(
                                                                                mclIntArrayRef1(
                                                                                  mclVv(
                                                                                    FootPlacement,
                                                                                    "Foo"
                                                                                    "tPl"
                                                                                    "ace"
                                                                                    "men"
                                                                                    "t"),
                                                                                  3),
                                                                                _mxarray22_))
                                                                            || mclScalarToBool(
                                                                                 mclEq(
                                                                                   mclIntArrayRef1(
                                                                                     mclVv(
                                                                                       FootPlacement,
                                                                                       "Foo"
                                                                                       "tPl"
                                                                                       "ace"
                                                                                       "men"
                                                                                       "t"),
                                                                                     2),
                                                                                   _mxarray41_))) {
                                                                            mlfAssign(
                                                                              &FootPlacement,
                                                                              _mxarray175_);
                                                                        } else {
                                                                            mlfAssign(
                                                                              &FootPlacement,
                                                                              _mxarray177_);
                                                                        }
                                                                    } else if (mclSwitchCompare(
                                                                                 v_00,
                                                                                 _mxarray41_)) {
                                                                        mclArrayAssign2(
                                                                          &BarArrows,
                                                                          _mxarray179_,
                                                                          mlfScalar(
                                                                            v_8),
                                                                          mlfCreateColonIndex());
                                                                        mlfAssign(
                                                                          &FootPlacement,
                                                                          _mxarray163_);
                                                                    } else if (mclSwitchCompare(
                                                                                 v_00,
                                                                                 _mxarray23_)) {
                                                                        mclArrayAssign2(
                                                                          &BarArrows,
                                                                          _mxarray181_,
                                                                          mlfScalar(
                                                                            v_8),
                                                                          mlfCreateColonIndex());
                                                                        mlfAssign(
                                                                          &FootPlacement,
                                                                          _mxarray183_);
                                                                    } else if (mclSwitchCompare(
                                                                                 v_00,
                                                                                 _mxarray40_)) {
                                                                        mclArrayAssign2(
                                                                          &BarArrows,
                                                                          _mxarray185_,
                                                                          mlfScalar(
                                                                            v_8),
                                                                          mlfCreateColonIndex());
                                                                        mlfAssign(
                                                                          &FootPlacement,
                                                                          _mxarray187_);
                                                                    } else if (mclSwitchCompare(
                                                                                 v_00,
                                                                                 _mxarray32_)) {
                                                                        mclArrayAssign2(
                                                                          &BarArrows,
                                                                          _mxarray189_,
                                                                          mlfScalar(
                                                                            v_8),
                                                                          mlfCreateColonIndex());
                                                                        mlfAssign(
                                                                          &FootPlacement,
                                                                          _mxarray191_);
                                                                    } else if (mclSwitchCompare(
                                                                                 v_00,
                                                                                 _mxarray24_)) {
                                                                        mclArrayAssign2(
                                                                          &BarArrows,
                                                                          _mxarray193_,
                                                                          mlfScalar(
                                                                            v_8),
                                                                          mlfCreateColonIndex());
                                                                        mlfAssign(
                                                                          &FootPlacement,
                                                                          _mxarray195_);
                                                                    }
                                                                    mxDestroyArray(v_00);
                                                                }
                                                                mlfAssign(
                                                                  &CurrentFoot,
                                                                  _mxarray44_);
                                                            } else {
                                                                mxDestroyArray(
                                                                  a_2);
                                                                if (mclEqBool(
                                                                      mclVv(
                                                                        CurrentFoot,
                                                                        "Curre"
                                                                        "ntFoo"
                                                                        "t"),
                                                                      _mxarray44_)) {
                                                                    mlfAssign(
                                                                      &CurrentFoot,
                                                                      mlfCeil(
                                                                        mclMtimes(
                                                                          mlfNRand(
                                                                            1,
                                                                            _mxarray22_,
                                                                            NULL),
                                                                          _mxarray41_)));
                                                                    if (mclEqBool(
                                                                          mclVv(
                                                                            CurrentFoot,
                                                                            "Cur"
                                                                            "ren"
                                                                            "tFo"
                                                                            "o"
                                                                            "t"),
                                                                          _mxarray22_)) {
                                                                        mlfAssign(
                                                                          &ArrowType,
                                                                          _mxarray22_);
                                                                    } else {
                                                                        mlfAssign(
                                                                          &ArrowType,
                                                                          _mxarray40_);
                                                                    }
                                                                } else {
                                                                    mxArray * a_3
                                                                      = mclInitialize(
                                                                          mclGt(
                                                                            mclVv(
                                                                              CurrentFoot,
                                                                              "Cur"
                                                                              "ren"
                                                                              "tFo"
                                                                              "o"
                                                                              "t"),
                                                                            _mxarray44_));
                                                                    if (mlfTobool(
                                                                          a_3)) {
                                                                        mlfAssign(
                                                                          &a_3,
                                                                          mclAnd(
                                                                            a_3,
                                                                            mclBoolToArray(
                                                                              v_8
                                                                              > 1)));
                                                                    } else {
                                                                        mlfAssign(
                                                                          &a_3,
                                                                          mlfScalar(
                                                                            0));
                                                                    }
                                                                    if (mlfTobool(
                                                                          a_3)
                                                                        && mlfTobool(
                                                                             mclAnd(
                                                                               a_3,
                                                                               mclLt(
                                                                                 mlfAbs(
                                                                                   mclMinus(
                                                                                     mclIntArrayRef1(
                                                                                       mclVv(
                                                                                         BarEnergy,
                                                                                         "Bar"
                                                                                         "Ene"
                                                                                         "rg"
                                                                                         "y"),
                                                                                       v_8
                                                                                       - 1),
                                                                                     mclIntArrayRef1(
                                                                                       mclVv(
                                                                                         BarEnergy,
                                                                                         "Bar"
                                                                                         "Ene"
                                                                                         "rg"
                                                                                         "y"),
                                                                                       v_8))),
                                                                                 _mxarray197_)))) {
                                                                        mxDestroyArray(
                                                                          a_3);
                                                                    } else {
                                                                        mxDestroyArray(
                                                                          a_3);
                                                                        mlfAssign(
                                                                          &CurrentFoot,
                                                                          mclPlus(
                                                                            mlfMod(
                                                                              mclVv(
                                                                                CurrentFoot,
                                                                                "Cur"
                                                                                "ren"
                                                                                "tFo"
                                                                                "o"
                                                                                "t"),
                                                                              _mxarray41_),
                                                                            _mxarray22_));
                                                                        mlfAssign(
                                                                          &PossibleMoves,
                                                                          _mxarray168_);
                                                                        {
                                                                            int v_01
                                                                              = mclForIntStart(
                                                                                  1);
                                                                            int e_00
                                                                              = mclForIntEnd(
                                                                                  mlfSize(
                                                                                    mclValueVarargout(),
                                                                                    mclVv(
                                                                                      AllowableMoves,
                                                                                      "All"
                                                                                      "owa"
                                                                                      "ble"
                                                                                      "Mov"
                                                                                      "e"
                                                                                      "s"),
                                                                                    _mxarray23_));
                                                                            if (v_01
                                                                                > e_00) {
                                                                                mlfAssign(
                                                                                  &ct3,
                                                                                  _mxarray97_);
                                                                            } else {
                                                                                for (; ; ) {
                                                                                    if (mclEqBool(mlfIndexRef(mclVv(AllowableMoves, "AllowableMoves"), "(?,?,?)", _mxarray23_, mlfCreateColonIndex(), mlfScalar(v_01)), mclVv(FootPlacement, "FootPlacement"))) {
                                                                                        mlfAssign(&PossibleMoves, mlfIndexRef(mclVv(AllowableMoves, "AllowableMoves"), "(?,?,?)", mclVv(CurrentFoot, "CurrentFoot"), mlfCreateColonIndex(), mlfScalar(v_01)));
                                                                                    }
                                                                                    if (v_01 == e_00) {
                                                                                        break;
                                                                                    }
                                                                                    ++v_01;
                                                                                }
                                                                                mlfAssign(
                                                                                  &ct3,
                                                                                  mlfScalar(
                                                                                    v_01));
                                                                            }
                                                                        }
                                                                        if (mclEqBool(
                                                                              mclVv(
                                                                                PossibleMoves,
                                                                                "Pos"
                                                                                "sib"
                                                                                "leM"
                                                                                "ove"
                                                                                "s"),
                                                                              _mxarray168_)) {
                                                                            mlfError(
                                                                              _mxarray170_,
                                                                              NULL);
                                                                        }
                                                                        mlfAssign(
                                                                          &ProbMoves,
                                                                          mlfCumsum(
                                                                            mclRdivide(
                                                                              mclVv(
                                                                                PossibleMoves,
                                                                                "Pos"
                                                                                "sib"
                                                                                "leM"
                                                                                "ove"
                                                                                "s"),
                                                                              mlfSum(
                                                                                mclVv(
                                                                                  PossibleMoves,
                                                                                  "Pos"
                                                                                  "sib"
                                                                                  "leM"
                                                                                  "ove"
                                                                                  "s"),
                                                                                NULL)),
                                                                            NULL));
                                                                        mlfAssign(
                                                                          &Temp,
                                                                          mlfFind(
                                                                            NULL,
                                                                            NULL,
                                                                            mclGe(
                                                                              mclVv(
                                                                                ProbMoves,
                                                                                "Pro"
                                                                                "bMo"
                                                                                "ve"
                                                                                "s"),
                                                                              mlfNRand(
                                                                                1,
                                                                                _mxarray22_,
                                                                                NULL))));
                                                                        mlfAssign(
                                                                          &ArrowType,
                                                                          mclIntArrayRef1(
                                                                            mclVv(
                                                                              Temp,
                                                                              "Tem"
                                                                              "p"),
                                                                            1));
                                                                    }
                                                                }
                                                                mlfAssign(
                                                                  &NewArrow,
                                                                  _mxarray168_);
                                                                mclArrayAssign1(
                                                                  &NewArrow,
                                                                  _mxarray22_,
                                                                  mclVv(
                                                                    ArrowType,
                                                                    "ArrowT"
                                                                    "ype"));
                                                                mclArrayAssign2(
                                                                  &BarArrows,
                                                                  mclVv(
                                                                    NewArrow,
                                                                    "NewArrow"),
                                                                  mlfScalar(
                                                                    v_8),
                                                                  mlfCreateColonIndex());
                                                                mclArrayAssign1(
                                                                  &FootPlacement,
                                                                  _mxarray44_,
                                                                  mclEq(
                                                                    mclVv(
                                                                      FootPlacement,
                                                                      "FootPlac"
                                                                      "ement"),
                                                                    mclVv(
                                                                      CurrentFoot,
                                                                      "CurrentF"
                                                                      "oot")));
                                                                mclArrayAssign1(
                                                                  &FootPlacement,
                                                                  mclVv(
                                                                    CurrentFoot,
                                                                    "Current"
                                                                    "Foot"),
                                                                  mclGt(
                                                                    mclVv(
                                                                      NewArrow,
                                                                      "NewAr"
                                                                      "row"),
                                                                    _mxarray44_));
                                                            }
                                                        }
                                                    } else {
                                                        mxDestroyArray(a_1);
                                                    }
                                                }
                                                done_:;
                                            }
                                        }
                                        if (mclEqBool(
                                              mlfScalar(
                                                svDoubleScalarMod(
                                                  (double) v_8, 2.0)),
                                              _mxarray22_)) {
                                            mlfAssign(
                                              &PrevBeatEnergy,
                                              mclIntArrayRef1(
                                                mclVv(BarEnergy, "BarEnergy"),
                                                v_8));
                                        }
                                        if (v_8 == e_8) {
                                            break;
                                        }
                                        ++v_8;
                                    }
                                    mlfAssign(&ct2, mlfScalar(v_8));
                                }
                            }
                            mlfIndexAssign(
                              &SectionArrowData,
                              "(?,?,?)",
                              mlfCreateColonIndex(),
                              mlfCreateColonIndex(),
                              mlfScalar(v_6),
                              mclVv(BarArrows, "BarArrows"));
                            if (v_6 == e_6) {
                                break;
                            }
                            ++v_6;
                        }
                        mlfAssign(&ct1, mlfScalar(v_6));
                    }
                }
                mlfAssign(&FreezeOn, mlfFalse(NULL));
                mlfAssign(&FreezeArrow, _mxarray78_);
                {
                    int v_02 = mclForIntStart(1);
                    int e_01
                      = mclForIntEnd(
                          mlfSize(
                            mclValueVarargout(),
                            mclVv(BarSimilarity, "BarSimilarity"),
                            _mxarray22_));
                    if (v_02 > e_01) {
                        mlfAssign(&ct1, _mxarray97_);
                    } else {
                        for (; ; ) {
                            mlfAssign(
                              &BarSection,
                              mclIntArrayRef1(
                                mclVv(SimilarSections, "SimilarSections"),
                                v_02));
                            mlfAssign(
                              &ArrowIndex,
                              mclPlus(
                                mclMtimes(
                                  mclMinus(
                                    mclPlus(
                                      _mxarray22_,
                                      mclMtimes(
                                        mlfScalar(v_02 - 1),
                                        mclVv(
                                          BarSizeInHalfBeats,
                                          "BarSizeInHalfBeats"))),
                                    _mxarray22_),
                                  mclMrdivide(
                                    mclVv(MaxArrowsPerBar, "MaxArrowsPerBar"),
                                    mclVv(
                                      BarSizeInHalfBeats,
                                      "BarSizeInHalfBeats"))),
                                _mxarray22_));
                            {
                                mxArray * a_
                                  = mclInitialize(
                                      mclNot(
                                        mlfIsempty(mclVv(Pauses, "Pauses"))));
                                if (mlfTobool(a_)
                                    && mlfTobool(
                                         mclAnd(
                                           a_,
                                           mlfAny(
                                             mclEq(
                                               mclPlus(
                                                 mclArrayRef2(
                                                   mclVv(Pauses, "Pauses"),
                                                   mlfCreateColonIndex(),
                                                   _mxarray22_),
                                                 _mxarray41_),
                                               mclPlus(
                                                 mclMtimes(
                                                   mlfScalar(v_02 - 1),
                                                   mclVv(BarSize, "BarSize")),
                                                 _mxarray22_)),
                                             NULL)))) {
                                    mxDestroyArray(a_);
                                    mclArrayAssign2(
                                      &BarArrows,
                                      _mxarray78_,
                                      mlfCreateColonIndex(),
                                      mlfCreateColonIndex());
                                } else {
                                    mxDestroyArray(a_);
                                    if (v_02 > 1
                                        && mclScalarToBool(
                                             mclEq(
                                               mclIntArrayRef1(
                                                 mclVv(
                                                   SimilarSections,
                                                   "SimilarSections"),
                                                 v_02 - 1),
                                               mclVv(
                                                 BarSection, "BarSection")))) {
                                        mlfAssign(
                                          &ChangeLeftRightProbability,
                                          _mxarray94_);
                                        mlfAssign(
                                          &ChangeUpDownProbability,
                                          _mxarray94_);
                                    } else {
                                        mlfAssign(
                                          &ChangeLeftRightProbability,
                                          _mxarray44_);
                                        mlfAssign(
                                          &ChangeUpDownProbability,
                                          _mxarray44_);
                                    }
                                    mlfAssign(
                                      &BarArrows,
                                      mlfIndexRef(
                                        mclVv(
                                          SectionArrowData, "SectionArrowData"),
                                        "(?,?,?)",
                                        mlfCreateColonIndex(),
                                        mlfCreateColonIndex(),
                                        mclVv(BarSection, "BarSection")));
                                    if (mclGtBool(
                                          mlfNRand(1, _mxarray22_, NULL),
                                          mclVv(
                                            ChangeLeftRightProbability,
                                            "ChangeLeftRightProbability"))) {
                                        mlfAssign(
                                          &Temp,
                                          mclArrayRef2(
                                            mclVv(BarArrows, "BarArrows"),
                                            mlfCreateColonIndex(),
                                            _mxarray22_));
                                        mclArrayAssign2(
                                          &BarArrows,
                                          mclArrayRef2(
                                            mclVv(BarArrows, "BarArrows"),
                                            mlfCreateColonIndex(),
                                            _mxarray40_),
                                          mlfCreateColonIndex(),
                                          _mxarray22_);
                                        mclArrayAssign2(
                                          &BarArrows,
                                          mclVv(Temp, "Temp"),
                                          mlfCreateColonIndex(),
                                          _mxarray40_);
                                    }
                                    if (mclGtBool(
                                          mlfNRand(1, _mxarray22_, NULL),
                                          mclVv(
                                            ChangeUpDownProbability,
                                            "ChangeUpDownProbability"))) {
                                        mlfAssign(
                                          &Temp,
                                          mclArrayRef2(
                                            mclVv(BarArrows, "BarArrows"),
                                            mlfCreateColonIndex(),
                                            _mxarray41_));
                                        mclArrayAssign2(
                                          &BarArrows,
                                          mclArrayRef2(
                                            mclVv(BarArrows, "BarArrows"),
                                            mlfCreateColonIndex(),
                                            _mxarray23_),
                                          mlfCreateColonIndex(),
                                          _mxarray41_);
                                        mclArrayAssign2(
                                          &BarArrows,
                                          mclVv(Temp, "Temp"),
                                          mlfCreateColonIndex(),
                                          _mxarray23_);
                                    }
                                }
                            }
                            if (mclNotBool(
                                  mlfIsempty(
                                    mclVv(LongFreezes, "LongFreezes")))) {
                                int v_03 = mclForIntStart(1);
                                int e_02
                                  = mclForIntEnd(
                                      mclVv(
                                        BarSizeInHalfBeats,
                                        "BarSizeInHalfBeats"));
                                if (v_03 > e_02) {
                                    mlfAssign(&ct2, _mxarray97_);
                                } else {
                                    for (; ; ) {
                                        mlfAssign(
                                          &CurrentBeat,
                                          mclPlus(
                                            mclMtimes(
                                              mlfScalar(v_02 - 1),
                                              mclVv(
                                                BarSizeInHalfBeats,
                                                "BarSizeInHalfBeats")),
                                            mlfScalar(v_03)));
                                        if (mlfTobool(
                                              mclVv(FreezeOn, "FreezeOn"))) {
                                            if (mclLeBool(
                                                  mclVv(
                                                    UserDifficultyRating,
                                                    "UserDifficultyRating"),
                                                  _mxarray23_)) {
                                                mclArrayAssign2(
                                                  &BarArrows,
                                                  _mxarray44_,
                                                  mlfScalar(v_03),
                                                  mlfCreateColonIndex());
                                            }
                                            {
                                                mxArray * a_
                                                  = mclInitialize(
                                                      mclLe(
                                                        mclVv(
                                                          UserDifficultyRating,
                                                          "UserDifficu"
                                                          "ltyRating"),
                                                        _mxarray24_));
                                                if (mlfTobool(a_)
                                                    && mlfTobool(
                                                         mclAnd(
                                                           a_,
                                                           mclEq(
                                                             mlfMod(
                                                               mclVv(
                                                                 CurrentBeat,
                                                                 "Current"
                                                                 "Beat"),
                                                               _mxarray40_),
                                                             _mxarray22_)))) {
                                                    mxDestroyArray(a_);
                                                    mclArrayAssign2(
                                                      &BarArrows,
                                                      _mxarray44_,
                                                      mlfScalar(v_03),
                                                      mlfCreateColonIndex());
                                                } else {
                                                    mxDestroyArray(a_);
                                                }
                                            }
                                            if (mclEqBool(
                                                  mlfMod(
                                                    mclVv(
                                                      CurrentBeat,
                                                      "CurrentBeat"),
                                                    _mxarray41_),
                                                  _mxarray44_)) {
                                                mclArrayAssign2(
                                                  &BarArrows,
                                                  _mxarray44_,
                                                  mlfScalar(v_03),
                                                  mlfCreateColonIndex());
                                            }
                                            if (mclGtBool(
                                                  mlfSum(
                                                    mclGt(
                                                      mclArrayRef2(
                                                        mclVv(
                                                          BarArrows,
                                                          "BarArrows"),
                                                        mlfScalar(v_03),
                                                        mlfCreateColonIndex()),
                                                      _mxarray44_),
                                                    NULL),
                                                  _mxarray22_)) {
                                                mclArrayAssign2(
                                                  &BarArrows,
                                                  _mxarray44_,
                                                  mlfScalar(v_03),
                                                  mlfCreateColonIndex());
                                            }
                                        }
                                        {
                                            mxArray * a_
                                              = mclInitialize(
                                                  mlfAny(
                                                    mclEq(
                                                      mclArrayRef2(
                                                        mclVv(
                                                          LongFreezes,
                                                          "LongFreezes"),
                                                        mlfCreateColonIndex(),
                                                        _mxarray41_),
                                                      mclVv(
                                                        CurrentBeat,
                                                        "CurrentBeat")),
                                                    NULL));
                                            if (mlfTobool(a_)
                                                && mlfTobool(
                                                     mclAnd(
                                                       a_,
                                                       mclVv(
                                                         FreezeOn,
                                                         "FreezeOn")))) {
                                                mxDestroyArray(a_);
                                                mclArrayAssign2(
                                                  &BarArrows,
                                                  _mxarray23_,
                                                  mlfScalar(v_03),
                                                  mclVv(
                                                    FreezeArrow,
                                                    "FreezeArrow"));
                                                mlfAssign(
                                                  &FreezeOn, mlfFalse(NULL));
                                                mlfAssign(
                                                  &FreezeArrow, _mxarray78_);
                                            } else {
                                                mxDestroyArray(a_);
                                            }
                                        }
                                        {
                                            mxArray * a_
                                              = mclInitialize(
                                                  mlfAny(
                                                    mclEq(
                                                      mclArrayRef2(
                                                        mclVv(
                                                          LongFreezes,
                                                          "LongFreezes"),
                                                        mlfCreateColonIndex(),
                                                        _mxarray22_),
                                                      mclVv(
                                                        CurrentBeat,
                                                        "CurrentBeat")),
                                                    NULL));
                                            if (mlfTobool(a_)
                                                && mlfTobool(
                                                     mclAnd(
                                                       a_,
                                                       mclNot(
                                                         mclVv(
                                                           FreezeOn,
                                                           "FreezeOn"))))) {
                                                mxDestroyArray(a_);
                                                mlfAssign(
                                                  &FreezeOn, mlfTrue(NULL));
                                                mlfAssign(
                                                  &FreezeArrow,
                                                  mlfCeil(
                                                    mclMtimes(
                                                      mlfNRand(
                                                        1, _mxarray22_, NULL),
                                                      _mxarray40_)));
                                                mlfAssign(
                                                  &Temp,
                                                  mclArrayRef2(
                                                    mclVv(
                                                      BarArrows, "BarArrows"),
                                                    mlfScalar(v_03),
                                                    mlfCreateColonIndex()));
                                                mclArrayAssign1(
                                                  &Temp,
                                                  _mxarray44_,
                                                  mclEq(
                                                    mclVv(Temp, "Temp"),
                                                    _mxarray22_));
                                                mclArrayAssign2(
                                                  &BarArrows,
                                                  mclVv(Temp, "Temp"),
                                                  mlfScalar(v_03),
                                                  mlfCreateColonIndex());
                                                mclArrayAssign2(
                                                  &BarArrows,
                                                  _mxarray41_,
                                                  mlfScalar(v_03),
                                                  mclVv(
                                                    FreezeArrow,
                                                    "FreezeArrow"));
                                            } else {
                                                mxDestroyArray(a_);
                                            }
                                        }
                                        if (v_03 == e_02) {
                                            break;
                                        }
                                        ++v_03;
                                    }
                                    mlfAssign(&ct2, mlfScalar(v_03));
                                }
                            }
                            {
                                int v_04 = mclForIntStart(1);
                                int e_03
                                  = mclForIntEnd(
                                      mclVv(
                                        BarSizeInHalfBeats,
                                        "BarSizeInHalfBeats"));
                                if (v_04 > e_03) {
                                    mlfAssign(&ct2, _mxarray97_);
                                } else {
                                    for (; ; ) {
                                        mlfAssign(
                                          &Index,
                                          mclPlus(
                                            mclVv(ArrowIndex, "ArrowIndex"),
                                            mclMtimes(
                                              mlfScalar(v_04 - 1),
                                              mclMrdivide(
                                                mclVv(
                                                  MaxArrowsPerBar,
                                                  "MaxArrowsPerBar"),
                                                mclVv(
                                                  BarSizeInHalfBeats,
                                                  "BarSizeInHalfBeats")))));
                                        mclArrayAssign2(
                                          &ArrowTrack,
                                          mclArrayRef2(
                                            mclVv(BarArrows, "BarArrows"),
                                            mlfScalar(v_04),
                                            mlfCreateColonIndex()),
                                          mclVv(Index, "Index"),
                                          mlfCreateColonIndex());
                                        if (v_04 == e_03) {
                                            break;
                                        }
                                        ++v_04;
                                    }
                                    mlfAssign(&ct2, mlfScalar(v_04));
                                }
                            }
                            if (v_02 == e_01) {
                                break;
                            }
                            ++v_02;
                        }
                        mlfAssign(&ct1, mlfScalar(v_02));
                    }
                }
                {
                    int v_05 = mclForIntStart(3);
                    int i_ = 2;
                    int e_04
                      = mclForIntIntEnd(
                          v_05,
                          i_,
                          mclMinus(
                            mlfSize(
                              mclValueVarargout(),
                              mclVv(ArrowTrack, "ArrowTrack"),
                              _mxarray22_),
                            _mxarray22_));
                    if (e_04 == mclIntMin()) {
                        mlfAssign(&ct1, _mxarray97_);
                    } else {
                        for (; ; ) {
                            if (mclGtBool(
                                  mlfSum(
                                    mclEq(
                                      mclArrayRef2(
                                        mclVv(ArrowTrack, "ArrowTrack"),
                                        mlfScalar(v_05),
                                        mlfCreateColonIndex()),
                                      _mxarray22_),
                                    NULL),
                                  _mxarray22_)) {
                                mclArrayAssign2(
                                  &ArrowTrack,
                                  _mxarray44_,
                                  mlfScalar(v_05 - 1),
                                  mlfCreateColonIndex());
                                mclArrayAssign2(
                                  &ArrowTrack,
                                  _mxarray44_,
                                  mlfScalar(v_05 + 1),
                                  mlfCreateColonIndex());
                            }
                            if (v_05 == e_04) {
                                break;
                            }
                            v_05 += i_;
                        }
                        mlfAssign(&ct1, mlfScalar(v_05));
                    }
                }
                mlfAssign(
                  &NumArrows,
                  mlfSum(
                    mclGt(
                      mclArrayRef1(
                        mclVv(ArrowTrack, "ArrowTrack"), mlfCreateColonIndex()),
                      _mxarray44_),
                    NULL));
                mlfAssign(
                  &FootRating,
                  mclMinus(
                    _mxarray105_,
                    mlfSum(
                      mclGt(
                        mclVv(DifficultyRatings, "DifficultyRatings"),
                        mclVv(NumArrows, "NumArrows")),
                      NULL)));
                mlfDisp(
                  mlfHorzcat(
                    _mxarray198_,
                    mlfInt2str(mclVv(FootRating, "FootRating")),
                    NULL));
                mclIntArrayAssign1(
                  &FootRatings, mclVv(FootRating, "FootRating"), v_);
                mlfIndexAssign(
                  &ArrowTracks,
                  "(?,?,?)",
                  mlfCreateColonIndex(),
                  mlfCreateColonIndex(),
                  mlfScalar(v_),
                  mclVv(ArrowTrack, "ArrowTrack"));
                if (v_ == e_) {
                    break;
                }
                ++v_;
            }
            mlfAssign(&ArrowSet, mlfScalar(v_));
        }
    }
    /*
     * disp( 'Created arrow patterns for each difficulty level.' );
     */
    mlfDisp(_mxarray200_);
    /*
     * 
     * % Now we need to output the arrow track to a step file.
     * 
     * % Output step file in .dwi format
     * fid = fopen ( strcat( OutputDirectory, StepFilename, '.dwi' ), 'wt');
     */
    mlfAssign(
      &fid,
      mlfFopen(
        NULL,
        NULL,
        mlfStrcat(
          mclVv(OutputDirectory, "OutputDirectory"),
          mclVv(StepFilename, "StepFilename"),
          _mxarray202_,
          NULL),
        _mxarray204_,
        NULL));
    /*
     * 
     * fprintf( fid, '#TITLE:%s;\n', FileName );
     */
    mclAssignAns(
      &ans,
      mlfNFprintf(
        0, mclVv(fid, "fid"), _mxarray206_, mclVv(FileName, "FileName"), NULL));
    /*
     * fprintf( fid, '#ARTIST:The Dancing Monkeys Project;\n' );
     */
    mclAssignAns(&ans, mlfNFprintf(0, mclVv(fid, "fid"), _mxarray208_, NULL));
    /*
     * fprintf( fid, '#GAP:%f;\n', GapInSeconds * 1000 );
     */
    mclAssignAns(
      &ans,
      mlfNFprintf(
        0,
        mclVv(fid, "fid"),
        _mxarray210_,
        mclMtimes(mclVv(GapInSeconds, "GapInSeconds"), _mxarray103_),
        NULL));
    /*
     * fprintf( fid, '#BPM:%f;\n', BPM );
     */
    mclAssignAns(
      &ans,
      mlfNFprintf(0, mclVv(fid, "fid"), _mxarray212_, mclVv(BPM, "BPM"), NULL));
    /*
     * fprintf( fid, '#FILE:%s;\n', MusicFullFilename );
     */
    mclAssignAns(
      &ans,
      mlfNFprintf(
        0,
        mclVv(fid, "fid"),
        _mxarray214_,
        mclVa(MusicFullFilename, "MusicFullFilename"),
        NULL));
    /*
     * 
     * % TODO: Fix DWI to use MaxArrowsPerBar
     * 
     * if ( ~ isempty( Pauses ) )
     */
    if (mclNotBool(mlfIsempty(mclVv(Pauses, "Pauses")))) {
        /*
         * fprintf( fid, '#FREEZE:' );
         */
        mclAssignAns(
          &ans, mlfNFprintf(0, mclVv(fid, "fid"), _mxarray216_, NULL));
        /*
         * for ct1 = 1 : size( Pauses, 1 )
         */
        {
            int v_ = mclForIntStart(1);
            int e_
              = mclForIntEnd(
                  mlfSize(
                    mclValueVarargout(),
                    mclVv(Pauses, "Pauses"),
                    _mxarray22_));
            if (v_ > e_) {
                mlfAssign(&ct1, _mxarray97_);
            } else {
                /*
                 * if ( ct1 > 1 )
                 * fprintf( fid, ',' );
                 * end
                 * fprintf( fid, '%d=%d', (( Pauses( ct1, 1 ) - (ct1-1)*BarSize )) * BarSize, round( Pauses( ct1, 2 )*1000 ) );
                 * end
                 */
                for (; ; ) {
                    if (mclGtBool(mlfScalar(v_), _mxarray22_)) {
                        mclAssignAns(
                          &ans,
                          mlfNFprintf(
                            0, mclVv(fid, "fid"), _mxarray218_, NULL));
                    }
                    mclAssignAns(
                      &ans,
                      mlfNFprintf(
                        0,
                        mclVv(fid, "fid"),
                        _mxarray220_,
                        mclMtimes(
                          mclMinus(
                            mclIntArrayRef2(mclVv(Pauses, "Pauses"), v_, 1),
                            mclMtimes(
                              mlfScalar(v_ - 1), mclVv(BarSize, "BarSize"))),
                          mclVv(BarSize, "BarSize")),
                        mlfRound(
                          mclMtimes(
                            mclIntArrayRef2(mclVv(Pauses, "Pauses"), v_, 2),
                            _mxarray103_)),
                        NULL));
                    if (v_ == e_) {
                        break;
                    }
                    ++v_;
                }
                mlfAssign(&ct1, mlfScalar(v_));
            }
        }
        /*
         * fprintf( fid, ';\n' );
         */
        mclAssignAns(
          &ans, mlfNFprintf(0, mclVv(fid, "fid"), _mxarray222_, NULL));
    /*
     * end
     */
    }
    /*
     * fprintf( fid, '\n// --- Arrows ---\n');
     */
    mclAssignAns(&ans, mlfNFprintf(0, mclVv(fid, "fid"), _mxarray224_, NULL));
    /*
     * 
     * DWIDifficultyNames = { 'BASIC', 'ANOTHER', 'MANIAC' };
     */
    mlfAssign(&DWIDifficultyNames, _mxarray226_);
    /*
     * for ArrowSet = 1 : 3
     */
    {
        int v_ = mclForIntStart(1);
        int e_ = 3;
        if (v_ > e_) {
            mlfAssign(&ArrowSet, _mxarray97_);
        } else {
            /*
             * FootRating = FootRatings( ArrowSet );
             * ArrowTrack = ArrowTracks( :, :, ArrowSet );
             * 
             * fprintf( fid, '#SINGLE:%s:%d:\n', DWIDifficultyNames{ ArrowSet }, FootRating );
             * 
             * % Assuming MaxArrowsPerBar == 8
             * for ct1 = 1 : size( ArrowTrack, 1 )
             * 
             * if ( ArrowTrack( ct1, : ) == [ -1 -1 -1 -1 ] )
             * % Don't write out any arrows as we have a pause.    
             * continue;    
             * end
             * ThisBeat = ArrowTrack( ct1, : ) > 0;
             * 
             * if ThisBeat == [ 0 0 0 0 ]
             * Character = '0';
             * elseif ThisBeat == [ 1 0 0 0 ]
             * Character = '4';
             * elseif ThisBeat == [ 0 1 0 0 ]
             * Character = '2';
             * elseif ThisBeat == [ 0 0 1 0 ]
             * Character = '8';
             * elseif ThisBeat == [ 0 0 0 1 ]
             * Character = '6';
             * elseif ThisBeat == [ 1 0 0 1 ]
             * Character = 'B';
             * elseif ThisBeat == [ 0 1 1 0 ]
             * Character = 'A';
             * elseif ThisBeat == [ 0 0 1 1 ]
             * Character = '9';
             * elseif ThisBeat == [ 0 1 0 1 ]
             * Character = '3';
             * elseif ThisBeat == [ 1 0 1 0 ]
             * Character = '7';
             * elseif ThisBeat == [ 1 1 0 0 ]
             * Character = '1';
             * end
             * fprintf( fid, '%c', Character );
             * 
             * % Freeze Arrows
             * ThisBeat = ( ArrowTrack( ct1, : ) == 2 );
             * if ( any( ThisBeat ) )
             * if ThisBeat == [ 1 0 0 0 ]
             * Character = '4';
             * elseif ThisBeat == [ 0 1 0 0 ]
             * Character = '2';
             * elseif ThisBeat == [ 0 0 1 0 ]
             * Character = '8';
             * elseif ThisBeat == [ 0 0 0 1 ]
             * Character = '6';
             * end
             * fprintf( fid, '!%c', Character );    
             * end
             * 
             * end
             * fprintf( fid, ';\n\n' );
             * end
             */
            for (; ; ) {
                mlfAssign(
                  &FootRating,
                  mclIntArrayRef1(mclVv(FootRatings, "FootRatings"), v_));
                mlfAssign(
                  &ArrowTrack,
                  mlfIndexRef(
                    mclVv(ArrowTracks, "ArrowTracks"),
                    "(?,?,?)",
                    mlfCreateColonIndex(),
                    mlfCreateColonIndex(),
                    mlfScalar(v_)));
                mclAssignAns(
                  &ans,
                  mlfNFprintf(
                    0,
                    mclVv(fid, "fid"),
                    _mxarray234_,
                    mlfIndexRef(
                      mclVv(DWIDifficultyNames, "DWIDifficultyNames"),
                      "{?}",
                      mlfScalar(v_)),
                    mclVv(FootRating, "FootRating"),
                    NULL));
                {
                    int v_06 = mclForIntStart(1);
                    int e_05
                      = mclForIntEnd(
                          mlfSize(
                            mclValueVarargout(),
                            mclVv(ArrowTrack, "ArrowTrack"),
                            _mxarray22_));
                    if (v_06 > e_05) {
                        mlfAssign(&ct1, _mxarray97_);
                    } else {
                        for (; ; ) {
                            if (mclEqBool(
                                  mclArrayRef2(
                                    mclVv(ArrowTrack, "ArrowTrack"),
                                    mlfScalar(v_06),
                                    mlfCreateColonIndex()),
                                  _mxarray236_)) {
                                goto continue_1;
                            }
                            mlfAssign(
                              &ThisBeat,
                              mclGt(
                                mclArrayRef2(
                                  mclVv(ArrowTrack, "ArrowTrack"),
                                  mlfScalar(v_06),
                                  mlfCreateColonIndex()),
                                _mxarray44_));
                            if (mclEqBool(
                                  mclVv(ThisBeat, "ThisBeat"), _mxarray168_)) {
                                mlfAssign(&Character, _mxarray238_);
                            } else if (mclEqBool(
                                         mclVv(ThisBeat, "ThisBeat"),
                                         _mxarray240_)) {
                                mlfAssign(&Character, _mxarray242_);
                            } else if (mclEqBool(
                                         mclVv(ThisBeat, "ThisBeat"),
                                         _mxarray244_)) {
                                mlfAssign(&Character, _mxarray246_);
                            } else if (mclEqBool(
                                         mclVv(ThisBeat, "ThisBeat"),
                                         _mxarray248_)) {
                                mlfAssign(&Character, _mxarray250_);
                            } else if (mclEqBool(
                                         mclVv(ThisBeat, "ThisBeat"),
                                         _mxarray252_)) {
                                mlfAssign(&Character, _mxarray254_);
                            } else if (mclEqBool(
                                         mclVv(ThisBeat, "ThisBeat"),
                                         _mxarray179_)) {
                                mlfAssign(&Character, _mxarray256_);
                            } else if (mclEqBool(
                                         mclVv(ThisBeat, "ThisBeat"),
                                         _mxarray173_)) {
                                mlfAssign(&Character, _mxarray258_);
                            } else if (mclEqBool(
                                         mclVv(ThisBeat, "ThisBeat"),
                                         _mxarray185_)) {
                                mlfAssign(&Character, _mxarray260_);
                            } else if (mclEqBool(
                                         mclVv(ThisBeat, "ThisBeat"),
                                         _mxarray193_)) {
                                mlfAssign(&Character, _mxarray262_);
                            } else if (mclEqBool(
                                         mclVv(ThisBeat, "ThisBeat"),
                                         _mxarray189_)) {
                                mlfAssign(&Character, _mxarray264_);
                            } else if (mclEqBool(
                                         mclVv(ThisBeat, "ThisBeat"),
                                         _mxarray181_)) {
                                mlfAssign(&Character, _mxarray266_);
                            }
                            mclAssignAns(
                              &ans,
                              mlfNFprintf(
                                0,
                                mclVv(fid, "fid"),
                                _mxarray268_,
                                mclVv(Character, "Character"),
                                NULL));
                            mlfAssign(
                              &ThisBeat,
                              mclEq(
                                mclArrayRef2(
                                  mclVv(ArrowTrack, "ArrowTrack"),
                                  mlfScalar(v_06),
                                  mlfCreateColonIndex()),
                                _mxarray41_));
                            if (mlfTobool(
                                  mlfAny(mclVv(ThisBeat, "ThisBeat"), NULL))) {
                                if (mclEqBool(
                                      mclVv(ThisBeat, "ThisBeat"),
                                      _mxarray240_)) {
                                    mlfAssign(&Character, _mxarray242_);
                                } else if (mclEqBool(
                                             mclVv(ThisBeat, "ThisBeat"),
                                             _mxarray244_)) {
                                    mlfAssign(&Character, _mxarray246_);
                                } else if (mclEqBool(
                                             mclVv(ThisBeat, "ThisBeat"),
                                             _mxarray248_)) {
                                    mlfAssign(&Character, _mxarray250_);
                                } else if (mclEqBool(
                                             mclVv(ThisBeat, "ThisBeat"),
                                             _mxarray252_)) {
                                    mlfAssign(&Character, _mxarray254_);
                                }
                                mclAssignAns(
                                  &ans,
                                  mlfNFprintf(
                                    0,
                                    mclVv(fid, "fid"),
                                    _mxarray270_,
                                    mclVv(Character, "Character"),
                                    NULL));
                            }
                            continue_1:
                            if (v_06 == e_05) {
                                break;
                            }
                            ++v_06;
                        }
                        mlfAssign(&ct1, mlfScalar(v_06));
                    }
                }
                mclAssignAns(
                  &ans, mlfNFprintf(0, mclVv(fid, "fid"), _mxarray272_, NULL));
                if (v_ == e_) {
                    break;
                }
                ++v_;
            }
            mlfAssign(&ArrowSet, mlfScalar(v_));
        }
    }
    /*
     * 
     * fclose( fid );
     */
    mclAssignAns(&ans, mlfFclose(mclVv(fid, "fid")));
    /*
     * disp( 'Created .dwi step file.' );
     */
    mlfDisp(_mxarray274_);
    /*
     * 
     * 
     * % Output step file in .sm format
     * fid = fopen ( strcat( OutputDirectory, StepFilename, '.sm' ), 'wt');
     */
    mlfAssign(
      &fid,
      mlfFopen(
        NULL,
        NULL,
        mlfStrcat(
          mclVv(OutputDirectory, "OutputDirectory"),
          mclVv(StepFilename, "StepFilename"),
          _mxarray276_,
          NULL),
        _mxarray204_,
        NULL));
    /*
     * 
     * fprintf( fid, '#TITLE:%s;\n', FileName );
     */
    mclAssignAns(
      &ans,
      mlfNFprintf(
        0, mclVv(fid, "fid"), _mxarray206_, mclVv(FileName, "FileName"), NULL));
    /*
     * fprintf( fid, '#ARTIST:The Dancing Monkeys Project;\n' );
     */
    mclAssignAns(&ans, mlfNFprintf(0, mclVv(fid, "fid"), _mxarray208_, NULL));
    /*
     * fprintf( fid, '#OFFSET:%f;\n', -( GapInSeconds + StepFileFudgeFactor ) );
     */
    mclAssignAns(
      &ans,
      mlfNFprintf(
        0,
        mclVv(fid, "fid"),
        _mxarray278_,
        mclUminus(
          mclPlus(
            mclVv(GapInSeconds, "GapInSeconds"),
            mclVv(StepFileFudgeFactor, "StepFileFudgeFactor"))),
        NULL));
    /*
     * fprintf( fid, '#BPMS:0=%f;\n', BPM );
     */
    mclAssignAns(
      &ans,
      mlfNFprintf(0, mclVv(fid, "fid"), _mxarray280_, mclVv(BPM, "BPM"), NULL));
    /*
     * fprintf( fid, '#MUSIC:%s;\n', OutputFile );
     */
    mclAssignAns(
      &ans,
      mlfNFprintf(
        0,
        mclVv(fid, "fid"),
        _mxarray282_,
        mclVv(OutputFile, "OutputFile"),
        NULL));
    /*
     * 
     * if ( ~ isempty( Pauses ) )
     */
    if (mclNotBool(mlfIsempty(mclVv(Pauses, "Pauses")))) {
        /*
         * fprintf( fid, '#STOPS:' );
         */
        mclAssignAns(
          &ans, mlfNFprintf(0, mclVv(fid, "fid"), _mxarray284_, NULL));
        /*
         * for ct1 = 1 : size( Pauses, 1 )
         */
        {
            int v_ = mclForIntStart(1);
            int e_
              = mclForIntEnd(
                  mlfSize(
                    mclValueVarargout(),
                    mclVv(Pauses, "Pauses"),
                    _mxarray22_));
            if (v_ > e_) {
                mlfAssign(&ct1, _mxarray97_);
            } else {
                /*
                 * if ( ct1 > 1 )
                 * fprintf( fid, ',' );
                 * end
                 * fprintf( fid, '%f=%f', (Pauses( ct1, 1 ) - (ct1-1)*BarSize), Pauses( ct1, 2 ) );
                 * end
                 */
                for (; ; ) {
                    if (mclGtBool(mlfScalar(v_), _mxarray22_)) {
                        mclAssignAns(
                          &ans,
                          mlfNFprintf(
                            0, mclVv(fid, "fid"), _mxarray218_, NULL));
                    }
                    mclAssignAns(
                      &ans,
                      mlfNFprintf(
                        0,
                        mclVv(fid, "fid"),
                        _mxarray286_,
                        mclMinus(
                          mclIntArrayRef2(mclVv(Pauses, "Pauses"), v_, 1),
                          mclMtimes(
                            mlfScalar(v_ - 1), mclVv(BarSize, "BarSize"))),
                        mclIntArrayRef2(mclVv(Pauses, "Pauses"), v_, 2),
                        NULL));
                    if (v_ == e_) {
                        break;
                    }
                    ++v_;
                }
                mlfAssign(&ct1, mlfScalar(v_));
            }
        }
        /*
         * fprintf( fid, ';\n' );
         */
        mclAssignAns(
          &ans, mlfNFprintf(0, mclVv(fid, "fid"), _mxarray222_, NULL));
    /*
     * end
     */
    }
    /*
     * fprintf( fid, '\n// --- Arrows ---\n');
     */
    mclAssignAns(&ans, mlfNFprintf(0, mclVv(fid, "fid"), _mxarray224_, NULL));
    /*
     * 
     * DifficultyNames = { 'Basic' 'easy' ; 'Standard' 'medium' ; 'Heavy' 'hard' };
     */
    mlfAssign(&DifficultyNames, _mxarray288_);
    /*
     * for ArrowSet = 1 : 3
     */
    {
        int v_ = mclForIntStart(1);
        int e_ = 3;
        if (v_ > e_) {
            mlfAssign(&ArrowSet, _mxarray97_);
        } else {
            /*
             * FootRating = FootRatings( ArrowSet );
             * ArrowTrack = ArrowTracks( :, :, ArrowSet );
             * 
             * fprintf( fid, '#NOTES:\n\tdance-single:\n\t%s:\n\t%s:\n\t%d:\n\t:\n' ...
             * , DifficultyNames{ ArrowSet, 1 }, DifficultyNames{ ArrowSet, 2 }, FootRating );
             * 
             * for ct1 = 1 : size( ArrowTrack, 1 )
             * 
             * if ( ArrowTrack( ct1, : ) == [ -1 -1 -1 -1 ] )
             * % Don't write out any arrows as we have a pause.    
             * continue;    
             * end
             * fprintf( fid, '%d%d%d%d\n', ArrowTrack( ct1, : ) );
             * 
             * if ( mod( ct1, MaxArrowsPerBar ) == 0 )
             * fprintf( fid, ',\n');
             * end
             * end
             * 
             * end
             */
            for (; ; ) {
                mlfAssign(
                  &FootRating,
                  mclIntArrayRef1(mclVv(FootRatings, "FootRatings"), v_));
                mlfAssign(
                  &ArrowTrack,
                  mlfIndexRef(
                    mclVv(ArrowTracks, "ArrowTracks"),
                    "(?,?,?)",
                    mlfCreateColonIndex(),
                    mlfCreateColonIndex(),
                    mlfScalar(v_)));
                mclAssignAns(
                  &ans,
                  mlfNFprintf(
                    0,
                    mclVv(fid, "fid"),
                    _mxarray302_,
                    mlfIndexRef(
                      mclVv(DifficultyNames, "DifficultyNames"),
                      "{?,?}",
                      mlfScalar(v_),
                      _mxarray22_),
                    mlfIndexRef(
                      mclVv(DifficultyNames, "DifficultyNames"),
                      "{?,?}",
                      mlfScalar(v_),
                      _mxarray41_),
                    mclVv(FootRating, "FootRating"),
                    NULL));
                {
                    int v_07 = mclForIntStart(1);
                    int e_06
                      = mclForIntEnd(
                          mlfSize(
                            mclValueVarargout(),
                            mclVv(ArrowTrack, "ArrowTrack"),
                            _mxarray22_));
                    if (v_07 > e_06) {
                        mlfAssign(&ct1, _mxarray97_);
                    } else {
                        for (; ; ) {
                            if (mclEqBool(
                                  mclArrayRef2(
                                    mclVv(ArrowTrack, "ArrowTrack"),
                                    mlfScalar(v_07),
                                    mlfCreateColonIndex()),
                                  _mxarray236_)) {
                                goto continue_2;
                            }
                            mclAssignAns(
                              &ans,
                              mlfNFprintf(
                                0,
                                mclVv(fid, "fid"),
                                _mxarray304_,
                                mclArrayRef2(
                                  mclVv(ArrowTrack, "ArrowTrack"),
                                  mlfScalar(v_07),
                                  mlfCreateColonIndex()),
                                NULL));
                            if (mclEqBool(
                                  mlfMod(
                                    mlfScalar(v_07),
                                    mclVv(MaxArrowsPerBar, "MaxArrowsPerBar")),
                                  _mxarray44_)) {
                                mclAssignAns(
                                  &ans,
                                  mlfNFprintf(
                                    0, mclVv(fid, "fid"), _mxarray306_, NULL));
                            }
                            continue_2:
                            if (v_07 == e_06) {
                                break;
                            }
                            ++v_07;
                        }
                        mlfAssign(&ct1, mlfScalar(v_07));
                    }
                }
                if (v_ == e_) {
                    break;
                }
                ++v_;
            }
            mlfAssign(&ArrowSet, mlfScalar(v_));
        }
    }
    /*
     * 
     * fclose( fid );
     */
    mclAssignAns(&ans, mlfFclose(mclVv(fid, "fid")));
    /*
     * disp('Created .sm step file.');
     */
    mlfDisp(_mxarray308_);
    /*
     * 
     * 
     * 
     * 
     * 
     * % Output the results to the screen.
     * disp( 'Results: ' );
     */
    mlfDisp(_mxarray310_);
    /*
     * disp( '  Song name:' );
     */
    mlfDisp(_mxarray312_);
    /*
     * disp( FileName );
     */
    mlfDisp(mclVv(FileName, "FileName"));
    /*
     * disp( '  BPM:' );
     */
    mlfDisp(_mxarray314_);
    /*
     * disp( BPM );
     */
    mlfDisp(mclVv(BPM, "BPM"));
    /*
     * disp( '  Gap:' );
     */
    mlfDisp(_mxarray316_);
    /*
     * disp( GapInSeconds );
     */
    mlfDisp(mclVv(GapInSeconds, "GapInSeconds"));
    /*
     * disp( '  Confidence:' );
     */
    mlfDisp(_mxarray318_);
    /*
     * disp( Confidence );
     */
    mlfDisp(mclVv(Confidence, "Confidence"));
    /*
     * 
     * toc;
     */
    mclAssignAns(&ans, mlfNToc(0));
    return_:
    mxDestroyArray(ans);
    mxDestroyArray(Directory);
    mxDestroyArray(FileName);
    mxDestroyArray(FileExt);
    mxDestroyArray(Temp);
    mxDestroyArray(ChosenDifficultyRatings);
    mxDestroyArray(LamePath);
    mxDestroyArray(LameFilename);
    mxDestroyArray(LameFileExt);
    mxDestroyArray(LameExe);
    mxDestroyArray(SmoothingFilterOrder);
    mxDestroyArray(SmoothingFilrerLowpassFrequency);
    mxDestroyArray(WindowLength);
    mxDestroyArray(PeakThreshold);
    mxDestroyArray(HeightWindowSize);
    mxDestroyArray(BeatPositioningThreshold);
    mxDestroyArray(MinimumBPM);
    mxDestroyArray(MaximumBPM);
    mxDestroyArray(IntervalGradientLimit);
    mxDestroyArray(MaxArrowsPerBar);
    mxDestroyArray(BarSize);
    mxDestroyArray(BarsBeginningPadding);
    mxDestroyArray(BarsEndPadding);
    mxDestroyArray(StepFilename);
    mxDestroyArray(StepFileFudgeFactor);
    mxDestroyArray(FadeSeconds);
    mxDestroyArray(MaxSongLengthInSeconds);
    mxDestroyArray(OutputFile);
    mxDestroyArray(OutputDirectory);
    mxDestroyArray(OutputFullFilename);
    mxDestroyArray(Status);
    mxDestroyArray(Result);
    mxDestroyArray(Temp1);
    mxDestroyArray(Frequency);
    mxDestroyArray(Temp2);
    mxDestroyArray(NumSamples);
    mxDestroyArray(SongSizeLimit);
    mxDestroyArray(SongData);
    mxDestroyArray(NumBits);
    mxDestroyArray(SongLength);
    mxDestroyArray(Mask);
    mxDestroyArray(NumTracks);
    mxDestroyArray(Mono);
    mxDestroyArray(m);
    mxDestroyArray(n);
    mxDestroyArray(SmoothedData);
    mxDestroyArray(WindowSizeInSamples);
    mxDestroyArray(WindowShape);
    mxDestroyArray(NormalisedMonoData);
    mxDestroyArray(NormalisedSmoothData);
    mxDestroyArray(Position);
    mxDestroyArray(Window);
    mxDestroyArray(SortedData);
    mxDestroyArray(Limit);
    mxDestroyArray(PeakData);
    mxDestroyArray(NonZeroData);
    mxDestroyArray(IndexToNonZeroData);
    mxDestroyArray(IndexToPeakData);
    mxDestroyArray(Peaks);
    mxDestroyArray(Troughs);
    mxDestroyArray(BeatStrengths);
    mxDestroyArray(BeatPositions);
    mxDestroyArray(ct1);
    mxDestroyArray(Peak);
    mxDestroyArray(TroughsLessThanPeak);
    mxDestroyArray(NearestTrough);
    mxDestroyArray(HeightWindow);
    mxDestroyArray(HalfHeightWindow);
    mxDestroyArray(PeakSize);
    mxDestroyArray(TroughSize);
    mxDestroyArray(Threshold);
    mxDestroyArray(Candidates);
    mxDestroyArray(CandidatesPos);
    mxDestroyArray(Pos);
    mxDestroyArray(BeatPos);
    mxDestroyArray(Offsets);
    mxDestroyArray(Offset);
    mxDestroyArray(Beats);
    mxDestroyArray(MaximumInterval);
    mxDestroyArray(MinimumInterval);
    mxDestroyArray(IntervalFitness);
    mxDestroyArray(IntervalGap);
    mxDestroyArray(HalfGapWindowSize);
    mxDestroyArray(GapWindow);
    mxDestroyArray(NumBeats);
    mxDestroyArray(i);
    mxDestroyArray(Gaps);
    mxDestroyArray(ExtraGaps);
    mxDestroyArray(FullGaps);
    mxDestroyArray(SortedGaps);
    mxDestroyArray(SortedIndex);
    mxDestroyArray(GapsFiltered);
    mxDestroyArray(Area);
    mxDestroyArray(Centre);
    mxDestroyArray(PosVal);
    mxDestroyArray(xPos);
    mxDestroyArray(GapsConfidence);
    mxDestroyArray(OffbeatPos);
    mxDestroyArray(OffBeatValue);
    mxDestroyArray(GapPeaks);
    mxDestroyArray(DoMoreWorkOn);
    mxDestroyArray(LookAt);
    mxDestroyArray(Y);
    mxDestroyArray(Range);
    mxDestroyArray(X);
    mxDestroyArray(NormalisedIntervalFitness);
    mxDestroyArray(FitnessIndex);
    mxDestroyArray(Confidence);
    mxDestroyArray(Interval);
    mxDestroyArray(GapInSamples);
    mxDestroyArray(GapInSeconds);
    mxDestroyArray(BPM);
    mxDestroyArray(WindowNum);
    mxDestroyArray(AbsoluteEnergy);
    mxDestroyArray(Energy);
    mxDestroyArray(BeatData);
    mxDestroyArray(SizeBeatData);
    mxDestroyArray(SelfSimilarity);
    mxDestroyArray(ct2);
    mxDestroyArray(PossibleBarStarts);
    mxDestroyArray(BarSimilarities);
    mxDestroyArray(BarSizeInHalfBeats);
    mxDestroyArray(FirstBarStart);
    mxDestroyArray(BarSimilarity);
    mxDestroyArray(Num1);
    mxDestroyArray(Num2);
    mxDestroyArray(Pos1);
    mxDestroyArray(Pos2);
    mxDestroyArray(BestBarStarts);
    mxDestroyArray(BarStart);
    mxDestroyArray(Z);
    mxDestroyArray(CurrentMax);
    mxDestroyArray(ThisClique);
    mxDestroyArray(CliqueSize);
    mxDestroyArray(SimilarSections);
    mxDestroyArray(NextSection);
    mxDestroyArray(X2);
    mxDestroyArray(Junk);
    mxDestroyArray(Index);
    mxDestroyArray(SelectedClique);
    mxDestroyArray(NodeInClique);
    mxDestroyArray(Next);
    mxDestroyArray(SimilarityOnBeats);
    mxDestroyArray(PauseThreshold);
    mxDestroyArray(FirstMajorEnergy);
    mxDestroyArray(LastMajorEnergy);
    mxDestroyArray(Pauses);
    mxDestroyArray(BarAbsoluteEnergy);
    mxDestroyArray(A);
    mxDestroyArray(Freezes);
    mxDestroyArray(FreezeStarted);
    mxDestroyArray(WaveformStart);
    mxDestroyArray(WaveformEnd);
    mxDestroyArray(FreezeEnd);
    mxDestroyArray(LongFreezes);
    mxDestroyArray(FreezeBeats);
    mxDestroyArray(DifficultyOffbeatModifier);
    mxDestroyArray(DifficultyRatings);
    mxDestroyArray(NumBars);
    mxDestroyArray(AllowableMoves);
    mxDestroyArray(EnergyDiff);
    mxDestroyArray(ArrowTrackSize);
    mxDestroyArray(ArrowTracks);
    mxDestroyArray(FootRatings);
    mxDestroyArray(ArrowSet);
    mxDestroyArray(UserDifficultyRating);
    mxDestroyArray(OffbeatModifier);
    mxDestroyArray(AvgArrowsPerLevel);
    mxDestroyArray(NumArrows);
    mxDestroyArray(ArrowsPerBar);
    mxDestroyArray(ModdedEnergy);
    mxDestroyArray(FullBarEnergy);
    mxDestroyArray(ct0);
    mxDestroyArray(CurrentFoot);
    mxDestroyArray(FootPlacement);
    mxDestroyArray(ArrowTrack);
    mxDestroyArray(InFreeze);
    mxDestroyArray(JumpThreshold);
    mxDestroyArray(SectionArrowData);
    mxDestroyArray(TempModdedEnergy);
    mxDestroyArray(TempEnergy);
    mxDestroyArray(TempFreezes);
    mxDestroyArray(BarModdedEnergy);
    mxDestroyArray(BarEnergy);
    mxDestroyArray(BarFreezes);
    mxDestroyArray(PlaceArrow);
    mxDestroyArray(NumArrowsToHave);
    mxDestroyArray(FreezeOn);
    mxDestroyArray(PrevBeatEnergy);
    mxDestroyArray(BarArrows);
    mxDestroyArray(ArrowType);
    mxDestroyArray(PossibleMoves);
    mxDestroyArray(ct3);
    mxDestroyArray(ProbMoves);
    mxDestroyArray(NewArrow);
    mxDestroyArray(FreezeArrow);
    mxDestroyArray(JumpType);
    mxDestroyArray(BarSection);
    mxDestroyArray(ArrowIndex);
    mxDestroyArray(ChangeLeftRightProbability);
    mxDestroyArray(ChangeUpDownProbability);
    mxDestroyArray(CurrentBeat);
    mxDestroyArray(FootRating);
    mxDestroyArray(fid);
    mxDestroyArray(DWIDifficultyNames);
    mxDestroyArray(ThisBeat);
    mxDestroyArray(Character);
    mxDestroyArray(DifficultyNames);
    mxDestroyArray(TempFile);
    mxDestroyArray(LameFullFilename);
    mxDestroyArray(RootDirectory);
    mxDestroyArray(HardDifficulty);
    mxDestroyArray(MedDifficulty);
    mxDestroyArray(EasyDifficulty);
    mxDestroyArray(MusicFullFilename);
    mclSetCurrentLocalFunctionTable(save_local_function_table_);
}
