GithubHelp home page GithubHelp logo

Comments (10)

melanchall avatar melanchall commented on June 28, 2024

Hi,

It's not possible for first code sample to have a name other than "Test". You're obviously showing me incomplete code. Because your new track chunk will have the "Test" name.

Please show complete code and how you check the name of a track chunk.

Also please note that I'm on vacation right now so delays in responses are possible.

Thanks,
Max

from drywetmidi.

breezy876 avatar breezy876 commented on June 28, 2024

This is the complete code. It's opening an existing MIDI then writing the 1st note of the 4th track to a new MIDI.

void BuildFile()
{
    string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), Configuration.config.midiFilePath, "EDM", "alicedeejay.mid");

    using (var f = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
    {
        var midiData = MidiFile.Read(f, new ReadingSettings
        {
            NoHeaderChunkPolicy = NoHeaderChunkPolicy.Ignore,
            NotEnoughBytesPolicy = NotEnoughBytesPolicy.Ignore,
            InvalidChannelEventParameterValuePolicy = InvalidChannelEventParameterValuePolicy.ReadValid,
            InvalidChunkSizePolicy = InvalidChunkSizePolicy.Ignore,
            InvalidMetaEventParameterValuePolicy = InvalidMetaEventParameterValuePolicy.SnapToLimits,
            MissedEndOfTrackPolicy = MissedEndOfTrackPolicy.Ignore,
            UnexpectedTrackChunksCountPolicy = UnexpectedTrackChunksCountPolicy.Ignore,
            ExtraTrackChunkPolicy = ExtraTrackChunkPolicy.Read,
            UnknownChunkIdPolicy = UnknownChunkIdPolicy.ReadAsUnknownChunk,
            SilentNoteOnPolicy = SilentNoteOnPolicy.NoteOff,
            TextEncoding = Encoding.Default
        });


        var track = midiData.GetTrackChunks().ToArray()[3];
        var notes = NotesManagingUtilities.GetNotes(track).ToArray();

        var midiFile = new MidiFile();
        var trackChunk = new TrackChunk(new SequenceTrackNameEvent() { Text = "Test" });

        using (var notesManager = trackChunk.ManageNotes())
        {
            notesManager.Objects.Add(notes[0]);
        }

        midiFile.Chunks.Add(trackChunk);
        midiFile.Write("My Future Great Song.mid");

    }

from drywetmidi.

melanchall avatar melanchall commented on June 28, 2024

It's opening an existing MIDI

It changes everything. Reading an existing file is not the same case as creation of a new one.

So you add SequenceTrackNameEvent("Test")) to the existing track chunk and expect this event will magically replace existing one? Obviously it won't. You just add another one event at the end of a track chunk.

To do what you want you have two choices:

  1. Find existing SequenceTrackNameEvent and change its Text property.
  2. Remove existing event and add a new one at the start of a track chunk (see Insert method on TrackChunk.Events).

But you again didn't show me complete code:

  1. using (var notesManager = trackChunk.ManageNotes()). What is trackChunk and where it is defined? There is no this field/var declaration in your code.
  2. There is no code for SequenceTrackNameEvent in your snippet.

Anyway now I believe you see what was wrong in your algorithm.

Thanks,
Max

from drywetmidi.

breezy876 avatar breezy876 commented on June 28, 2024

Hello. I am aware of what is required in a MIDI file as Iv'e been working with them for years- that adding a new event won't change the track name as the first one gets selected by any MIDI player/editor. That is why in the code I create a new MidiFile instance, a new track (with the expected name), add a note (taken from the existing file) to the track and then write to it. The code still was not complete, I have added the 2 missing lines. Please review.

from drywetmidi.

breezy876 avatar breezy876 commented on June 28, 2024

I just discovered that for some reason when I open it in MIDIEditor the track name of the first track is "Test", but in others (FL Studio) it is "Acoustic Piano 001". I am very confused. There are also two tracks, the first I added and a second that gets added presumably automatically by the library that has a tempo change and time signature event, possibly by the note from the other MIDI that gets read and added to it. Is it possible a program change event for note tracks is also required for compatibility with certain software to resolve this??

from drywetmidi.

melanchall avatar melanchall commented on June 28, 2024

Well, if we look at this example:

var midiFile = new MidiFile();

var trackChunk = new TrackChunk(new SequenceTrackNameEvent("Test"));

using (var notesManager = trackChunk.ManageNotes())
{
    // code to add notes goes here and is working...
}

midiFile.Chunks.Add(trackChunk);
midiFile.Write("My Future Great Song.mid");

it's guaranteed the track chunk will have Test name.

Looks like some DAWs (FL in your example) use a program to name a track chunk. But there is an interesting thing here. In our example we don't specify a program. In this case the MIDI spec says nothing about what program is default one. Many software use zero program (which is Acoustic Piano according to GM) but that just a way these software operate, it's not by the MIDI spec.

Is it possible a program change event for note tracks is also required for compatibility with certain software to resolve this??

Definitely no. More than that program is a number, we can't specify text there.

My conclusion is: it's wrong to use a program to name a track, especially if Sequence/Track Name event is present there. Maybe FL has an option what to use for tracks names?

In any case you're doing all correct, and there are no bugs in the library. I recommend to contact FL forum or tech support to get clarification why they use program for naming.

from drywetmidi.

breezy876 avatar breezy876 commented on June 28, 2024

I don't understand. I open other MIDIs in FL Studio and they have the correct track names (same as in MidiEditor), but when I use your code to create a new MIDI from scratch as above. Only MidiEditor software has the correct track name- "Test".

from drywetmidi.

breezy876 avatar breezy876 commented on June 28, 2024

Off-topic- are you interested in Collaborating on a project that would utilise your library for the MIDI processing? There is potential profit to be made for both of us. I will provide further details of the project after your answer- if yes.

from drywetmidi.

melanchall avatar melanchall commented on June 28, 2024

Well, send me two files please:

  1. One created with DryWetMIDI.
  2. An arbitrary one FL shows correct track names for.

are you interested in Collaborating on a project that would utilise your library for the MIDI processing?

Thank you for the offer, but no. Unfortunately I have small amount of free time so I just want to have some rest, hope you understand :-)

from drywetmidi.

melanchall avatar melanchall commented on June 28, 2024

@breezy876 Any news?

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.