Back To Schedule
Tuesday, November 19 • 12:00 - 12:25
Units of measurement in C++

Log in to save this to your schedule, view media, leave feedback and see who's attending!

When writing interfaces in C++ that are expected to operate on variables that units of measurement, it is common for represent these variables as a numeric type, like float or int, and then describe the expected unit using variable names. For every different type of unit a library writer wants to support, a different function must be written (for example: setDelayTimeInSeconds(double timeInSeconds), setDelayTimeInMilliseconds(double timeInMilliseconds), setDelayTimeInSamples(size_t numSamples)). This is tedious, and if these functions are member functions, changes to a different part of the class can result in needing to change multiple functions in some way. Alternatively, having a single function that can only operate on one type of unit can make calls to that function verbose, especially if different call sites have different types of units that need to be converted before being passed into the function.

In this talk, we'll look at how we can use the type system to enforce type correctness of the units we operate on. Conversion operators can be used to reduce the amount of overloads needed to handle different types of input, as well as automatically handle converting between different units. We'll look at how unit types can be used with JUCE's ADSR and StateVariableFilter classes, how they can be integrated with an AudioProcessorValueTreeState, and, time permitting, how to use a type that represents a periodic value to simplify the writing of an oscillator class.

avatar for Mark Jordan-Kamholz

Mark Jordan-Kamholz

Developer, Sinecure Audio
Mark Jordan-Kamholz is an Audio Software Developer and Designer. Currently based in Berlin, he has spent this year programming the sounds for Robert Henke's 8032av project in 6502 assembly. For the past 3 years, he has been making plugins in C++ using JUCE with his company Sinecure... Read More →

Tuesday November 19, 2019 12:00 - 12:25 GMT
Upper River Room Puddle Dock, London EC4V 3DB