You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, this is probably inappropriate to ask here, but can anyone help me use the "seedrandom" package with scribbletune's progression method?
If I understand correctly, and based on my experience with the method so far, scribbletune.progression() returns a random chord progression that follows the rules of music theory.
I want to return a random chord progression that follows the rules of music theory, but I also want to seed it, so I can return the same progression again later.
I tried finding where the Math.random() function is in the index.js of the scribbletune package so I can maybe pass the seeded random function in as a third parameter to replace the Math.random() function within the progression() method, but I wasn't skilled enough to find it xp.
const mySeededChord = progression('M', 23424); // e.g. 'I V vi V'
and then later,
const myChordFromSeed = progression('M', 23424); // continues to return 'I V vi V'
If this is indeed the case, then one possible scenario is to create a map object inside the progression method's closure and if a seed was passed, store the generated chord internally in the map against the provided seed. The next time the request comes for this method with that same seed, then first look up the map and see if that seed exists, if it does, then just return as is without any computing.
const getProgFactory = ({ T, P, D }: TPD) => {
const seeds = {};
return(count: number = 4, seed: number) => {
if (seeds[seed]) {
// return early
return seeds[seed];
}
// If seed was not passed, continue executing this method
// which generates chords in a variable called `chords`
if (seed) {
seeds[seed] = chords;
}
return chords;
};
}
This will obviously not be persistent and will only last during each session of using Scribbletune (within the terminal or the browser). To make it persistent we may have to give some more thought and even implement a provision for cleaning up the persisted seeds. For the browser we could use local storage and for the terminal we could use a simple file based persistence.
Lemme know if you re interested in implementing any of this, I can help you get in any or all of these changes as a new feature in Scribbletune!
@walmik
Sorry I took so long to respond. Shortly after I made this issue I got frustrated because I was editing progression.ts, utils.ts, etc then trying to run my app immediately after each edit and getting no new results no matter what I changed, so I gave up until just a few hours ago when I decided to give it another go. I realize now I was just being dumb and not realizing that the .ts files are probably just used for compiling the module, but I have no experience compiling node modules, so I decided to just edit scribbletune's index.js file directly. This is the solution I came up with that works perfectly for my use case:
I hope you don't mind that the solution I came up with is very specific to my use case and probably won't fit into the main scribbletune module. You wouldn't want me writing code for scribbletune anyway as my code is usually a total mess XD.
Activity
walmik commentedon May 24, 2020
Hello @vinceTheProgrammer
Does your usecase need something like this:
and then later,
If this is indeed the case, then one possible scenario is to create a map object inside the
progressionmethod's closure and if a seed was passed, store the generated chord internally in the map against the provided seed. The next time the request comes for this method with that same seed, then first look up the map and see if that seed exists, if it does, then just return as is without any computing.A good place to start would be to affect this method https://github.com/scribbletune/scribbletune/blob/master/src/progression.ts#L105-L160
This will obviously not be persistent and will only last during each session of using Scribbletune (within the terminal or the browser). To make it persistent we may have to give some more thought and even implement a provision for cleaning up the persisted seeds. For the browser we could use local storage and for the terminal we could use a simple file based persistence.
Lemme know if you re interested in implementing any of this, I can help you get in any or all of these changes as a new feature in Scribbletune!
vinceTheProgrammer commentedon Jul 7, 2020
@walmik
Sorry I took so long to respond. Shortly after I made this issue I got frustrated because I was editing
progression.ts,utils.ts, etc then trying to run my app immediately after each edit and getting no new results no matter what I changed, so I gave up until just a few hours ago when I decided to give it another go. I realize now I was just being dumb and not realizing that the.tsfiles are probably just used for compiling the module, but I have no experience compiling node modules, so I decided to just edit scribbletune'sindex.jsfile directly. This is the solution I came up with that works perfectly for my use case:In my app's index file:
At the top of scribbletune's index file:
At pickOne() and dice():
I hope you don't mind that the solution I came up with is very specific to my use case and probably won't fit into the main scribbletune module. You wouldn't want me writing code for scribbletune anyway as my code is usually a total mess XD.