bool SOUNDFILESAVER_save(const char *filename, enum SOUNDFILESAVER_what what_to_save, float samplerate, int libsndfile_format, float post_recording_length, const char **error_string){ PlayStop(); { SF_INFO sf_info; memset(&sf_info,0,sizeof(sf_info)); sf_info.samplerate = samplerate; sf_info.channels = 2; sf_info.format = libsndfile_format; { g_sndfile = sf_open(filename,SFM_WRITE,&sf_info); if(g_sndfile==NULL){ printf("Why: \"%s\"\n",sf_strerror(NULL)); if(error_string!=NULL) *error_string = sf_strerror(NULL); return false; } } } g_saving_was_successful = true; g_filename = talloc_strdup(filename); g_post_writing_left = post_recording_length; g_save_state=BEFORE_WRITING; PaUtil_FullMemoryBarrier(); { MIXER_start_saving_soundfile(); if(what_to_save==SAVE_SONG) PlaySongFromStart(root->song->tracker_windows); else PlayBlockFromStart(root->song->tracker_windows,false); } PaUtil_FullMemoryBarrier(); g_save_state=IS_WRITING; return true; }
bool OS_SYSTEM_KeyboardFilter(void *focused_widget, void *void_msg){ MSG *msg = void_msg; static int last_pressed_key = -1; static int64_t last_pressed_key_time = -1; static int last_pressed_keyswitch = -1; struct Tracker_Windows *window=root->song->tracker_windows; #if 0 static int num=0; if(msg->message!=WM_TIMER && msg->message!=0x84 && msg->message!=WM_MOUSEFIRST && msg->message!=WM_MOUSEMOVE && msg->message!=WM_SETCURSOR){ char *temp=""; printf("Got something. Message: 0x%x. wParam: 0x%x. lParam: 0x%x. Num: %d. Name: \"%s\", Left shift? 0x%x\n",(int)msg->message,(int)msg->wParam,(int)msg->lParam,num++,temp,(int)GetKeyState(VK_LSHIFT)); fflush(stdout); } #endif switch(msg->message){ case WM_HOTKEY: //printf("Got HotKey\n"); //fflush(stdout); return true; case WM_KEYDOWN: case WM_SYSKEYDOWN: if(num_users_of_keyboard>0) return false; tevent.ID=TR_KEYBOARD; tevent.SubID=get_keyboard_subID(msg); last_pressed_key = tevent.SubID; if(last_pressed_key_time==-1) last_pressed_key_time = MIXER_get_time(); tevent.keyswitch=get_keyswitch(); last_pressed_keyswitch = tevent.keyswitch; /* printf("____________ key down: %x. Switch down: %x, left ctrl: %x, left alt: %x, right ctrl: %x, right alt: %x\n", last_pressed_key,last_pressed_keyswitch, EVENT_LEFTCTRL, EVENT_LEFTALT, EVENT_RIGHTCTRL, EVENT_RIGHTALT ); */ EventReciever(&tevent,window); return true; case WM_KEYUP: case WM_SYSKEYUP: if(msg->wParam==VK_RWIN){ right_windows_down = false; return false; } if(msg->wParam==VK_LWIN){ left_windows_down = false; return false; } if(num_users_of_keyboard>0) return false; int keynum = get_keyboard_subID(msg); tevent.ID=TR_KEYBOARDUP; tevent.SubID=keynum; tevent.keyswitch=get_keyswitch(); int64_t time_now = MIXER_get_time(); //printf("____________ key: %x. Switch down: %x, Switch up: %x\n",keynum,last_pressed_keyswitch,tevent.keyswitch); //printf("keynum: %d, last_pressed: %d, ALT_R: %d, time_now: %d, last_time: %d, diff: %d\n",keynum,last_pressed_key,EVENT_ALT_R,(int)time_now,(int)last_pressed_key_time,(int)(time_now-last_pressed_key_time)); //fflush(stdout); if( (time_now-last_pressed_key_time) < pc->pfreq/4){ // i.e. only play if holding the key less than 0.25 seconds. bool isplaykeyswitch = (last_pressed_keyswitch & EVENT_RIGHTALT) || last_pressed_keyswitch==EVENT_RIGHTSHIFT; /* printf("****************** last_pressed_keyswitch: %x (%x) (%x) (%d)\n",last_pressed_keyswitch, EVENT_RIGHTALT, EVENT_LEFTALT|EVENT_LEFTCTRL, EVENT_RIGHTALT|EVENT_LEFTCTRL); printf("isplaykeyswitch: %d, keynum==last_pressed_key: %d, keynum==0: %d, (tevent.keyswitch==0: %d || (similar: %x/%x/%x))\n", isplaykeyswitch, keynum==last_pressed_key, keynum==0, tevent.keyswitch==0, tevent.keyswitch,EVENT_RIGHTALT,last_pressed_keyswitch); */ if (isplaykeyswitch) if(keynum==last_pressed_key && keynum==0 && (tevent.keyswitch==0 || (tevent.keyswitch==EVENT_RIGHTALT && EVENT_RIGHTALT==last_pressed_keyswitch))) PlayBlockFromStart(window,true); // true == do_loop } last_pressed_key_time = -1; EventReciever(&tevent,window); return true; default: break; } return false; }
void playBlockFromStart(int windownum){ struct Tracker_Windows *window=getWindowFromNum(windownum); if(window==NULL) return; PlayBlockFromStart(window,true); // true == do_loop }