Skip to content

added sample-editor scripting feature - #282

Closed
coderofsalvation wants to merge 1 commit into
milkytracker:masterfrom
coderofsalvation:feat/sampleditor-scripting
Closed

coderofsalvation wants to merge 1 commit into
milkytracker:masterfrom
coderofsalvation:feat/sampleditor-scripting

Conversation

@coderofsalvation

@coderofsalvation coderofsalvation commented Aug 26, 2022 •

Copy link
Copy Markdown
Contributor

image

A simple scripting-bridge for MilkyTracker SampleEditor
Instead of bloating milkytracker with more effects/plugins, the burden of maintenance is reversed: external
applications & scripts can 'hook' into the sample-editor using the 'Script'-contextmenu.

DEMO video

https://drive.google.com/file/d/1dG_vmeCFSbmhLlnlHpgcLNB6zScXXTng/view?usp=sharing

Usecases

  • generate samples using puredata/csound or your favorite wave-editor etc
  • dump gig/sf2-soundfont wave-files into directory
  • write custom SAMPLERS: sample ANY SYNTH/APP/INPUT into milkytracker
  • apply a complex effect to a sample
  • automate tedious tasks
  • use your favorite scripting language to automate things
  • Create script-pipelines between different tools / commands, pick random samples from folders etc.

example scripting: https://gitlab.com/coderofsalvation/milkytracker-scripts

@Claytone

Copy link
Copy Markdown
Contributor

This is actually insanely cool, thanks for sharing!

@coderofsalvation
coderofsalvation force-pushed the feat/sampleditor-scripting branch from 15a3185 to ffa6b5b Compare August 31, 2022 09:23
@coderofsalvation
coderofsalvation force-pushed the feat/sampleditor-scripting branch 4 times, most recently from 7cd97c9 to 12cb5a3 Compare September 15, 2022 14:44
@coderofsalvation
coderofsalvation force-pushed the feat/sampleditor-scripting branch from 12cb5a3 to cd6e10f Compare September 15, 2022 16:03
@minidcon7

Copy link
Copy Markdown

Why is pull request not accepted?.

@coderofsalvation

coderofsalvation commented Dec 5, 2024 •

Copy link
Copy Markdown
Contributor Author

we had a big release blocking this feature (we wanted to take things step by step) but this might soon get some attention again

@coderofsalvation

coderofsalvation commented Jan 8, 2025 •

Copy link
Copy Markdown
Contributor Author

I've been thinking about the following:

Embedding lua is something I've played with (and discussed with others).
However, I've noticed that a lua api is easy to put in, but makes things hard to maintain and/or change (changing an api-call will break all previous scripts, requires versioning and much more testing for all platforms.).
Therefore, I still think the polyglot 'script-out' approach (of this PR) might be more lightweight, without ballooning the lightweight-ness of milkytracker (which runs on haiku, amiga etc).

perhaps broadening this feature, would allow for more generic and powerful polyglot integrations/plugins:

pattern editor

~/$CONFIGPATH/scripts.pattern.txt

generate pattern; generateXPpattern.sh %s
import midi; midi2xp %s %s |.mid
export midi; xp2midi %s

Note: |.mid will make milkytracker popup a filepicker (which filters on .mid files) before calling midi2xp <midifile> /tmp/pattern.xp

rightclick > Script > generate pattern         
                      import midi
                      export midi
                      ------------
                      scripts config                        # calls linux/mac: $EDITOR ~/$CONFIGPATH/scripts.pattern.txt
                                                                          mac:  open  ~/$CONFIGPATH/scripts.pattern.txt
                                                                          win: start ~/$CONFIGPATH/scripts.pattern.txt      

sample editor

~/$CONFIGPATH/scripts.sample.txt

sox chorus;sox %s -D %s chorus 0.7 0.9 55 0.4 0.25 2 -t
sox contrast;sox %s -D %s contrast 0.2
AI generate trumpet;apicall_to_LLM %s

see example: https://gitlab.com/coderofsalvation/milkytracker-scripts/-/blob/master/scripts.txt?ref_type=heads

rightclick > Script > sox chorus         
                      sox contrast
                      AI generate trumpet
                      ------------
                      scripts config                       # calls linux: $EDITOR ~/$CONFIGPATH/scripts.sample.txt
                                                                          mac:  open  ~/$CONFIGPATH/scripts.sample.txt
                                                                          win: start ~/$CONFIGPATH/scripts.sample.txt        

Any feedback appreciated

@coderofsalvation

Copy link
Copy Markdown
Contributor Author

There have been ideas in the milkytracker chat about a controlling the cursor with a script:

<raina> this sounds like a thing for some external accessibility automator, it would just need the cursor position and editstep from milky. like when you hit a special key combo, IF you're on the note column, insert note 1, tab, insert note 2, tab, insert note 3 and shift-tab back to the original column. it would need to know how many rows to step back too between each note

Idea: instead of pattern editor script (shell/py/lua/bat/ps1) just exiting with code 0.
When it returns a string starting with MTKB: then all ascii/controlcharacters can be parsed by milkytracker as keyboard input.
SInce the first argument of a pattern script (%s) is the pattern (.xp file), any script can optionally analyze the current pattern-state as well.
Perhaps 3 extra arguments should be passed: cursor-row, cursor-channel, cursor-column

$ ./mypatternscript.py currentpattern.xp 23 1 7
MTKB: ^[[tab..... 

this hypothetical script would receive (and optionally mutate) currentpattern.xp, receive cursor on row 23, channel 1, last effect column (7) and return keystrokes as a response.

@coderofsalvation

coderofsalvation commented Feb 19, 2025 •

Copy link
Copy Markdown
Contributor Author

@Claytone @minidcon7 good news! I'm approaching the end of the refactor. Could you maybe help testing it?

this is the branch: https://github.com/milkytracker/MilkyTracker/tree/feat/polyscript

the idea is that you put ffmpeg / ffmpeg.exe / sox / sox.exe into the milkytracker config directory (~/.config/milkytracker on mac/linux) or in your PATH and then the addons get detected/shown. You can run ADDON_DEBUG=1 ./milkytracker for more output.

Refactor wins:

  • syntax is simpler now
  • 'edit scripts'-button to livecode addons
  • 'import from addon' to (re)import the output of a background process (DAW e.g.) later on
  • commands are now parametric via slider formatstrings:

%p(foo:1:5:2) in a command, gets substituted by the value of slider 'foo'.
For example the chorus addon (from sox) in the video below looks like this:

sox chorus                 ; sox %s -D %s chorus 0.%p(gain_in:0:9:7) ......
simplescreenrecorder-2025-02-19_17.08.12.mp4

I'm going to postpone all the other wild ideas (as I would personally not really use them).
But there's the groundworks to go in to these direction for those interested.

@coderofsalvation

Copy link
Copy Markdown
Contributor Author

this is merged to master and works on linux/mac: see https://github.com/milkytracker/milkyTracker-addons

for windows-users more testing is needed (I don't have the resources to test windows fully, so feel free to jump in)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants