1- import { ButtonToolbar , CommandHost , formatHotkey , FullScreen , GridFrameContainer , HFlex , ICommand , IComponent , StatusBar , TabFrameContainer , visitNodeAndChildNodesBreadth , visitNodeAndChildNodesDepth } from "./nutz" ;
1+ import { ButtonToolbar , CommandHost , formatHotkey , FullScreen , getOrCreateDirectory , GridFrameContainer , HFlex , ICommand , IComponent , StatusBar , TabFrameContainer , visitNodeAndChildNodesBreadth , visitNodeAndChildNodesDepth } from "./nutz" ;
22import { MenuBar } from "./nutz/Menubar" ;
33import { ModalDialogContainer } from "./nutz/ModalDialogContainer" ;
44import { mainMenu } from './menu/menu' ;
@@ -25,6 +25,8 @@ import { ChorusFactory } from "./audio/plugins/Chorus";
2525import { CompressorFactory } from "./audio/plugins/Compressor" ;
2626import { MasterizerFactory } from "./audio/plugins/Masterizer" ;
2727import { SaturationFactory } from "./audio/plugins/Saturation" ;
28+ import { getInstrumentName } from "./components/PatternEditorHelper" ;
29+ import { importJsonPreset } from "./presetfile/JsonPreset" ;
2830
2931class PeakMeter implements IComponent {
3032 app : Appl ;
@@ -383,6 +385,29 @@ export class Appl extends CommandHost implements IComponent {
383385 this . recordOffset = 0 ;
384386 }
385387
388+ async createInstrument ( instrumentId : string , x : number , y : number ) {
389+ const instrument = this . song . createInstrument ( instrumentId , getInstrumentName ( this . song . instruments , instrumentId ) , x , y , { } ) ;
390+
391+ // If instrument has notes: Create sequence column and empty pattern with default pattern columns
392+ const instrumenteer = this . playerSongAdapter . instrumentMap . get ( instrument ) ;
393+ if ( instrumenteer . factory . maxPolyphony > 0 ) {
394+ const column = this . song . createSequenceColumn ( instrument ) ;
395+ const pa = this . song . createPattern ( instrument , "00" , 64 , 4 ) ;
396+ this . song . createPatternColumn ( pa , instrument , "midinote" ) ;
397+ }
398+
399+ // Load default preset bank if exist
400+ const instrumentName = instrument . instrumentId . replace ( / [ \/ \\ : * ? " < > | ] / g, "_" ) ;
401+
402+ const instrumentPresetHandle = await getOrCreateDirectory ( this . homeDir , "presets" , instrumentName )
403+
404+ const bankHandle = await instrumentPresetHandle . getFileHandle ( "default.mprs" )
405+ const bank = await importJsonPreset ( bankHandle ) ;
406+
407+ console . log ( "Createing instrument with bank" , bank )
408+ this . song . setInstrumentBank ( instrument , bank ) ;
409+ }
410+
386411 onInput = ( ev : CustomEvent < Float32Array [ ] > ) => {
387412 const inputs = ev . detail ;
388413 const inputLength = inputs [ 0 ] . length ;
0 commit comments