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

Method StorePatterns

Source/Compiler.cpp:1484–1560  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1482// Patterns
1483
1484void CCompiler::StorePatterns(unsigned int Track)
1485{
1486 /*
1487 * Store patterns and save references to them for the frame list
1488 *
1489 */
1490
1491 CPatternCompiler PatternCompiler(*m_pModule, m_iAssignedInstruments, (const DPCM_List_t *)m_iSamplesLookUp.data(), m_pLogger); // // //
1492
1493 int PatternCount = 0;
1494 int PatternSize = 0;
1495
1496 // Iterate through all patterns
1497 for (unsigned i = 0; i < MAX_PATTERN; ++i) {
1498 m_ChannelOrder.ForeachChannel([&] (stChannelID j) { // // //
1499 // And store only used ones
1500 if (IsPatternAddressed(Track, i, j)) {
1501
1502 // Compile pattern data
1503 PatternCompiler.CompileData(Track, i, j);
1504
1505 auto label = stChunkLabel {CHUNK_PATTERN, Track, i, j.ToInteger()}; // // //
1506
1507 bool StoreNew = true;
1508
1509#ifdef REMOVE_DUPLICATE_PATTERNS
1510 unsigned int Hash = PatternCompiler.GetHash();
1511
1512 // Check for duplicate patterns
1513 if (auto it = m_PatternMap.find(Hash); it != m_PatternMap.end()) {
1514 const CChunk *pDuplicate = it->second;
1515 // Hash only indicates that patterns may be equal, check exact data
1516 if (PatternCompiler.CompareData(pDuplicate->GetStringData(PATTERN_CHUNK_INDEX))) {
1517 // Duplicate was found, store a reference to existing pattern
1518 m_DuplicateMap.try_emplace(label, pDuplicate->GetLabel()); // // //
1519 ++m_iDuplicatePatterns;
1520 StoreNew = false;
1521 }
1522 }
1523#endif /* REMOVE_DUPLICATE_PATTERNS */
1524
1525 if (StoreNew) {
1526 // Store new pattern
1527 CChunk &Chunk = CreateChunk(label); // // //
1528
1529#ifdef REMOVE_DUPLICATE_PATTERNS
1530 if (m_PatternMap.count(Hash))
1531 ++m_iHashCollisions;
1532 m_PatternMap[Hash] = &Chunk;
1533#endif /* REMOVE_DUPLICATE_PATTERNS */
1534
1535 // Store pattern data as string
1536 Chunk.StoreString(PatternCompiler.GetData());
1537
1538 PatternSize += PatternCompiler.GetDataSize();
1539 ++PatternCount;
1540 }
1541 }

Callers

nothing calls this directly

Calls 15

from_intFunction · 0.85
ForeachChannelMethod · 0.80
ToIntegerMethod · 0.80
GetHashMethod · 0.80
CompareDataMethod · 0.80
StoreStringMethod · 0.80
GetDataPointerTargetMethod · 0.80
cendMethod · 0.80
SetDataPointerTargetMethod · 0.80
dataMethod · 0.45
CompileDataMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected