Giter Club home page Giter Club logo

Comments (8)

melanchall avatar melanchall commented on July 19, 2024

Hi,

First of all, do you need to change speed of playback using Playback class of the library or you need to create new file that is faster or slower than original one?

from drywetmidi.

Yorgg avatar Yorgg commented on July 19, 2024

Hi,

Create a new file with faster/slower tempo. Well, I don't need to create a file - just require an object in memory.

from drywetmidi.

melanchall avatar melanchall commented on July 19, 2024

Well, you can use this code:

midiFile.GetTrackChunks().First().Events.Insert(0, new SetTempoEvent(SetTempoEvent.DefaultTempo));

foreach (var trackChunk in midiFile.GetTrackChunks())
{
    foreach (var setTempoEvent in trackChunk.Events.OfType<SetTempoEvent>())
    {
        var microsecondsPerQuarterNote = setTempoEvent.MicrosecondsPerQuarterNote;
        setTempoEvent.MicrosecondsPerQuarterNote = (long)Math.Round(microsecondsPerQuarterNote * 0.8);
    }
}

This code changes all Set Tempo events so playback will be 20% faster (0.8 means quarter note will be 20% shorter in terms of microseconds). To decrease speed use multiplication with values greater than 1.0.

Please let me know if it works.

from drywetmidi.

Yorgg avatar Yorgg commented on July 19, 2024

This works, thank you.

from drywetmidi.

Yorgg avatar Yorgg commented on July 19, 2024

Hi,

This method doesn't seem to work on the midi file below. It doesn't match the tempo of the audio file produced by Ableton.

I increased tempo from 120 to 150 => setTempoEvent.MicrosecondsPerQuarterNote = (long)Math.Round(microsecondsPerQuarterNote * 0.75f);

The only difference I can see from the other files I tried is that Ableton recognizes this midi file as having a 6/8 time signature.
ravel_miroirs_3.zip

from drywetmidi.

melanchall avatar melanchall commented on July 19, 2024

Hi,

How did you change tempo with Ableton? Just set 150 instead of 120? And then export to wav? Can you attach audio file produced by Ableton?

from drywetmidi.

melanchall avatar melanchall commented on July 19, 2024

Also why you use 0.75? 120 / 150 = 0.8. 0.8 should give you the correct result.

from drywetmidi.

Yorgg avatar Yorgg commented on July 19, 2024

Ah. You are right. I was dividing in the wrong order. thanks!

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.