<commit_before>import {
  compose,
  curry,
  filter,
  identity,
  map,
  partial,
  prop,
  range,
  repeat,
  transduce,
} from 'ramda'
import React from 'react'
import {connect} from 'react-redux'
import store from '../../store'
import {
  activePatternCellClick,
  addAudioGraphSource,
  removeKeysFromAudioGraphContaining,
  updateActivePatternActivePosition,
} from '../../actions'
import {mapIndexed} from '../../tools/indexedIterators'
import Pattern from '../organisms/Pattern'
import PlayButton from '../atoms/PlayButton'
import Navigation from '../organisms/Navigation'
import pitchFromScaleIndex from '../../audioHelpers/pitchFromScaleIndex'
import scaleIndexToFrequency from '../../audioHelpers/scaleIndexToFrequency'
import PatternMenu from '../organisms/PatternMenu'
import noteNameFromPitch from '../../audioHelpers/noteNameFromPitch'
import {noteExists} from '../../reducers/patterns'

const playStopSubject = new Rx.Subject

const onPlay = dispatch =>
  Rx.Observable
    .generateWithRelativeTime(0,
                              () => true,
                              x => x + 1,
                              x => x,
                              () => 60000 / store.getState().bpm)
    .takeUntil(playStopSubject)
    .map(count => {
      const {activePatternIndex, patterns, scale} = store.getState()
      const {notes, octave, xLength, yLength} = patterns[activePatternIndex]
      return {
        notes,
        octave,
        yLength,
        lastPosition: (count - 1) % xLength,
        position: count % xLength,
        scale,
      }
    })
    .do(compose(
      dispatch,
      updateActivePatternActivePosition,
      prop('position')
    ))
    .do(compose(
      dispatch,
      removeKeysFromAudioGraphContaining,
      ({lastPosition}) => `pattern-editor-${lastPosition}`)
    )
    .subscribe(({<commit_msg>fix(PatternEditor) fix bug where shrinking pattern with note playing causes note not to cease<commit_after>import {
  compose,
  curry,
  filter,
  identity,
  map,
  partial,
  prop,
  range,
  repeat,
  transduce,
} from 'ramda'
import React from 'react'
import {connect} from 'react-redux'
import store from '../../store'
import {
  activePatternCellClick,
  addAudioGraphSource,
  removeKeysFromAudioGraphContaining,
  updateActivePatternActivePosition,
} from '../../actions'
import {mapIndexed} from '../../tools/indexedIterators'
import Pattern from '../organisms/Pattern'
import PlayButton from '../atoms/PlayButton'
import Navigation from '../organisms/Navigation'
import pitchFromScaleIndex from '../../audioHelpers/pitchFromScaleIndex'
import scaleIndexToFrequency from '../../audioHelpers/scaleIndexToFrequency'
import PatternMenu from '../organisms/PatternMenu'
import noteNameFromPitch from '../../audioHelpers/noteNameFromPitch'
import {noteExists} from '../../reducers/patterns'

let lastPosition
const playStopSubject = new Rx.Subject

const onPlay = dispatch =>
  Rx.Observable
    .generateWithRelativeTime(0,
                              () => true,
                              x => x + 1,
                              x => x,
                              () => 60000 / store.getState().bpm)
    .takeUntil(playStopSubject)
    .map(count => {
      const {activePatternIndex, patterns, scale} = store.getState()
      const {notes, octave, xLength, yLength} = patterns[activePatternIndex]
      return {
        notes,
        octave,
        yLength,
        position: count % xLength,
        scale,
      }
    })
    .do(compose(
      dispatch,
      updateActivePatternActivePosition,
      prop('position')
    ))
    .do(compose(
      dispatch,
      removeKeysFromAudioGraphContaining,
      _ => `pattern-editor-${lastPosition}`)
    )
    .do(({position}) => lastPosition = position)
    .subscribe(({
{'fraction_non_alphanumeric': 0.11972573839662447, 'fraction_numerical': 0.003955696202531646, 'mean_word_length': 2.595260663507109, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2548510', 'n_tokens_mistral': 1070, 'n_tokens_neox': 1056, 'n_words': 252}