Comments (10)
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.
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.
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:
- Find existing
SequenceTrackNameEvent
and change itsText
property. - Remove existing event and add a new one at the start of a track chunk (see
Insert
method onTrackChunk.Events
).
But you again didn't show me complete code:
using (var notesManager = trackChunk.ManageNotes())
. What istrackChunk
and where it is defined? There is no this field/var declaration in your code.- 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.
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.
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.
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.
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.
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.
Well, send me two files please:
- One created with DryWetMIDI.
- 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.
@breezy876 Any news?
from drywetmidi.
Related Issues (20)
- HELP !!! Notes in panel to midi file?? HOT 9
- please help a noob HOT 6
- Remove all notes example from the README not working HOT 9
- Using wetdrymidi in C# project causes error CS0009
- InputDevice event listening crash HOT 2
- Crash when running in Unity on M2 MacBook HOT 3
- MidiDeviceException Internal error HOT 9
- Android Support
- Unity cannot exit after use HOT 10
- MidiClock sync problem HOT 6
- MIDI Tempo changes count returns 1 but the song has 6 tempo changes. HOT 1
- add il2cpp mode HOT 5
- CustomChunk no mididata throw error HOT 4
- CSharp Code Error HOT 2
- MIDI File returns error: InvalidMetaEventParameterValueException HOT 1
- Unable to send Note-On event to device HOT 8
- How to use DryWetMidi in Visual Basic (VS 2022) ? HOT 20
- Plans for MIDI 2.0 Support? HOT 2
- Skipping notes HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from drywetmidi.