Subversion Repositories svn.mios32

Compare Revisions

Ignore whitespace Rev 2490 → Rev 2491

/trunk/apps/synthesizers/midibox_quad_genesis/src/cmdeditor.c
21,6 → 21,36
#include "mode_prog.h"
 
 
void DrawUsageOnVoices(VgmUsageBits usage, u8 r){
u32 u = usage.all;
u8 i;
for(i=0; i<6; ++i){
FrontPanel_GenesisLEDSet(r, i+1, 0, (u & 0x00000001)); //FM
u >>= 1;
}
for(i=0; i<6; ++i){
FrontPanel_GenesisLEDSet(r+1, i+1, 0, (u & 0x00000001)); //LFO
u >>= 1;
}
FrontPanel_GenesisLEDSet(r, 7, 0, (u & 0x00000001)); //DAC
u >>= 1;
if(r == 0){
FrontPanel_LEDSet(FP_LED_CH3_4FREQ, (u & 0x00000001)); //FM3 special
FrontPanel_LEDSet(FP_LED_CH3_CSM, (u & 0x00000001));
}
u >>= 1;
FrontPanel_GenesisLEDSet(r, 0, 0, (u & 0x00000001)); //FM globals
u >>= 10; //Skip LFO globals
for(i=0; i<4; ++i){
FrontPanel_GenesisLEDSet(r, i+8, 0, (u & 0x00000001)); //SQ, NS
u >>= 1;
}
if(r == 0){
FrontPanel_LEDSet(FP_LED_NS_SQ3, (u & 0x00000001)); //SQ3/NS
}
}
 
 
void DrawCmdLine(VgmChipWriteCmd cmd, u8 row, u8 ctrlled){
u16 outbits = ctrlled;
if(cmd.cmd == 0x50){
853,4 → 883,3
 
 
 
 
/trunk/apps/synthesizers/midibox_quad_genesis/src/cmdeditor.h
16,10 → 16,13
#include <vgm.h>
#include "syeng.h"
 
extern void DrawUsageOnVoices(VgmUsageBits usage, u8 r);
 
extern void DrawCmdLine(VgmChipWriteCmd cmd, u8 row, u8 ctrlled);
extern void DrawCmdContent(VgmChipWriteCmd cmd, u8 clear);
extern void GetCmdDescription(VgmChipWriteCmd cmd, char* desc);
 
 
extern VgmChipWriteCmd EditCmd(VgmChipWriteCmd cmd, u8 encoder, s32 incrementer, u8 button, u8 state, u8 reqvoice, u8 reqop);
 
extern u8 EditState(VgmSource* vgs, VgmHead* head, u8 encoder, s32 incrementer, u8 button, u8 state, u8 voice, u8 op);
26,4 → 29,5
 
extern VgmSource* CreateNewVGM(u8 type, VgmUsageBits usage);
 
 
#endif /* _CMDEDITOR_H */
/trunk/apps/synthesizers/midibox_quad_genesis/src/capturer.c
22,7 → 22,7
#include "syeng.h"
 
static u8 cvoice;
static void (*callback_f)();
static void (*callback_f)(u8 success);
 
static void DrawMenu(){
FrontPanel_GenesisLEDSet((selchan>>4), 0, 1, 1);
29,7 → 29,7
FrontPanel_GenesisLEDSet(((selchan>>2)&3), (selchan&3)+8, 1, 1);
MIOS32_LCD_Clear();
MIOS32_LCD_CursorSet(0,0);
MIOS32_LCD_PrintFormattedString("Capture voice to port %d chn %d", (selchan>>4)+1, (selchan&0xF)+1);
MIOS32_LCD_PrintFormattedString("Capture voice 0x%02X to port %d chn %d", cvoice, (selchan>>4)+1, (selchan&0xF)+1);
u8 v = cvoice & 0x0F;
if(v == 0 || v == 7 || v > 11){
MIOS32_LCD_CursorSet(0,1);
37,7 → 37,7
}
}
 
void Capturer_Start(u8 origvoice, void (*callback)()){
void Capturer_Start(u8 origvoice, void (*callback)(u8 success)){
subscreen = SUBSCREEN_CAPTURER;
cvoice = origvoice;
callback_f = callback;
55,7 → 55,12
void Capturer_BtnSystem(u8 button, u8 state){
if(!state) return;
if(button == FP_B_MENU){
//Clear voice selection LEDs
FrontPanel_GenesisLEDSet((selchan>>4), 0, 1, 0);
FrontPanel_GenesisLEDSet(((selchan>>2)&3), (selchan&3)+8, 1, 0);
//Done
subscreen = 0;
callback_f(0);
return;
}else if(button == FP_B_CAPTURE || button == FP_B_ENTER){
//Compute usage
143,7 → 148,7
FrontPanel_GenesisLEDSet(((selchan>>2)&3), (selchan&3)+8, 1, 0);
//Done
subscreen = 0;
callback_f();
callback_f(1);
return;
}
}
/trunk/apps/synthesizers/midibox_quad_genesis/src/syeng.c
200,7 → 200,7
syngenesis[g].channels[v].use = 0;
}
 
static void StandbyPI(synproginstance_t* pi){
static void SetPIMappedVoicesUse(synproginstance_t* pi, u8 use){
u8 i, v;
VgmHead_Channel pimap;
syngenesis_t* sg;
209,28 → 209,32
if(pimap.nodata) continue;
sg = &syngenesis[pimap.map_chip];
if(i == 0){
//We were using OPN2 globals
for(v=0; v<8; ++v){
sg->channels[v].use = 1;
if(pimap.option){
//Only using globals for LFO
//Don't touch use, since multiple voices may be using it
}else{
//We were using OPN2 globals
for(v=0; v<8; ++v){
sg->channels[v].use = use;
}
//Skip to PSG section
i = 7;
continue;
}
//Skip to PSG section
i = 7;
continue;
}
if(i >= 1 && i <= 6){
}else if(i >= 1 && i <= 6){
//FM voice
v = pimap.map_voice;
sg->channels[v+1].use = 1;
sg->channels[v+1].use = use;
}else if(i == 7){
//DAC
sg->channels[7].use = 1;
sg->channels[7].use = use;
}else if(i >= 8 && i <= 10){
//SQ voice
v = pimap.map_voice;
sg->channels[v+8].use = 1;
sg->channels[v+8].use = use;
}else{
//Noise
sg->channels[11].use = 1;
sg->channels[11].use = use;
}
}
}
246,7 → 250,7
full = 1;
for(v=1; v<6; ++v){
use = syngenesis[g].channels[v].use;
if(!use) full = 0;
if(use <= 1) full = 0;
if(syngenesis[g].channels[v].lfo){
//Only for voices using the LFO
score += use_scores[use];
304,7 → 308,7
if(vlfo && proper){
sgusage->lfo = 1;
//Send LFO commands from this head to the same chip as this channel is on
pi->mapping[0] = (VgmHead_Channel){.nodata = 0, .mute = 0, .map_chip = g, .map_voice = 0, .option = 0};
pi->mapping[0] = (VgmHead_Channel){.nodata = 0, .mute = 0, .map_chip = g, .map_voice = 0, .option = 1};
//TODO potential bug:
/*
If we have a VGM with two voices in LFO Fixed mode, and the first gets
364,6 → 368,7
}
}
}
DBG("FindBestVoice asked forceg %d voices %d-%d sumoverv %d, result G%d V%d", forceg, vstart, vend, sumoverv, *bestg, *bestv);
}
 
static s32 AllocatePI(u8 piindex, VgmUsageBits pusage){
831,11 → 836,12
}
 
void SyEng_PlayVGMOnPI(synproginstance_t* pi, VgmSource* source, u8 rootnote, u8 startplaying){
SetPIMappedVoicesUse(pi, pi->isstatic ? 3 : 2);
pi->head = VGM_Head_Create(source, VGM_getFreqMultiplier((s8)pi->note - (s8)rootnote), 0x1000);
CopyPIMappingToHead(pi, pi->head);
u32 vgmtime = VGM_Player_GetVGMTime();
VGM_Head_Restart(pi->head, vgmtime);
DBG("PlayVGMOnPi after restart, iswait %d iswrite %d isdone %d firstoftwo %d, cmd %08X", pi->head->iswait, pi->head->iswrite, pi->head->isdone, pi->head->firstoftwo, pi->head->writecmd.all);
//DBG("PlayVGMOnPi after restart, iswait %d iswrite %d isdone %d firstoftwo %d, cmd %08X", pi->head->iswait, pi->head->iswrite, pi->head->isdone, pi->head->firstoftwo, pi->head->writecmd.all);
pi->head->playing = startplaying;
pi->recency = vgmtime;
}
955,7 → 961,7
//DBG("PI ch %d note %d doesn't have noteoff VGM, doing nothing", pi->sourcechannel, pi->note);
}
//Mark pi as not playing, release resources
StandbyPI(pi);
SetPIMappedVoicesUse(pi, 1);
pi->playing = 0;
}
 
1051,6 → 1057,10
 
void SyEng_PrintEngineDebugInfo(){
u8 i, g, v;
DBG("=====================================================");
DBG("============ SyEng_PrintEngineDebugInfo =============");
DBG("=====================================================");
/*
DBG("==== CHANNELS ====");
synprogram_t* prog;
VgmSource* src;
1079,6 → 1089,8
}
}
}
*/
/*
DBG("==== PIs ====");
synproginstance_t* pi;
VgmHead_Channel ch;
1106,6 → 1118,7
}
vgmh2_free(buf);
vgmh2_free(buf2);
*/
DBG("==== SYNGENESISES ====");
syngenesis_t* sg;
syngenesis_usage_t* sgu;
/trunk/apps/synthesizers/midibox_quad_genesis/src/capturer.h
17,7 → 17,7
extern "C" {
#endif
 
extern void Capturer_Start(u8 origvoice, void (*callback)());
extern void Capturer_Start(u8 origvoice, void (*callback)(u8 success));
 
extern void Capturer_BtnSystem(u8 button, u8 state);
extern void Capturer_BtnGVoice(u8 gvoice, u8 state);
/trunk/apps/synthesizers/midibox_quad_genesis/src/mode_voice.c
147,10 → 147,12
FrontPanel_LEDSet(FP_LED_SELOP_1 + selop, 1);
}
}
static void CapturerDone(){
static void CapturerDone(u8 success){
Mode_Voice_GotFocus();
MIOS32_LCD_CursorSet(0,0);
MIOS32_LCD_PrintString("-Captured- ");
if(success){
MIOS32_LCD_CursorSet(0,0);
MIOS32_LCD_PrintString("-Captured- ");
}
}
 
void Mode_Voice_Tick(){
/trunk/apps/synthesizers/midibox_quad_genesis/src/mode_prog.c
28,31 → 28,6
static VgmUsageBits newvgmusage;
 
 
static void DrawUsage(VgmUsageBits usage){
u32 u = usage.all;
u8 i;
for(i=0; i<6; ++i){
FrontPanel_GenesisLEDSet(0, i+1, 0, (u & 0x00000001)); //FM
u >>= 1;
}
for(i=0; i<6; ++i){
FrontPanel_GenesisLEDSet(1, i+1, 0, (u & 0x00000001)); //LFO
u >>= 1;
}
FrontPanel_GenesisLEDSet(0, 7, 0, (u & 0x00000001)); //DAC
u >>= 1;
FrontPanel_LEDSet(FP_LED_CH3_4FREQ, (u & 0x00000001)); //FM3 special
FrontPanel_LEDSet(FP_LED_CH3_CSM, (u & 0x00000001));
u >>= 1;
FrontPanel_GenesisLEDSet(0, 0, 0, (u & 0x00000001)); //FM globals
u >>= 10; //Skip LFO globals
for(i=0; i<4; ++i){
FrontPanel_GenesisLEDSet(0, i+8, 0, (u & 0x00000001)); //SQ, NS
u >>= 1;
}
FrontPanel_LEDSet(FP_LED_NS_SQ3, (u & 0x00000001)); //SQ3/NS
}
 
static void DrawMenu(){
MIOS32_LCD_Clear();
MIOS32_LCD_CursorSet(0,0);
160,7 → 135,7
}
void Mode_Prog_GotFocus(){
DrawMenu();
if(submode == 1) DrawUsage(newvgmusage);
if(submode == 1) DrawUsageOnVoices(newvgmusage, 0);
}
 
void Mode_Prog_Tick(){
187,12 → 162,12
}else if(v <= 0xB){
newvgmusage.all ^= (1 << (v+16));
}
DrawUsage(newvgmusage);
DrawUsageOnVoices(newvgmusage, 0);
}else if(g == 1){
if(v >= 1 && v <= 6){
newvgmusage.all ^= (1 << (v+5));
newvgmusage.all &= 0xFFFFF03F | ((newvgmusage.all & 0x0000003F) << 6);
DrawUsage(newvgmusage);
DrawUsageOnVoices(newvgmusage, 0);
}
}
break;
225,7 → 200,7
submode = 0;
cursor = 5;
DrawMenu();
DrawUsage((VgmUsageBits){.all=0});
DrawUsageOnVoices((VgmUsageBits){.all=0}, 0);
return;
}
switch(submode){
263,7 → 238,7
submode = 1;
newvgmusage.all = selprogram->usage.all;
DrawMenu();
DrawUsage(newvgmusage);
DrawUsageOnVoices(newvgmusage, 0);
}
}
break;
312,11 → 287,11
switch(button){
case FP_B_CH3MODE:
newvgmusage.fm3_special ^= 1;
DrawUsage(newvgmusage);
DrawUsageOnVoices(newvgmusage, 0);
break;
case FP_B_NSFREQ:
newvgmusage.noisefreqsq3 ^= 1;
DrawUsage(newvgmusage);
DrawUsageOnVoices(newvgmusage, 0);
break;
}
break;
/trunk/apps/synthesizers/midibox_quad_genesis/src/mode_vgm.c
19,6 → 19,7
#include "frontpanel.h"
#include "genesisstate.h"
#include "cmdeditor.h"
#include "capturer.h"
#include "mode_prog.h"
 
VgmSource* selvgm;
34,6 → 35,32
static u16 vsolos;
static VgmChipWriteCmd lastcmddrawn;
 
void SetUpSelvoice(VgmUsageBits usage){
u32 u = usage.all;
u8 i;
for(i=0; i<6; ++i){
if(u & 1){
selvoice = i+1;
return;
}
}
if(usage.dac){
selvoice = 7;
return;
}
if(usage.opn2_globals){
selvoice = 0;
return;
}
u = usage.all >> 16;
for(i=0; i<4; ++i){
if(u & 1){
selvoice = i+8;
return;
}
}
selvoice = 1;
}
 
void Mode_Vgm_SelectVgm(VgmSource* newselvgm){
s32 oldaddr = -1;
51,6 → 78,7
if(oldaddr >= 0) pi->head->srcaddr = oldaddr;
vmutes = selvgm->mutes;
vsolos = 0;
SetUpSelvoice(selvgm->usage);
}
void Mode_Vgm_InvalidateVgm(VgmSource* maybeselvgm){
if(maybeselvgm == NULL || maybeselvgm == selvgm){
80,7 → 108,6
}
 
static void DrawMenu(){
lastcmddrawn.all = 0;
MIOS32_LCD_Clear();
if(selvgm == NULL){
MIOS32_LCD_CursorSet(0,0);
215,6 → 242,8
vmutes = 0;
vsolos = 0;
usagechange = 0;
selvoice = 1;
selop = 0;
}
void Mode_Vgm_GotFocus(){
submode = 0;
235,6 → 264,13
}
DrawMenu();
}
static void CapturerDone(u8 success){
Mode_Vgm_GotFocus();
if(success){
MIOS32_LCD_CursorSet(0,0);
MIOS32_LCD_PrintString("-Captured- ");
}
}
 
void Mode_Vgm_Tick(){
 
357,9 → 393,11
if(statemode){
//Draw voice state
u8 mg, mv;
mg = pi->mapping[selvoice].map_chip;
mv = GetRealMapVoice(selvoice, pi->mapping[selvoice].map_voice);
DrawGenesisState_All(mg, mv, selop);
if(!pi->mapping[selvoice].nodata){
mg = pi->mapping[selvoice].map_chip;
mv = GetRealMapVoice(selvoice, pi->mapping[selvoice].map_voice);
DrawGenesisState_All(mg, mv, selop);
}
//Activity lights
if(submode == 0){
for(v=0; v<12; ++v){
405,6 → 443,8
}
}
}
//Draw usage
DrawUsageOnVoices(selvgm->usage, 2);
}
 
void Mode_Vgm_BtnGVoice(u8 gvoice, u8 state){
490,6 → 530,7
}
void Mode_Vgm_BtnSystem(u8 button, u8 state){
if(selvgm == NULL) return;
VgmHead* head;
switch(button){
case FP_B_MENU:
submode = 0;
566,8 → 607,9
if(statemode) return;
if(selvgm->type == VGM_SOURCE_TYPE_RAM){
EnsurePreviewPiOK();
VGM_HeadRAM_Backward1(proginstances[vgmpreviewpi].head);
DrawMenu();
if(VGM_HeadRAM_Backward1(proginstances[vgmpreviewpi].head) >= 0){
DrawMenu();
}
}
break;
case FP_B_CMDDN:
575,8 → 617,9
if(statemode) return;
if(selvgm->type == VGM_SOURCE_TYPE_RAM){
EnsurePreviewPiOK();
VGM_HeadRAM_Forward1(proginstances[vgmpreviewpi].head);
DrawMenu();
if(VGM_HeadRAM_Forward1(proginstances[vgmpreviewpi].head) >= 0){
DrawMenu();
}
}
break;
case FP_B_STATEUP:
583,8 → 626,10
if(!state) return;
if(selvgm->type == VGM_SOURCE_TYPE_RAM){
EnsurePreviewPiOK();
VGM_HeadRAM_BackwardState(proginstances[vgmpreviewpi].head, 0xFFFFFFFF, 100);
DrawMenu();
if(VGM_HeadRAM_BackwardState(proginstances[vgmpreviewpi].head,
0xFFFFFFFF, 100) >= 0){
DrawMenu();
}
}
break;
case FP_B_STATEDN:
591,8 → 636,10
if(!state) return;
if(selvgm->type == VGM_SOURCE_TYPE_RAM){
EnsurePreviewPiOK();
VGM_HeadRAM_ForwardState(proginstances[vgmpreviewpi].head, 0xFFFFFFFF, 100, 0);
DrawMenu();
if(VGM_HeadRAM_ForwardState(proginstances[vgmpreviewpi].head,
0xFFFFFFFF, 100, 0) >= 0){
DrawMenu();
}
}
break;
case FP_B_NEW:
615,30 → 662,36
break;
case FP_B_MARKST:
if(!state) return;
{
EnsurePreviewPiOK();
VgmHead* head = proginstances[vgmpreviewpi].head;
if(selvgm->markstart == head->srcaddr || head->srcaddr >= selvgm->markend){
selvgm->markstart = 0;
}else{
selvgm->markstart = head->srcaddr;
}
DrawMenu();
EnsurePreviewPiOK();
head = proginstances[vgmpreviewpi].head;
if(selvgm->markstart == head->srcaddr || head->srcaddr >= selvgm->markend){
selvgm->markstart = 0;
}else{
selvgm->markstart = head->srcaddr;
}
DrawMenu();
break;
case FP_B_MARKEND:
if(!state) return;
{
EnsurePreviewPiOK();
VgmHead* head = proginstances[vgmpreviewpi].head;
if(selvgm->markend == head->srcaddr || head->srcaddr <= selvgm->markstart){
selvgm->markend = 0xFFFFFFFF;
}else{
selvgm->markend = head->srcaddr;
}
DrawMenu();
EnsurePreviewPiOK();
head = proginstances[vgmpreviewpi].head;
if(selvgm->markend == head->srcaddr || head->srcaddr <= selvgm->markstart){
selvgm->markend = 0xFFFFFFFF;
}else{
selvgm->markend = head->srcaddr;
}
DrawMenu();
break;
case FP_B_CAPTURE:
if(!state) return;
EnsurePreviewPiOK();
synproginstance_t* pi = &proginstances[vgmpreviewpi];
if(pi->mapping[selvoice].nodata) return;
u8 mg, mv;
mg = pi->mapping[selvoice].map_chip;
mv = GetRealMapVoice(selvoice, pi->mapping[selvoice].map_voice);
Capturer_Start((mg << 4) | mv, &CapturerDone);
break;
}
break;
case 1: