Comments (1)
I try to set different TPQ with method setTPQ, but the actual ticks do not change accordingly.
Yes, setting the TPQ/PPQN value just changes that value in the MIDI header and does not change the timestamps within the file.
I added an example program to do what you want:
https://github.com/craigsapp/midifile/blob/master/src-programs/retick.cpp
The main contents of the program that do all of the work:
midifile/src-programs/retick.cpp
Lines 41 to 52 in 7b7dcc3
factor
rescales the absolute tick timestamps by the given factor to convert from the old TPQ to the new TPQ.
Demonstration (in linux/unix):
make
cd bin
./createmidifile2 # this creates twinkle.mid with TPQ set to 120
./retick twinkle.mid -t 100 twinkle100.mid # convert timestamps to quarter note = 100 ticks
./retick twinkle.mid -t 100 # display output in ASCII format
Here is the result of ./retick twinkle.mid -t 100
:
"MThd" ; MIDI header chunk marker
4'6 ; bytes to follow in header chunk
2'1 ; file format: Type-1 (multitrack)
2'3 ; number of tracks
2'100 ; ticks per quarter note
;;; TRACK 0 ----------------------------------
"MTrk" ; MIDI track chunk marker
4'43 ; bytes to follow in track chunk
v0 ff 3 v28 "Twinkle, Twinkle Little Star" ; track name
v0 ff 51 v3 t104 ; tempo
v0 ff 2f v0 ; end-of-track
;;; TRACK 1 ----------------------------------
"MTrk" ; MIDI track chunk marker
4'131 ; bytes to follow in track chunk
v0 ff 3 v6 "Melody" ; track name
v0 c0 '40 ; patch-change
v0 90 '72 '64 ; note-on C5
v100 80 '72 '64 ; note-off C5
v0 90 '72 '64 ; note-on C5
v100 80 '72 '64 ; note-off C5
v0 90 '79 '64 ; note-on G5
v100 80 '79 '64 ; note-off G5
v0 90 '79 '64 ; note-on G5
v100 80 '79 '64 ; note-off G5
v0 90 '81 '64 ; note-on A5
v100 80 '81 '64 ; note-off A5
v0 90 '81 '64 ; note-on A5
v100 80 '81 '64 ; note-off A5
v0 90 '79 '64 ; note-on G5
v200 80 '79 '64 ; note-off G5
v0 90 '77 '64 ; note-on F5
v100 80 '77 '64 ; note-off F5
v0 90 '77 '64 ; note-on F5
v100 80 '77 '64 ; note-off F5
v0 90 '76 '64 ; note-on E5
v100 80 '76 '64 ; note-off E5
v0 90 '76 '64 ; note-on E5
v100 80 '76 '64 ; note-off E5
v0 90 '74 '64 ; note-on D5
v100 80 '74 '64 ; note-off D5
v0 90 '74 '64 ; note-on D5
v100 80 '74 '64 ; note-off D5
v0 90 '72 '64 ; note-on C5
v200 80 '72 '64 ; note-off C5
v0 ff 2f v0 ; end-of-track
;;; TRACK 2 ----------------------------------
"MTrk" ; MIDI track chunk marker
4'141 ; bytes to follow in track chunk
v0 ff 3 v9 "Bass line" ; track name
v0 c1 '58 ; patch-change
v0 91 '48 '90 ; note-on C3
v100 81 '48 '90 ; note-off C3
v0 91 '60 '90 ; note-on C4
v100 81 '60 '90 ; note-off C4
v0 91 '64 '90 ; note-on E4
v100 81 '64 '90 ; note-off E4
v0 91 '60 '90 ; note-on C4
v100 81 '60 '90 ; note-off C4
v0 91 '65 '90 ; note-on F4
v100 81 '65 '90 ; note-off F4
v0 91 '60 '90 ; note-on C4
v100 81 '60 '90 ; note-off C4
v0 91 '64 '90 ; note-on E4
v100 81 '64 '90 ; note-off E4
v0 91 '60 '90 ; note-on C4
v100 81 '60 '90 ; note-off C4
v0 91 '62 '90 ; note-on D4
v100 81 '62 '90 ; note-off D4
v0 91 '59 '90 ; note-on B3
v100 81 '59 '90 ; note-off B3
v0 91 '60 '90 ; note-on C4
v100 81 '60 '90 ; note-off C4
v0 91 '57 '90 ; note-on A3
v100 81 '57 '90 ; note-off A3
v0 91 '53 '90 ; note-on F3
v100 81 '53 '90 ; note-off F3
v0 91 '55 '90 ; note-on G3
v100 81 '55 '90 ; note-off G3
v0 91 '48 '90 ; note-on C3
v200 81 '48 '90 ; note-off C3
v0 ff 2f v0 ; end-of-track
And here is the output of the command
./retick twinkle.mid -t 960
"MThd" ; MIDI header chunk marker
4'6 ; bytes to follow in header chunk
2'1 ; file format: Type-1 (multitrack)
2'3 ; number of tracks
2'960 ; ticks per quarter note
;;; TRACK 0 ----------------------------------
"MTrk" ; MIDI track chunk marker
4'43 ; bytes to follow in track chunk
v0 ff 3 v28 "Twinkle, Twinkle Little Star" ; track name
v0 ff 51 v3 t104 ; tempo
v0 ff 2f v0 ; end-of-track
;;; TRACK 1 ----------------------------------
"MTrk" ; MIDI track chunk marker
4'143 ; bytes to follow in track chunk
v0 ff 3 v6 "Melody" ; track name
v0 c0 '40 ; patch-change
v0 90 '72 '64 ; note-on C5
v960 80 '72 '64 ; note-off C5
v0 90 '72 '64 ; note-on C5
v960 80 '72 '64 ; note-off C5
v0 90 '79 '64 ; note-on G5
v960 80 '79 '64 ; note-off G5
v0 90 '79 '64 ; note-on G5
v960 80 '79 '64 ; note-off G5
v0 90 '81 '64 ; note-on A5
v960 80 '81 '64 ; note-off A5
v0 90 '81 '64 ; note-on A5
v960 80 '81 '64 ; note-off A5
v0 90 '79 '64 ; note-on G5
v1920 80 '79 '64 ; note-off G5
v0 90 '77 '64 ; note-on F5
v960 80 '77 '64 ; note-off F5
v0 90 '77 '64 ; note-on F5
v960 80 '77 '64 ; note-off F5
v0 90 '76 '64 ; note-on E5
v960 80 '76 '64 ; note-off E5
v0 90 '76 '64 ; note-on E5
v960 80 '76 '64 ; note-off E5
v0 90 '74 '64 ; note-on D5
v960 80 '74 '64 ; note-off D5
v0 90 '74 '64 ; note-on D5
v960 80 '74 '64 ; note-off D5
v0 90 '72 '64 ; note-on C5
v1920 80 '72 '64 ; note-off C5
v0 ff 2f v0 ; end-of-track
;;; TRACK 2 ----------------------------------
"MTrk" ; MIDI track chunk marker
4'155 ; bytes to follow in track chunk
v0 ff 3 v9 "Bass line" ; track name
v0 c1 '58 ; patch-change
v0 91 '48 '90 ; note-on C3
v960 81 '48 '90 ; note-off C3
v0 91 '60 '90 ; note-on C4
v960 81 '60 '90 ; note-off C4
v0 91 '64 '90 ; note-on E4
v960 81 '64 '90 ; note-off E4
v0 91 '60 '90 ; note-on C4
v960 81 '60 '90 ; note-off C4
v0 91 '65 '90 ; note-on F4
v960 81 '65 '90 ; note-off F4
v0 91 '60 '90 ; note-on C4
v960 81 '60 '90 ; note-off C4
v0 91 '64 '90 ; note-on E4
v960 81 '64 '90 ; note-off E4
v0 91 '60 '90 ; note-on C4
v960 81 '60 '90 ; note-off C4
v0 91 '62 '90 ; note-on D4
v960 81 '62 '90 ; note-off D4
v0 91 '59 '90 ; note-on B3
v960 81 '59 '90 ; note-off B3
v0 91 '60 '90 ; note-on C4
v960 81 '60 '90 ; note-off C4
v0 91 '57 '90 ; note-on A3
v960 81 '57 '90 ; note-off A3
v0 91 '53 '90 ; note-on F3
v960 81 '53 '90 ; note-off F3
v0 91 '55 '90 ; note-on G3
v960 81 '55 '90 ; note-off G3
v0 91 '48 '90 ; note-on C3
v1920 81 '48 '90 ; note-off C3
v0 ff 2f v0 ; end-of-track
from midifile.
Related Issues (20)
- How to get sub tracks HOT 3
- Channel number is off by one HOT 3
- Undefined References HOT 2
- cmake fails looking for midicater.cpp HOT 2
- AppVeyor trying to compile hum2mid HOT 1
- Codefactor pull request related to rand vs. rand_r
- upgrade to lock free wait free data structures instead of using std::vector
- comparison of constant -1 with expression of type 'char' is always false HOT 1
- documentation question
- Please add the 'install' target HOT 7
- The 'midicat' program conflicts with sndio HOT 2
- Add import/export of base64-encoded MIDI files HOT 1
- Failed to parse some midi files HOT 1
- bug: useless code in MidiFile::getAbsoluteTickTime HOT 1
- Installation and building of tools should be optional with CMake
- Read and write MIDI files streamly HOT 1
- MIDI 2.0 Support HOT 1
- Can we publish release code with version?
- ausing offset HOT 1
- Add tuning changes HOT 5
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 midifile.