[EOS/DEMO] SimpleBeats (Simplified Dynamic Metronome)

All about the past, current and future webteases and the art of webteasing in general.
---
fapnip
Explorer At Heart
Explorer At Heart
Posts: 431
Joined: Mon Apr 06, 2020 1:54 pm

[EOS/DEMO] SimpleBeats (Simplified Dynamic Metronome)

Post by fapnip »

Here's a demonstration of SimpleBeats, a simplified version of my other dynamic metronome, without any visualization stuff and the bloat that it brings:

Demo/Example tease:
https://milovana.com/webteases/showteas ... 80f6304c34

JSON (right-click, save-as):
https://milovana.com/webteases/geteossc ... 80f6304c34

It's "simplified" in respect to how you interface with it and not having the overhead of visualization stuff. (The core code is still a bit of an anti-pattern mess, but you don't need to look at that.)

To INSTALL or UPDATE the core SimpleBeats functions/actions/files into an existing tease:

1. Open The Simple Beats demo as the source in Eos Magpie:
https://codepen.io/fapnip/full/GRjwPXP?id=51698&key=80f6304c34

2. Paste your tease's private share link as the target in Eos Magpie.

3. If installing for the first time, check the box for the "simpleBeatsExample" Magpie module. ("SimpleBeats" and "setTimeout" modules should automatically select.) If updating, flip the switch for "Apply Auto Updates from Source".

4. Click the download button that will appear.

5. In the Eos Editor for your tease, download a back-up copy of your existing tease, just in case. (Seriously. Do it. Things can go wrong.)

6. Restore the downloaded merged magpie JSON from step 4 over your existing tease.

7. Ask for help here.


After you've added the base code to your start page (first two IF actions (!window.setTimeout and !window.SimpleBeats) in the demo's start page), and created your SimpleBeats instance and loaded your beat samples (third IF (!window.beats) action), you can interface with your new instance (called "beats" in the example) via:

Code: Select all

beats.bpm(120) // Start a metronome of 120 bpm (default pattern is '+AF')
beats.bpm(300) // change to 300 bpm (any sane number should work)
beats.bpm(36) // change to 36 bpm
beats.bpm(beats.getBpm() + 10) // increase bpm a touch
beats.bpm(36, '+AH+AH+AF') // change to 36 bpm, but with a triple tap pattern at twice the bpm
beats.bpm(120, '+AF+AF+AF+AF+AF+_F+_F+_F') // change to 120 bpm, with a pattern of 5 beats followed by 3 rests.
beats.setVolume(beats.getVolume() - 0.1) // Decrease metronome volume a touch.
beats.stop() // stop the metronome
beats.bpm(100, '+AF', 30, function(){pages.goto('my-next-page')}) // Since v0.9.0, play +A @ 100BPM, 30 times, then run a function.
beats.bpm(100) // Re-start it (Will run last pattern used if a new pattern is not provided.)
if (beats.isPlaying()) {
  // Do something different if the metronome is running
}
// Or do something crazy, like:

// Cycle between 80 and 200 in 5 bpm steps, stepping on every beat.
beats.bpm(80, '+AF<eval>var startBpm = 80; var endBpm = 280; this.$bpmStep = this.$bpmStep || 5; var newBpm = this.getBpm() + this.$bpmStep; if(newBpm > endBpm || newBpm < startBpm){this.$bpmStep = 0 - this.$bpmStep; newBpm = Math.max(Math.min(this.getBpm() + this.$bpmStep, endBpm), startBpm);} this.setBpm(newBpm)</eval>')

// Or goto the start page after every 6 iterations of the beat pattern:
beats.bpm(80, '+AF<eval>if(this.getLoopCount() % 6 === 0) { pages.goto('start') }</eval>')

// ('this' in beat a eval is available as of v0.8.2, and is equal to the SimpleBeats instance running the pattern.)

// Or, as of v0.8.1, you can add an event listener for each loop, and do what you will in it
// Define your listener function (your listener function should be defined only once, like in your init script)
// If you do it in an eval, you'll need to wrap it in something like: if (!window.myLoopListener) { ... }
function myLoopListener(e) {
  // 'this' === the beats instance that dispatched the event
  // 'e' === Event payload (timestamp, type, etc.)
  console.log('Last beat in loop', this, e)
  if(this.getLoopCount() >= 20) {
    // We did 20 or more beats.  That's enough
    this.stop()
  }
}
// Add the listener to your SimpleBeats instance
beats.addEventListener('loop', myLoopListener)
// and when you no longer want to listen
beats.removeEventListener('loop', myLoopListener)
More Advanced Things:
(ignore everything below until you've got your head mostly wrapped around the above, and you already have some simple beats playing.)

You can create multiple SimpleBeats instances, and each instance can contain multiple beat sounds.

The example "beats" instance is created by:

1. Creating two Audio.play actions, both pointing to the exact same mp3 sample, with Volume = 0, Loops = 1, "Continue across pages" enabled, then with the first Audio.play action having an Identifier of "beatA-1" and the second of "beatA-2".

If you had more sample sounds you wanted to use, you could add two more Audio.play actions for each sample, with the identifiers "beatB-1" and "beatB-2", then "beatC-1" and "beatC-2", etc., all the way to to "Z". (If you're insane, you could move on to lower case a-z to load a total of 52 samples.) These can then be used in your beat patterns like beats.bpm(120, '+AF+BF+CF');, with the "A", "B" and "C" relating to the letter in your sample Identifier.

To get a little ahead, you can also add a prefix to the sample Identifiers. For example, "alt1-beatA-1", "alt1-beatA-2", etc., with "alt1-" being the prefix. (More on this later. The "beats" instance example does not use a prefix.)

2. In an Eval action immediately following the audio actions, you create your SimpleBeats instance:

Code: Select all

// Create new global "beats" instance of SimpleBeats
window.beats = new SimpleBeats()
// Now load all "beat[A-Za-z]-[1-2]" samples into that instance.
beats.loadSamples()
Note that it's important that this only be done once, so it's best to wrap all your Audio.play actions and evals for this in an IF action with a condition of "!window.myInstanceName", so "!window.beats" in this example.

Now, if you created some Audio play actions having a prefix in the Identifier name, like "alt1-beatA-1", "alt1-beatA-2", etc., using beats.loadSamples() isn't going to load them, since it'll be looking for samples without a prefix.

To load samples with a prefix, you'd do something like:

Code: Select all

// Create new global "beats" instance of SimpleBeats
window.beats = new SimpleBeats()
// Now load all "alt1-beat[A-Za-z]-[1-2]" samples into that instance.
beats.loadSamples('alt1-')
Or, if you already loaded an instance named "beats" with un-prefixed samples, you could create another instance like:

Code: Select all

// Create new global "otherBeats" instance of SimpleBeats
window.otherBeats = new SimpleBeats()
// Now load all "alt1-beat[A-Za-z]-[1-2]" samples into that instance.
otherBeats.loadSamples('alt1-')
Last edited by fapnip on Mon Sep 27, 2021 1:06 pm, edited 40 times in total.
Carnal1
Explorer At Heart
Explorer At Heart
Posts: 206
Joined: Wed Jan 30, 2019 4:56 am
Gender: Male
Sexual Orientation: Open to new ideas!

Re: [EOS/DEMO] SimpleBeats (Simplified Dynamic Metronome)

Post by Carnal1 »

Tested all the options up to 300bpm and surprisingly (to me anyway) all seem to work ok on old android 4.4 tablet. :-)
fapnip
Explorer At Heart
Explorer At Heart
Posts: 431
Joined: Mon Apr 06, 2020 1:54 pm

Re: [EOS/DEMO] SimpleBeats (Simplified Dynamic Metronome)

Post by fapnip »

Carnal1 wrote: Sun Jul 25, 2021 10:23 pm all seem to work ok on old android 4.4 tablet. :-)
Really??

I wonder if it's a memory issue. Could you try this FapJack and let me know if it works any better? It has "moans" audio files disabled. They're kinda big.
https://milovana.com/webteases/showteas ... 3fee901ee2
Carnal1
Explorer At Heart
Explorer At Heart
Posts: 206
Joined: Wed Jan 30, 2019 4:56 am
Gender: Male
Sexual Orientation: Open to new ideas!

Re: [EOS/DEMO] SimpleBeats (Simplified Dynamic Metronome)

Post by Carnal1 »

I tried and it doesn't work. It's like FapJack - Example/Base - v1.15.2 and FapJack - Dev2 from the other day: with the default audio profile, it erratically & unrhythmically gives maybe 10-30% of expected beats. Changing to the alternate audio profile seems to work better and seems to get the number of beats but in a very unrhythmical manner.

I immediately reopened Simplified Dynamic Metronome - v0.6.1 from above and it still seems to work ok. The beats are not perfectly regular, but more come in like groups with a very hardly discernable difference in timing between them. Without studying your code, I assume an artifact of how they're generated. Certainly playable up to 300bpm which is the fastest I tested.

One thing I've noted and I can't imagine why it'd matter, but this one uses the more drum-like sound which in the other teases comes closer to working. In the unplayable teases this sound usually at least seems to produce the required number of beats, but so unrythmicaly as to be unplayable.
fapnip
Explorer At Heart
Explorer At Heart
Posts: 431
Joined: Mon Apr 06, 2020 1:54 pm

Re: [EOS/DEMO] SimpleBeats (Simplified Dynamic Metronome)

Post by fapnip »

Carnal1 wrote: Mon Jul 26, 2021 7:15 am I tried and it doesn't work. It's like FapJack - Example/Base - v1.15.2 and FapJack - Dev2
Shoot. But thanks for trying!
Carnal1 wrote: Mon Jul 26, 2021 7:15 amWithout studying your code, I assume an artifact of how they're generated.
We're at the mercy of a very slow JavaScript interpreter (all JS in an Eos tease is run in a sandboxed interpreter, effectively emulating JavaScript, in JavaScript.) If the host Eos player gets busy doing something else, like calculating the background color to display behind an image it just loaded, it could delay when and how often it's able to step the interpreter, and as a result will delay how quickly my interpreted "timer" event handlers get executed. If a timer interval gets delayed, future interval events will be executed earlier, until we're caught up executing intervals at the correct interval.

Complicating matters, Eos's JS interpreter doesn't have native setTimeout/setInteval functions, so I need to emulate them by starting silent audio files back from their end a given number of ms so I can then capture the "end" event they will emit.

All these extra steps, audio objects, etc., all add up to more ram/cpu resource being consumed -- so if the host device isn't up to the task, there'll be issues. Fortunately, most devices today are plenty fast enough for this.
Carnal1 wrote: Mon Jul 26, 2021 7:15 am One thing I've noted and I can't imagine why it'd matter, but this one uses the more drum-like sound which in the other teases comes closer to working. In the unplayable teases this sound usually at least seems to produce the required number of beats, but so unrythmicaly as to be unplayable.
Without a comparable Android device to replicate the issue on, I'm not sure I'll ever figure this one out. Could be the size of the audio file? Could slight variations in their encodings, with some consuming more resource than others? Could be... ???
Last edited by fapnip on Tue Jul 27, 2021 7:46 pm, edited 1 time in total.
Carnal1
Explorer At Heart
Explorer At Heart
Posts: 206
Joined: Wed Jan 30, 2019 4:56 am
Gender: Male
Sexual Orientation: Open to new ideas!

Re: [EOS/DEMO] SimpleBeats (Simplified Dynamic Metronome)

Post by Carnal1 »

Thanks for trying. And for your explanation of what's likely going on.

Just as an added bit, I got eos teases working on chrome on my phone (G7 android 10). (I think an ad blocker was interfering) and tested all teases/demos/examples I'd been trying with my tablet. All worked ok as long as I was able to select "alternate" audio profile (even the original problem tease, FapJack with Mia) that sounded more drumbeat, but with the default clicky sound, the same ones that didn't work on tablet, didn't work on phone.
fapnip
Explorer At Heart
Explorer At Heart
Posts: 431
Joined: Mon Apr 06, 2020 1:54 pm

Re: [EOS/DEMO] SimpleBeats (Simplified Dynamic Metronome)

Post by fapnip »

Carnal1 wrote: Tue Jul 27, 2021 12:28 am the default clicky sound, the same ones that didn't work on tablet, didn't work on phone.
It's not the best sound -- I probably shouldn't have it set as the default, but it should work.

What exactly doesn't work? No sound at all? Missing every nth/random beat? etc.
Carnal1
Explorer At Heart
Explorer At Heart
Posts: 206
Joined: Wed Jan 30, 2019 4:56 am
Gender: Male
Sexual Orientation: Open to new ideas!

Re: [EOS/DEMO] SimpleBeats (Simplified Dynamic Metronome)

Post by Carnal1 »

The sound itself is fine, it sounds like the beat sound on many teases. But it misses playing the majority of the beats. It's especially noticeable during a penalty. For instance if supposed to beat 30 times I'll only hear 5-10 beats very irregularly spaced. I think it's doing the same during the dealing, but it's not as obvious. It seems very peculiar that changing to the alternate sound works fine tho.
fapnip
Explorer At Heart
Explorer At Heart
Posts: 431
Joined: Mon Apr 06, 2020 1:54 pm

Re: [EOS/DEMO] SimpleBeats (Simplified Dynamic Metronome)

Post by fapnip »

Carnal1 wrote: Tue Jul 27, 2021 6:33 am It seems very peculiar that changing to the alternate sound works fine tho.
Please try this tease:
https://milovana.com/webteases/showteas ... 1e2b73ed36

I've tweaked and re-encoded the sample for the default beat.

I wonder if it has something to do with length of the sample, with some devices/audio stacks not getting warmed up enough to be able to play such a short sample on every iteration?

The drum beat sample is around 400ms. The original "default" is only 52ms. The updated default is still only 78ms. If the updated one doesn't work, I wonder if adding a few more ms of silence to the beginning/end would fix it?

Also, does the "click" for the Fap Roulette work? (Does it click every time the random option changes?)
Carnal1
Explorer At Heart
Explorer At Heart
Posts: 206
Joined: Wed Jan 30, 2019 4:56 am
Gender: Male
Sexual Orientation: Open to new ideas!

Re: [EOS/DEMO] SimpleBeats (Simplified Dynamic Metronome)

Post by Carnal1 »

fapnip wrote: Tue Jul 27, 2021 2:34 pm Please try this tease:
https://milovana.com/webteases/showteas ... 1e2b73ed36
This one works well in both audio modes on my G7 Android 10 phone. And yes, the 'click' sounds as it should.
fapnip
Explorer At Heart
Explorer At Heart
Posts: 431
Joined: Mon Apr 06, 2020 1:54 pm

Re: [EOS/DEMO] SimpleBeats (Simplified Dynamic Metronome)

Post by fapnip »

Carnal1 wrote: Tue Jul 27, 2021 7:12 pm This one works well in both audio modes on my G7 Android 10 phone. And yes, the 'click' sounds as it should.
Thanks!
fapnip
Explorer At Heart
Explorer At Heart
Posts: 431
Joined: Mon Apr 06, 2020 1:54 pm

Re: [EOS/DEMO] SimpleBeats (Simplified Dynamic Metronome)

Post by fapnip »

Added instructions on how to import the core SimpleBeats functions/actions/files into an existing tease in the first post.
Darigaaz
Explorer
Explorer
Posts: 88
Joined: Wed Oct 07, 2020 11:12 pm
Gender: Male
Sexual Orientation: Straight

Re: [EOS/DEMO] SimpleBeats (Simplified Dynamic Metronome)

Post by Darigaaz »

I just tried a simple beat in my next next tease and it works perfectly. Thanks!
Darigaaz
Explorer
Explorer
Posts: 88
Joined: Wed Oct 07, 2020 11:12 pm
Gender: Male
Sexual Orientation: Straight

Re: [EOS/DEMO] SimpleBeats (Simplified Dynamic Metronome)

Post by Darigaaz »

beats.addEventListener is undefined for me. Where can I find the version 0.8.1 you are mentioning ?
fapnip
Explorer At Heart
Explorer At Heart
Posts: 431
Joined: Mon Apr 06, 2020 1:54 pm

Re: [EOS/DEMO] SimpleBeats (Simplified Dynamic Metronome)

Post by fapnip »

Darigaaz wrote: Mon Aug 23, 2021 5:32 pm beats.addEventListener is undefined for me. Where can I find the version 0.8.1 you are mentioning ?
The most recent version should always be in the tease linked in the first post. The Magpie instructions above should work the same for updating, but just replacing the first two IF actions in your start page with the first two from the imported "---example-dynamic-beats-import" page, if the version numbers in those IFs don't match. (Someday I may update Magpie to ease the process of installing and updating modules -- but until then...)
Post Reply