Closed Firionus closed 2 years ago
waiting on #27 to finalize API and test against the server implementation
When adding new fixtures, the client needs to assign their DMX Addresses. By default it makes sense to put these in the "next free gap" of the approriate size. I wrote an algorithm in Kotlin to find these gaps:
/**
* Finds the first gap in [inputList] at or after [target]. The minimum size of the gap can be specified by [gapSize].
*
* [inputList] does not have to be sorted.
*/
fun nextGap(inputList: List<Int>, target: Int, gapSize: Int = 1): Int {
val list = inputList.sorted()
var firstCandidate = list.binarySearch(target)
if (firstCandidate < 0) {
// negative returned index means the targetFid does not exist in Patch yet
firstCandidate = -firstCandidate-1
}
var last: Int = target-1
var current: Int
for (i in firstCandidate..list.lastIndex) {
current = list[i]
if (current > last + gapSize) {
return last + 1
}
last = current
}
return last + 1
}
Note this algorithm does not consider the upper limit of 512 on DMX Addresses, so that needs to be added in an outer layer.
The associated unit test:
@Test
fun testFindGapAtOrAfter() {
val exampleArray = arrayOf(10,11,12,20,21,23)
exampleArray.shuffle(kotlin.random.Random(42))
val exampleList = exampleArray.asList()
// gapSize 1
assertEquals(1, nextGap(exampleList, 1))
assertEquals(3, nextGap(exampleList, 3))
assertEquals(13, nextGap(exampleList, 10))
assertEquals(13, nextGap(exampleList, 12))
assertEquals(19, nextGap(exampleList, 19))
assertEquals(22, nextGap(exampleList, 20))
assertEquals(22, nextGap(exampleList, 21))
assertEquals(22, nextGap(exampleList, 22))
assertEquals(24, nextGap(exampleList, 23))
assertEquals(24, nextGap(exampleList, 24))
// bigger gapSize
assertEquals(1, nextGap(exampleList, 1, 9))
assertEquals(24, nextGap(exampleList, 1, 10))
assertEquals(13, nextGap(exampleList, 12, 7))
assertEquals(24, nextGap(exampleList, 12, 8))
assertEquals(18, nextGap(exampleList, 18, 2))
assertEquals(24, nextGap(exampleList, 18, 3))
assertEquals(24, nextGap(exampleList, 23, 9))
assertEquals(24, nextGap(exampleList, 24, 9))
}
working on this on branch feature/patch-ui
Implement Patch UI according to Wireframes while leaving out non-essential features.
ToDo
after implementing API server-side:
Ensure Hotkey Help Dialog opens by pressing "?" on german keyboard (#51)fix WebSocket connection issue (only in firefox, needs minutes to properly connect, Chrome works) (#52)track https://forum.kee.pm/t/bug-firefox-the-kee-browser-extension-stalls-websocket-connections-to-localhost/3473change Reconnection Behavior to use HTTP for checking whether Server is up and only then try to connect WS once or twiceValidate incoming messages -> nah, it all comes from our own server, so we should be fine. If we want to do it in the future, we can use io-ts or something like thatChange Adress format to Universe.Address to avoid sorting issues, etc. -> don't know why I would want this as a user nowInstall a CSS-in-JS solution and use it throughout the code base (Emotion? Other ones?) (pushed to later date when we actually need it)Try if it can be solved with a custom editor and/or mutatorsPatch Tables (way too much work and Tabulator isn't an end solution anyway)Ommited Features
moved to other issues
Mockup