MCPcopy Create free account
hub / github.com/HertzDevil/0CC-FamiTracker / ImportInstruments

Method ImportInstruments

Source/ModuleImporter.cpp:141–206  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

139}
140
141void CModuleImporter::ImportInstruments() {
142 if (inst_mode_ == import_mode_t::none)
143 return;
144
145 const inst_type_t INST[] = {INST_2A03, INST_VRC6, INST_N163, INST_S5B}; // // //
146
147 auto *pInsts = modfile_.GetInstrumentManager();
148 auto *pSamps = modfile_.GetDSampleManager();
149 auto *pImportedInsts = imported_.GetInstrumentManager();
150 auto *pImportedSamps = imported_.GetDSampleManager(); // // //
151
152 int seqTable[std::size(INST)][MAX_SEQUENCES][SEQ_COUNT] = { };
153 int SamplesTable[MAX_DSAMPLES] = { };
154
155 for (size_t i = 0; i < std::size(INST); ++i) for (auto t : enum_values<sequence_t>()) {
156 for (unsigned int s = 0; s < MAX_SEQUENCES; ++s)
157 if (auto pImportSeq = pImportedInsts->GetSequence(INST[i], t, s); pImportSeq && pImportSeq->GetItemCount() > 0) {
158 for (unsigned j = 0; j < MAX_SEQUENCES; ++j) {
159 auto pSeq = pInsts->GetSequence(INST[i], t, j);
160 if (pSeq && pSeq->GetItemCount() > 0)
161 continue;
162 // TODO: continue if blank sequence is used by some instrument
163 *pSeq = *pImportSeq; // // //
164 // Save a reference to this sequence
165 seqTable[i][s][value_cast(t)] = j;
166 break;
167 }
168 }
169 }
170
171 // Copy DPCM samples
172 for (int i = 0; i < MAX_DSAMPLES; ++i) {
173 if (auto pImportDSample = pImportedSamps->ReleaseDSample(i)) { // // //
174 // Save a reference to this DPCM sample
175 int Index = pSamps->GetFirstFree();
176 pSamps->SetDSample(Index, std::move(pImportDSample));
177 SamplesTable[i] = Index;
178 }
179 }
180
181 // Copy instruments
182 pImportedInsts->VisitInstruments([&] (const CInstrument &inst, std::size_t i) {
183 if (auto it = inst_index_.find(i); it != inst_index_.end()) {
184 auto pNewInst = inst.Clone(); // // //
185
186 // Update references
187 if (auto *pSeq = dynamic_cast<CSeqInstrument *>(pNewInst.get())) {
188 for (auto t : enum_values<sequence_t>())
189 if (pSeq->GetSeqEnable(t)) {
190 for (size_t j = 0; j < std::size(INST); ++j)
191 if (INST[j] == pNewInst->GetType()) {
192 pSeq->SetSeqIndex(t, seqTable[j][pSeq->GetSeqIndex(t)][value_cast(t)]);
193 break;
194 }
195 }
196 // Update DPCM samples
197 if (auto *p2A03 = dynamic_cast<CInstrument2A03 *>(pSeq))
198 for (int n = 0; n < NOTE_COUNT; ++n)

Callers

nothing calls this directly

Calls 15

sizeFunction · 0.85
value_castFunction · 0.85
ReleaseDSampleMethod · 0.80
VisitInstrumentsMethod · 0.80
SetSampleIndexMethod · 0.80
GetInstrumentManagerMethod · 0.45
GetDSampleManagerMethod · 0.45
GetSequenceMethod · 0.45
GetItemCountMethod · 0.45
GetFirstFreeMethod · 0.45
SetDSampleMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected