|
From: <pst...@us...> - 2008-04-08 17:25:58
|
Revision: 443
http://jazzplusplus.svn.sourceforge.net/jazzplusplus/?rev=443&view=rev
Author: pstieber
Date: 2008-04-08 10:25:46 -0700 (Tue, 08 Apr 2008)
Log Message:
-----------
Converted some char* variables and functions to std::string.
Modified Paths:
--------------
trunk/jazz/src/Harmony.cpp
trunk/jazz/src/HarmonyP.cpp
trunk/jazz/src/HarmonyP.h
Modified: trunk/jazz/src/Harmony.cpp
===================================================================
--- trunk/jazz/src/Harmony.cpp 2008-04-08 14:03:32 UTC (rev 442)
+++ trunk/jazz/src/Harmony.cpp 2008-04-08 17:25:46 UTC (rev 443)
@@ -1057,12 +1057,12 @@
Rectangle.width,
Rectangle.height);
- const char* pName = Context.ChordName();
+ string ChordName = Context.GetChordName();
int TextWidth, TextHeight;
- Dc.GetTextExtent(pName, &TextWidth, &TextHeight);
+ Dc.GetTextExtent(ChordName.c_str(), &TextWidth, &TextHeight);
Dc.DrawText(
- pName,
+ ChordName.c_str(),
Rectangle.x + (Rectangle.width - TextWidth) / 2,
Rectangle.y + (Rectangle.height - TextHeight) / 2);
}
@@ -1110,7 +1110,7 @@
{
JZRectangle Rectangle;
ChordRect(Rectangle, Context);
- Dc.DrawText(Context.ScaleName(), 5, Rectangle.y);
+ Dc.DrawText(Context.GetScaleName().c_str(), 5, Rectangle.y);
}
}
@@ -1518,7 +1518,7 @@
struct tNamedChord
{
- const char* mpName;
+ const std::string mName;
int bits;
};
@@ -1542,7 +1542,7 @@
{ " 75-", 0x451},
};
-tNamedChord scale_names[n_scale_names] =
+tNamedChord mScaleNames[n_scale_names] =
{
{ "***** major scales *****", 0x0},
{ "maj I (ionic)", 0xab5},
@@ -1698,13 +1698,17 @@
scale_chk[i] = new wxCheckBox(this, wxID_ANY, " ", wxPoint(x, y+2*h));//(wxFunction)ScaleCheck,
if (notename[i])
{
- (void) new wxStaticText(this, wxID_ANY, (char *)notename[i], wxPoint(x, y+3*h));
+ new wxStaticText(this, wxID_ANY, notename[i], wxPoint(x, y + 3 * h));
}
- (void) new wxStaticText(this, wxID_ANY, (char *)HBChord::ScaleName(i + chord_key), wxPoint(x, y+0*h));
+ new wxStaticText(
+ this,
+ wxID_ANY,
+ HBChord::ScaleName(i + chord_key),
+ wxPoint(x, y + 0 * h));
}
y += 4*h;
- // list boxes x y w h
+ // list boxes x y w h
#ifdef OBSOLETE
SetLabelPosition(wxVERTICAL);
#endif
@@ -1713,7 +1717,7 @@
for (i = 0; i < n_chord_names; i++)
{
- cnames[i] = (char *)chord_names[i].mpName;
+ cnames[i] = chord_names[i].mName;
}
chord_lst = new wxListBox(this, -1, wxPoint(10, y), wxSize(100, 200), n_chord_names, cnames, wxLB_SINGLE| wxLB_NEEDED_SB);//"Chords"
@@ -1723,7 +1727,7 @@
wxString* snames = new wxString[n_scale_names];
for (i = 0; i < n_scale_names; i++)
{
- snames[i] = (char *)scale_names[i].mpName;
+ snames[i] = mScaleNames[i].mName;
}
scale_lst = new wxListBox(
this,
@@ -1755,9 +1759,9 @@
{
// show single notes
int i;
- char buf[30];
- chord.Name(buf, ChordKey(0));
- chord_msg->SetLabel(buf);
+ string ChordName;
+ chord.CreateName(ChordName, ChordKey(0));
+ chord_msg->SetLabel(ChordName.c_str());
for (i = 0; i < 12; i++)
{
chord_chk[i]->SetValue(0 != chord.Contains(ChordKey(i)));
@@ -1784,11 +1788,11 @@
HBChord s = scale;
s.Rotate(-ScaleKey());
i = chord_lst->GetSelection();
- if (i < 0 || s.Keys() != scale_names[i].bits)
+ if (i < 0 || s.Keys() != mScaleNames[i].bits)
{
for (i = 0; i < n_scale_names; i++)
{
- if (scale_names[i].bits == s.Keys())
+ if (mScaleNames[i].bits == s.Keys())
{
scale_lst->SetSelection(i);
break;
@@ -1863,7 +1867,6 @@
void HBContextDlg::OnChordCheck()
{
- char buf[30];
chord.Clear();
for (int i = 0; i < 12; i++)
{
@@ -1872,8 +1875,9 @@
chord += ChordKey(i);
}
}
- chord.Name(buf, ChordKey());
- chord_msg->SetLabel(buf);
+ string ChordName;
+ chord.CreateName(ChordName, ChordKey());
+ chord_msg->SetLabel(ChordName.c_str());
RestartPlayer();
}
@@ -1910,7 +1914,7 @@
int i = scale_lst->GetSelection();
if (i >= 0)
{
- HBChord s(scale_names[i].bits);
+ HBChord s(mScaleNames[i].bits);
s.Rotate(ScaleKey());
scale = s;
ShowValues();
Modified: trunk/jazz/src/HarmonyP.cpp
===================================================================
--- trunk/jazz/src/HarmonyP.cpp 2008-04-08 14:03:32 UTC (rev 442)
+++ trunk/jazz/src/HarmonyP.cpp 2008-04-08 17:25:46 UTC (rev 443)
@@ -25,13 +25,15 @@
#include <assert.h>
#include <string.h>
+#include <iostream>
+
using namespace std;
// ========================================================================
// HBChord
// ========================================================================
-const char *const HBChord::scale_names[2][12] =
+const string const HBChord::mScaleNames[2][12] =
{
{ "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" },
{ "C", "Db", "D", "Eb", "E", "F", "Gb", "G", "Ab", "A", "Bb", "B" }
@@ -54,17 +56,18 @@
if (l >= 0) operator += (l);
}
-void HBChord::Name(char *buf, int key, int flat)
+void HBChord::CreateName(string& ChordName, int key, int flat)
{
HBChord c = *this;
- strcpy(buf, ScaleName(key, flat));
- int i = strlen(buf);
- c.Rotate(-key); // transpose to C
+ ChordName = ScaleName(key, flat);
- // special cases
+ // Transpose to C.
+ c.Rotate(-key);
+
+ // Handle special cases.
if (c == C0)
{
- strcat(buf, "o");
+ ChordName.append("o");
return;
}
@@ -79,21 +82,24 @@
if (c.Contains(3))
{
if (!c.Contains(4))
- buf[i++] = 'm';
+ {
+ ChordName.append("m");
+ }
else
+ {
sharp9 = true;
+ }
}
// 7
if (c.Contains(11))
{
- buf[i++] = 'j';
- buf[i++] = '7';
+ ChordName.append("j7");
seven = true;
}
else if (c.Contains(10))
{
- buf[i++] = '7';
+ ChordName.append("j");
seven = true;
}
@@ -102,32 +108,35 @@
{
if (!c.Contains(4))
{
- strcpy(buf + i, "sus4");
- i += 5;
+ ChordName.append("sus4");
}
else
+ {
nat11 = true;
+ }
}
// 5
if (c.Contains(7))
{
if (c.Contains(6))
+ {
sharp11 = true;
+ }
if (c.Contains(8))
+ {
flat13 = true;
+ }
}
else
{
if (c.Contains(6))
{
- buf[i++] = '5';
- buf[i++] = '-';
+ ChordName.append("5-");
}
if (c.Contains(8))
{
- buf[i++] = '5';
- buf[i++] = '+';
+ ChordName.append("5+");
}
}
@@ -135,56 +144,49 @@
if (c.Contains(9))
{
if (!seven)
- buf[i++] = '6';
+ {
+ ChordName.append("6");
+ }
else
+ {
nat13 = true;
+ }
}
// 9
if (c.Contains(1))
{
- buf[i++] = '9';
- buf[i++] = '-';
+ ChordName.append("9-");
}
if (c.Contains(2))
{
- buf[i++] = '9';
+ ChordName.append("5");
}
if (sharp9)
{
- buf[i++] = '9';
- buf[i++] = '+';
+ ChordName.append("9+");
}
// 11
if (nat11)
{
- buf[i++] = '1';
- buf[i++] = '1';
- buf[i++] = ' ';
+ ChordName.append("11 ");
}
if (sharp11)
{
- buf[i++] = '1';
- buf[i++] = '1';
- buf[i++] = '+';
+ ChordName.append("11+");
}
// 13
if (flat13)
{
- buf[i++] = '1';
- buf[i++] = '3';
- buf[i++] = '-';
+ ChordName.append("13-");
}
if (nat13)
{
- buf[i++] = '1';
- buf[i++] = '3';
+ ChordName.append("13");
}
-
- buf[i++] = 0;
}
@@ -332,22 +334,21 @@
Initialize();
}
-const char * HBContext::ChordName() const
+string HBContext::GetChordName() const
{
#if NAME_TABLE
- // use table of chordnames (fast)
- static char buf[20];
+ // Use the table of chord names (fast).
int chord_key = ChordKey();
- strcpy(buf, HBChord::ScaleName(chord_key, flat_keys[scale_nr]));
- strcat(buf, chord_names[scale_type][chord_nr]);
- return buf; // "Dm75-"
+ string ChordName = HBChord::ScaleName(chord_key, flat_keys[scale_nr]);
+ ChordName.append(chord_names[scale_type][chord_nr]);
+ return ChordName;
#else
- // compute chordname (slow, but flexible)
- static char buf[20];
+ // Compute the chord name (slow, but flexible).
int chord_key = ChordKey();
HBChord chord = Chord();
- chord.Name(buf, chord_key, flat_keys[chord_key]);
- return buf;
+ string ChordName;
+ chord.CreateName(ChordName, chord_key, flat_keys[chord_key]);
+ return ChordName;
#endif
}
@@ -356,16 +357,16 @@
return chord_nr_names[chord_nr]; // "IV"
}
-const char * HBContext::ScaleName() const
+const string& HBContext::GetScaleName() const
{
- static char buf[20];
+ static string ScaleName;
//strcpy(buf, scale_names[flat_keys[scale_nr]][scale_nr]);
- strcpy(buf, HBChord::ScaleName(scale_nr, flat_keys[scale_nr]));
+ ScaleName = HBChord::ScaleName(scale_nr, flat_keys[scale_nr]);
#if 0
strcat(buf, "/");
strcat(buf, scale_type_names[scale_type]);
#endif
- return buf;
+ return ScaleName;
}
const char * HBContext::ScaleTypeName() const
@@ -698,7 +699,7 @@
gensc(chords);
cout << "};\n\n";
- cout << "tNamedChord scale_names[n_scale_names] = {\n";
+ cout << "tNamedChord mScaleNames[n_scale_names] = {\n";
gensc(scales);
cout << "};\n\n";
Modified: trunk/jazz/src/HarmonyP.h
===================================================================
--- trunk/jazz/src/HarmonyP.h 2008-04-08 14:03:32 UTC (rev 442)
+++ trunk/jazz/src/HarmonyP.h 2008-04-08 17:25:46 UTC (rev 443)
@@ -24,6 +24,7 @@
#define JZ_HARMONYP_H
#include <iostream>
+#include <string>
// ------------------------------------------------------------------
// HBChord
@@ -194,18 +195,19 @@
*this += key+1;
}
- void Name(char *buf, int key, int flat = 0);
+ void CreateName(std::string& CordName, int key, int flat = 0);
- static const char * ScaleName(int key, int flat = 0)
+ static const std::string ScaleName(int key, int flat = 0)
{
- return scale_names[flat != 0][(key + 240) % 12];
+ return mScaleNames[flat != 0][(key + 240) % 12];
}
protected:
int keys;
private:
- static const char * const scale_names[2][12];
+
+ static const std::string const mScaleNames[2][12];
};
inline std::ostream& operator << (std::ostream& os, HBChord const &a)
@@ -323,16 +325,19 @@
seq_nr = n;
}
- const char* ChordName() const; // "Dm75-"
+ // For example "Dm75-"
+ std::string GetChordName() const;
- const char* ChordNrName() const; // "IV"
+ // For example "IV"
+ const char* ChordNrName() const;
const char* ContextName() const // "mixo#11"
{
return context_names[scale_type][chord_nr];
}
- const char* ScaleName() const; // "C#"
+ // For example "C#"
+ const std::string& GetScaleName() const;
const char* ScaleTypeName() const; // "major"
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|