<commit_before>const acorn = require( 'acorn' )

const callDepths = [
  'SCORE',
  'THIS.METHOD',
  'THIS.METHOD.SEQ',
  'THIS.METHOD[ 0 ].SEQ',
  'THIS.METHOD.VALUES.REVERSE.SEQ',
  'THIS.METHOD[ 0 ].VALUES.REVERSE.SEQ',
  'TRACKS[0].METHOD[ 0 ].VALUES.REVERSE.SEQ',  
  'TRACKS[0].METHOD.SEQ',
  'TRACKS[0].METHOD[0].SEQ',
  'TRACKS[0].METHOD.VALUES.REVERSE.SEQ',
  'TRACKS[0].METHOD[0].VALUES.REVERSE.SEQ'
]

const trackNames = [ 'this', 'tracks', 'master', 'returns' ]

const Utility = require( './utility.js' )
const $ = Utility.create

let Marker = {
  genWidgets: { dirty:false },
  _patternTypes: [ 'values', 'timings', 'index' ],

  prepareObject( obj ) {
    obj.markup = {
      textMarkers: {},
      cssClasses:  {} 
    }  
  },

  process( code, position, codemirror, track ) {
    let shouldParse = code.includes( '.seq' ) || code.includes( 'Steps(' ) || code.includes( 'Score(' ),
        isGen = false

    if( !shouldParse ) { // check for gen~ assignment
      for( let ugen of Gibber.Gen.names ) {

        for( let ugen of Gibber.Gen.names ) {
          let idx = code.indexOf( ugen )
          if( idx !== -1 && code.charAt( idx + ugen.length ) === '('  ) {
            shouldParse = true
            isGen = true

            break;
          }
        }
      }
    }

    if( !shouldParse ) return

    let tree = acorn.parse( code, { locations:true, ecmaVersion:6 } ).body
    
    for( let node of tree ) {
      if( node.type === 'ExpressionStatement' ) { // not control flow
        node.verticalOffset  = position.start.line
        node.horizontalOffset = position.horizontalOffset === undefined ? 0 : position.horizontalOffset
        try {
          if( isGen ) {
            this.processGen( node, codemirror, track )
          }else{ 
            this._process[ node.type ]( node, codemirror, track )
          }
        } catch( error ) {
          console.log( 'error processing annotation for', node.expression.type, error )
        }
      }
    }
  },
  
  processGen( node, cm, track ) {
    let ch = node.end, line = node.verticalOffset, start = ch - 1, end = node.end 
    
    cm.replaceRange( ') ', { line, ch:start }, { line, ch } )

    let widget = document.createElement( 'canvas' )
    widget.ctx = widget.getContext('2d')
    widget.style.display = 'inline-block'
    widget.style.verticalAlign = 'middle'
    widget.style.height = '1.1em'
    widget.style.width = '60px'
    widget.style.backgroundColor = 'transparent'
    widget.style.borderLeft = '1px solid #666'
    widget.style.borderRight = '1px solid #666'
    widget.setAttribute( 'width', 60 )
    widget.setAttribute( 'height', 13 )
    widget.ctx.fillStyle = 'rgba(46,50,53,1)'
    widget.ctx.strokeStyle = '#eee'
    widget.ctx.lineWidth = .5
    widget.gen = Gibber.Gen.lastConnected
    widget.values = []

    let oldWidget = Marker.genWidgets[ widget.gen.paramID ] 

    if( oldWidget !== undefined ) {
      oldWidget.parentNode.removeChild( oldWidget )
    } <commit_msg>working WavePattern; need to re-add regular Gen modulations<commit_after>const acorn = require( 'acorn' )

const callDepths = [
  'SCORE',
  'THIS.METHOD',
  'THIS.METHOD.SEQ',
  'THIS.METHOD[ 0 ].SEQ',
  'THIS.METHOD.VALUES.REVERSE.SEQ',
  'THIS.METHOD[ 0 ].VALUES.REVERSE.SEQ',
  'TRACKS[0].METHOD[ 0 ].VALUES.REVERSE.SEQ',  
  'TRACKS[0].METHOD.SEQ',
  'TRACKS[0].METHOD[0].SEQ',
  'TRACKS[0].METHOD.VALUES.REVERSE.SEQ',
  'TRACKS[0].METHOD[0].VALUES.REVERSE.SEQ'
]

const trackNames = [ 'this', 'tracks', 'master', 'returns' ]

const Utility = require( './utility.js' )
const $ = Utility.create

let Marker = {
  genWidgets: { dirty:false },
  _patternTypes: [ 'values', 'timings', 'index' ],

  prepareObject( obj ) {
    obj.markup = {
      textMarkers: {},
      cssClasses:  {} 
    }  
  },

  process( code, position, codemirror, track ) {
    let shouldParse = code.includes( '.seq' ) || code.includes( 'Steps(' ) || code.includes( 'Score(' ),
        isGen = false

    if( !shouldParse ) { // check for gen~ assignment
      for( let ugen of Gibber.__gen.gen.names ) {

        for( let ugen of Gibber.__gen.gen.names ) {
          let idx = code.indexOf( ugen )
          if( idx !== -1 && code.charAt( idx + ugen.length ) === '('  ) {
            shouldParse = true
            isGen = true

            break;
          }
        }
      }
    }

    if( !shouldParse ) return

    let tree = acorn.parse( code, { locations:true, ecmaVersion:6 } ).body
    
    for( let node of tree ) {
      if( node.type === 'ExpressionStatement' ) { // not control flow
        node.verticalOffset  = position.start.line
        node.horizontalOffset = position.horizontalOffset === undefined ? 0 : position.horizontalOffset
        try {
          if( isGen ) {
            this.processGen( node, codemirror, track )
          }else{ 
            this._process[ node.type ]( node, codemirror, track )
          }
        } catch( error ) {
          console.log( 'error processing annotation for', node.expression.type, error )
        }
      }
    }
  },
  
  processGen( node, cm, track ) {
    let ch = node.end, line = node.verticalOffset, start = ch - 1, end = node.end 
    
    cm.replaceRange( ') ', { line, ch:start }, { line, ch } )

    let widget = document.createElement( 'canvas' )
    widget.ctx = widget.getContext('2d')
    widget.style.display = 'inline-block'
    widget.style.verticalAlign = 'middle'
    widget.style.height = '1.1em'
    widget.style.width = '60px'
    widget.style.backgroundColor = 'transparent'
    widget.style.borderLeft = '1px solid #666'
    widget.style.borderRight = '1px solid #666'
    widget.setAttribute( 'width', 60 )
    widget.setAttribute( 'height', 13 )
    widget.ctx.fillStyle = 'rgba(46,50,53,1)'
    widget.ctx.strokeStyle = '#eee'
    widget.ctx.lineWidth = .5
    widget.gen = Gibber.__gen.gen.lastConnected
    widget.values = []

    let oldWidget = Marker.genWidgets[ widget.gen.paramID ] 

    if( oldWidget !== undefined ) {
      oldWidget.parentNode.removeChild( oldWidget )
    } 
{'fraction_non_alphanumeric': 0.14958677685950414, 'fraction_numerical': 0.012892561983471074, 'mean_word_length': 2.4341657207718503, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6670623', 'n_tokens_mistral': 2097, 'n_tokens_neox': 2003, 'n_words': 429}