midi delta time - midi

i need help..
i need to know exactly midi delta time format?is it millisecond,tick or what??
and i need formula to convert timestamp in millisecond into midi delta time...
thanks before..

Delta time is always specified in ticks, which are determined by the PPQ (pulses per quarter note).
So given an offset in milliseconds, you must first convert that to samples (using the sample rate), and then to pulses based on the current tempo and the PPQ.

Related

Need to extract earliest and latest data reads from each day with multiple time stamps (seconds)

I have a very large csv file which contains multiple meter reads for 8 meters - the readings have been taken every few seconds. I want to create a summary showing the first and last meter read for each day and for each meter - how could I do that please?

iCalendar durations where the duration's date portion ends inside a DST discontinuity

RFC 5545 and other standards like JSCalendar define a P1DT12H duration as one nominal day plus 12 exact hours. Normally this will be 36 real-world ("exact" or "accurate") hours, but:
If a Spring DST transition happens during the "one nominal day" part of that duration, then the accurate duration will be only 35 hours.
If a Fall DST transition happens during the "one nominal day" part, then the accurate duration will be 37 hours.
But what if the starting date/time is exactly one nominal day before a discontinuous period? For example, a P1DT12H duration added to 2020-03-07T02:30 in America/Los_Angeles where DST starts at 2020-03-08T02:00. In that case, what should be the calculated local time at the end of that duration?
Is it 2020-03-08T14:30? 2020-03-08T13:30? 2020-03-08T15:30? Something else? Also: why?
The problem is that the naive way of calculating the exact duration would be to add the date portion of the duration using nominal units, then convert that intermediate result to UTC and add the time portion of the duration using exact time. But that intermediate result is an invalid nominal time that's skipped, then the local time of that intermediate value is 2020-03-08T03:30 (3:30AM, not 2:30AM) because RFC 5545 says:
If the local time described does not occur (when changing from standard to daylight time), the DATE-TIME value is interpreted using the UTC offset before the gap in local times.
So using that interpretation of the spec, the final result after adding the 12-exact-hour time portion should be 2020-03-08T15:30 or 3:30PM.
Is this the "correct" answer according to RFC 5455? If not, what should be the answer and why?
Or is this an ambiguity in the standard and there's no objectively correct answer?
I was hoping someone else would answer. Here is my understanding:
Two concepts here:
Either one has the DTEND and is calculating the DURATION, which as you have established, will vary if there is daylight saving change during the event, OR
one has the duration and is calculating the DTEND. It is best to do that in UTC for safety sake.
RE your question:
But what if the starting date/time is exactly one nominal day before a discontinuous period? In that case, what should be the calculated local time at the end of that duration?
For calculating DTEND, nominal day at same time takes us to invalid time. If one uses UTC to calc that nominal day, one gets 3.30 am. The spec says:
In the case of discontinuities in the time scale, such as the change
from standard time to daylight time and back, the computation of the
exact duration requires the subtraction or addition of the change of
duration of the discontinuity.
I understand this to mean yes, when working out the CALCULATED duration (ie where you have DTSTART and DTEND) will vary depending in the events point in the calendar, as you have noted.
RE your question
But that intermediate result is an invalid nominal time that's skipped, then the local time of that intermediate value is 2020-03-08T03:30 (3:30AM, not 2:30AM...."
Yes, however in calculating further I think you went wrong adding the 12H to the local time. Spec says use the earlier UTC offset, which I take to mean use that to get UTC time, use UTC for the calcs, then convert back.
If the local time described does not occur (when changing from
standard to daylight time), the DATE-TIME value is interpreted using
the UTC offset before the gap in local times.
Note this is the UTC offset. So one nominal day takes us to 2.30am which does not 'exist' in LA on 8 March, so we use the UTC offset before the time gap. -8 hours which gives us UTC=10h30.
Plus 12H gives us UTC 22H30.
If we stay with the -8 offset for calculation purposes, we get local time 14:30.
*It is not 100% spelled out in the specification that this is it. More worked examples to confirm would be good.
Advice I have seen elsewhere is to store times in UTC time, do the calcs in UTC time, then for display, calculate local time.*
RE:
Is it 2020-03-08T14:30?
Is this the "correct" answer according to RFC 5455? If not, what should be the answer and why?
I understand it to be 14H30. I cross checked using PHP, with calcs in LosAngeles and in UTC time before DST & during DST, using both datetime->add https://www.php.net/manual/en/datetime.add.php and https://www.php.net/manual/en/datetime.modify.php and consistently got that answer.
I think correct is 2020-03-08T14:30 because if one uses the UTC offset as specified and calcs in UTC, that is what one gets.
PHP Workings
add a nominal day P01D
Before DST:
2020-03-06T02:30:00-08:00
2020-03-07T02:30:00-08:00 with modify
2020-03-07T02:30:00-08:00 add date interval
Over DST:
2020-03-07T02:30:00-08:00
2020-03-08T03:30:00-07:00 with modify
2020-03-08T03:30:00-07:00 add date interval
add a nominal day plus 12 H ie: P01DT12H
Before DST:
2020-03-06T02:30:00-08:00
2020-03-07T14:30:00-08:00 add date interval
Over DST:
2020-03-07T02:30:00-08:00
2020-03-08T14:30:00-07:00 with modify
2020-03-08T14:30:00-07:00 add date interval
For checking offset: https://www.timeanddate.com/worldclock/meetingtime.html?day=8&month=3&year=2020&p1=137&iv=0

Convert timestamps to milliseconds - MATLAB

I have a bunch of files with timestamps associated with x and y coordinates. Currently the format of the timestamps is the following:
2016-11-08T15:55:01.7802880+00:00
I need to convert these into manipulatable format, as for example in milliseconds using matlab. I do not wan´t to extract only the milliseconds in the timestamps (example: .780), I need the absolute duration in milliseconds.
Thanks in advance!
Cheers
I'm sure there's a way to convert it with Matlab functions, but I've used this for the past little while.
Gets the job done.
ISO8601toserial.m File Exchange

Midi set tempo meta event

The Set Tempo Meta event itself contains a delta field as well. Is this delta defined in the previous tempo or in the new tempo (the tempo in this event)?
Thanks
Delta times are expressed in MIDI ticks, which are independent of tempo.
If you are calculating the real-time duration in microseconds of the delta time of the new tempo, you would use the MPQN of the previous tempo event to perform that calculation.

Converting MIDI ticks to actual playback seconds

I want to know how to convert MIDI ticks to actual playback seconds.
For example, if the MIDI PPQ (Pulses per quarter note) is 1120, how would I convert it into real world playback seconds?
The formula is 60000 / (BPM * PPQ) (milliseconds).
Where BPM is the tempo of the track (Beats Per Minute).
(i.e. a 120 BPM track would have a MIDI time of (60000 / (120 * 192)) or 2.604 ms for 1 tick.
If you don't know the BPM then you'll have to determine that first. MIDI times are entirely dependent on the track tempo.
You need two pieces of information:
PPQ (pulses per quarter note), which is defined in the header of a midi file, once.
Tempo (in microseconds per quarter note), which is defined by "Set Tempo" meta events and can change during the musical piece.
Ticks can be converted to playback seconds as follows:
ticks_per_quarter = <PPQ from the header>
µs_per_quarter = <Tempo in latest Set Tempo event>
µs_per_tick = µs_per_quarter / ticks_per_quarter
seconds_per_tick = µs_per_tick / 1.000.000
seconds = ticks * seconds_per_tick
Note that PPQ is also called "division" or "ticks per quarter note" in the document linked above.
Note that Tempo is commonly represented in BPM (a frequency) but raw MIDI represents it in µs per quarter (a period).