Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Sound API

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone,
I have got the follg code which when compiled gives the error
"Expected Instrument[] but founf javax.sound.midi.Instrument[]"
at the line
Instrument instrs[] = synth.getLoadedInstruments();

Can anyone please help me in this regard?
import javax.sound.midi.*;
public class Waves
{
public static void main(String[] args)
{
try
{
// Locate the default synthesizer
Synthesizer synth = MidiSystem.getSynthesizer();
// Open the synthesizer
synth.open();
// Get the available Midi channels - there are usually 16
MidiChannel channels[] = synth.getChannels();
// Get the synth's soundbank where all the sounds are stored
Soundbank bank = synth.getDefaultSoundbank();
// Load all the available instruments
synth.loadAllInstruments(bank);
// Get a list of the available instruments
Instrument instrs[] = synth.getLoadedInstruments();
Instrument seashore = null;
// Loop through the instruments
for (int i=0; i < instrs.length; i++)
{
// Stop when you find the seashore
if (instrs[i].getName().equals("Seashore"))
{
seashore = instrs[i];
break;
}
}
if (seashore == null)
{
System.out.println("Can't find the beach");
System.exit(0);
}
// Get the information describing the Seashore instrument - the
// patch contains the soundbank and program number
Patch seashorePatch = seashore.getPatch();
// Set 5 channels to use the Seashore instrument
channels[1].programChange(seashorePatch.getBank(),
seashorePatch.getProgram());
channels[2].programChange(seashorePatch.getBank(),
seashorePatch.getProgram());
channels[3].programChange(seashorePatch.getBank(),
seashorePatch.getProgram());
// Start the Seashore note on 3 different channels. By waiting a short
// time before starting the next note, you get a much more continuous sound
channels[1].noteOn(32, 127);
Thread.sleep(3500);
channels[2].noteOn(32, 127);
Thread.sleep(1500);
channels[3].noteOn(32, 127);
// Wait forever
for (;
{
try { Thread.sleep(999999999); } catch (Exception ignore) {}
}
}
catch (Exception exc)
{
exc.printStackTrace();
}
}
}

Thanks in advance
Indira.
 
Who knew that furniture could be so violent? Put this tiny ad out there to see what happens:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic