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
[WIP] [Peripheral] Speaker #201
Conversation
…rc/main/java/dan200/computercraft/core/apis/TimeAPI.java
getSelectedBoundingBox expects a bounding box relative to (0, 0, 0) but we were returning one relative to the current block. Instead we allow the default behaviour to continue, which will call getBoundingBox and offset it.
# Conflicts: # src/main/java/dan200/computercraft/core/apis/SoundAPI.java
| @@ -277,6 +281,9 @@ public void preInit( FMLPreInitializationEvent event ) | |||
| Config.turtlesCanPush = Config.config.get( Configuration.CATEGORY_GENERAL, "turtlesCanPush", turtlesCanPush ); | |||
| Config.turtlesCanPush.setComment( "If set to true, Turtles will push entities out of the way instead of stopping if there is space to do so" ); | |||
|
|
|||
| Config.minTimeBetweenSounds = Config.config.get( Configuration.CATEGORY_GENERAL, "minTimeBetweenSounds", minTimeBetweenSounds); | |||
| Config.minTimeBetweenSounds.setComment("The minimum time in between calls to sound.play on one computer in milliseconds" ); | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll need to add a language key to en_US.lang. Something like gui.computercraft:config.min_time_between_sounds=Minimum time between sounds. Make sure it fits on the screen though. It might also be a good idea to add a .setMinValue(0) so people cannot use negatives.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had added the setMinValue. I don't understand the language key: won't this snippet do it -
for (Property property : Config.config.getCategory( Configuration.CATEGORY_GENERAL ).getOrderedValues())
{
property.setLanguageKey( "gui.computercraft:config." + CaseFormat.LOWER_CAMEL.to( CaseFormat.LOWER_UNDERSCORE, property.getName() ) );
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That will register the language key, but you haven't actually provided a translation - if you open the GUI, you'll just see minTimeBetweenSounds. If you add the appropriate string to en_US.lang, then it should be translated correctly.
|
|
||
| ResourceLocation resourceName = new ResourceLocation((String) arguments[0]); | ||
|
|
||
| if (System.currentTimeMillis() - this.lastPlayTime > ComputerCraft.Config.minTimeBetweenSounds.getDouble()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to keep an instance clock variable, incrementing it each time advance is called. This way it'll keep in sync with os.clock() and won't cause issues in the event of server lag. See OSAPI for how it's done there.
Also, store the config value on a field in ComputerCraft when loading the config options - it should be pretty obvious how other config options handle it.
|
|
||
| // play | ||
| case 0: | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrap each case statement in braces, so variables are not shared between them. It isn't strictly needed now, but if additional methods are added you'll want them.
| /** | ||
| * Sound API for ComputerCraft. Provides an interface to Forge's API. | ||
| * Possible use cases are notification apis, alert sounds, or playing music | ||
| */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Javadoc should go at the beginning of the class definition, not inside it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, haha! In Python it is the opposite.
|
|
||
| private String[] methods; | ||
| private ServerComputer computer; | ||
| private long lastPlayTime; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dan generally prefixes fields with m_. I don't know how strict he is on this convention, but it might be consistent with the rest of the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy to stop using this.member in favour of m_member.
| float pitch = 1f; | ||
|
|
||
| // Check if arguments are correct | ||
| if (arguments.length == 0) // Too few args |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just me being petty now, but braces on all the if statements! Unless the condition and body are all on the same line it is, IMO, better to have explicit braces.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, ok. To me it just looked cleaner, but it's just peanuts to me
|
I've added your suggestions @SquidDev and I fixed the pitch issue. Do you have any other suggestions or shall I remove the WIP tag? |
|
Hmm, I don't think this should be a default API, but a peripheral instead. This way server admins can control specifically who can play sound and who can't, because sounds can be incredibly useful, but also incredibly annoying, even when there's a timeout. |
Thanks, @gegy1000 !
|
I don't think this belongs into CC itself; looks like something a peripheral in an addon should do. |
Well #172 adds pocket computer peripheral support, so that is less of an issue. If we expand that to allow multiple upgrades, then you will be able to have a noteblock and modem on the same pocket computer. |
|
@SquidDev would it be called a noteblock? It could be a speaker, perhaps. |
|
@Lignum do you mean a physical peripheral? Also, your comment about it being annoying - the sound volumedoes drop off over range, very quickly (20~ blocks), limiting the amount that it can be used to grief. How would making it a peripheral make it controllable? Through blacklisting? |
|
I wonder if I could do a permission for sound. |
It doesn't really matter, that was an example. I think I've generally seen this method provided via iron noteblocks (such as Peripherals++ or Plethora). Though let's be honest Comptronics's tape drives are way cooler |
|
Woah, cool! This I feel encourages even more innovation, as you need to invent your own format. Theirs are still cooler though |
|
@apemanzilla yeah, it was just a thought. I guess it would be too easy |
Thanks, @gegy1000 !
|
Hmm, if anyone is good at texturing and wants to try their hand at a speaker peripheral, feel free. I might otherwise just try a retexture of the Wireless Modem with a retextured front. |
|
I think it should be a full block, with common side textures and a distinct
front like the disk drive/printer/etc. If you commit placeholders I'm sure
someone can spruce them up
…On 7 May 2017 7:18 a.m., "Restioson" ***@***.***> wrote:
Hmm, if anyone is good at texturing and wants to try their hand at a
speaker peripheral, feel free. I might otherwise just try a retexture of
the Wireless Modem with a retextured front.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#201 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AB3bbLVJcfDm86USvI3GBiRGfdVA2ektks5r3WI5gaJpZM4NSr6S>
.
|
|
The turtle version would still necessarily look like a flat panel
…On 7 May 2017 7:28 a.m., "Restioson" ***@***.***> wrote:
@dan200 <https://github.com/dan200> ah, ok. If it were a full block,
would turtles not be able to have them? Visually it would look odd. Will
pocket computers be able to have them as per #172
<#172> ?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#201 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AB3bbNCSvtWSAUIdm-oJ1uVmS34deawAks5r3WR0gaJpZM4NSr6S>
.
|
|
Could that be a retextured modem as I described earlier? It could look like a cut down version of the full block. It'd just use the modem's model. |
|
Sure, look at how the crafty upgrade works
…On 7 May 2017 7:29 a.m., "Restioson" ***@***.***> wrote:
Could that be a retextured modem as I described earlier?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#201 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AB3bbDFzlTwC8p7uzhZ9CLmnYiZgFBbZks5r3WTjgaJpZM4NSr6S>
.
|
|
It might be neater to close this PR and re-open a new one with the relevant files copied across - a lot has changed since the original commit and it'll remove the number of merge commits. I'm going to describe the process I've gone to get my repo set up, just so I can explain the rebasing process. There are probably nicer ways, but this works for me. You've probably done several of these steps already, so skip the ones you've already got:
Then assume you create a new branch
Note that your |
|
@Vexatos yeah, that was unintentional. |
|
Yeah.. this PR is messy now. A peripheral seems a distinct enough thing from an API to warrant a new one anyway. |
|
I'm closing this PR |
Ok just throwing a suggestion here but How about splitting the features. Then if someone needs better or more sounds they plug in peripheral Speaker that allows them to What you thing about this idea @Restioson. That way we get to have a bird (basic sounds in computers and pockets) and eat a bird (All the sounds in speaker). |
|
OpenComputers uses a separate class for synthesizing square waves of a specific frequency manually for its beeps. Should the "motherboard beeps" in CC be square too? Also, wasn't there something about CC (by default) not exposing anything from "outside the game"? Wouldn't Minecraft sounds count as that? |
|
They are in the game, just not by name. |
|
I don't really follow? Do you mean that as a player you cannot play them? |
|
I mean that the names do not appear in-game. |
|
@Vexatos i see what you mean. |
This changes the previous behaviour a little, but hopefully is more sane: - Only require the socket to be open when first calling receive. This means if it closes while receving, you won't get an error. This behaviour is still not perfect - the socket could have closed, but the event not reached the user yet, but it's better. - Listen to websocket_close events while receiving, and return null should it match ours. See dan200#201

Closed
PR has been closed due to a number of factors. Below is the original PR.
Speaker API
This PR adds a new peripheral: the speaker peripheral. This allows computers to play any sound! Theoretically, you can even play sounds from other mods, provided that you use the correct domain. However, as of writing,
speaker.playthrows a NPE due toItemPocketComputer'sServerComputer.getPos()returningnull. This is fixed in #172 .Possible Use Cases
Example
Functions
speaker.playsound- Takes 1 positional arguments (stringresource name) and 2 optional positional arguments (doublevolume anddoublepitch). Returnstrueorfalsebased on whether theresourcenameexists and is a sound. Plays the sound atresourcenamewithvolumeandpitch, under categoryRECORDS.Summation of changes
speaker_enableconfig optionspeakerperipheral & providerspeaker.playsound(resourceLocator, volume, pitch)function in javaspeaker.playnote(noteblockInstrument, volume, pitch)function in javaWIP
Rewrite as peripheral.
Thanks
Special thanks to @SquidDev for helping me understand and navigate the codebase, and @gegy1000 for helping me out with Forge.