Kevin Simonson

Ranch Hand
+ Follow
since Oct 22, 2011
Cows and Likes
Cows
Total received
2
In last 30 days
0
Total given
0
Likes
Total received
4
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Kevin Simonson

Paul Clapham wrote:You could try Java | MIDI Introduction or MIDI basics and a lot of people liked About Java's Sound Stuff.


I took a look at the section titled "MIDI basics" at "http://rememberjava.com/midi/2017/01/13/midi_basics.html", and tried incorporating the method {testPlayNote()} it lists like so:

but when I try to compile it the compiler very understandably complains:

Before this snippet of code the website says, "To play a single C note through the default included 'Gervill' soft synthezier, the following snippet will do." Clearly that's not true. What's the object {getSynthesizer()} needs to be called on?
2 months ago

Paul Clapham wrote:You could try Java | MIDI Introduction or MIDI basics and a lot of people liked About Java's Sound Stuff.

I didn't look at any Youtube tutorials because I'm a text-oriented person and I'm not good at understanding video explanations of text.


I went to that website you pointed me to, the MIDI Introduction, and tried to copy the program {MyMidiPlayer} it had there, with a few modifications. (I like to have my {main} method at the end of the code, for one thing.) My code follows.
<br /> When I tried to run it I got: <br /> <br /> D:\Ct>j8 MyMidiPlayer
Enter the number of notes to be played:
3
Jul 29, 2021 9:08:48 PM java.util.prefs.WindowsPreferences <init>
WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002. Windows RegCreateKeyEx(...) returned error code 5.
/Undefined external error./
javax.sound.midi.MidiUnavailableException: Undefined external error.
       at com.sun.media.sound.MidiOutDevice.nOpen(Native Method)
       at com.sun.media.sound.MidiOutDevice.implOpen(MidiOutDevice.java:54)
       at com.sun.media.sound.AbstractMidiDevice.doOpen(AbstractMidiDevice.java:154)
       at com.sun.media.sound.AbstractMidiDevice.openInternal(AbstractMidiDevice.java:144)
       at com.sun.media.sound.AbstractMidiDevice.getReceiverReferenceCounting(AbstractMidiDevice.java:350)
       at javax.sound.midi.MidiSystem.getReceiver(MidiSystem.java:273)
       at javax.sound.midi.MidiSystem.getSequencer(MidiSystem.java:481)
       at javax.sound.midi.MidiSystem.getSequencer(MidiSystem.java:392)
       at MyMidiPlayer.setUpPlayer(MyMidiPlayer.java:35)
       at MyMidiPlayer.main(MyMidiPlayer.java:63)

D:\Ct>

Any idea what this is trying to tell me, or what I'm doing wrong?
2 months ago

Norm Radder wrote:Have you done a search on that topic?  I see several java programs on stackexchange that do that.


I did a search on "java music sounds" and it came up with two results that looked like they were worth exploring, "https://www.youtube.com/watch?v=VMSTTg5EEnY" and "https://www.youtube.com/watch?v=3q4f6I5zi2w". But both of those involved reading external audio files. All I want to do is have my Java program produce a simple melody consisting of D-C-C#-D at certain times in my program, and F#-E-F-F# at other times, and A#-G#-A-A# at other times. (This isn't what I asked in my first post; I had it backwards then.) So I don't have an audio file. How can I generate these three melodies and have the Java program play them? Is there some other string I should do a Google search on to find web pages that will help me with that?

Now I did find an article at "https://docs.oracle.com/javase/tutorial/sound/index.html". Is this a good website to figure out how to generate my short melodies?
2 months ago
How can I write a Java program that makes musical sounds? In particular, I'd like to write code that would take one second to play C, then D, then C#, and then C again, taking exactly one quarter second for each note. I'd also like to write code that does the same thing for E-F#-F-E, and that does the same thing for G#-A#-A-G#. Can anyone tell me how I can do this?
3 months ago
What is the granularity of (Math.random())? If I had the following code:

then I'm reasonably sure (iNumber) can have any value between zero inclusive and (intLimit) exclusive completely at random, without any of those numbers being more likely than any other number. But what about:

Is (lNumber) just as likely to be any integer between zero and (longLimit) as another, or are there some (long) values in that range that (lNumber) will never be? And if the latter, what is the highest value (longLimit) can have such that (lNumber) is as likely to be any number in the range from zero to (longLimit) as any other number in that range?
1 year ago
I just wrote a little program to see what happens when I enter keys using class {KeyListener}. The program is:

This works just fine for every key I enter except the tab key. Nothing happens when I press the tab key. Does anyone know what I have to do to get my code to process the tab key?
3 years ago
I implemented a Red Black Tree for a program I'm writing like so:

and then I wrote a driver to test it:

which works just fine. But I had to cast the result of method {insert()} to get an object of type
{Frwrd}, so I thought I'd use Java generics, and pass {Frwrd} in as a parameterized type. So
rewritten versions of the same two files are:

and driver:

When I compile this I get:

D:\Langs\Java\Src\Alan\Alt>\Langs\Java\8u40-windows-x64\bin\javac -Xlint:unchecked RedBlack.java
RedBlack.java:47: warning: [unchecked] unchecked cast
   newRoot.high.set( inq, (TR) this);
                               ^
 required: TR
 found:    RedBlack<TR>
 where TR is a type-variable:
   TR extends RedBlack<TR> declared in class RedBlack
RedBlack.java:59: warning: [unchecked] unchecked cast
     return (TR) this;
                 ^
 required: TR
 found:    RedBlack<TR>
 where TR is a type-variable:
   TR extends RedBlack<TR> declared in class RedBlack
RedBlack.java:63: warning: [unchecked] unchecked cast
   { stRoot.merge( (TR) this);
                        ^
 required: TR
 found:    RedBlack<TR>
 where TR is a type-variable:
   TR extends RedBlack<TR> declared in class RedBlack
RedBlack.java:72: error: rotate(int) has private access in RedBlack
       { stRoot = stRoot.rotate( 0);
                        ^
 where TR is a type-variable:
   TR extends RedBlack<TR> declared in class RedBlack
RedBlack.java:75: error: rotate(int) has private access in RedBlack
       { stRoot = stRoot.rotate( 1);
                        ^
 where TR is a type-variable:
   TR extends RedBlack<TR> declared in class RedBlack
2 errors
3 warnings

D:\Langs\Java\Src\Alan\Alt>

The announced errors on lines 72 and 79 can both be fixed by replacing the {private} qualifier for
method {rotate()} with {protected}, and then the new version of {Frwrd} works just fine. But why
does it need to be {protected}? Method {stInsert()} is declared to be {private}, and that works just
fine when called by method {insert()}; why can't method {insert()} be happy when it calls {private}
method {rotate()}?

The other things the compiler complains about don't keep the program from compiling, but they're
still of some concern to me. They entirely have to do with the {(TR)} cast on {this}. That being the
case, I don't know why the compiler is complaining; {TR} is declared to be a subtype of {RedBlack},
so clearly a cast from {RedBlack< TR>} to {TR} is legal. So why the compiler complaint?

Is there some other way to implement a Red Black Tree that wouldn't involve code that would generate
these types of complaints? Or should I just be happy with the fact that the code compiles?
3 years ago

Paul Clapham wrote:Anyway I would suggest that



might work better. That's what I did in this sort of situation, at least I think it's this sort of situation.


Thanks! That resolved the problem.
3 years ago
An extraneous line got into my listing; it should actually say:

Sorry for the discrepancy!
3 years ago
I wrote this piece of code and stored it in file "Bug.java":

Then I tried compiling it and got error messages:

D:\Langs\Java\Src\Alan\Bug>D:\Langs\Java\8u40-windows-x64\bin\javac Bug.java
Bug.java:21: error: incompatible types: Object cannot be converted to BG
   high.set( opp, hmm.high.get( inq));
                              ^
 where BG is a type-variable:
   BG extends Bug declared in class Bug
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
1 error

D:\Langs\Java\Src\Alan\Bug>

This seems to be saying that {hmm.high.get( inq)} will return an {Object}, which "cannot be converted to BG". But {hmm.high} is actually a {List< BG>}, so why would that objects {get()} method be returning an {Object}? Shouldn't it return an object of type {BG}? Which then gets assigned to the element of {this.high} that corresponds to index {opp}? {this.high} is once again of type {List< BG>} so it looks like this should work. Does anybody have any idea why my code isn't working? Thanks in advance for any pointers anyone can give me.
3 years ago

Stephan van Hulst wrote:Actually, you shouldn't be using Thread.sleep() at all. If you want to block the current thread until the track has finished playing, you should use locks and conditions and add a meta event listener to the sequencer.


Stephan, can you tell me where I can go to find out how to "use locks and conditions" and adding "a meta event listener to the sequencer"? Are those things new to Java 8 or Java 9? I'm mostly familiar with Java 6 and 7, and I don't remember anything about locks, conditions, or meta event listeners.
4 years ago

Kevin Simonson wrote:

Carey Brown wrote:What is an example of command line arguments that you're using?
Edit: sorry I missed your comment at the end.


java Synth 96 6 0 127 6500


Although I think what I'm going to go with for my game is probably:

java Synth 96 7 0 127 5500
4 years ago

Carey Brown wrote:What is "rsltn" ?


Resolution. I guess I should have spelled it out.
4 years ago

Carey Brown wrote:What is an example of command line arguments that you're using?
Edit: sorry I missed your comment at the end.


java Synth 96 6 0 127 6500
4 years ago
After I got Stephan's code working, I decided I'd try to simplify it somewhat, and, in case you're interested, here's what I came up with:

That last comment line is just a suggested list of arguments to call it with. Let me know what you think of this Java class.
4 years ago