9 changed files with 121 additions and 0 deletions
			
			
		
								
									Binary file not shown.
								
							
						
					
								
									Binary file not shown.
								
							
						
					
								
									Binary file not shown.
								
							
						
					
								
									Binary file not shown.
								
							
						
					
								
									Binary file not shown.
								
							
						
					
								
									Binary file not shown.
								
							
						
					| @ -0,0 +1 @@ | |||||
|  | g++ -o main -I/usr/include/SDL2  main.cpp -lSDL2 -lSDL2_image -lSDL2_ttf -lSDL2_mixer | ||||
								
									Binary file not shown.
								
							
						
					| @ -0,0 +1,120 @@ | |||||
|  | #include <stdio.h> | ||||
|  | 
 | ||||
|  | #include "SDL.h" | ||||
|  | #include "SDL_mixer.h" | ||||
|  | #include "SDL_image.h" | ||||
|  | #include <unistd.h> | ||||
|  | #include <syslog.h> | ||||
|  | #include <string.h> | ||||
|  | #include <math.h> | ||||
|  | 
 | ||||
|  | #define NUM_WAVEFORMS 6 | ||||
|  | const char* _waveFileNames[] = { | ||||
|  |   "BANK1/1.wav", | ||||
|  |   "BANK1/2.wav", | ||||
|  |   "BANK1/3.wav", | ||||
|  |   "BANK1/4.wav", | ||||
|  |   "BANK1/5.wav", | ||||
|  |   "BANK1/6.wav", | ||||
|  | }; | ||||
|  | 
 | ||||
|  | Mix_Chunk* _sample[6]; | ||||
|  | 
 | ||||
|  | int Init(void) { | ||||
|  | 
 | ||||
|  |   memset(_sample, 0, sizeof(Mix_Chunk*) * 6); | ||||
|  | 
 | ||||
|  |   // Set up the audio stream
 | ||||
|  |   int result = Mix_OpenAudio(44100, AUDIO_S16SYS, 2, 512); | ||||
|  |   if( result < 0 ) { | ||||
|  |     fprintf(stderr, "Unable to open audio: %s\n", SDL_GetError()); | ||||
|  |     exit(-1); | ||||
|  |   } | ||||
|  | 
 | ||||
|  |   result = Mix_AllocateChannels(4); | ||||
|  |   if( result < 0 ) { | ||||
|  |     fprintf(stderr, "Unable to allocate mixing channels: %s\n", SDL_GetError()); | ||||
|  |     exit(-1); | ||||
|  |   } | ||||
|  | 
 | ||||
|  |   // Load waveforms
 | ||||
|  |   for( int i = 0; i < NUM_WAVEFORMS; i++ ) { | ||||
|  |     _sample[i] = Mix_LoadWAV(_waveFileNames[i]); | ||||
|  |     if( _sample[i] == NULL ) { | ||||
|  |       fprintf(stderr, "Unable to load wave file: %s\n", _waveFileNames[i]); | ||||
|  |     } | ||||
|  |   } | ||||
|  | 
 | ||||
|  |   return true; | ||||
|  | } | ||||
|  | 
 | ||||
|  | int main(int argc, char** argv) { | ||||
|  | 
 | ||||
|  |   SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO ); | ||||
|  |   atexit(SDL_Quit); | ||||
|  | 
 | ||||
|  |   SDL_Window* window = SDL_CreateWindow("Sonquencer", | ||||
|  |                                         SDL_WINDOWPOS_UNDEFINED, | ||||
|  |                                         SDL_WINDOWPOS_UNDEFINED, | ||||
|  |                                         800, | ||||
|  |                                         600, | ||||
|  |                                         SDL_WINDOW_RESIZABLE); | ||||
|  | 
 | ||||
|  |   if (Init() == false) { return -1;} | ||||
|  | 
 | ||||
|  |   SDL_Event Event; | ||||
|  | 
 | ||||
|  |   bool done = false; | ||||
|  |   while (!done) { | ||||
|  |     bool gotEvent = SDL_PollEvent(&Event); | ||||
|  | 
 | ||||
|  |     while (!done && gotEvent) { | ||||
|  |       switch (Event.type) { | ||||
|  |         case SDL_KEYDOWN: | ||||
|  | 
 | ||||
|  |           switch (Event.key.keysym.sym) { | ||||
|  |             case '1': | ||||
|  |               Mix_PlayChannel(-1, _sample[0], 0); | ||||
|  |               break; | ||||
|  |             case '2': | ||||
|  |               Mix_PlayChannel(-1, _sample[1], 0); | ||||
|  |               break; | ||||
|  |             case '3': | ||||
|  |               Mix_PlayChannel(-1, _sample[2], 0); | ||||
|  |               break; | ||||
|  |             case '4': | ||||
|  |               Mix_PlayChannel(-1, _sample[3], 0); | ||||
|  |               break; | ||||
|  |             case '5': | ||||
|  |               Mix_PlayChannel(-1, _sample[4], 0); | ||||
|  |               break; | ||||
|  |             case '6': | ||||
|  |               Mix_PlayChannel(-1, _sample[5], 0); | ||||
|  |               break; | ||||
|  |             default: | ||||
|  |               break; | ||||
|  |           } | ||||
|  |           break; | ||||
|  | 
 | ||||
|  |             case SDL_QUIT: | ||||
|  |               done = true; | ||||
|  |               break; | ||||
|  | 
 | ||||
|  |             default: | ||||
|  |               break; | ||||
|  |       } | ||||
|  |       if( !done ) { gotEvent = SDL_PollEvent(&Event); } | ||||
|  |     } | ||||
|  | 
 | ||||
|  |     usleep(1000); | ||||
|  | 
 | ||||
|  |   } | ||||
|  | 
 | ||||
|  |   for( int i = 0; i < NUM_WAVEFORMS; i++ ) { | ||||
|  |     Mix_FreeChunk(_sample[i]); | ||||
|  |   } | ||||
|  | 
 | ||||
|  |   Mix_CloseAudio(); | ||||
|  |   SDL_Quit(); | ||||
|  |   return 0; | ||||
|  | } | ||||
					Loading…
					
					
				
		Reference in new issue