|
-
Jun 18th, 2021, 02:14 PM
#4
New Member
Re: Visual Basic Customized Piano. I'm a Noob. So please tolerate my stupid questions
Counldn't download your project, some error with 'terms of use' but it was possible to open Form1.txt
Maybe you could reduce the complexity of the question by dividing it into a technical part and a musical part.
Is it really necessary to do a calculation for the note numbers ? Maybe a conversion/mapping table would also do the job, means an array in VB. For example: Note number 0 corresponds to the element with index 0 in the array and holds the number of the note that will actually be played. This way you could map any note to wathever you want, like creating a table on paper.
For the note numbers: I would recommend to use the MIDI Note numbers with the range of 0 to 127 where Note number 69 = A4 = 440 Hz. (instead of using an own note numbering system). When following the standard there is a chance to reuse parts of your work in the future, and having compatibility from the beginning with MIDI-Keyboards, Sound generators and so on.
About the sound 1:
Code:
Select Case e.KeyCode
Case Keys.Q
button1.PerformClick()
This way you can play a sound one time, but you can't play different note-durations. A complete different playing function is needed and the use of MouseDown/MouseUp or KeyDown/KeyUp (where KeyDown starts the Sound, play it continuously (or play at least the decay until silence) and stops the sound whenever KeyUp occurs)
About the sound 2: The documatation says:
The My.Computer.Audio.Play method allows the application to play only one background sound at a time;..
I don't think Audio.Play is usable for playing notes.
There is maybe another way, but quite difficult for beginners. (had to learn that by myself as I begun programming VB .Net)
On many PC's and Notebooks there is a Software-Synthesizer installed by default named like 'Microsoft GS Wavetable Synth' See also: Device Manger / Software Devices
If the Device is present one have to start with 'midiOutGetNumDevs' 'midiOutGetDevCapsA' and so on
to get the exact name of the device, then the device can be opened with 'midiOutOpen' and after that one can send NoteOn / NoteOff Messages to the device. (like: NoteOn, NoteNumber, Velocity)
One of the difficulties is that these functions were never ported to .Net so one have to handle the functions from Winmm.dll written for C++ ...quite difficult and time consuming...
But maybe you can find a Library (Midi I/O or similar, which provides functions like MidiOutOpen, MidiOutShortMsg and so on for you) on GitHub or elsewhere.
And there is another downside: The Software Synthesizer has a little delay (0.1 - 0.5 Seconds) between pressing a key and hearing the tone. There is no markable delay anymore when using a MIDI (Hardware) sound generator.
A complete other way would be using a Library (OpenSource Project) that is specialized to playing multiple sound at the same time with as little delay as possible.
Anyway, I see a lot of work.
Last edited by kensen; Jun 18th, 2021 at 02:17 PM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|