|
 The keys i say are the keys from my piano MIDI keyboard (hardware piano keyboard)!... Not from PC´s keyboard!!!
This is all the code i have now....plus the clsMIDI module:
Imports System.Runtime.InteropServices
Public Class Form1
Dim m As New clsMIDI
Dim hMidiIn As Integer
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
FillInstrumentCombo()
If midiInGetNumDevs() = 0 Then
MsgBox("No MIDI devices connected!")
End If
Dim InCaps As New MIDIINCAPS
Dim DevCnt As Integer
For DevCnt = 0 To (midiInGetNumDevs - 1)
midiInGetDevCaps(DevCnt, InCaps, Len(InCaps))
ComboBox1.Items.Add(InCaps.szPname)
Next DevCnt
End Sub
Declare Function midiInOpen Lib "winmm.dll" (ByRef lphMidiIn As Integer,
ByVal uDeviceID As Integer, <MarshalAs(UnmanagedType.FunctionPtr)> ByVal dwCallback As MidiDelegate,
ByVal dwInstance As Integer, ByVal dwFlags As Integer) As Integer
Public Delegate Sub MidiDelegate(ByVal MidiInHandle As Int32, ByVal wMsg As Int32, ByVal Instance As Int32, ByVal wParam As Int32, ByVal lParam As Int32)
Public ptrCallback As New MidiDelegate(AddressOf MidiInProc)
Public Delegate Sub DisplayDataDelegate(wParam)
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
midiInStop(hMidiIn)
midiInReset(hMidiIn)
midiInClose(hMidiIn)
Dim DeviceID As Integer = ComboBox1.SelectedIndex
midiInOpen(hMidiIn, DeviceID, ptrCallback, 0, CALLBACK_FUNCTION Or MIDI_IO_STATUS)
midiInStart(hMidiIn)
Dim duration = CInt(cboduration.Text)
m.NoteDuration = duration
End Sub
Function MidiInProc(ByVal MidiInHandle As Int32, ByVal wMsg As Int32, ByVal Instance As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Integer
TextBox1.Invoke(New DisplayDataDelegate(AddressOf DisplayData), New Object() {wParam})
Dim DataByte3 = (wParam And &HFF00) >> 8
m.PlayMIDINote(DataByte3, 127)
End Function
Private Sub DisplayData(wParam)
Dim StatusByte As Byte
Dim DataByte1 As Byte
Dim DataByte2 As Byte
StatusByte = (wParam And &HFF)
DataByte1 = (wParam And &HFF00) >> 8
DataByte2 = (wParam And &HFF0000) >> 16
TextBox1.AppendText(String.Format("{0:X2} {1:X2} {2:X2}{3}", StatusByte, DataByte1, DataByte2, vbCrLf))
End Sub
Private Sub FillInstrumentCombo()
For i = 0 To 121
cboinstruments.Items.Add(Instrument.GMInstrumentNames(i))
Next
cboinstruments.SelectedIndex = 0
End Sub
Private Sub cboInstruments_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboinstruments.SelectedIndexChanged
m.CurrentInstrument = cboinstruments.Text
End Sub
Private Sub hsbVolume_ValueChanged(sender As Object, e As EventArgs) Handles hsbvolume.ValueChanged
m.Volume = hsbvolume.Value
End Sub
Private Sub cboduration_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboduration.SelectedIndexChanged
Dim duration = CInt(cboduration.Text)
m.NoteDuration = duration
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
midiInStop(hMidiIn)
midiInReset(hMidiIn)
midiInClose(hMidiIn)
m.STOPAllMIDINotes()
End
End Sub
Private Sub Button2_MouseDown(sender As Object, e As MouseEventArgs) Handles Button2.MouseDown
m.PlayMIDINote(60, 127)
End Sub
Private Sub Button2_MouseUp(sender As Object, e As MouseEventArgs) Handles Button2.MouseUp
m.STOPMIDINote(60)
End Sub
End Class
When i press the MIDI keyboard keys it plays..but when i unpress it it plays again...i would like it to play only when i press!
This is the code i am using for it to play (check underlined):
Function MidiInProc(ByVal MidiInHandle As Int32, ByVal wMsg As Int32, ByVal Instance As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Integer
TextBox1.Invoke(New DisplayDataDelegate(AddressOf DisplayData), New Object() {wParam})
Dim DataByte3 = (wParam And &HFF00) >> 8
m.PlayMIDINote(DataByte3, 127)
End Function
if i leave it like this it plays when i press and when i unpress the MIDI keyboard keys...but if i set it like this:
Function MidiInProc(ByVal MidiInHandle As Int32, ByVal wMsg As Int32, ByVal Instance As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Integer
TextBox1.Invoke(New DisplayDataDelegate(AddressOf DisplayData), New Object() {wParam})
Dim DataByte3 = (wParam) >> 8
m.PlayMIDINote(DataByte3, 127)
End Function
It only plays when i unpress...
I would like it to play only when i press the MIDI keyboard keys!
Thanks....
modified 7-Jan-19 21:02pm.
|
|
|
|
|
Alienoiz wrote: The keys i say are the keys from my piano MIDI keyboard (hardware piano keyboard)!... Not from PC´s keyboard!!! Alright
Please post the contents of your TextBox1 after pressing and releasing a single key.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
No - not for a single key but for two different keys please, in sequence.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
i am not understanding : ((((
can you set an example?... i guess the textbox1 is not affecting the MIDI playing!!!
What is making the play its the "m.playMIDINote" function!!!
The textbox1 is just for showing the data that is being sent from the MIDI Keyboard into the PC!
modified 7-Jan-19 21:02pm.
|
|
|
|
|
Alienoiz wrote: The textbox1 is just for showing the data that is being sent from the MIDI Keyboard into the PC!
Yes and I want to see that
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
ouch..i am sorry..i understood something else..
here...00 00 00 appears when i select the MIDI keyboard from combobox1..next is the data from 3 followed keys:
00 00 00
90 30 36
80 30 00
90 31 38
80 31 00
90 32 22
80 32 00
modified 7-Jan-19 21:02pm.
|
|
|
|
|
OK - try this:
Function MidiInProc(ByVal MidiInHandle As Int32, ByVal wMsg As Int32, ByVal Instance As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Integer
Dim Status As Byte
Dim Note As Byte
Dim Velocity As Byte
TextBox1.Invoke(New DisplayDataDelegate(AddressOf DisplayData), New Object() {wParam})
Status = (wParam And &HFF)
If Status = 90 Then
Note = (wParam And &HFF00) >> 8
Velocity = (wParam And &HFF0000) >> 16
m.PlayMIDINote(Note, Velocity)
End If
End Function
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
i understand the code..yes..but it is not working! : (
modified 7-Jan-19 21:02pm.
|
|
|
|
|
You need to go into more detail with problem descriptions. "Not working" is not helping me understand. Does it not do anything any more or still the same problem as before or what?
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
sorry..everything works except the sound ... no sound!!
modified 7-Jan-19 21:02pm.
|
|
|
|
|
if i set it like this:
If Status <> 90 Then
it seems to work...the 90/80 might not be the "correct" value!
modified 7-Jan-19 21:02pm.
|
|
|
|
|
I missed that you formatted the output as hexadecimal. Change that line to:
If Status = 144 Then
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
OOOOOOOOKKKKKKK..seems good..A LOT OF THANKS!
modified 7-Jan-19 21:02pm.
|
|
|
|
|
i am encountering this issue..i do not know where to put the
Dim duration = CInt(cboduration.Text)
m.NoteDuration = duration
code.... i tried several ways, but when i load the app, it doesnt updades..only after a manual update it plays ok! Basically when i load the app..the duration is infinite!!
modified 7-Jan-19 21:02pm.
|
|
|
|
|
I have an idea how to fix that but I'm leaving for a vacation trip until Monday. I'll get back to you then.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
OK..thanks..later then!
modified 7-Jan-19 21:02pm.
|
|
|
|
|
It looks like something gets stuck..i overpassed the problem by adding this:
m.PlayMIDINote(0, 0)
m.STOPMIDINote(0)
to the form´s load event!!
modified 7-Jan-19 21:02pm.
|
|
|
|
|
I copied the code from : [^]
..to see if it works/ed ....
modified 7-Jan-19 21:02pm.
|
|
|
|
|
Hi.
(Uppsssie just missed the there where more Replies, is just saw only that about the First Error Message )
I did alot of VB.NET and VB6 MIDI Stuff. That´s why I started to learn Programing.
To be honest, I used like You a Library, Mostly MidiOx. (Oldie, but goldie...)
It is always the same things that are nessesary for Midi Handling.
First check if the Midi Device(s) are Present. Then Open them and Store it in a Instance (Variable). Then use the Subparts (Properties) like Channel number (MIDI-Channel) etc.
Then handle (Midi is mostly about Timings) the Midi Events.
But if You have a USB Midi Controller, You have to make Sure it has a Tone Generator.
Like the Korg NanoPads, they can only be used as Input Devices.
Maybe thats the cause for the Error-Messages.
If that´s the Case, use Your Computer and find a Software Synthesizer (Or some Tone Generator, Sampler etc.) and connect them inside the Computer. Of course Virtual Plugs (And there is no WLAN-Cable ) to connect the MIDI Input (Controller) with the Generator
(You can make your own Sampler in VB A Soundboard for example).
Or use a DAW ( 'Digital Audio Workstation' Application like: Cubase, Reason, Logik Fruity-Loops to name some of them, and all are Commercial I can´t remeber some Freeware atm.)
Please consider to use a MIDI analyzer Software like MIDIOX to see how MIDI DATA is transported and Connected Interchanged etc.)
For the VB Programming, it is very easy to Programm basic Midi Handling.
Lik I sad:
First get the Inputs and Outputs of the Midi-Devices in a List.
Like Jazz.GetDevices()
Then find the Proper Device, maybe with a Index or by a Name, whats the most convinitent way to do it.
Then Get the Input of Your USB-Controller.
Test it with MidiOX it has all Information allready awailable to see what is named what etc.
Then Connect the Midi-Messages of the Inputs and send them to the Tone generator Input.
So You have to Reroute the Midi Flow from the Controller to the Tonegenerator.
Wow very Complicated explained.
Let me break it Down. Your VB-App will have to have Inputs and Outputs.
The USB-Controller will be a Input in Your App. You have to use then the Output of your App to create some Noise (A Symphony for Example).
But if the Output should be a Soundboard that will be Playing MP3/or Wav Files on a Keyboardpress (Pianokeyboard) You can ommit the Output and just play the Files with the Windows Soundsystem, when the NoteOn Message is recieved.
When Jazz Library is saying Down and Up, it is ment the MidiMessages NoteOn and NoteOff.
Then you look inside the NoteOn-Message for the Channel Bit the ToneHight Bit and here we are.
And if You want to use the MidiMessages to behave like a real Instroment You have to handle also the NotOff-Message, to cancle the NoteOn.
A Piano Key makes a Noise as long You holding down the Key (Or it gets Quiet). But from a Programmers View it is a "Gate".
The Begin of the Gate is Called NoteOn and the End of the Gate is Called NoteOff.
I think You get the Idea.
Besides these 'easiest' Midi-Messages, there are alot of another Messages like SysEx (System Exclusive), but only in some cases there will be a need to do SysEx handling at all. Usally You will use them to send Data (like Backups) to/from the Mididevice(s).
So if you gonna use Jazz it is the right choise (I think i never used it).
It is the best way to use a Library for that Task.
Midi is very old and Robust and there is no need to recreate all the Midi-Bit Handling. Just focus on the Normal Tasks like Playing Music.
If You need some more advices please Ask, because Millions of People are doing Midi, but not in VB. Sniff me is very Sad about VB...
Happy new Year from Hamburg, Gemany

modified 28-Dec-17 22:49pm.
|
|
|
|
|
I have this XLS Sheet to create, or a report that groups sales by states and by customers.
Some of the customers have multiple locations in states, and have different customer names but it' the same customer.
EG.
ABC Company (Ontario)
ABC Company (Anaheim)
ABC Company *
(San Jose) ABC Company
I'm not even sure what to call this so I can search the internet.
Nor where to even start on this.
But this is my final GroupBy Call before I send it to the XLS creator.
Dim gCustomersItems_Final As List(Of model_itemDistribution_Items) = gCustomer_items.OrderBy(Function(ob) ob.FSSTATE).ThenBy(Function(tb) tb.FCOMPANY).GroupBy(Function(v) New With {Key v.FCOMPANY, Key v.FSSTATE}).Select(Function(cl) New model_itemDistribution_Items() With {
.FSADDR1 = cl.First().FSADDR1,
.FITEMNO = cl.First().FITEMNO,
.FDESCRIPT = cl.First().FDESCRIPT,
.FSHIPQTY = cl.Sum(Function(qty) qty.FSHIPQTY),
.FCSAMT = cl.Sum(Function(amount) amount.FCSAMT),
.FSCITY = cl.First().FSCITY,
.FSSTATE = cl.First().FSSTATE,
.FSZIPCODE = cl.First().FSZIPCODE,
.FSCOUNTRY = cl.First().FSCOUNTRY,
.FCUSTNO = cl.First().FCUSTNO,
.FCOMPANY = cl.First().FCOMPANY,
.FSALESPN = cl.First().FSALESPN,
.FMAXDATE = cl.Max(Function(m) m.FSHIPDATE)
}).ToList()
If it ain't broke don't fix it
|
|
|
|
|
The problem is that the database is badly designed, the Customer table needs a grouping field that is common to all the branch records, you need a company table with a foreign key to your customer table so you can group them.
I will be astonished if you can cater for all the garbage in that users can type for a company name. You should never rely on user input for key values (grouping makes it a key value).
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Your right. There is so much garbage in the database from all the users with half a brain that entered customers.
I tried the Levenstein and it came close to extracting but it takes too long to test and adjust the integer.
Now I'm just going to try and manually change the names first based on a static list and then run the function.
If it ain't broke don't fix it
|
|
|
|
|
Surely the static list would be better used as a Company table content and linking ot to the customer table. It will require a change to the UI to support the Company. Not trivial but will make your life a lot simpler down the track.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
not able find error
addn:
If h = 1 Then lr = Range("GTB").Rows.Count + 9
If h = 2 Then lr = Range("NGTB").Rows.Count + 9
Set Gcell = wb.Sheets(InputSheet).Cells.Find(GetVal(CStr(Area(x, j))))
GCA = Gcell.Address(ReferenceStyle:=xlA1, _
RowAbsolute:=False, ColumnAbsolute:=False)
Range("B" & lr).Value = i
Range("C" & lr).Value = "01-" + headers(1, j) + "-" + Year
'Range("D" & lr).Value = i
Range("G" & lr).Value = Area(x, 15)
Range("H" & lr).Value = Area(x, 16)
Range("I" & lr).Value = Area(x, 14)
Range("E" & lr).Value = Area(x, 17)
Range("J" & lr).Value = Now()
wb.Sheets(InputSheet).Range(GCA).Copy Range("D" & lr)
Range("D" & lr).Font.Size = 9
Range("D" & lr).Font.Name = "Calibri"
End If
nxtc:
Next j
Next x
Erase Area, headers
nw:
Next i
Next h
Del Worksheets("GTB AUDIT"), "GTB", wb
Del Worksheets("NOT GTB AUDIT"), "NGTB", wb
Ordering
FormatGTB Sects
FormatNGTB Sects
wb.Close False
Application.ScreenUpdating = True
'ActiveCell.MergeArea.Rows.Count
End Sub
|
|
|
|
|
actually error line is :
l Worksheets("GTB AUDIT"), "GTB", wb
|
|
|
|
|