-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
220 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"net/http" | ||
"os/exec" | ||
"runtime" | ||
"time" | ||
) | ||
|
||
var ( | ||
errAlreadyStarted = errors.New("Reaper already started") | ||
errUnknownOS = errors.New("Unknown operating system") | ||
errFailedToStart = errors.New("Failed to start Reaper") | ||
errRecodingFailed = errors.New("Failed to start recording") | ||
errRecordingStopFailed = errors.New("Failed to stop recording") | ||
errFailedToStop = errors.New("Failed to stop Reaper") | ||
errReaperNotStarted = errors.New("Reaper not started") | ||
) | ||
|
||
func startReaper() error { | ||
lock.Lock() | ||
defer lock.Unlock() | ||
|
||
var cmd *exec.Cmd | ||
|
||
if reaperProcess != nil && !reaperProcess.ProcessState.Exited() { | ||
return errAlreadyStarted | ||
} | ||
|
||
mediaList = listFiles(MediaGlob) | ||
|
||
if runtime.GOOS == "windows" { | ||
cmd = exec.Command("C:\\Program Files\\REAPER (x64)\\reaper.exe") | ||
} else if runtime.GOOS == "darwin" { | ||
cmd = exec.Command("/Applications/REAPER.app/Contents/MacOS/REAPER") | ||
} | ||
|
||
if cmd == nil { | ||
return errUnknownOS | ||
} | ||
|
||
err := cmd.Start() | ||
if err != nil { | ||
return errFailedToStart | ||
} | ||
|
||
reaperProcess = cmd | ||
|
||
if isReaperOn(40*time.Second) == false { | ||
return errRecodingFailed | ||
} | ||
|
||
_, err = http.Get(ReaperAddress + "/_/1013;TRANSPORT") | ||
if err != nil { | ||
return errRecodingFailed | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func stopReaper() error { | ||
lock.Lock() | ||
defer lock.Unlock() | ||
|
||
if reaperProcess == nil { | ||
return errReaperNotStarted | ||
} | ||
|
||
_, err := http.Get(ReaperAddress + "/_/40667;TRANSPORT") | ||
if err != nil { | ||
return errRecordingStopFailed | ||
} | ||
|
||
if err := stopProcess(reaperProcess.Process); err != nil { | ||
return errFailedToStop | ||
} | ||
|
||
reaperProcess = nil | ||
|
||
return nil | ||
} |
Oops, something went wrong.