-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathkeybinds.go
167 lines (154 loc) · 3.32 KB
/
keybinds.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package main
import (
"log"
"github.com/mum4k/termdash/keyboard"
)
type keybind struct {
key keyboard.Key
desc string
callback func()
}
func getAvailableKeybinds() []keybind {
var keys []keybind
if !isRecordingTake {
keys = append(keys, []keybind{
{
key: keyboard.KeyArrowDown,
desc: "Next Chunk",
callback: keybindNextChunk,
},
{
key: keyboard.KeyArrowUp,
desc: "Previous Chunk",
callback: keybindPreviousChunk,
},
{
key: ' ',
desc: "Start Take",
callback: func() { startTake(false) },
},
{
key: 's',
desc: "Start Sync Take",
callback: func() { startTake(true) },
},
{
key: 'r',
desc: "End Session",
callback: keybindEndSession,
},
}...)
if len(currentSession.Doc.headers) > 0 && len(currentSession.Doc.GetChunk(int(selectedChunk)).Takes) > 0 {
keys = append(keys, []keybind{
{
key: 'g',
desc: "Mark Good",
callback: keybindMarkGood,
},
{
key: 'b',
desc: "Mark Bad",
callback: keybindMarkBad,
},
{
key: 'p',
desc: "Play Selected Take",
callback: keybindPlayTake,
},
}...)
}
if ui.audio.selectionActive {
keys = append(keys,
keybind{
key: 't',
desc: "New Take from selection",
callback: keybindCreateTakeFromSelection,
},
)
}
} else {
keys = append(keys, []keybind{
{
key: ' ',
desc: "End Take",
callback: func() { endTake() },
},
{
key: 'g',
desc: "End Take & Mark Good",
callback: keybindMarkGood,
},
{
key: 'b',
desc: "End Take & Mark Bad",
callback: keybindMarkBad,
},
}...)
}
keys = append(keys, []keybind{
{
key: 'f',
desc: "Toggle Stick Viewport To End",
callback: func() { ui.audio.stickToEnd = !ui.audio.stickToEnd },
},
{
key: keyboard.KeyCtrlD,
desc: "Toggle Debug",
callback: func() { ui.audio.showDebug = !ui.audio.showDebug },
},
}...)
return keys
}
func keybindPreviousChunk() {
if isRecordingTake {
return
}
if selectedChunk > 0 {
selectedChunk -= 1
}
chunk := currentSession.Doc.GetChunk(int(selectedChunk))
selectedTake = len(chunk.Takes) - 1
}
func keybindNextChunk() {
if isRecordingTake {
return
}
if selectedChunk < uint(currentSession.Doc.CountChunks()-1) {
selectedChunk += 1
}
chunk := currentSession.Doc.GetChunk(int(selectedChunk))
selectedTake = len(chunk.Takes) - 1
}
func keybindMarkGood() {
currentSession.Doc.GetChunk(int(selectedChunk)).Takes[selectedTake].Mark = Good
if isRecordingTake {
endTake()
}
}
func keybindMarkBad() {
currentSession.Doc.GetChunk(int(selectedChunk)).Takes[selectedTake].Mark = Bad
if isRecordingTake {
endTake()
}
}
func keybindCreateTakeFromSelection() {
if ui.audio.selectionActive {
chunk := currentSession.Doc.GetChunk(int(selectedChunk))
take := Take{}
take.Start = ui.audio.selected.Start
take.End = ui.audio.selected.End
chunk.Takes = append(chunk.Takes, take)
selectedTake = len(chunk.Takes) - 1
ui.audio.Deselect()
}
}
func keybindEndSession() {
err := EndSession()
if err != nil {
log.Print(err)
}
}
func keybindPlayTake() {
take := currentSession.Doc.GetChunk(int(selectedChunk)).Takes[selectedTake]
go playbackTake(take)
}