Giter Club home page Giter Club logo

Comments (8)

melanchall avatar melanchall commented on July 19, 2024

Hi,

Thank you for using the library.

DryWetMIDI is just a .NET library, it's not about UI. It provides features to work with MIDI files and devices. You can use it in any .NET Framework application: console or GUI, WinForms or WPF.

Please tell me, what's the problem you've encountered?

If you want to use MIDI file splitting features, please read the article in the library Wiki: MIDI file splitter. You need add using Melanchall.DryWetMidi.Tools to access tools.

If you want to draw content of a MIDI file, it's up to you. DryWetMIDI is not about visual representation of MIDI entities.

from drywetmidi.

dza6549 avatar dza6549 commented on July 19, 2024

Thanks for your very quick reply @melanchall

I have read the article MIDI file splitter but do not understand how to implement in WinForms.

Problem: I cannot see DryWetMIDI methods in Intellisense with a basic WinForms app. I have downloaded the Nuget package but I have obviously misunderstood something.

`using Melanchall.DryWetMidi;
using Melanchall.DryWetMidi.MusicTheory;
using Melanchall.DryWetMidi.Tools;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            string midiPath = @"myMidiFile.mid";

            // Failed to see lib
            //Melanchall.DryWetMidi.Common.Read(string filePath, ReadingSettings settings = null)
            //BuildMoonlightSonata();
            //dry-wet
        }
    }
}`

from drywetmidi.

melanchall avatar melanchall commented on July 19, 2024

Melanchall.DryWetMidi.Common.Read

Where did you see that? :) Please take a look at the library README:

To read a MIDI file you have to use Read static method of the MidiFile:
var midiFile = MidiFile.Read("Some Great Song.mid");

Also please tell me what does it mean?

I have downloaded the Nuget package

You need to install package via NuGet Package Manager inside Visual Studio.

from drywetmidi.

dza6549 avatar dza6549 commented on July 19, 2024

@melanchall

Sorry man for my ignorance, I am obviously very stupid basic and do not understand classes. I tried random things from here https://github.com/melanchall/drywetmidi/wiki/Reading-a-MIDI-file

You can see I here have errors
pack3

NuGet package is installed
pack2
pack1

from drywetmidi.

melanchall avatar melanchall commented on July 19, 2024

You need add

using Melanchall.DryWetMidi.Smf;

Please take a look at this symbol in Visual Studio from your screenshot:

image

If you click this dropdown, VS will suggest you to add missed using automatically.

from drywetmidi.

dza6549 avatar dza6549 commented on July 19, 2024

Thanks @melanchall

I can read/write the midi file now. I was very stupid and did not read carefully enough.

Can I ask some more questions please?

1: CsvConvertor - I have using Tools but I get an error message
CsvConvertor

2: Can I split a midi file into channels and save separate midi files? I have tried many methods (please see my ignorant code below) and I can't find a way to get even basic event information. What I want to do is split a midi file into tracks and then split the tracks into bars or using a grid. I would greatly appreciate if you could suggest to me how I might do this.

Thanks for your time.

Horrible code failures:

`
            foreach (var trackChunk in midiFile.GetTrackChunks())
            {
                Console.WriteLine("Track Chunk ID: " + trackChunk.ChunkId.ToString());

                using (var manager = new TimedEventsManager(trackChunk.Events))
                {
                    TimedEventsCollection timedEvents = manager.Events;
                    TimedEvent firstEvent = timedEvents.First();
                    Console.WriteLine("First Event Delta Time: " + firstEvent.Event.DeltaTime.ToString());
                    //firstEvent.Time = 123;
                    //timedEvents.Add(new TimedEvent(new InstrumentNameEvent("Guitar"), 456));
                }

                //using (var notesManager = trackChunk.ManageNotes())
                //{
                //    //notesManager.Notes.RemoveAll(n => n.NoteName == NoteName.CSharp);
                //    //Console.WriteLine("Notes: " + notesManager.Notes.);
                //}
            }

            //foreach (var midiEvent in midiFile.GetTrackChunks().Select(c => c.Events))
            //{
            //    Console.WriteLine("Event: " + midiEvent.ToString());
            //}

            //var trackChunks = midiFile.GetTrackChunks();
            //using (var notesManager = new NotesManager(trackChunk.Events))
            //{
            //    NotesCollection notes = notesManager.Notes;
            //}

            //using (var chordsManager = new ChordsManager(trackChunk.Events))
            //{
            //    ChordsCollection chords = chordsManager.Chords;
            //}

            using (var notesManager = midiFile.GetTrackChunks().First().ManageNotes())
            {
                NotesCollection notes = notesManager.Notes;

                // Get all C# notes
                //IEnumerable<Note> cSharpNotes = notes.Where(n => n.NoteName == NoteName.CSharp);

                // Reduce length of all C# notes by 100
                foreach (var note in notes)
                {
                    Console.WriteLine("Note length: " + note.Length);
                }

                //var notesEndedAt20Seconds = notesManager.Notes.EndAtTime(new MetricTimeSpan(0, 0, 20), tempoMap);
                //var firstNoteLength = notesEndedAt20Seconds.First().LengthAs<MetricTimeSpan>(tempoMap);
            }`

from drywetmidi.

melanchall avatar melanchall commented on July 19, 2024

1

var csvConverter = new CsvConverter();
csvConverter.ConvertMidiFileToCsv(midiFile, "D:\taiko.csv", true, null);

2

// Split by channel

var midiFilesByChannels = midiFile.SplitByChannel();

// Split each new file by grid with step of 1 bar and save each 1-bar file

var grid = new SteppedGrid(new BarBeatTimeSpan(1, 0));

foreach (var midiFileByChannel in midiFilesByChannels)
{
    var channel = midiFileByChannel.GetTimedEvents().Select(e => e.Event).OfType<ChannelEvent>().First().Channel;
    var oneBarFiles = midiFileByChannel.SplitByGrid(grid);

    var i = 0;
    foreach (var oneBarFile in oneBarFiles)
    {
        oneBarFile.Write($"File_{channel}_{i++}.mid");
    }
}

from drywetmidi.

dza6549 avatar dza6549 commented on July 19, 2024

@melanchall

This is incredible! Thank you so much :)

Cheers

from drywetmidi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.