Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created a SoundIterator Object #112

Merged
merged 2 commits into from
Jul 20, 2019
Merged

Created a SoundIterator Object #112

merged 2 commits into from
Jul 20, 2019

Conversation

frastlin
Copy link
Contributor

@frastlin frastlin commented Jul 5, 2019

I added one file: src/sound_iterator.js

I also added the tests to the bottom of the html file. I updated webpack because it wouldn't run on my machine with the old version, but I'm not exactly sure how to remove that from the PR.

@frastlin frastlin mentioned this pull request Jul 5, 2019
@rserota
Copy link
Owner

rserota commented Jul 9, 2019

Hey, thanks for submitting this PR. I haven't had much time to test it yet, but it looks good so far. My only thought at the moment, is that it seems like another way to group multiple wads together, but polywads already sort of do that. Do you think it would be feasible to adapt the polywad interface to do what you need to do?
If the similarities between polywads and sound iterators are only superficial, then it might just make things more complicated to combine them, but in general I like Wad to have few, flexible functions, rather than a tool for every occasion.

@frastlin
Copy link
Contributor Author

frastlin commented Jul 9, 2019

PolyWads are meant to have wads playing together. This is meant to have wads playing one after another. This could be used if you wanted to group polywads together in an arpeggio that was either random or always in the same order.
The tests demonstrate the full functionality pretty well:

var iterator = new Wad.SoundIterator({files: [
    new Wad({source: 'sawtooth', volume: 0.5, env:{hold:1}}),
    new Wad({source: 'square', volume: 0.5, env:{hold:1}}),
    new Wad({source: 'sine', volume: 0.5, env:{hold:1}}),
]})

// repeated calls to play will repeat the sounds over and over again in the same order they were added
document.getElementById('play-next-nonrandom-sound').addEventListener('click', function(){
    iterator.random = false
    iterator.play()
})

document.getElementById('play-next-random-sound').addEventListener('click', function(){
    iterator.random = true
    iterator.randomPlaysBeforeRepeat = 0
    iterator.play()
})

document.getElementById('play-next-sound-with-1-randomPlaysBeforeRepeat').addEventListener('click', function(){
    iterator.random = true
    iterator.randomPlaysBeforeRepeat = 1
    iterator.play()
})

var newSound = new Wad({source:'triangle', volume: 0.5, env:{hold:1}})

document.getElementById('add-sound').addEventListener('click', function(){
    iterator.add(newSound)
})

document.getElementById('remove-sound').addEventListener('click', function(){
    iterator.remove(newSound)
})

@frastlin
Copy link
Contributor Author

frastlin commented Jul 9, 2019

This is very much a utility class, and the times I've thought when it would be useful are:

  • Footsteps for games
  • Arpeggios
  • Generic responses in games for stuff like: "I don't think so", "It doesn't look like it will work", "I'm not sure about that"...
  • Grunts or hits during a fight

With a little more code, it could run a song comprised of Wad objects, but currently the timing functionality is not there, just the ordering.

It's really just an iterator that removes the boilerplate from the above functions. I use it in most of my projects.

@rserota rserota merged commit c652b72 into rserota:master Jul 20, 2019
@rserota
Copy link
Owner

rserota commented Jul 20, 2019

This looks great, thanks for contributing!

You briefly mentioned some timing functionality that could be useful? How are you imagining that would work? I've actually been thinking about adding timing features to Wad.

@frastlin
Copy link
Contributor Author

frastlin commented Jul 20, 2019

How I would do it is:
Create a set of notes using an oscillator with an env:hold duration for the duration of the notes.
Then create a silence oscillator with an env: hold duration for rests. Then you can just attach sounds and silent oscillators to make a set of notes, then there could be a function to play the sounds in order until they are done.

This would require:

  • A silence oscillator
  • Add an on end event for the SoundIterator
  • Add a playIteratorInOrder method on the SoundIterator object.

Then there could be syntactic sugar for adding notes, like having an oscillator Wad object, and pass it into a createSequence method on the SoundIterator object that has the arguments: oscillator, text music notation. The text music notation could be a string of either ABC notation, LilyPond notation, or a custom notation system, or all of the above. The parser will just add notes and rests to the SoundIterator that are based off the passed oscillator or polyWad.

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.

2 participants