[quote=“jrlanglois”]I don’t see anything wrong with the code in regards to how C++ is being used… I think you mean design? Which I don’t see anything wrong with that, either.
Regardless, convertTimestampTicksToSeconds() is related to a juce::MidiFile, which means that you should probably use that only in relation to loading MIDI files. Use your judgement!
Simply put; If you start mixing time formats (ie: setting tick timestamps for MIDI messages at one place, and seconds at another, and combining them), you’re asking for trouble. It should be clear how you’re setting such up, shouldn’t it?
I personally rather work with seconds for MIDI because I find it intuitive. 1 tick means nothing to me, especially without a nice zoomable piano roll at hand.[/quote]
Yeah I meant design you’re right, however a function returning doubles which are actually ints could be seen as a code problem, but I’m splitting hair here
I don’t think our applications do the same thing ! In mine, MidiFiles are mostly used for loading/saving midi sequences (so for example if someone converts the events timstamps to seconds at loading to display the length of the file, it breaks the rest of the code) . I also HAVE to use different time formats, because my “little DAW” uses audio and midi together.
You’re right, it is very clear how to set it up, what I meant is that normally (I don’t remember who I’m quoting), a lib should also be hard to misuse.
My only point is that in a project with several people, one of them can screw up other peoples code. That is of course always possible, but I like to have guards against that.
If you’re alone and you know what you’re doing, it’s not a problem at all
What about getEventTimeAsTicks and getEventTimeAsSeconds ?
That’s being said, in my own code, I use the “pointer to some kind of abstract time object” approach, and it works pretty well, and it’s quite powerful (handles tempo changes in real time for example) but, as you said, I have doubts about scalability ! That being said, the tests I’ve done so far, don’t show any overhead, and I tried to keep the Time class small, so it doesn’t use too much memory.
I also use some typedefs (SamplesNumber, TicksNumber, and so on …) which is very usefull to clearup the code and catch mistakes.
(For example SamplesNumber and TicksNumber are both a kind of unsigned int, but I can temporarily typedef SamplesNumber to float and I’ll have a warning everytime I try to assign a SampleNumber to a TickNumber at compile time. )
I personally like strong typing and to make my code fool-proof. Maybe because I make mistakes so often that I need the compiler to stop me ?