{"action":"created","comment":{"url":"https://api.github.com/repos/mixxxdj/mixxx/pulls/comments/47919013","id":47919013,"diff_hunk":"@@ -0,0 +1,115 @@\n+#ifndef UTIL_DURAITON_H\n+#define UTIL_DURAITON_H\n+\n+#include <QtGlobal>\n+#include <QMetaType>\n+#include <QString>\n+\n+namespace mixxx {\n+\n+// Represents a duration in a type-safe manner. Provides conversion methods to\n+// convert between physical units. Durations can be negative.\n+class Duration {\n+  public:\n+    // Returns a Duration object representing a duration of 'seconds'.\n+    static Duration fromSeconds(qint64 seconds) {\n+        return Duration(seconds * kNanosPerSecond);\n+    }\n+\n+    // Returns a Duration object representing a duration of 'millis'.\n+    static Duration fromMillis(qint64 millis) {\n+        return Duration(millis * kNanosPerMilli);\n+    }\n+\n+    // Returns a Duration object representing a duration of 'micros'.\n+    static Duration fromMicros(qint64 micros) {\n+        return Duration(micros * kNanosPerMicro);\n+    }\n+\n+    // Returns a Duration object representing a duration of 'nanos'.\n+    static Duration fromNanos(qint64 nanos) {\n+        return Duration(nanos);\n+    }\n+\n+    Duration() : m_timestamp_nanos(0) {}\n+\n+    // Returns the duration as an integer number of seconds (rounded-down).\n+    inline qint64 toSeconds() const {\n+        return m_timestamp_nanos / kNanosPerSecond;\n+    }\n+\n+    // Returns the duration as an integer number of milliseconds (rounded-down).\n+    inline qint64 toMillis() const {\n+        return m_timestamp_nanos / kNanosPerMilli;\n+    }\n+\n+    // Returns the duration as an integer number of microseconds (rounded-down).\n+    inline qint64 toMicros() const {\n+        return m_timestamp_nanos / kNanosPerMicro;\n+    }\n+\n+    // Returns the duration as an integer number of nanoseconds.\n+    inline qint64 toNanos() const {\n+        return m_timestamp_nanos;\n+    }\n+\n+    const Duration operator+(const Duration& other) const {\n+        Duration result = *this;\n+        result += other;\n+        return result;\n+    }\n+\n+    Duration& operator+=(const Duration& other) {\n+        m_timestamp_nanos += other.m_timestamp_nanos;\n+        return *this;\n+    }\n+\n+    const Duration operator-(const Duration& other) const {\n+        Duration result = *this;\n+        result -= other;\n+        return result;\n+    }\n+\n+    Duration& operator-=(const Duration& other) {\n+        m_timestamp_nanos -= other.m_timestamp_nanos;\n+        return *this;\n+    }\n+\n+    bool operator==(const Duration& other) const {\n+        return m_timestamp_nanos == other.m_timestamp_nanos;\n+    }\n+\n+    bool operator!=(const Duration& other) const {\n+        return !(*this == other);\n+    }\n+\n+    // Formats the duration as a two's-complement hexadecimal string.\n+    QString formatHex() const {\n+        // Format as fixed-width (8 digits).\n+        return \"0x\" + QString(\"%1\").arg(m_timestamp_nanos, 16, 16,\n+                                        QLatin1Char('0'));\n+    }\n+\n+    QString formatHumanReadable() const {\n+        return QString(\"%1 ns\").arg(m_timestamp_nanos);\n+    }\n+\n+  private:\n+    static const qint64 kMillisPerSecond = 1e3;\n+    static const qint64 kMicrosPerSecond = 1e6;\n+    static const qint64 kNanosPerSecond = 1e9;\n+    static const qint64 kNanosPerMilli = 1e6;\n+    static const qint64 kNanosPerMicro = 1e3;","path":"src/util/duration.h","position":102,"original_position":102,"commit_id":"15f101c8566e262c4ca8ce6e349e0245f9cb8c87","original_commit_id":"06c9c959740fdfc27c76fc21a87b666f45c16d17","user":{"login":"daschuer","id":1777442,"avatar_url":"https://avatars.githubusercontent.com/u/1777442?v=3","gravatar_id":"","url":"https://api.github.com/users/daschuer","html_url":"https://github.com/daschuer","followers_url":"https://api.github.com/users/daschuer/followers","following_url":"https://api.github.com/users/daschuer/following{/other_user}","gists_url":"https://api.github.com/users/daschuer/gists{/gist_id}","starred_url":"https://api.github.com/users/daschuer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daschuer/subscriptions","organizations_url":"https://api.github.com/users/daschuer/orgs","repos_url":"https://api.github.com/users/daschuer/repos","events_url":"https://api.github.com/users/daschuer/events{/privacy}","received_events_url":"https://api.github.com/users/daschuer/received_events","type":"User","site_admin":false},"body":"Oh sorry, I misread it. \r\nqint64 / int does not involve casting as well. \r\n ","created_at":"2015-12-17T15:33:01Z","updated_at":"2015-12-17T15:33:01Z","html_url":"https://github.com/mixxxdj/mixxx/pull/815#discussion_r47919013","pull_request_url":"https://api.github.com/repos/mixxxdj/mixxx/pulls/815","_links":{"self":{"href":"https://api.github.com/repos/mixxxdj/mixxx/pulls/comments/47919013"},"html":{"href":"https://github.com/mixxxdj/mixxx/pull/815#discussion_r47919013"},"pull_request":{"href":"https://api.github.com/repos/mixxxdj/mixxx/pulls/815"}}},"pull_request":{"url":"https://api.github.com/repos/mixxxdj/mixxx/pulls/815","id":53979383,"html_url":"https://github.com/mixxxdj/mixxx/pull/815","diff_url":"https://github.com/mixxxdj/mixxx/pull/815.diff","patch_url":"https://github.com/mixxxdj/mixxx/pull/815.patch","issue_url":"https://api.github.com/repos/mixxxdj/mixxx/issues/815","number":815,"state":"open","locked":false,"title":"Add controller message timestamps.","user":{"login":"rryan","id":26527,"avatar_url":"https://avatars.githubusercontent.com/u/26527?v=3","gravatar_id":"","url":"https://api.github.com/users/rryan","html_url":"https://github.com/rryan","followers_url":"https://api.github.com/users/rryan/followers","following_url":"https://api.github.com/users/rryan/following{/other_user}","gists_url":"https://api.github.com/users/rryan/gists{/gist_id}","starred_url":"https://api.github.com/users/rryan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rryan/subscriptions","organizations_url":"https://api.github.com/users/rryan/orgs","repos_url":"https://api.github.com/users/rryan/repos","events_url":"https://api.github.com/users/rryan/events{/privacy}","received_events_url":"https://api.github.com/users/rryan/received_events","type":"User","site_admin":false},"body":"Not ready for merge -- just looking for feedback and happened to do this on the 1.12 branch.\r\n\r\n* Adds a Duration helper class.\r\n* Attaches timestamps to MIDI/HID/Bulk messages and prints them with --controllerDebug\r\n\r\nPortMIDI is the only API that provides us with a timestamp. We should work out how to get better timestamps from HIDAPI, HSS1394, and libusb.","created_at":"2015-12-17T14:03:03Z","updated_at":"2015-12-17T15:33:01Z","closed_at":null,"merged_at":null,"merge_commit_sha":"329bf4c4f0827f3566f765b173085d754ff4771b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mixxxdj/mixxx/pulls/815/commits","review_comments_url":"https://api.github.com/repos/mixxxdj/mixxx/pulls/815/comments","review_comment_url":"https://api.github.com/repos/mixxxdj/mixxx/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mixxxdj/mixxx/issues/815/comments","statuses_url":"https://api.github.com/repos/mixxxdj/mixxx/statuses/15f101c8566e262c4ca8ce6e349e0245f9cb8c87","head":{"label":"rryan:timestamps","ref":"timestamps","sha":"15f101c8566e262c4ca8ce6e349e0245f9cb8c87","user":{"login":"rryan","id":26527,"avatar_url":"https://avatars.githubusercontent.com/u/26527?v=3","gravatar_id":"","url":"https://api.github.com/users/rryan","html_url":"https://github.com/rryan","followers_url":"https://api.github.com/users/rryan/followers","following_url":"https://api.github.com/users/rryan/following{/other_user}","gists_url":"https://api.github.com/users/rryan/gists{/gist_id}","starred_url":"https://api.github.com/users/rryan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rryan/subscriptions","organizations_url":"https://api.github.com/users/rryan/orgs","repos_url":"https://api.github.com/users/rryan/repos","events_url":"https://api.github.com/users/rryan/events{/privacy}","received_events_url":"https://api.github.com/users/rryan/received_events","type":"User","site_admin":false},"repo":{"id":10690290,"name":"mixxx","full_name":"rryan/mixxx","owner":{"login":"rryan","id":26527,"avatar_url":"https://avatars.githubusercontent.com/u/26527?v=3","gravatar_id":"","url":"https://api.github.com/users/rryan","html_url":"https://github.com/rryan","followers_url":"https://api.github.com/users/rryan/followers","following_url":"https://api.github.com/users/rryan/following{/other_user}","gists_url":"https://api.github.com/users/rryan/gists{/gist_id}","starred_url":"https://api.github.com/users/rryan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rryan/subscriptions","organizations_url":"https://api.github.com/users/rryan/orgs","repos_url":"https://api.github.com/users/rryan/repos","events_url":"https://api.github.com/users/rryan/events{/privacy}","received_events_url":"https://api.github.com/users/rryan/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/rryan/mixxx","description":"Mixxx is Free DJ software that gives you everything you need to perform live mixes.","fork":true,"url":"https://api.github.com/repos/rryan/mixxx","forks_url":"https://api.github.com/repos/rryan/mixxx/forks","keys_url":"https://api.github.com/repos/rryan/mixxx/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rryan/mixxx/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rryan/mixxx/teams","hooks_url":"https://api.github.com/repos/rryan/mixxx/hooks","issue_events_url":"https://api.github.com/repos/rryan/mixxx/issues/events{/number}","events_url":"https://api.github.com/repos/rryan/mixxx/events","assignees_url":"https://api.github.com/repos/rryan/mixxx/assignees{/user}","branches_url":"https://api.github.com/repos/rryan/mixxx/branches{/branch}","tags_url":"https://api.github.com/repos/rryan/mixxx/tags","blobs_url":"https://api.github.com/repos/rryan/mixxx/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rryan/mixxx/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rryan/mixxx/git/refs{/sha}","trees_url":"https://api.github.com/repos/rryan/mixxx/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rryan/mixxx/statuses/{sha}","languages_url":"https://api.github.com/repos/rryan/mixxx/languages","stargazers_url":"https://api.github.com/repos/rryan/mixxx/stargazers","contributors_url":"https://api.github.com/repos/rryan/mixxx/contributors","subscribers_url":"https://api.github.com/repos/rryan/mixxx/subscribers","subscription_url":"https://api.github.com/repos/rryan/mixxx/subscription","commits_url":"https://api.github.com/repos/rryan/mixxx/commits{/sha}","git_commits_url":"https://api.github.com/repos/rryan/mixxx/git/commits{/sha}","comments_url":"https://api.github.com/repos/rryan/mixxx/comments{/number}","issue_comment_url":"https://api.github.com/repos/rryan/mixxx/issues/comments{/number}","contents_url":"https://api.github.com/repos/rryan/mixxx/contents/{+path}","compare_url":"https://api.github.com/repos/rryan/mixxx/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rryan/mixxx/merges","archive_url":"https://api.github.com/repos/rryan/mixxx/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rryan/mixxx/downloads","issues_url":"https://api.github.com/repos/rryan/mixxx/issues{/number}","pulls_url":"https://api.github.com/repos/rryan/mixxx/pulls{/number}","milestones_url":"https://api.github.com/repos/rryan/mixxx/milestones{/number}","notifications_url":"https://api.github.com/repos/rryan/mixxx/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rryan/mixxx/labels{/name}","releases_url":"https://api.github.com/repos/rryan/mixxx/releases{/id}","created_at":"2013-06-14T14:11:10Z","updated_at":"2014-09-27T19:25:20Z","pushed_at":"2015-12-17T15:00:14Z","git_url":"git://github.com/rryan/mixxx.git","ssh_url":"git@github.com:rryan/mixxx.git","clone_url":"https://github.com/rryan/mixxx.git","svn_url":"https://github.com/rryan/mixxx","homepage":"http://mixxx.org","size":257470,"stargazers_count":1,"watchers_count":1,"language":"TypeScript","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":2,"forks":2,"open_issues":2,"watchers":1,"default_branch":"master"}},"base":{"label":"mixxxdj:1.12","ref":"1.12","sha":"2e75b0a1b90946a84929913dddbb8799222a842b","user":{"login":"mixxxdj","id":1743769,"avatar_url":"https://avatars.githubusercontent.com/u/1743769?v=3","gravatar_id":"","url":"https://api.github.com/users/mixxxdj","html_url":"https://github.com/mixxxdj","followers_url":"https://api.github.com/users/mixxxdj/followers","following_url":"https://api.github.com/users/mixxxdj/following{/other_user}","gists_url":"https://api.github.com/users/mixxxdj/gists{/gist_id}","starred_url":"https://api.github.com/users/mixxxdj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mixxxdj/subscriptions","organizations_url":"https://api.github.com/users/mixxxdj/orgs","repos_url":"https://api.github.com/users/mixxxdj/repos","events_url":"https://api.github.com/users/mixxxdj/events{/privacy}","received_events_url":"https://api.github.com/users/mixxxdj/received_events","type":"Organization","site_admin":false},"repo":{"id":10126031,"name":"mixxx","full_name":"mixxxdj/mixxx","owner":{"login":"mixxxdj","id":1743769,"avatar_url":"https://avatars.githubusercontent.com/u/1743769?v=3","gravatar_id":"","url":"https://api.github.com/users/mixxxdj","html_url":"https://github.com/mixxxdj","followers_url":"https://api.github.com/users/mixxxdj/followers","following_url":"https://api.github.com/users/mixxxdj/following{/other_user}","gists_url":"https://api.github.com/users/mixxxdj/gists{/gist_id}","starred_url":"https://api.github.com/users/mixxxdj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mixxxdj/subscriptions","organizations_url":"https://api.github.com/users/mixxxdj/orgs","repos_url":"https://api.github.com/users/mixxxdj/repos","events_url":"https://api.github.com/users/mixxxdj/events{/privacy}","received_events_url":"https://api.github.com/users/mixxxdj/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mixxxdj/mixxx","description":"Mixxx is Free DJ software that gives you everything you need to perform live mixes.","fork":false,"url":"https://api.github.com/repos/mixxxdj/mixxx","forks_url":"https://api.github.com/repos/mixxxdj/mixxx/forks","keys_url":"https://api.github.com/repos/mixxxdj/mixxx/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mixxxdj/mixxx/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mixxxdj/mixxx/teams","hooks_url":"https://api.github.com/repos/mixxxdj/mixxx/hooks","issue_events_url":"https://api.github.com/repos/mixxxdj/mixxx/issues/events{/number}","events_url":"https://api.github.com/repos/mixxxdj/mixxx/events","assignees_url":"https://api.github.com/repos/mixxxdj/mixxx/assignees{/user}","branches_url":"https://api.github.com/repos/mixxxdj/mixxx/branches{/branch}","tags_url":"https://api.github.com/repos/mixxxdj/mixxx/tags","blobs_url":"https://api.github.com/repos/mixxxdj/mixxx/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mixxxdj/mixxx/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mixxxdj/mixxx/git/refs{/sha}","trees_url":"https://api.github.com/repos/mixxxdj/mixxx/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mixxxdj/mixxx/statuses/{sha}","languages_url":"https://api.github.com/repos/mixxxdj/mixxx/languages","stargazers_url":"https://api.github.com/repos/mixxxdj/mixxx/stargazers","contributors_url":"https://api.github.com/repos/mixxxdj/mixxx/contributors","subscribers_url":"https://api.github.com/repos/mixxxdj/mixxx/subscribers","subscription_url":"https://api.github.com/repos/mixxxdj/mixxx/subscription","commits_url":"https://api.github.com/repos/mixxxdj/mixxx/commits{/sha}","git_commits_url":"https://api.github.com/repos/mixxxdj/mixxx/git/commits{/sha}","comments_url":"https://api.github.com/repos/mixxxdj/mixxx/comments{/number}","issue_comment_url":"https://api.github.com/repos/mixxxdj/mixxx/issues/comments{/number}","contents_url":"https://api.github.com/repos/mixxxdj/mixxx/contents/{+path}","compare_url":"https://api.github.com/repos/mixxxdj/mixxx/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mixxxdj/mixxx/merges","archive_url":"https://api.github.com/repos/mixxxdj/mixxx/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mixxxdj/mixxx/downloads","issues_url":"https://api.github.com/repos/mixxxdj/mixxx/issues{/number}","pulls_url":"https://api.github.com/repos/mixxxdj/mixxx/pulls{/number}","milestones_url":"https://api.github.com/repos/mixxxdj/mixxx/milestones{/number}","notifications_url":"https://api.github.com/repos/mixxxdj/mixxx/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mixxxdj/mixxx/labels{/name}","releases_url":"https://api.github.com/repos/mixxxdj/mixxx/releases{/id}","created_at":"2013-05-17T15:14:38Z","updated_at":"2015-12-15T11:08:03Z","pushed_at":"2015-12-17T15:00:15Z","git_url":"git://github.com/mixxxdj/mixxx.git","ssh_url":"git@github.com:mixxxdj/mixxx.git","clone_url":"https://github.com/mixxxdj/mixxx.git","svn_url":"https://github.com/mixxxdj/mixxx","homepage":"http://mixxx.org","size":264190,"stargazers_count":408,"watchers_count":408,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":270,"mirror_url":null,"open_issues_count":70,"forks":270,"open_issues":70,"watchers":408,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mixxxdj/mixxx/pulls/815"},"html":{"href":"https://github.com/mixxxdj/mixxx/pull/815"},"issue":{"href":"https://api.github.com/repos/mixxxdj/mixxx/issues/815"},"comments":{"href":"https://api.github.com/repos/mixxxdj/mixxx/issues/815/comments"},"review_comments":{"href":"https://api.github.com/repos/mixxxdj/mixxx/pulls/815/comments"},"review_comment":{"href":"https://api.github.com/repos/mixxxdj/mixxx/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mixxxdj/mixxx/pulls/815/commits"},"statuses":{"href":"https://api.github.com/repos/mixxxdj/mixxx/statuses/15f101c8566e262c4ca8ce6e349e0245f9cb8c87"}}}}