// 删除所有仪器
//************************************
// Method:    DeleteAllInstrument
// FullName:  CInstrumentList::DeleteAllInstrument
// Access:    public 
// Returns:   void
// Qualifier:
// Parameter: void
//************************************
void CInstrumentList::DeleteAllInstrument(void)
{
	CInstrument* pInstrument = NULL;	// 仪器对象指针
	POSITION pos = NULL;				// 位置	
	unsigned int uiKey = 0;					// 索引键	
	unsigned int icount = m_oInstrumentMap.GetCount();
	if (icount == 0)
	{
		return;
	}
	pos = m_oInstrumentMap.GetStartPosition();	// 得到索引表起始位置
	while(NULL != pos)
	{
		ProcessMessages();
		pInstrument = NULL;		
		m_oInstrumentMap.GetNextAssoc(pos, uiKey, pInstrument);	// 得到仪器对象
		if(NULL != pInstrument)	
		{
			// 显示设备断开连接的图标
			OnShowDisconnectedIcon(pInstrument->m_uiIPAddress);
			// 将仪器从索引表中删除
			DeleteInstrumentFromMap(uiKey);
			// 重置仪器
			pInstrument->OnReset();
			// 仪器加在空闲仪器队列尾部
			m_olsInstrumentFree.AddTail(pInstrument);
			m_uiCountFree++;
		}
	}
}
// 删除采集站尾包之后的仪器
void CInstrumentList::TailFrameDeleteInstrument(CInstrument* pInstrumentDelete)
{
	CInstrument* pInstrument = NULL;	// 仪器对象指针
	POSITION pos = NULL;				// 位置	
	unsigned int uiKey;					// 索引键	

	pos = m_oInstrumentMap.GetStartPosition();	// 得到索引表起始位置
	while(NULL != pos)
	{
		pInstrument = NULL;		
		m_oInstrumentMap.GetNextAssoc(pos, uiKey, pInstrument);	// 得到仪器对象
		if(NULL != pInstrument)	
		{
			ProcessMessages();
			if (pInstrumentDelete->m_uiLocation < pInstrument->m_uiLocation)
			{
				// 显示设备断开连接的图标
				OnShowDisconnectedIcon(pInstrument->m_uiIPAddress);
				// 将仪器从索引表中删除
				DeleteInstrumentFromMap(uiKey);
				// 重置仪器
				pInstrument->OnReset();
				// 仪器加在空闲仪器队列尾部
				m_olsInstrumentFree.AddTail(pInstrument);
				m_uiCountFree++;
			}
		}
	}
	pInstrument = NULL;
	delete pInstrument;
}	
Example #3
0
	void MainWindow::refreshInstruments()
	{
		FtmDocument *d = m_dinfo->doc();

		int current = m_dinfo->currentInstrument();

		instruments->clear();
		int instc = d->GetInstrumentCount();

		instrumentName->clear();
		instrumentName->setEnabled(instc > 0);
		for (int i = 0; i < 64; i++)
		{
			if (!d->IsInstrumentUsed(i))
				continue;

			CInstrument *inst = d->GetInstrument(i);

			QListWidgetItem *item = new QListWidgetItem;
			const char *res;
			switch (inst->GetType())
			{
			case INST_NONE:
			case INST_2A03:
				res = ":/inst/2a03";
				break;
			case INST_VRC6:
				res = ":/inst/vrc6";
				break;
			case INST_VRC7:
				res = ":/inst/vrc7";
				break;
			case INST_FDS:
				res = ":/inst/fds";
				break;
			default:
				res = NULL;
				break;
			}

			if (res != NULL)
				item->setIcon(QIcon(res));
			setInstrumentName(item, i, inst->GetName());

			item->setData(Qt::UserRole, qVariantFromValue(i));
			instruments->addItem(item);

			if (i == current)
			{
				instruments->setCurrentItem(item);
				instrumentName->setText(inst->GetName());
			}
		}
	}
// 删除所有仪器
void CInstrumentList::DeleteAllInstrument(void)
{
	CInstrument* pInstrument = NULL;	// 仪器对象指针
	POSITION pos = NULL;				// 位置	
	unsigned int uiKey;					// 索引键	
	unsigned int icount = m_oInstrumentMap.GetCount();
	if (icount == 0)
	{
		return;
	}
	pos = m_oInstrumentMap.GetStartPosition();	// 得到索引表起始位置
	while(NULL != pos)
	{
		pInstrument = NULL;		
		m_oInstrumentMap.GetNextAssoc(pos, uiKey, pInstrument);	// 得到仪器对象
		if(NULL != pInstrument)	
		{
			CStatic* icon;
			if(pInstrument->m_uiIPAddress == 81)
			{
				icon =(CStatic*)m_pwnd->GetDlgItem(IDC_STATIC_INSTRUMENT1);
				icon->SetIcon(m_iconDisconnected);
			}
			else if(pInstrument->m_uiIPAddress == 91)
			{
				icon =(CStatic*)m_pwnd->GetDlgItem(IDC_STATIC_INSTRUMENT2);
				icon->SetIcon(m_iconDisconnected);
			}
			else if(pInstrument->m_uiIPAddress == 101)
			{
				icon =(CStatic*)m_pwnd->GetDlgItem(IDC_STATIC_INSTRUMENT3);
				icon->SetIcon(m_iconDisconnected);
			}
			else if(pInstrument->m_uiIPAddress == 111)
			{
				icon =(CStatic*)m_pwnd->GetDlgItem(IDC_STATIC_INSTRUMENT4);
				icon->SetIcon(m_iconDisconnected);
			}
			DeleteInstrumentFromMap(uiKey);
			// 重置仪器
			pInstrument->OnReset();
			// 仪器加在空闲仪器队列尾部
			m_olsInstrumentFree.AddTail(pInstrument);
			m_uiCountFree++;
		}
	}
}
Example #5
0
	void MainWindow::instrumentNameChange(QString s)
	{
		QModelIndex idx = instruments->currentIndex();
		if (idx.row() < 0)
			return;

		int i = idx.data(Qt::UserRole).value<int>();

		FtmDocument *doc = m_dinfo->doc();
		doc->lock();

		CInstrument *inst = doc->GetInstrument(i);
		inst->SetName(s.toAscii());

		doc->unlock();

		setInstrumentName(instruments->currentItem(), idx.row(), s.toAscii());
	}
Example #6
0
	void MainWindow::instrumentSelect()
	{
		QModelIndex idx = instruments->currentIndex();
		int i = idx.data(Qt::UserRole).value<int>();

		CInstrument *inst;

		FtmDocument *doc = m_dinfo->doc();
		{
			FtmDocument_lock_guard lock(doc);

			inst = doc->GetInstrument(i);
			if (inst == NULL)
				return;
			instrumentName->setText(inst->GetName());
		}

		m_dinfo->setCurrentInstrument(i);

		m_instrumenteditor->setInstrument(doc, inst);
	}
CInstrument2A03Interface const *CFamiTrackerDocWrapper::Get2A03Instrument(int Instrument) const
{
	CInstrument *pInstrument = m_pDocument->GetInstrument(Instrument);
	pInstrument->Release(); // Prevent memory leak, no instrument will be removed during export
	return dynamic_cast<CInstrument2A03Interface const *>(pInstrument);
}
void CInstrumentEditDlg::SetCurrentInstrument(int Index)
{
    CFamiTrackerDoc *pDoc = CFamiTrackerDoc::GetDoc();
    CInstrumentContainer<CInstrument> instContainer(pDoc, Index);
    CInstrument *pInstrument = instContainer();
    int InstType = pInstrument->GetType();

    // Dialog title
    char Name[256];
    pDoc->GetInstrumentName(Index, Name);
    CString Suffix;
    Suffix.Format(_T("%02X. %s (%s)"), Index, Name, CHIP_NAMES[InstType]);
    CString Title;
    AfxFormatString1(Title, IDS_INSTRUMENT_EDITOR_TITLE, Suffix);
    SetWindowText(Title);

    if (InstType != m_iSelectedInstType) {
        ShowWindow(SW_HIDE);
        ClearPanels();

        switch (InstType) {
        case INST_2A03: {
            int Channel = CFamiTrackerView::GetView()->GetSelectedChannel();
            int Type = pDoc->GetChannelType(Channel);
            bool bShowDPCM = (Type == CHANID_DPCM) || (static_cast<CInstrument2A03*>(pInstrument)->AssignedSamples());
            InsertPane(new CInstrumentEditor2A03(), !bShowDPCM);
            InsertPane(new CInstrumentEditorDPCM(), bShowDPCM);
        }
        break;
        case INST_VRC6:
            InsertPane(new CInstrumentEditorVRC6(), true);
            break;
        case INST_VRC7:
            InsertPane(new CInstrumentEditorVRC7(), true);
            break;
        case INST_FDS:
            InsertPane(new CInstrumentEditorFDS(), true);
            InsertPane(new CInstrumentEditorFDSEnvelope(), false);
            break;
        case INST_N163:
            InsertPane(new CInstrumentEditorN163(), true);
            InsertPane(new CInstrumentEditorN163Wave(), false);
            break;
        case INST_S5B:
            InsertPane(new CInstrumentEditorS5B(), true);
            break;
        }

        m_iSelectedInstType = InstType;
    }

    for (int i = 0; i < PANEL_COUNT; ++i) {
        if (m_pPanels[i] != NULL) {
            m_pPanels[i]->SelectInstrument(Index);
        }
    }

    ShowWindow(SW_SHOW);
    UpdateWindow();

    m_iSelectedInstType = InstType;
}
/**
* 响应显示属性值
* @param unsigned int uiIndex 仪器索引号
* @return void
*/
void CLeftViewBarInstrumentBottom::OnShowProperty(unsigned int uiIndex)
{
    m_wndDetourGraphView.ShowWindow(SW_HIDE);
    m_wndDetourScrollBar.ShowWindow(SW_HIDE);

    CInstrument* pInstrument = &m_pSiteData->m_oInstrumentList.m_pArrayInstrument[uiIndex];
    CString strData;
    COleVariant oVariant = "";
    CBCGPProp* pGroupBase = NULL;
    CBCGPProp* pGroupTest = NULL;
    CBCGPProp* pSub = NULL;

    pGroupBase = m_wndPropList.GetProperty(0);

    pSub = pGroupBase->GetSubItem(0);
    strData.Format("%d", pInstrument->m_uiSN);
    oVariant = strData;
    pSub->SetValue(oVariant);

    pSub = pGroupBase->GetSubItem(1);
    strData = m_pSiteData->GetBoxTypeStringByID(pInstrument->m_uiInstrumentType);
    oVariant = strData;
    pSub->SetValue(oVariant);

    pSub = pGroupBase->GetSubItem(2);
    strData.Format("%d", pInstrument->m_uiIP);
    oVariant = strData;
    pSub->SetValue(oVariant);

    pSub = pGroupBase->GetSubItem(3);
    strData.Format("%d", pInstrument->m_uiLineNb);
    oVariant = strData;
    pSub->SetValue(oVariant);

    pSub = pGroupBase->GetSubItem(4);
    strData.Format("%d", pInstrument->m_uiPointNb);
    oVariant = strData;
    pSub->SetValue(oVariant);

    pSub = pGroupBase->GetSubItem(5);
    strData.Format("%d", pInstrument->m_uiChannelNb);
    oVariant = strData;
    pSub->SetValue(oVariant);

    pGroupTest = m_wndPropList.GetProperty(1);

    // 仪器噪声测试值
    pSub = pGroupTest->GetSubItem(0);
    strData = pInstrument->GetTestResultString(4, 0);
    oVariant = strData;
    pSub->SetValue(oVariant);

    // 仪器畸变测试值
    pSub = pGroupTest->GetSubItem(1);
    strData = pInstrument->GetTestResultString(5, 0);
    oVariant = strData;
    pSub->SetValue(oVariant);

    // 仪器串音测试值
    pSub = pGroupTest->GetSubItem(2);
    strData = pInstrument->GetTestResultString(7, 0);
    oVariant = strData;
    pSub->SetValue(oVariant);

    // 仪器增益测试值
    pSub = pGroupTest->GetSubItem(3);
    strData = pInstrument->GetTestResultString(6, 0);
    oVariant = strData;
    pSub->SetValue(oVariant);

    // 仪器相位测试值
    pSub = pGroupTest->GetSubItem(4);
    strData = pInstrument->GetTestResultString(6, 1);
    oVariant = strData;
    pSub->SetValue(oVariant);

    // 仪器共模测试值
    pSub = pGroupTest->GetSubItem(5);
    strData = pInstrument->GetTestResultString(8, 0);
    oVariant = strData;
    pSub->SetValue(oVariant);

    m_wndPropList.ShowWindow(SW_SHOW);
    SetWindowText("Instrument Properties");
}
Example #10
0
/*****************************************************************************
 * CControlLogic::QueueNotes()
 *****************************************************************************
 * Retrieves notes from the note recorders, and dispatches them appropriately.
 * Called during the Mix.
 */
void CControlLogic::QueueNotes(STIME stEndTime)
{
    CNote note;
    
    while (m_Notes.GetNote(stEndTime,&note))
    {
		if (note.m_bKey > 0x7F)	// Special command events.
		{
			long lTemp;
			DWORD dwPart = note.m_bPart;
			DWORD dwCommand = note.m_bKey;
			BYTE bData = note.m_bVelocity;
			switch (dwCommand)
			{
            case NOTE_PROGRAMCHANGE:
                m_dwProgram[dwPart] = bData |
                    (m_bBankH[dwPart] << 16) | 
                    (m_bBankL[dwPart] << 8);
                break;
			case NOTE_CC_BANKSELECTH:
				m_bBankH[dwPart] = bData;
				break;
			case NOTE_CC_BANKSELECTL:
				m_bBankL[dwPart] = bData;
				break;
			case NOTE_CC_POLYMODE:
				m_fMono[dwPart] = FALSE;
				break;
			case NOTE_CC_MONOMODE:
				m_fMono[dwPart] = TRUE;
				break;
			case NOTE_CC_RPN_MSB:
				m_nCurrentRPN[dwPart] = (m_nCurrentRPN[dwPart] & 0x7f) + (bData << 7);
				break;
			case NOTE_CC_RPN_LSB:
				m_nCurrentRPN[dwPart] = (m_nCurrentRPN[dwPart] & 0x3f80) + bData;
				break;
			case NOTE_CC_NRPN:
				m_nCurrentRPN[dwPart] = 0x3FFF;
				break;
			case NOTE_CC_DATAENTRYLSB:
				m_nData[dwPart] &= ~0x7F;
				m_nData[dwPart] |= bData;
				switch (m_nCurrentRPN[dwPart])
				{
				case RPN_PITCHBEND: // Don't do anything, Roland ignores lsb
					break;
				case RPN_FINETUNE:
					lTemp = m_nData[dwPart];
					lTemp -= 8192;
					lTemp *= 100;
					lTemp /= 8192;
					m_prFineTune[dwPart] = lTemp;
					break;
				case RPN_COARSETUNE: // Ignore lsb
					break;            
				}
				break;
			case NOTE_CC_DATAENTRYMSB:
				m_nData[dwPart] &= ~(0x7F << 7);
				m_nData[dwPart] |= bData << 7;
				switch (m_nCurrentRPN[dwPart])
				{
				case RPN_PITCHBEND:
					m_PitchBend[dwPart].m_prRange = bData * 100;
					break;
				case RPN_FINETUNE:
					lTemp = m_nData[dwPart];
					lTemp -= 8192;
					lTemp *= 100;
					lTemp /= 8192;
					m_prFineTune[dwPart] = lTemp;
					break;
				case RPN_COARSETUNE:
					m_prCoarseTune[dwPart] = 100 * (bData - 64);
					break;        
				}
				break;
			case NOTE_SUSTAIN: // special sustain marker
	            m_fSustain[dwPart] = (BOOL) bData;
				if (bData == FALSE)
				{
					CVoice * pVoice = m_pSynth->m_VoicesInUse.GetHead();
					for (;pVoice != NULL;pVoice = pVoice->GetNext())
					{
						if (pVoice->m_fSustainOn &&
							(pVoice->m_nPart == dwPart) &&
							(pVoice->m_pControl == this))
						{
							pVoice->StopVoice(note.m_stTime);
						}
					}
				} 
				break;
			case NOTE_ALLOFF:
				{
					CVoice *pVoice = m_pSynth->m_VoicesInUse.GetHead();
					for (;pVoice != NULL; pVoice = pVoice->GetNext())
					{
						if (pVoice->m_fNoteOn && !pVoice->m_fSustainOn &&
							(pVoice->m_nPart == dwPart) &&
							(pVoice->m_pControl == this))
						{
							if (m_fSustain[dwPart])
							{
								pVoice->m_fSustainOn = TRUE;
							}
							else
							{
								pVoice->StopVoice(note.m_stTime);
							}
						}
					}
				}
				break;
			case NOTE_SOUNDSOFF:
				{
					CVoice *pVoice = m_pSynth->m_VoicesInUse.GetHead();
					for (;pVoice != NULL; pVoice = pVoice->GetNext())
					{
						if (pVoice->m_fNoteOn &&
							(pVoice->m_nPart == dwPart) &&
							(pVoice->m_pControl == this))
						{
							pVoice->StopVoice(note.m_stTime);
						}
					}
				}
				break;
			case NOTE_ASSIGNRECEIVE:
				m_bPartToChannel[dwPart] = (BYTE) bData;
				break;
			case NOTE_MASTERVOLUME:
				m_vrMasterVolume = CMIDIRecorder::VelocityToVolume(bData);
				break;
			}
		}
        else if (note.m_bVelocity == 0)  // Note Off.
        {
            CVoice * pVoice = m_pSynth->m_VoicesInUse.GetHead();
            WORD nPart = note.m_bPart;
            for (;pVoice != NULL;pVoice = pVoice->GetNext())
            {
                if (pVoice->m_fNoteOn && !pVoice->m_fSustainOn &&
                    (pVoice->m_nKey == (WORD) note.m_bKey) &&
                    (pVoice->m_nPart == nPart) &&
					(pVoice->m_pControl == this)) 
                {
                    if (m_fSustain[nPart])
                    {
                        pVoice->m_fSustainOn = TRUE;
                    }
                    else
                    {
                        pVoice->StopVoice(note.m_stTime);
                    }
                    break;
                }
            }
        }
        else   // Note On.
        {
            DWORD dwProgram = m_dwProgram[note.m_bPart];
            if (m_bDrums[note.m_bPart])
            {
                dwProgram |= F_INSTRUMENT_DRUMS;
            }
			if (m_fMono[note.m_bPart])
			{
				CVoice * pVoice = m_pSynth->m_VoicesInUse.GetHead();
				WORD nPart = note.m_bPart;
				for (;pVoice != NULL;pVoice = pVoice->GetNext())
				{
					if (pVoice->m_fNoteOn && (pVoice->m_nPart == nPart) &&
						(pVoice->m_pControl == this)) 
					{
						pVoice->StopVoice(note.m_stTime);
					}
				}
			}
			// While we are working with the instrument, including copying
			// the data over from the region, we have to make sure it
			// can not be removed from the instrument list.
			EnterCriticalSection(&m_pInstruments->m_CriticalSection);
            CInstrument * pInstrument = 
                m_pInstruments->GetInstrument(dwProgram,note.m_bKey);
            if (!pInstrument) 
			{
				if (dwProgram & F_INSTRUMENT_DRUMS)
				{
					dwProgram = F_INSTRUMENT_DRUMS;
					pInstrument = 
						m_pInstruments->GetInstrument(dwProgram,note.m_bKey);
				}
				else if (m_fXGActive)
				{
					if ((dwProgram & 0x7F0000) == 0x7F0000)	// Drum?
					{
						dwProgram &= 0x7F007F;				// Enforce 0 LSB
						pInstrument = 
							m_pInstruments->GetInstrument(dwProgram,note.m_bKey);
                        if (!pInstrument)
                        {
                            dwProgram = 0x7F0000;
						    pInstrument = 
							    m_pInstruments->GetInstrument(dwProgram,note.m_bKey);
                        }
					}
                    else
                    {
						dwProgram &= 0x7F;	// Fall back to GM set.
						pInstrument = 
							m_pInstruments->GetInstrument(dwProgram,note.m_bKey);
					}
				}
			}
            if (pInstrument != NULL)
            {
                CSourceRegion * pRegion = 
                    pInstrument->ScanForRegion(note.m_bKey);
                if (pRegion != NULL)
                {
                    WORD nPart = note.m_bPart;
                    CVoice * pVoice = m_pSynth->m_VoicesInUse.GetHead();
                    if (!pRegion->m_bAllowOverlap)
                    {
                        for (;pVoice != NULL; pVoice = pVoice->GetNext())
                        {
                            if ((pVoice->m_nPart == nPart) &&
                                (pVoice->m_nKey == note.m_bKey) &&
								(pVoice->m_pControl == this))
                            {
                                pVoice->QuickStopVoice(note.m_stTime);
                            }
                        }    
                    }

                    if (pRegion->m_bGroup != 0)
                    {
                        pVoice = m_pSynth->m_VoicesInUse.GetHead();
                        for (;pVoice != NULL;pVoice = pVoice->GetNext())
                        {
                            if ((pVoice->m_dwGroup == pRegion->m_bGroup) &&
                                (pVoice->m_nPart == nPart) &&
                                (pVoice->m_dwProgram == dwProgram) &&
								(pVoice->m_pControl == this))
                            {
                                pVoice->QuickStopVoice(note.m_stTime);
                            }
                        }
                    }
                    
                    pVoice = m_pSynth->m_VoicesFree.RemoveHead();
                    if (pVoice == NULL)
                    {
                        pVoice = m_pSynth->m_VoicesExtra.RemoveHead();
                    }

                    if (pVoice == NULL)
                    {
                        pVoice = m_pSynth->StealVoice(m_dwPriority[nPart]);
                    }

                    if (pVoice != NULL)
                    {
						PREL prPitch = m_prFineTune[nPart] + m_prScaleTune[nPart][note.m_bKey % 12];
						if (!m_bDrums[nPart]) 
						{
							if (m_fXGActive)
							{
								if ((dwProgram & 0x7F0000) != 0x7F0000)
								{
									prPitch += m_prCoarseTune[nPart];
								}
							}
							else
							{
								prPitch += m_prCoarseTune[nPart];
							}
                        }
						pVoice->m_nKey = note.m_bKey;
                        pVoice->m_nPart = nPart;
                        pVoice->m_dwProgram = dwProgram;
                        pVoice->m_dwPriority = m_dwPriority[nPart];
						pVoice->m_pControl = this;

                        if (pVoice->StartVoice( m_pSynth,
                                                pRegion, note.m_stTime, 
                                                &m_ModWheel[nPart],     
                                                &m_PitchBend[nPart],
                                                &m_Expression[nPart],   
                                                &m_Volume[nPart],
                                                &m_Pan[nPart],          
                                                (WORD)note.m_bKey,
							                    (WORD)note.m_bVelocity, 
                                                m_vrMasterVolume, 
							                    prPitch))
                        {
                            pVoice->m_fInUse = TRUE;

                            m_pSynth->QueueVoice(pVoice);
                        }
                        else
                        {
                            m_pSynth->m_VoicesFree.AddHead(pVoice);
                        }
                    } 
                    else 
                    {
                        m_pSynth->m_BuildStats.dwNotesLost++;
                    }
                } 
                else 
                {
                    m_pSynth->m_BuildStats.dwNotesLost++;
                }
            } 
            else 
            {
                Trace(1, "No instrument/region was found for patch # %lx, note %ld\n",
                          dwProgram, (long) note.m_bKey);
            }
			LeaveCriticalSection(&m_pInstruments->m_CriticalSection);
        }
    }
}