fbpx


The MIDI Forum

  Saturday, 30 January 2021
  8 Replies
  2.2K Visits
1
Votes
Undo
  Subscribe
Hello,

I have a M-Audio controller keyboard, I am looking for a sample code that to play any note/key input on selected instruments sounds set (e.g: 3-Electric Grand Piano, 25-Acoustic Nylon Guitar, ... where 3, 25 are General MIDI instrument codes number).
I did a lot of research and tried several examples but no luck.....

Below are one of example I tried, but no luck, your guide, help would be greatly appreciated.
Thank you.
Vu.

//var context = new AudioContext(),
// oscillators = {};

//if (navigator.requestMIDIAccess) {
// navigator.requestMIDIAccess()
// .then(success, failure);
//}

//function success(midi) {
// var inputs = midi.inputs.values();
// // inputs is an Iterator

// for (var input = inputs.next() ; input && !input.done; input = inputs.next()) {
// // each time there is a midi message call the onMIDIMessage function
// input.value.onmidimessage = onMIDIMessage;
// }
//}

//function failure() {
// console.error('No access to your midi devices.')
//}

//function onMIDIMessage(message) {
// var frequency = midiNoteToFrequency(message.data[1]);
// if (message.data[0] === 144 && message.data[2] > 0) {
// playNote(frequency);
// }

// if (message.data[0] === 128 || message.data[2] === 0) {
// stopNote(frequency);
// }
//}

//function midiNoteToFrequency(note) {
// return Math.pow(2, ((note - 69) / 12)) * 440;
//}

//function playNote(frequency) {
// oscillators[frequency] = context.createOscillator();
// oscillators[frequency].frequency.value = frequency;
// oscillators[frequency].connect(context.destination);
// oscillators[frequency].start(context.currentTime);
//}

//function stopNote(frequency) {
// oscillators[frequency].stop(context.currentTime);
// oscillators[frequency].disconnect();
//}
8 months ago
·
#7768
Accepted Answer
0
Votes
Undo
Hello,
Thank you all very much for responded.
I was able to find a great source (link below) and make it works the way I needed.

https://surikov.github.io/webaudiofont/

Thank you.
Vu.
8 months ago
·
#7752
0
Votes
Undo
It is not clear what you are ultimately trying to achieve.
Are you wanting to play a single note and have that note play on multiple instruments simultaneously?
8 months ago
·
#7753
1
Votes
Undo
Thank you for responding,
I need to play any note(s) that having selected sound out put as I want:

For instance:
I have a drop-down list of Sound Sets: (3-Electric Grand Piano, 25-Acoustic Nylon Guitar etc....)
If I selected "Electric Grand Piano" from that list.
Then I want to play note (say "C4" ) that give me out put of sound C4-"Electric Grand Piano"....

Thank you.
8 months ago
·
#7754
0
Votes
Undo
Okay, so you want to be able to select an instrument and then play that instrument.

Next question: Do you need to do it programmatically or is it enough to configure your M-Audio controller to allow you to select the instrument using a slider or rotary encoder?
8 months ago
·
#7755
0
Votes
Undo
Thank you for responding,

I need to programmatically!.

I have a question as for 2nd option you mentioned thought: does it mean, if I have different controller (let say AKAI-Controller), it will give me different instrument using slider or rotary encoder?
If you could also provide me the information how to do this second option that would be supper good!.

Mean time, I am trying to understand the example from the link below, that might give me a good idea...
https://andyhall.github.io/webaudio-instruments/

Thank you very much in advance!.
Vu.
8 months ago
·
#7756
0
Votes
Undo
If you need a JavaScript synth with GM sounds, please have a look at https://github.com/jazz-soft/JZZ-synth-Tiny
8 months ago
·
#7757
0
Votes
Undo
if I have different controller (let say AKAI-Controller), it will give me different instrument using slider or rotary encoder?
The idea is to send a standard Program Change message using the slider or rotary encoder. This selects the instrument in the target MIDI device. See the MIDI specification for details.

Unfortunately, prior to the General MIDI standard, different MIDI devices have different instrument lists, so the same program number sent to two different devices might select two completely different instruments.

You will find a lot of MIDI code on github using many different programming languages. Choose the language and platform that you are most familiar with and start there.
8 months ago
·
#7765
0
Votes
Undo
Hello,

The code example you give, I suspect, is NOT trying to do anything like what you want.

I suspect that it's using a variety of C++. The program seems to be receiving a midi note number, and then converting the note number into a frequency, and then using an oscillator (not a midi instrument or suchlike) to create a sound. I don't see anything that might make the 'sound' be anything different for different instruments.

Your program needs more to receive a basic midi instruction, and then send that same instruction out again to your midi instrument. No oscillators involved. You then need additional code regarding instrument selection, and use of any relevant controllers.

Depending on the midi device involved, you might be able to use simple Program Change to select different instruments, or you might need to use Bank Select instructions as well.

I'm not sure if you need the midi input, and the keyboard controller, to achieve your purpose. I have written versions of software similar to this, for testing/auditioning sounds, and I have used the computer keyboard for input and converted the key pressed into midi note number via a table. Shift and key has generated a chord based on the selected note. Other key combinations has applied certain controllers, or changed volume/pan etc. You can make it all as fancy as you need.

On my various computers I may have different versions, at least one is specific to the Roland LAPC-I soundcard that I have, and the 1,000+ instrument patches that can be loaded. This is using just the midi ports to send out the midi data from the PC to the Roland card. Relatively simple changes could make the prog work with other devices.

Am I descibing something like what you were trying to achieve?

Geoff
8 months ago
·
#7768
Accepted Answer
0
Votes
Undo
Hello,
Thank you all very much for responded.
I was able to find a great source (link below) and make it works the way I needed.

https://surikov.github.io/webaudiofont/

Thank you.
Vu.
  • Page :
  • 1
There are no replies made for this post yet.
Be one of the first to reply to this post!