Skip to content

Commit 7d7dd4a

Browse files
committed
Fix for music being stopped after a few seconds
1 parent c1d2a13 commit 7d7dd4a

3 files changed

Lines changed: 80 additions & 4 deletions

File tree

README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#Steam Controller Singer
2+
3+
This project is a fork of [Pila's SteamControllerSinger](https://gitlab.com/Pilatomic/SteamControllerSinger) including a dirty fix to make the Steam Controller sing again.
4+
5+
##HOW TO
6+
7+
1. Turn on your Steam Controller
8+
9+
2. Drag the midi file onto steamcontrollersinger executable
10+
11+
3. When prompted, press ENTER
12+
13+
4. Enjoy!
14+
15+
16+
##MORE INFORMATIONS
17+
18+
Usage from command prompt :
19+
steamcontrollersinger [-r][-l DEBUG_LEVEL] [-i INTERVAL] MIDI_FILE"
20+
21+
-i INTERVAL argument to choose player sleep interval (in microseconds). Lower generally means better song fidelity, but higher cpu usage, and at some point goidn lower won't improve any more. Default value is 10000
22+
23+
-l DEBUG_LEVEL argument to choose libusb debug level. Default is 0, no debug output. max is 4, max verbosity output
24+
25+
-r to enable repeat mode, which plays continously (restart the song when finished)
26+
27+
28+
Midi files tips :
29+
Notes from midi channel 0 are played on right haptic
30+
Notes from midi channel 1 are played on left haptic
31+
Notes from others channels are ignored
32+
33+
Avoid multiple notes active at the same time on the same channel, since haptic actuators can only play one note
34+
35+
##CHANGELOG
36+
[V1.7]
37+
- Fixed music stopped playing after a few seconds
38+
39+
[V1.6]
40+
- Fixed major bugs in playback algorithm
41+
42+
[V1.5]
43+
- Changed debug level argument from -d to -l
44+
- Added -r argument to enable demo mode
45+
- Enhanced arguments parsing
46+
- Does not rely on Steam Controller duration anymore
47+
- Updated note display
48+
- Now stops playing when interrupting the process ( on Ctrl+C )
49+
50+
[V1.4]
51+
- Fixed a bug in MIDI librairie that would compute a null duration for notes when ON event and previous OFF event had the same timetick
52+
53+
[V1.3]
54+
- Added -iINTERVAL argument
55+
- Added -dDEBUG_LEVEL argument
56+
57+
[V1.2]
58+
- Fixed being stuck on "Command error" when disconnecting controller while playing. Now continue playing (even if keep failing)
59+
- Removed the now deprecated 20ms note duration reduction

main.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ struct SteamControllerInfos{
3636
SteamControllerInfos steamController1;
3737

3838

39-
bool SteamController_OpenAndClaim(SteamControllerInfos* controller){
39+
bool SteamController_Open(SteamControllerInfos* controller){
4040
if(!controller)
4141
return false;
4242

@@ -59,7 +59,11 @@ bool SteamController_OpenAndClaim(SteamControllerInfos* controller){
5959

6060
//On Linux, automatically detach and reattach kernel module
6161
libusb_set_auto_detach_kernel_driver(controller->dev_handle,1);
62+
63+
return true;
64+
}
6265

66+
bool SteamController_Claim(SteamControllerInfos* controller){
6367
//Claim the USB interface controlling the haptic actuators
6468
int r = libusb_claim_interface(controller->dev_handle,controller->interfaceNum);
6569
if(r < 0) {
@@ -79,7 +83,6 @@ void SteamController_Close(SteamControllerInfos* controller){
7983
std::cin.ignore();
8084
return;
8185
}
82-
libusb_close(controller->dev_handle);
8386
}
8487

8588

@@ -126,7 +129,7 @@ int SteamController_PlayNote(SteamControllerInfos* controller, int haptic, int n
126129
r = libusb_control_transfer(controller->dev_handle,0x21,9,0x0300,2,dataBlob,64,1000);
127130
if(r < 0) {
128131
cout<<"Command Error "<<r<< endl;
129-
return 1;
132+
exit(0);
130133
}
131134

132135
return 0;
@@ -199,9 +202,11 @@ void playSong(SteamControllerInfos* controller,const ParamsStruct params){
199202

200203
//Get current time point, will be used to know elapsed time
201204
std::chrono::steady_clock::time_point tOrigin = std::chrono::steady_clock::now();
205+
std::chrono::steady_clock::time_point tRestart = std::chrono::steady_clock::now();
202206

203207
//Iterate through events
204208
MidiFileEvent_t currentEvent = MidiFile_getFirstEvent(midifile);
209+
205210
while(currentEvent != NULL){
206211
usleep(params.intervalUSec);
207212

@@ -210,6 +215,13 @@ void playSong(SteamControllerInfos* controller,const ParamsStruct params){
210215

211216
//We now need to play all events with tick < currentTime
212217
long currentTick = MidiFile_getTickFromTime(midifile,timeElapsedSince(tOrigin));
218+
219+
//Every 5 seconds, reclaim the controller to avoid timeouts
220+
if(timeElapsedSince(tRestart) > 5){
221+
tRestart = std::chrono::steady_clock::now();
222+
SteamController_Close(&steamController1);
223+
SteamController_Claim(&steamController1);
224+
}
213225

214226
//Iterate through all events until the current time, and selecte potential events to play
215227
for( ; currentEvent != NULL && MidiFileEvent_getTick(currentEvent) < currentTick ; currentEvent = MidiFileEvent_getNextEventInFile(currentEvent)){
@@ -343,7 +355,10 @@ int main(int argc, char** argv)
343355
libusb_set_debug(NULL, params.libusbDebugLevel);
344356

345357
//Gaining access to Steam Controller
346-
if(!SteamController_OpenAndClaim(&steamController1)){
358+
if(!SteamController_Open(&steamController1)){
359+
return 1;
360+
}
361+
if(!SteamController_Claim(&steamController1)){
347362
return 1;
348363
}
349364

@@ -358,6 +373,8 @@ int main(int argc, char** argv)
358373

359374
//Releasing access to Steam Controller
360375
SteamController_Close(&steamController1);
376+
377+
libusb_close((&steamController1)->dev_handle);
361378

362379
libusb_exit(NULL);
363380

steamcontrollersinger

81.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)