melanchall / drywetmidi

.NET library to read, write, process MIDI files and to work with MIDI devices
https://melanchall.github.io/drywetmidi
MIT License
523 stars 73 forks source link

How to use DryWetMidi in Visual Basic (VS 2022) ? #295

Closed gitanova closed 3 weeks ago

gitanova commented 2 months ago

DryWetMidi is definitely the best thing I have found on my long journey so far. Unfortunately, I have little experience with C# and so I have to switch to VB.NET (2022). It would be a huge help if someone had already made finished examples using drywetmidi under VB.NET and could share them. It would be a big help for me if someone could give me a working VB example for creating a list with all the events of a midi file. Despite my old age, I am actually still capable of learning - and have created many projects in VB - but unfortunately I can no longer manage the switch to C. I was VERY THANKFUL for some DryWetMidi examples in VB! Special greetings from Austria! Michael

CIRCE-EYES commented 2 months ago

Hi Gitanova, click on my icon. My projects are under VB. NET.

Write me ir you like.

gitanova commented 2 months ago

Thank you very much indeed! This is a great help for me! For my first drywetmidi-project I just want to get a list of all noteon/noteoff events with corresponding channel and timestamp which are inside a certain midi-file. As a next step I want to edit some of those "events" and play the events in the list. When I'm happy with the editing I want to create a midi-file at last. Could you please give me a hint how to this with drywetmidi? (I understand most of your programming, but I could not manage to work out my needs above...) Can you help?

CIRCE-EYES commented 2 months ago

DRYWETMIDI its simple the Best ! E-mail me for issue about tour question.

circex@telefonica.net

gitanova commented 2 months ago

Sorry, your mailadress seems to have some problems ... SMTP error from remote mail server after RCPT TO:[circex@telefonica.net](mailto:circex@telefonica.net)

So please answer her in Github! Thank you!

gitanova commented 2 months ago

In any case, I would really appreciate your help. It would be best if you could help me with a few lines of code to realize my project! Thanks in advance. Michael

melanchall commented 2 months ago

Hi @gitanova,

I'm the author of the library. But my main programming language is C#. @CIRCE-EYES has a lot of experience with DryWetMIDI in VB.NET.

@CIRCE-EYES I really appreciate your assistance since I have no coding at VB.NET at all :-)

If you need my help, please ask your questions.

gitanova commented 2 months ago

@melanchall May I ask YOU for help - I don't mind if your code is C#... I'm on the way to learn how to convert it to VB.net. I read your written instructions for the drywetmidi library very carefully - but I still can't get very far on my own. Therefore, I ask for your help and thank you again for your work, which certainly deserves great recognition!

  1. Record a MIDI file from a connected MIDI keyboard and save it to a (temporary) file on the hard drive.

  2. Display an event list (time stamp, channel, NoteON or NoteOff, (Prg-Change, ...) in a listbox or text window, or grid, ....

  3. Clicked event (the listbox or text field, ..) should be output immediately via Midi. Individual values ​​should be able to be changed manually.

  4. The edited MIDI file should then be saved on the hard drive under a specific name

I would be extremely grateful if you could send me a few lines of code for the 4 tasks mentioned above.

With the very best regards

Michael

melanchall commented 2 months ago
  1. You will find answer in the article. If it's still not clear, please ask your question with more details (what exactly is not clear, what you've tried, what's wrong and so on).
  2. I can only tell you how to get events. How to populate listboxes and so on is completely up to you. Well, if you want to get events with their absolute times (or you need delta-times?): var timedEvents = midiFile.GetTimedEvents();. Read about TimedEvent to know what proeprties it provides. You can also get times in different formats, learn more.
  3. Read the article first. I assume "should be output" means to send an event to a MIDI device.
  4. midiFile.Write("path/to/file.mid"); You can found it in the article.

In fact your questions are too common. Be more specific please. I recommend you to start writing your code and I'll try to help with problem places.

CIRCE-EYES commented 2 months ago

Hello Michael, first of all I would like to know what your knowledge is about graphics in the VB environment. Net, have you made programs with graphical functions? In my examples you will see a very simple syntax to be able to do everything you want, except the list of events in a Midi file, but don't worry, I have two solutions for you.

These three programs list the Midi events. And the best thing is that two of them are made in VB. Net!!! I hope they are useful for you.

VB. Net https://github.com/operatortwo/Midi_File

https://github.com/operatortwo/Mmultitool

C#

https://github.com/jeffbourdier/MIDIopsy.git

Greetings and I wait news about the first question I asked you about graphics.

Greetings

CIRCE-EYES commented 2 months ago

I forgot to say that my e-mail runs well.

circex@telefonica.net

gitanova commented 2 months ago

@melanchall: I really appreciate your help! Unfortunately, I am an old man and come from hardware development. Therefore, my knowledge of “modern” programming languages ​​is quite limited. But I really enjoy learning new things. With your information I will now get started and if any questions arise, I really appreciate asking for your help!

Thanks again! Michael

Of course, if I'm "successful", I will also publish my source code here and perhaps help others benefit from it too!

gitanova commented 2 months ago

@CIRCE-EYES: A big thank you to you too for your work - I have already found the two pages of operatorII - the third page with the Midi editor was completely new to me - unfortunately the source code cannot be made to work in Visual Studio 2022. The Disigner.rex file seems to be missing...

Thank you anyway!

Unfortunately, my graphics experience in VB.net is not particularly good - you would have to be a game programmer to have such expertise - unfortunately!

Nevertheless many thanks!

Michael

melanchall commented 2 months ago

@gitanova

With your information I will now get started and if any questions arise, I really appreciate asking for your help!

This is a good approach! Because we will be able to see real problems and solve them quickly.

gitanova commented 2 months ago

Thanks to your very good documentation, I was able to get a large part of my project running!

But where I'm stuck is the following:

I would like to change the tempo while playing back a midi file. This also works quite well with:

_playback.Speed ​​= _playback.Speed ​​* 1.02

But this also shifts the current position and if I increase the speed, some midi events are "skipped". It shouldn't be like that...

Is there a solution where the playback position remains the same and only the other events are played back at a faster or slower tempo?

Where can I download the latest drywetmidi.dll?

Many thanks!

melanchall commented 2 months ago
  1. How did you install the library into your project?
  2. What version of the library do you use?

The proper way is to install the library via NuGet. Just please search on the Web how to install NuGet packages from Visual Studio (or other IDE if you use them).

Latest version of the library is 7.0.2 and available via NuGet: https://www.nuget.org/packages/Melanchall.DryWetMidi

gitanova commented 2 months ago

I am using the drywetmidi.dll vom CIRCE's-VB.NET project. It is version 5.1.3.

gitanova commented 2 months ago

When I use NuGet (version 7.02) I'm getting a lot of error while compiling in VB.NET... :-(

gitanova commented 2 months ago

I've found the reason why I was getting errors!

The line: Imports Melanchall.DryWetMidi.Devices has to be changed to: Imports Melanchall.DryWetMidi.Multimedia

result: No errors while compiling!

gitanova commented 2 months ago

Tempo changes work like a charm now too! Thank you!

melanchall commented 2 months ago

Tempo changes work like a charm now too!

Yes, that has been fixed in the 7.0.1 release.

@gitanova Thank you for using the library! I don't know how old are you, but honestly you solve programming problems better than some young programmers. I believe the skill of researching is much more important than a programming language knowledge. You can learn a language pretty quickly, but how to search for information, how to investigate problems, how to use docs and so on - the thing that is much harder. And you're successful with that :-)