Skip to content

Commit

Permalink
Fixed zone member index issue, addresses #522. (#528)
Browse files Browse the repository at this point in the history
  • Loading branch information
hmatuschek authored Dec 30, 2024
1 parent 3c7c673 commit 2d38c4a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
16 changes: 10 additions & 6 deletions lib/opengd77base_codeplug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1469,27 +1469,31 @@ OpenGD77BaseCodeplug::ZoneElement::setName(const QString &name) {
writeASCII(Offset::name(), name, Limit::nameLength(), 0xff);
}


bool
OpenGD77BaseCodeplug::ZoneElement::hasMember(unsigned n) const {
if (n >= Limit::memberCount())
return false;
return (0 != member(n));
return 0 != getUInt16_le(Offset::channels() + Offset::betweenChannels()*n);
}

unsigned
OpenGD77BaseCodeplug::ZoneElement::member(unsigned n) const {
if (n >= Limit::memberCount())
return 0;
return getUInt16_le(Offset::channels()+Offset::betweenChannels()*n);
return getUInt16_le(Offset::channels() + Offset::betweenChannels()*n)-1;
}

void
OpenGD77BaseCodeplug::ZoneElement::setMember(unsigned n, unsigned idx) {
if (n >= Limit::memberCount())
return;
setUInt16_le(Offset::channels()+Offset::betweenChannels()*n, idx);
setUInt16_le(Offset::channels() + Offset::betweenChannels()*n, idx+1);
}

void
OpenGD77BaseCodeplug::ZoneElement::clearMember(unsigned n) {
setMember(n, 0);
setUInt16_le(Offset::channels() + Offset::betweenChannels()*n, 0);
}


Expand Down Expand Up @@ -2161,12 +2165,12 @@ OpenGD77BaseCodeplug::GroupListElement::hasContactIndex(unsigned int i) const {

unsigned int
OpenGD77BaseCodeplug::GroupListElement::contactIndex(unsigned int i) const {
return getUInt16_le(Offset::contacts() + i*Offset::betweenContacts())-1;
return getUInt16_le(Offset::contacts() + i*Offset::betweenContacts()) - 1;
}

void
OpenGD77BaseCodeplug::GroupListElement::setContactIndex(unsigned int i, unsigned int contactIdx) {
setUInt16_le(Offset::contacts() + i*Offset::betweenContacts(), contactIdx+1);
setUInt16_le(Offset::contacts() + i*Offset::betweenContacts(), contactIdx + 1);
}

void
Expand Down
7 changes: 3 additions & 4 deletions lib/opengd77base_codeplug.hh
Original file line number Diff line number Diff line change
Expand Up @@ -805,12 +805,11 @@ public:
/** Sets the name of the zone. */
virtual void setName(const QString &name);

/** Returns @c true if a member is stored at the given index.
* That is, if the index is not 0. */
/** Returns @c true if a member is stored at the given index. */
virtual bool hasMember(unsigned n) const;
/** Returns the n-th member index (+1). */
/** Returns the n-th member index. */
virtual unsigned member(unsigned n) const;
/** Sets the n-th member index (+1). */
/** Sets the n-th member index. */
virtual void setMember(unsigned n, unsigned idx);
/** Clears the n-th member index. */
virtual void clearMember(unsigned n);
Expand Down

0 comments on commit 2d38c4a

Please sign in to comment.