import { LayoutGenerator , LayoutGeneratorMeta } from "." ; import type { Controller } from "../Controller" ; import { NOTES } from "../helpers" ; import type { Note } from "@tonaljs/core" ; import { note } from "@tonaljs/core" ; import { enharmonic } from "@tonaljs/note" ; import { transpose } from "@tonaljs/core" ; import { Interval } from "@tonaljs/tonal" ; type LayoutAbleton = "3rds" | "4ths" ; class LayoutGeneratorAbleton extends LayoutGenerator { readonly root : Note ; readonly layout : LayoutAbleton ; constructor ( root , layout ) { super ( root ) ; this . layout = layout ; } generate ( controller ) { let notes = { } ; let currentPadNumber = controller . offset ; let currentNoteIndex = NOTES . indexOf ( this . root . pc ) ; let currentOctave = this . root . oct ; let rows = [ ] ; for ( let r = 0 ; r < controller . rows ; r ++ ) { let row = [ ] ; if ( r === 0 ) { for ( let c = 0 ; c < controller . columns ; c ++ ) { notes [ currentPadNumber ] = note ( `${ NOTES [ currentNoteIndex ] }${ currentOctave }` ) ; row . push ( notes [ currentPadNumber ] ) ; if ( currentNoteIndex === NOTES . length - 1 ) { currentNoteIndex = 0 ; currentOctave ++ ; } else { currentNoteIndex ++ ; } currentPadNumber ++ ; } } else { for ( let c = 0 ; c < controller . columns ; c ++ ) { const previousRowNote = rows [ r - 1 ] [ c ] ; let newNote ; if ( this . layout === '3rds' ) { } else if ( this . layout === '4ths' ) { newNote = note ( transpose ( previousRowNote . name , '4P' ) ) ; } if ( newNote . acc === 'b' ) { newNote = note ( enharmonic ( newNote . name ) ) ; } notes [ currentPadNumber ] = newNote ; row . push ( notes [ currentPadNumber ] ) ; currentPadNumber ++ ; } } rows . push ( row ) ; } return notes ; } } export class LayoutGeneratorAbleton4ths extends LayoutGeneratorAbleton { readonly root : Note ; constructor ( root ) { super ( root , "4ths" ) ; } static getInstance ( root ) { return new LayoutGeneratorAbleton4ths ( root ) ; } static getMeta ( ) { return { id : 'ableton4ths' , label : '4ths chromatic' } ; } } export class LayoutGeneratorAbleton3rds extends LayoutGeneratorAbleton { readonly root : Note ; constructor ( root ) { super ( root , "3rds" ) ; } static getInstance ( root ) { return new LayoutGeneratorAbleton3rds ( root ) ; } static getMeta ( ) { return { id : 'ableton3ds' , label : '3ds Chromatic' } ; } }