Mercurial > hg > dmlib
changeset 147:ead759da30b4
Various improvements, implement channel muting.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 05 Oct 2012 09:38:50 +0300 |
parents | 3226778033fd |
children | 6a838784fb3a |
files | ppl.c |
diffstat | 1 files changed, 87 insertions(+), 43 deletions(-) [+] |
line wrap: on
line diff
--- a/ppl.c Fri Oct 05 09:38:35 2012 +0300 +++ b/ppl.c Fri Oct 05 09:38:50 2012 +0300 @@ -16,11 +16,19 @@ SDL_Surface *screen; SDL_Event event; int optScrWidth, optScrHeight, optVFlags, optScrDepth; + + int actChannel; + BOOL pauseFlag; + + JSSModule *mod; + JSSMixer *dev; + JSSPlayer *plr; + SDL_AudioSpec afmt; } engine; struct { - Uint32 boxBg, inboxBg, box1, box2, viewDiv, activeRow; + Uint32 boxBg, inboxBg, box1, box2, viewDiv, activeRow, activeChannel; } col; @@ -233,6 +241,7 @@ col.box2 = dmCol(0.3, 0.3, 0.15); col.viewDiv = dmCol(0,0,0); col.activeRow = dmCol(0.5,0.4,0.1); + col.activeChannel = dmCol(0.6, 0.8, 0.2); return TRUE; } @@ -325,14 +334,23 @@ } -void dmDisplayPattern(SDL_Surface *screen, int x0, int y0, int x1, int y1, JSSPattern *pat, int row, int choffs) +void dmDisplayPattern(SDL_Surface *screen, int x0, int y0, int x1, int y1, JSSPattern *pat, int row) { int cwidth = (font->width * 10 + 3 * 4 + 5), lwidth = 6 + font->width * 3, qwidth = ((x1 - x0 - lwidth) / cwidth), qheight = ((y1 - y0 - 4) / (font->height + 1)), - nrow, nchannel, yc, + nrow, nchannel, yc, choffs, midrow = qheight / 2; + + if (engine.actChannel < qwidth / 2) + choffs = 0; + else + if (engine.actChannel >= pat->nchannels - qwidth/2) + choffs = pat->nchannels - qwidth; + else + choffs = engine.actChannel - qwidth/2; + dmDrawBox3D(screen, x0 + lwidth, y0, x1, y1, col.inboxBg, col.box2, col.box1); @@ -340,9 +358,22 @@ yc = y0 + 2 + (font->height + 1) * midrow; dmFillRect(screen, x0 + lwidth + 1, yc - 1, x1 - 1, yc + font->height, col.activeRow); - for (nchannel = 1; nchannel < qwidth; nchannel++) + for (nchannel = 0; nchannel < qwidth; nchannel++) { - dmDrawVLine(screen, y0 + 1, y1 - 1, x0 + lwidth + 1 + nchannel * cwidth, col.viewDiv); + int bx0 = x0 + lwidth + 1 + nchannel * cwidth, + bx1 = bx0 + cwidth; + + if (engine.actChannel == nchannel + choffs) + { + dmFillRect(screen, bx0+1, y0 + 1, bx1-1, y1 - 1, col.activeChannel); + } + + dmDrawVLine(screen, y0 + 1, y1 - 1, bx1, col.viewDiv); + + if (jvmGetMute(engine.dev, nchannel + choffs)) + { + dmDrawBMTextConstQ(screen, font, DMD_TRANSPARENT, bx0 + 10, y1, "MUTED"); + } } for (nrow = 0; nrow < qheight; nrow++) @@ -382,13 +413,8 @@ { BOOL initSDL = FALSE; DMResource *file = NULL; - JSSModule *mod = NULL; - JSSMixer *dev = NULL; - JSSPlayer *plr = NULL; - SDL_AudioSpec afmt; int result = -1; - memset(&afmt, 0, sizeof(afmt)); memset(&engine, 0, sizeof(engine)); engine.optScrWidth = 640; @@ -423,7 +449,7 @@ dmMsg(1, "Reading file: %s\n", optFilename); #ifdef JSS_SUP_XM dmMsg(2, "* Trying XM...\n"); - result = jssLoadXM(file, &mod); + result = jssLoadXM(file, &engine.mod); #endif #ifdef JSS_SUP_JSSMOD if (result != 0) @@ -439,7 +465,7 @@ bufgot, dmferror(file), dmErrorStr(dmferror(file))); goto error_exit; } - result = jssLoadJSSMOD(buf, bufsize, &mod); + result = jssLoadJSSMOD(buf, bufsize, &engine.mod); dmFree(buf); } #endif @@ -453,7 +479,7 @@ } // Try to convert it - if ((result = jssConvertModuleForPlaying(mod)) != DMERR_OK) + if ((result = jssConvertModuleForPlaying(engine.mod)) != DMERR_OK) { dmError("Could not convert module for playing, %d: %s\n", result, dmErrorStr(result)); @@ -512,8 +538,8 @@ dmMsg(2, "Initializing miniJSS mixer with: %d, %d, %d\n", optOutFormat, optOutChannels, optOutFreq); - dev = jvmInit(optOutFormat, optOutChannels, optOutFreq, JMIX_AUTO); - if (dev == NULL) + engine.dev = jvmInit(optOutFormat, optOutChannels, optOutFreq, JMIX_AUTO); + if (engine.dev == NULL) { dmError("jvmInit() returned NULL\n"); goto error_exit; @@ -521,24 +547,24 @@ switch (optOutFormat) { - case JSS_AUDIO_S16: afmt.format = AUDIO_S16SYS; break; - case JSS_AUDIO_U16: afmt.format = AUDIO_U16SYS; break; - case JSS_AUDIO_S8: afmt.format = AUDIO_S8; break; - case JSS_AUDIO_U8: afmt.format = AUDIO_U8; break; + case JSS_AUDIO_S16: engine.afmt.format = AUDIO_S16SYS; break; + case JSS_AUDIO_U16: engine.afmt.format = AUDIO_U16SYS; break; + case JSS_AUDIO_S8: engine.afmt.format = AUDIO_S8; break; + case JSS_AUDIO_U8: engine.afmt.format = AUDIO_U8; break; default: dmError("Unsupported audio format %d (could not set matching SDL format)\n", optOutFormat); goto error_exit; } - afmt.freq = optOutFreq; - afmt.channels = optOutChannels; - afmt.samples = optOutFreq * optOutChannels * 4; - afmt.callback = audioCallback; - afmt.userdata = (void *) dev; + engine.afmt.freq = optOutFreq; + engine.afmt.channels = optOutChannels; + engine.afmt.samples = optOutFreq * optOutChannels * 4; + engine.afmt.callback = audioCallback; + engine.afmt.userdata = (void *) engine.dev; // Open the audio device - if (SDL_OpenAudio(&afmt, NULL) < 0) + if (SDL_OpenAudio(&engine.afmt, NULL) < 0) { dmError("Couldn't open SDL audio: %s\n", SDL_GetError()); @@ -546,16 +572,16 @@ } // Initialize player - if ((plr = jmpInit(dev)) == NULL) + if ((engine.plr = jmpInit(engine.dev)) == NULL) { dmError("jmpInit() returned NULL\n"); goto error_exit; } - jvmSetCallback(dev, jmpExec, plr); - jmpSetModule(plr, mod); - jmpPlayOrder(plr, 0); - jvmSetGlobalVol(dev, 60); + jvmSetCallback(engine.dev, jmpExec, engine.plr); + jmpSetModule(engine.plr, engine.mod); + jmpPlayOrder(engine.plr, 0); + jvmSetGlobalVol(engine.dev, 100); // Initialize video if (!dmInitializeVideo()) @@ -563,11 +589,10 @@ SDL_WM_SetCaption(dmProgDesc, dmProgName); - // okay, main loop here ... "play" module and print out info SDL_PauseAudio(0); - while (!engine.exitFlag && plr->isPlaying) + while (!engine.exitFlag && engine.plr->isPlaying) { while (SDL_PollEvent(&engine.event)) switch (engine.event.type) @@ -579,6 +604,25 @@ engine.exitFlag = TRUE; break; + case SDLK_SPACE: + engine.pauseFlag = !engine.pauseFlag; + SDL_PauseAudio(engine.pauseFlag); + break; + + case SDLK_LEFT: + if (engine.actChannel > 0) + engine.actChannel--; + break; + + case SDLK_RIGHT: + if (engine.actChannel < engine.mod->nchannels) + engine.actChannel++; + break; + + case SDLK_RETURN: + jvmMute(engine.dev, engine.actChannel, !jvmGetMute(engine.dev, engine.actChannel)); + break; + default: break; } @@ -616,18 +660,18 @@ dmDrawBMTextQ(engine.screen, font, DMD_TRANSPARENT, 5, 5, "%s v%s by ccr/TNSP - (c) Copyright 2012 TNSP", dmProgDesc, dmProgVersion); - JSS_LOCK(dev); - JSS_LOCK(plr); + JSS_LOCK(engine.dev); + JSS_LOCK(engine.plr); dmDrawBMTextQ(engine.screen, font, DMD_TRANSPARENT, 5, 5 + 12, "Tempo: %3d | Speed: %3d | Row: %3d | Order: %d", - plr->tempo, plr->speed, plr->row, plr->order - ); + engine.plr->tempo, engine.plr->speed, engine.plr->row, engine.plr->order); dmDisplayPattern(engine.screen, 5, 30, engine.screen->w - 6, engine.screen->h - 10, - plr->pattern, plr->row, 0); - JSS_UNLOCK(plr); - JSS_UNLOCK(dev); + engine.plr->pattern, engine.plr->row); + + JSS_UNLOCK(engine.plr); + JSS_UNLOCK(engine.dev); #endif // Flip screen @@ -635,7 +679,7 @@ SDL_UnlockSurface(engine.screen); SDL_Flip(engine.screen); - SDL_Delay(16); + SDL_Delay(engine.pauseFlag ? 80 : 16); } error_exit: @@ -645,9 +689,9 @@ SDL_FreeSurface(engine.screen); SDL_LockAudio(); - jmpClose(plr); - jvmClose(dev); - jssFreeModule(mod); + jmpClose(engine.plr); + jvmClose(engine.dev); + jssFreeModule(engine.mod); SDL_UnlockAudio(); dmFreeBitmapFont(font);